Skip to content

Commit

Permalink
fix (#1727)
Browse files Browse the repository at this point in the history
* fix

* remove maxSequenceSize

* linter
  • Loading branch information
ARR552 authored Mar 3, 2023
1 parent e6c122f commit ebb4bd6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 35 deletions.
5 changes: 0 additions & 5 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down
1 change: 0 additions & 1 deletion config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ SyncChunkSize = 100
GenBlockNumber = 66
[Sequencer]
MaxSequenceSize = "2000000"
WaitPeriodPoolIsEmpty = "1s"
WaitPeriodSendSequence = "5s"
LastBatchVirtualizationTimeMaxWaitPeriod = "5s"
Expand Down
1 change: 0 additions & 1 deletion config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ SyncChunkSize = 100
GenBlockNumber = 66

[Sequencer]
MaxSequenceSize = "2000000"
WaitPeriodPoolIsEmpty = "1s"
WaitPeriodSendSequence = "5s"
LastBatchVirtualizationTimeMaxWaitPeriod = "5s"
Expand Down
23 changes: 0 additions & 23 deletions sequencer/config.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"`

Expand Down Expand Up @@ -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
}
16 changes: 13 additions & 3 deletions sequencer/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"math/big"
"time"

ethman "github.com/0xPolygonHermez/zkevm-node/etherman"
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/config/debug.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ SyncChunkSize = 100
GenBlockNumber = 66

[Sequencer]
MaxSequenceSize = "2000000"
WaitPeriodPoolIsEmpty = "1s"
WaitPeriodSendSequence = "5s"
LastBatchVirtualizationTimeMaxWaitPeriod = "5s"
Expand Down
1 change: 0 additions & 1 deletion test/config/test.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ SyncChunkSize = 100
GenBlockNumber = 66

[Sequencer]
MaxSequenceSize = "2000000"
WaitPeriodPoolIsEmpty = "1s"
WaitPeriodSendSequence = "15s"
LastBatchVirtualizationTimeMaxWaitPeriod = "10s"
Expand Down

0 comments on commit ebb4bd6

Please sign in to comment.