move size check into loop

This commit is contained in:
William Banfield
2022-03-09 16:34:32 -05:00
parent 5353718733
commit 209a5c73cb

View File

@@ -261,6 +261,9 @@ func (rpp *ResponsePrepareProposal) Validate(maxSizeBytes int64, otxs [][]byte)
for _, tr := range rpp.TxRecords {
if tr.isIncluded() {
size += int64(len(tr.Tx))
if size > maxSizeBytes {
return fmt.Errorf("transaction data size %d exceeds maximum %d", size, maxSizeBytes)
}
if _, ok := ntx[string(tr.Tx)]; ok {
return errors.New("duplicate included transaction")
}
@@ -279,8 +282,5 @@ func (rpp *ResponsePrepareProposal) Validate(maxSizeBytes int64, otxs [][]byte)
return fmt.Errorf("transaction incorrectly marked as %s", tr.Action.String())
}
}
if size > maxSizeBytes {
return fmt.Errorf("transaction data size %d exceeds maximum %d", size, maxSizeBytes)
}
return nil
}