Skip to content

Commit

Permalink
feat: remove sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniRamirezM committed Nov 12, 2024
1 parent 67c37e4 commit caa1a3d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 53 deletions.
20 changes: 4 additions & 16 deletions sequencesender/txbuilder/banana_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
}
Expand Down
37 changes: 0 additions & 37 deletions sequencesender/txbuilder/banana_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit caa1a3d

Please sign in to comment.