Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1727

Merged
merged 3 commits into from
Mar 3, 2023
Merged

fix #1727

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -64,7 +64,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 @@ -55,7 +55,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 @@ -55,7 +55,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 @@ -55,7 +55,6 @@ SyncChunkSize = 100
GenBlockNumber = 66

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