reject too large transactions

This commit is contained in:
alex.sharov 2021-08-07 14:05:02 +07:00
parent 99e371c421
commit b88f70de0e

View File

@ -117,6 +117,22 @@ const ParseTransactionErrorPrefix = "parse transaction payload"
// ParseTransaction extracts all the information from the transactions's payload (RLP) necessary to build TxSlot
// it also performs syntactic validation of the transactions
func (ctx *TxParseContext) ParseTransaction(payload []byte, pos int, slot *TxSlot, sender []byte) (p int, err error) {
const (
// txSlotSize is used to calculate how many data slots a single transaction
// takes up based on its size. The slots are used as DoS protection, ensuring
// that validating a new transaction remains a constant operation (in reality
// O(maxslots), where max slots are 4 currently).
txSlotSize = 32 * 1024
// txMaxSize is the maximum size a single transaction can have. This field has
// non-trivial consequences: larger transactions are significantly harder and
// more expensive to propagate; larger transactions also take more resources
// to validate whether they fit into the pool or not.
txMaxSize = 4 * txSlotSize // 128KB
)
if len(payload) > txMaxSize {
return 0, fmt.Errorf("%s: too large tx.size=%dKb", ParseTransactionErrorPrefix, len(payload)/1024)
}
if len(payload) == 0 {
return 0, fmt.Errorf("%s: empty rlp", ParseTransactionErrorPrefix)
}