From 8c3dbcef56d633215c8fa468eb6867569eb3657f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Ram=C3=ADrez?= <58293609+ToniRamirezM@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:35:23 +0100 Subject: [PATCH] feat: remove sanity check (#178) --- sequencesender/txbuilder/banana_base.go | 20 +++-------- sequencesender/txbuilder/banana_base_test.go | 37 -------------------- 2 files changed, 4 insertions(+), 53 deletions(-) diff --git a/sequencesender/txbuilder/banana_base.go b/sequencesender/txbuilder/banana_base.go index 2868bb4b..ee21228d 100644 --- a/sequencesender/txbuilder/banana_base.go +++ b/sequencesender/txbuilder/banana_base.go @@ -149,21 +149,25 @@ func (t *TxBuilderBananaBase) NewSequence( counterL1InfoRoot, err := t.GetCounterL1InfoRoot(ctx, greatestL1Index) if err != nil { + log.Errorf("error getting CounterL1InfoRoot: %s", err) return nil, err } sequence.CounterL1InfoRoot = counterL1InfoRoot l1InfoRoot, err := t.getL1InfoRoot(sequence.CounterL1InfoRoot) if err != nil { + log.Errorf("error getting L1InfoRootMap: %s", err) return nil, err } err = t.CheckL1InfoTreeLeafCounterVsInitL1InfoMap(ctx, sequence.CounterL1InfoRoot) if err != nil { + log.Errorf("error checking L1InfoTreeLeafCounterVsInitL1InfoMap: %s", err) return nil, err } sequence.L1InfoRoot = l1InfoRoot accInputHash, err := t.rollupContract.LastAccInputHash(&bind.CallOpts{Pending: false}) if err != nil { + log.Errorf("error getting LastAccInputHash: %s", err) return nil, err } @@ -187,26 +191,10 @@ func (t *TxBuilderBananaBase) NewSequence( sequence.OldAccInputHash = oldAccInputHash sequence.AccInputHash = accInputHash - - err = SequenceSanityCheck(sequence) - if err != nil { - return nil, fmt.Errorf("sequenceSanityCheck fails. Err: %w", err) - } res := NewBananaSequence(*sequence) return res, nil } -func SequenceSanityCheck(seq *etherman.SequenceBanana) error { - maxL1InfoIndex, err := calculateMaxL1InfoTreeIndexInsideSequence(seq) - if err != nil { - return err - } - if seq.CounterL1InfoRoot < maxL1InfoIndex+1 { - return fmt.Errorf("wrong CounterL1InfoRoot(%d): BatchL2Data (max=%d) ", seq.CounterL1InfoRoot, maxL1InfoIndex) - } - return nil -} - func (t *TxBuilderBananaBase) getL1InfoRoot(counterL1InfoRoot uint32) (common.Hash, error) { return t.globalExitRootContract.L1InfoRootMap(&bind.CallOpts{Pending: false}, counterL1InfoRoot) } diff --git a/sequencesender/txbuilder/banana_base_test.go b/sequencesender/txbuilder/banana_base_test.go index 44d7a7b1..e5911500 100644 --- a/sequencesender/txbuilder/banana_base_test.go +++ b/sequencesender/txbuilder/banana_base_test.go @@ -6,13 +6,11 @@ import ( "math/big" "testing" - "github.com/0xPolygon/cdk/etherman" "github.com/0xPolygon/cdk/l1infotreesync" "github.com/0xPolygon/cdk/log" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/0xPolygon/cdk/sequencesender/txbuilder" "github.com/0xPolygon/cdk/sequencesender/txbuilder/mocks_txbuilder" - "github.com/0xPolygon/cdk/state" "github.com/0xPolygon/cdk/state/datastream" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -92,41 +90,6 @@ func TestBananaBaseNewSequenceBatch(t *testing.T) { // TODO: check that the seq have the right values } -func TestBananaSanityCheck(t *testing.T) { - batch := state.BatchRawV2{ - Blocks: []state.L2BlockRaw{ - { - BlockNumber: 1, - ChangeL2BlockHeader: state.ChangeL2BlockHeader{ - DeltaTimestamp: 1, - IndexL1InfoTree: 1, - }, - }, - }, - } - data, err := state.EncodeBatchV2(&batch) - require.NoError(t, err) - require.NotNil(t, data) - seq := etherman.SequenceBanana{ - CounterL1InfoRoot: 2, - Batches: []etherman.Batch{ - { - L2Data: data, - }, - }, - } - err = txbuilder.SequenceSanityCheck(&seq) - require.NoError(t, err, "inside batchl2data max is 1 and counter is 2 (2>=1+1)") - seq.CounterL1InfoRoot = 1 - err = txbuilder.SequenceSanityCheck(&seq) - require.Error(t, err, "inside batchl2data max is 1 and counter is 1. The batchl2data is not included in counter") -} - -func TestBananaSanityCheckNilSeq(t *testing.T) { - err := txbuilder.SequenceSanityCheck(nil) - require.Error(t, err, "nil sequence") -} - func TestBananaEmptyL1InfoTree(t *testing.T) { testData := newBananaBaseTestData(t)