diff --git a/config/config_test.go b/config/config_test.go index 4479f1f96f..ae0af557ba 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -14,7 +14,6 @@ import ( "github.com/0xPolygonHermez/zkevm-node/config/types" "github.com/0xPolygonHermez/zkevm-node/log" "github.com/0xPolygonHermez/zkevm-node/pricegetter" - "github.com/0xPolygonHermez/zkevm-node/sequencer" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -106,10 +105,6 @@ func Test_Defaults(t *testing.T) { path: "Sequencer.MaxSteps", expectedValue: uint32(8388608), }, - { - path: "Sequencer.MaxSequenceSize", - expectedValue: sequencer.MaxSequenceSize{Int: new(big.Int).SetInt64(2000000)}, - }, { path: "Sequencer.MaxAllowedFailedCounter", expectedValue: uint64(50), diff --git a/config/default.go b/config/default.go index 873a821d10..94fcbc5f54 100644 --- a/config/default.go +++ b/config/default.go @@ -64,7 +64,6 @@ SyncChunkSize = 100 GenBlockNumber = 66 [Sequencer] -MaxSequenceSize = "2000000" WaitPeriodPoolIsEmpty = "1s" WaitPeriodSendSequence = "5s" LastBatchVirtualizationTimeMaxWaitPeriod = "5s" diff --git a/config/environments/local/local.node.config.toml b/config/environments/local/local.node.config.toml index 89d714b36e..9618237a32 100644 --- a/config/environments/local/local.node.config.toml +++ b/config/environments/local/local.node.config.toml @@ -55,7 +55,6 @@ SyncChunkSize = 100 GenBlockNumber = 66 [Sequencer] -MaxSequenceSize = "2000000" WaitPeriodPoolIsEmpty = "1s" WaitPeriodSendSequence = "5s" LastBatchVirtualizationTimeMaxWaitPeriod = "5s" diff --git a/sequencer/config.go b/sequencer/config.go index d20ff0559c..dee7f85238 100644 --- a/sequencer/config.go +++ b/sequencer/config.go @@ -1,11 +1,7 @@ package sequencer import ( - "fmt" - "math/big" - "github.com/0xPolygonHermez/zkevm-node/config/types" - base "github.com/0xPolygonHermez/zkevm-node/encoding" ) // Config represents the configuration of a sequencer @@ -57,9 +53,6 @@ type Config struct { // MaxSteps is max steps batch can handle MaxSteps uint32 `mapstructure:"MaxSteps"` - // Maximum size, in gas size, a sequence can reach - MaxSequenceSize MaxSequenceSize `mapstructure:"MaxSequenceSize"` - // Maximum allowed failed counter for the tx before it becomes invalid MaxAllowedFailedCounter uint64 `mapstructure:"MaxAllowedFailedCounter"` @@ -134,19 +127,3 @@ type FinalizerCfg struct { // to be read in order to provide the private keys to sign the L1 txs PrivateKeys []types.KeystoreFileConfig `mapstructure:"PrivateKeys"` } - -// MaxSequenceSize is a wrapper type that parses token amount to big int -type MaxSequenceSize struct { - *big.Int `validate:"required"` -} - -// UnmarshalText unmarshal token amount from float string to big int -func (m *MaxSequenceSize) UnmarshalText(data []byte) error { - amount, ok := new(big.Int).SetString(string(data), base.Base10) - if !ok { - return fmt.Errorf("failed to unmarshal string to float") - } - m.Int = amount - - return nil -} diff --git a/sequencer/sequencesender.go b/sequencer/sequencesender.go index 9915ef2ad6..18655bd77d 100644 --- a/sequencer/sequencesender.go +++ b/sequencer/sequencesender.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "math/big" "time" ethman "github.com/0xPolygonHermez/zkevm-node/etherman" @@ -22,6 +21,16 @@ import ( const ( ethTxManagerOwner = "sequencer" monitoredIDFormat = "sequence-from-%v-to-%v" + // 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 ) func (s *Sequencer) tryToSendSequence(ctx context.Context, ticker *time.Ticker) { @@ -135,12 +144,13 @@ func (s *Sequencer) getSequencesToSend(ctx context.Context) ([]types.Sequence, e // Check if can be send sender := common.HexToAddress(s.cfg.Finalizer.SenderAddress) tx, err = s.etherman.EstimateGasSequenceBatches(sender, sequences) - if err == nil && new(big.Int).SetUint64(tx.Gas()).Cmp(s.cfg.MaxSequenceSize.Int) >= 1 { + if err == nil && tx.Size() > txMaxSize { metrics.SequencesOvesizedDataError() - log.Infof("oversized Data on TX oldHash %s (%d > %d)", tx.Hash(), tx.Gas(), s.cfg.MaxSequenceSize) + log.Infof("oversized Data on TX oldHash %s (txSize %d > 128KB)", tx.Hash(), tx.Size()) err = txpool.ErrOversizedData } if err != nil { + log.Infof("Handling estimage gas send sequence error: %v", err) sequences, err = s.handleEstimateGasSendSequenceErr(ctx, sequences, currentBatchNumToSequence, err) if sequences != nil { // Handling the error gracefully, re-processing the sequence as a sanity check diff --git a/test/config/debug.node.config.toml b/test/config/debug.node.config.toml index bd408d01ea..413c8a1e06 100644 --- a/test/config/debug.node.config.toml +++ b/test/config/debug.node.config.toml @@ -55,7 +55,6 @@ SyncChunkSize = 100 GenBlockNumber = 66 [Sequencer] -MaxSequenceSize = "2000000" WaitPeriodPoolIsEmpty = "1s" WaitPeriodSendSequence = "5s" LastBatchVirtualizationTimeMaxWaitPeriod = "5s" diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index 286cc783cd..f39260edb7 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -55,7 +55,6 @@ SyncChunkSize = 100 GenBlockNumber = 66 [Sequencer] -MaxSequenceSize = "2000000" WaitPeriodPoolIsEmpty = "1s" WaitPeriodSendSequence = "15s" LastBatchVirtualizationTimeMaxWaitPeriod = "10s"