diff --git a/.gitignore b/.gitignore index 8cade7ad..958ed6ff 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ target/ book/ index.html tmp +.vscode \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 9f149430..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Debug cdk", - "type": "go", - "request": "launch", - "mode": "auto", - "program": "cmd/", - "cwd": "${workspaceFolder}", - "args":[ - "run", - "-cfg", "tmp/cdk/local_config/test.kurtosis.toml", - "-components", "sequence-sender,aggregator", - "-custom-network-file", "tmp/cdk/local_config/local_config/genesis.json" - ] - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug executable 'cdk'", - "cargo": { - "args": [ - "build", - "--bin=cdk", - "--package=cdk" - ], - "filter": { - "name": "cdk", - "kind": "bin" - } - }, - "args": [ - "rollup" - ], - "cwd": "${workspaceFolder}" - }, - ] -} diff --git a/aggregator/aggregator.go b/aggregator/aggregator.go index dce5ed1b..3d865ba1 100644 --- a/aggregator/aggregator.go +++ b/aggregator/aggregator.go @@ -374,12 +374,14 @@ func (a *Aggregator) handleReceivedDataStream(entry *datastreamer.FileEntry, cli a.currentStreamBatch.L1InfoRoot = a.currentStreamBatch.GlobalExitRoot } - accInputHash, err := cdkcommon.CalculateAccInputHash(oldDBBatch.Batch.AccInputHash, a.currentStreamBatch.BatchL2Data, a.currentStreamBatch.L1InfoRoot, uint64(a.currentStreamBatch.Timestamp.Unix()), a.currentStreamBatch.Coinbase, forcedBlockhashL1) - if err != nil { - log.Errorf("Error calculating acc input hash: %v", err) - return err - } - + accInputHash := cdkcommon.CalculateAccInputHash( + oldDBBatch.Batch.AccInputHash, + a.currentStreamBatch.BatchL2Data, + a.currentStreamBatch.L1InfoRoot, + uint64(a.currentStreamBatch.Timestamp.Unix()), + a.currentStreamBatch.Coinbase, + forcedBlockhashL1, + ) a.currentStreamBatch.AccInputHash = accInputHash dbBatch := state.DBBatch{ @@ -409,7 +411,7 @@ func (a *Aggregator) handleReceivedDataStream(entry *datastreamer.FileEntry, cli } // Retrieve the witness - if dbBatch.Witness == nil || len(dbBatch.Witness) == 0 { + if len(dbBatch.Witness) == 0 { a.witnessRetrievalChan <- dbBatch } } diff --git a/cmd/run.go b/cmd/run.go index 7fe45095..0f2021f8 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -4,6 +4,7 @@ import ( "context" "crypto/ecdsa" "fmt" + "math/big" "os" "os/signal" "runtime" @@ -53,12 +54,14 @@ func start(cliCtx *cli.Context) error { } components := cliCtx.StringSlice(config.FlagComponents) - + l1Client := runL1ClientIfNeeded(components, c.SequenceSender.EthTxManager.Etherman.URL) + reorgDetectorL1 := runReorgDetectorL1IfNeeded(cliCtx.Context, components, l1Client, c.ReorgDetectorL1.DBPath) + l1InfoTreeSync := runL1InfoTreeSyncerIfNeeded(cliCtx.Context, components, *c, l1Client, reorgDetectorL1) for _, component := range components { switch component { case SEQUENCE_SENDER: c.SequenceSender.Log = c.Log - seqSender := createSequenceSender(*c) + seqSender := createSequenceSender(*c, l1Client, l1InfoTreeSync) // start sequence sender in a goroutine, checking for errors go seqSender.Start(cliCtx.Context) @@ -71,15 +74,7 @@ func start(cliCtx *cli.Context) error { } }() case AGGORACLE: - l1Client, err := ethclient.Dial(c.AggOracle.URLRPCL1) - if err != nil { - log.Fatal(err) - } - reorgDetector := newReorgDetectorL1(cliCtx.Context, *c, l1Client) - go reorgDetector.Start(cliCtx.Context) - syncer := newL1InfoTreeSyncer(cliCtx.Context, *c, l1Client, reorgDetector) - go syncer.Start(cliCtx.Context) - aggOracle := createAggoracle(*c, l1Client, syncer) + aggOracle := createAggoracle(*c, l1Client, l1InfoTreeSync) go aggOracle.Start(cliCtx.Context) } } @@ -130,7 +125,11 @@ func createAggregator(ctx context.Context, c config.Config, runMigrations bool) return aggregator } -func createSequenceSender(cfg config.Config) *sequencesender.SequenceSender { +func createSequenceSender( + cfg config.Config, + l1Client *ethclient.Client, + l1InfoTreeSync *l1infotreesync.L1InfoTreeSync, +) *sequencesender.SequenceSender { ethman, err := etherman.NewClient(ethermanconfig.Config{ EthermanConfig: ethtxman.Config{ URL: cfg.SequenceSender.EthTxManager.Etherman.URL, @@ -152,8 +151,12 @@ func createSequenceSender(cfg config.Config) *sequencesender.SequenceSender { log.Fatal(err) } cfg.SequenceSender.SenderAddress = auth.From - - txBuilder, err := newTxBuilder(cfg, ethman) + blockFialityType := etherman.BlockNumberFinality(cfg.SequenceSender.BlockFinality) + blockFinality, err := blockFialityType.ToBlockNum() + if err != nil { + log.Fatalf("Failed to create block finality. Err: %w, ", err) + } + txBuilder, err := newTxBuilder(cfg, ethman, l1Client, l1InfoTreeSync, blockFinality) if err != nil { log.Fatal(err) } @@ -165,7 +168,13 @@ func createSequenceSender(cfg config.Config) *sequencesender.SequenceSender { return seqSender } -func newTxBuilder(cfg config.Config, ethman *etherman.Client) (txbuilder.TxBuilder, error) { +func newTxBuilder( + cfg config.Config, + ethman *etherman.Client, + l1Client *ethclient.Client, + l1InfoTreeSync *l1infotreesync.L1InfoTreeSync, + blockFinality *big.Int, +) (txbuilder.TxBuilder, error) { auth, _, err := ethman.LoadAuthFromKeyStore(cfg.SequenceSender.PrivateKey.Path, cfg.SequenceSender.PrivateKey.Password) if err != nil { log.Fatal(err) @@ -179,9 +188,26 @@ func newTxBuilder(cfg config.Config, ethman *etherman.Client) (txbuilder.TxBuild switch contracts.VersionType(cfg.Common.ContractVersions) { case contracts.VersionBanana: if cfg.Common.IsValidiumMode { - txBuilder = txbuilder.NewTxBuilderBananaValidium(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, da, *auth, cfg.SequenceSender.MaxBatchesForL1) + txBuilder = txbuilder.NewTxBuilderBananaValidium( + ethman.Contracts.Banana.Rollup, + ethman.Contracts.Banana.GlobalExitRoot, + da, + *auth, + cfg.SequenceSender.MaxBatchesForL1, + l1InfoTreeSync, + l1Client, + blockFinality, + ) } else { - txBuilder = txbuilder.NewTxBuilderBananaZKEVM(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, *auth, cfg.SequenceSender.MaxTxSizeForL1) + txBuilder = txbuilder.NewTxBuilderBananaZKEVM( + ethman.Contracts.Banana.Rollup, + ethman.Contracts.Banana.GlobalExitRoot, + *auth, + cfg.SequenceSender.MaxTxSizeForL1, + l1InfoTreeSync, + l1Client, + blockFinality, + ) } case contracts.VersionElderberry: if cfg.Common.IsValidiumMode { @@ -392,3 +418,78 @@ func newL1InfoTreeSyncer( } return syncer } + +func isNeeded(casesWhereNeeded, actualCases []string) bool { + for _, actaulCase := range actualCases { + for _, caseWhereNeeded := range casesWhereNeeded { + if actaulCase == caseWhereNeeded { + return true + } + } + } + return false +} + +func runL1InfoTreeSyncerIfNeeded( + ctx context.Context, + components []string, + cfg config.Config, + l1Client *ethclient.Client, + reorgDetector *reorgdetector.ReorgDetector, +) *l1infotreesync.L1InfoTreeSync { + if !isNeeded([]string{AGGORACLE, SEQUENCE_SENDER}, components) { + return nil + } + l1InfoTreeSync, err := l1infotreesync.New( + ctx, + cfg.L1InfoTreeSync.DBPath, + cfg.L1InfoTreeSync.GlobalExitRootAddr, + cfg.L1InfoTreeSync.RollupManagerAddr, + cfg.L1InfoTreeSync.SyncBlockChunkSize, + etherman.BlockNumberFinality(cfg.L1InfoTreeSync.BlockFinality), + reorgDetector, + l1Client, + cfg.L1InfoTreeSync.WaitForNewBlocksPeriod.Duration, + cfg.L1InfoTreeSync.InitialBlock, + cfg.L1InfoTreeSync.RetryAfterErrorPeriod.Duration, + cfg.L1InfoTreeSync.MaxRetryAttemptsAfterError, + ) + if err != nil { + log.Fatal(err) + } + go l1InfoTreeSync.Start(ctx) + return l1InfoTreeSync +} + +func runL1ClientIfNeeded(components []string, urlRPCL1 string) *ethclient.Client { + if !isNeeded([]string{SEQUENCE_SENDER, AGGREGATOR, AGGORACLE}, components) { + return nil + } + log.Debugf("dialing L1 client at: %s", urlRPCL1) + l1CLient, err := ethclient.Dial(urlRPCL1) + if err != nil { + log.Fatal(err) + } + return l1CLient +} + +func runReorgDetectorL1IfNeeded(ctx context.Context, components []string, l1Client *ethclient.Client, dbPath string) *reorgdetector.ReorgDetector { + if !isNeeded([]string{SEQUENCE_SENDER, AGGREGATOR, AGGORACLE}, components) { + return nil + } + rd := newReorgDetector(ctx, dbPath, l1Client) + go rd.Start(ctx) + return rd +} + +func newReorgDetector( + ctx context.Context, + dbPath string, + client *ethclient.Client, +) *reorgdetector.ReorgDetector { + rd, err := reorgdetector.New(ctx, client, dbPath) + if err != nil { + log.Fatal(err) + } + return rd +} diff --git a/common/common.go b/common/common.go index f0f36575..259b2a8d 100644 --- a/common/common.go +++ b/common/common.go @@ -40,7 +40,8 @@ func CalculateAccInputHash( l1InfoRoot common.Hash, timestampLimit uint64, sequencerAddr common.Address, - forcedBlockhashL1 common.Hash) (common.Hash, error) { + forcedBlockhashL1 common.Hash, +) common.Hash { v1 := oldAccInputHash.Bytes() v2 := batchData v3 := l1InfoRoot.Bytes() @@ -74,5 +75,5 @@ func CalculateAccInputHash( log.Debugf("Sequencer Address: %v", sequencerAddr) log.Debugf("Forced BlockHashL1: %v", forcedBlockhashL1) - return common.BytesToHash(keccak256.Hash(v1, v2, v3, v4, v5, v6)), nil + return common.BytesToHash(keccak256.Hash(v1, v2, v3, v4, v5, v6)) } diff --git a/config/default.go b/config/default.go index 58404105..c32e43d9 100644 --- a/config/default.go +++ b/config/default.go @@ -25,6 +25,8 @@ SequencesTxFileName = "sequencesender.json" GasOffset = 80000 WaitPeriodPurgeTxFile = "15m" MaxPendingTx = 1 +MaxBatchesForL1 = 300 +BlockFinality = "FinalizedBlock" [SequenceSender.StreamClient] Server = "127.0.0.1:6900" [SequenceSender.EthTxManager] diff --git a/dataavailability/datacommittee/datacommittee.go b/dataavailability/datacommittee/datacommittee.go index 67c7884a..22abd589 100644 --- a/dataavailability/datacommittee/datacommittee.go +++ b/dataavailability/datacommittee/datacommittee.go @@ -215,6 +215,13 @@ func (d *Backend) PostSequenceBanana(ctx context.Context, sequence etherman.Sequ L1InfoRoot: sequence.L1InfoRoot, MaxSequenceTimestamp: daTypes.ArgUint64(sequence.MaxSequenceTimestamp), } + hashToSign := common.BytesToHash(sequenceBanana.HashToSign()) + if hashToSign != sequence.AccInputHash { + return nil, fmt.Errorf( + "calculated accInputHash diverges: DA = %s vs Seq = %s", + hashToSign, sequence.AccInputHash, + ) + } signature, err := sequenceBanana.Sign(d.privKey) if err != nil { diff --git a/etherman/types.go b/etherman/types.go index 1bdb29ae..0f705899 100644 --- a/etherman/types.go +++ b/etherman/types.go @@ -167,7 +167,7 @@ type SequenceBanana struct { AccInputHash common.Hash L1InfoRoot common.Hash MaxSequenceTimestamp uint64 - IndexL1InfoRoot uint32 + CounterL1InfoRoot uint32 L2Coinbase common.Address LastVirtualBatchNumber uint64 } @@ -191,7 +191,7 @@ func NewSequenceBanana(batches []Batch, l2Coinbase common.Address) *SequenceBana return &SequenceBanana{ Batches: batches, MaxSequenceTimestamp: maxSequenceTimestamp, - IndexL1InfoRoot: indexL1InfoRoot, + CounterL1InfoRoot: indexL1InfoRoot, L2Coinbase: l2Coinbase, } } diff --git a/go.mod b/go.mod index 30a2a942..db589d91 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/0xPolygon/cdk go 1.22.4 require ( - github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726125827-301fa4c59245 - github.com/0xPolygon/cdk-data-availability v0.0.8 + github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240819092536-5a65d4761b2f + github.com/0xPolygon/cdk-data-availability v0.0.9 github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3 github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.10-0.20240716105056-c051c96d0234 diff --git a/go.sum b/go.sum index d2d50209..6f3298bd 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,19 @@ github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726125827-301fa4c59245 h1:BBmVd50JQID9UyUR3vWFMKr2pMHD3mrqjpuB9DDepBw= github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726125827-301fa4c59245/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240816153044-04551a6747e1 h1:51BkwYm+mGPkI+M1HHPk0L/7jOeo/TAljLWffVFZDVI= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240816153044-04551a6747e1/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240819092536-5a65d4761b2f h1:i9oCNDG4N7ha3fNkEKbito/HF3o4gjnW6//cpTwnp8E= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240819092536-5a65d4761b2f/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= github.com/0xPolygon/cdk-data-availability v0.0.8 h1:bMmOYZ7Ei683y80ric3KzMPXtRGmchAmfjIRzghaHb4= github.com/0xPolygon/cdk-data-availability v0.0.8/go.mod h1:3XkZ0zn0GsvAT01MPQMmukF534CVSFmtrcoK3F/BK6Q= +github.com/0xPolygon/cdk-data-availability v0.0.9-0.20240815124433-d1436f1a29c8 h1:M4dqgOJtUjAJiQ2m+SNH1cTYnBuFsXJJpEJ3eOG/V20= +github.com/0xPolygon/cdk-data-availability v0.0.9-0.20240815124433-d1436f1a29c8/go.mod h1:5A+CU4FGeyG8zTDJc0khMzRxPzFzmpRydeEWmLztgh4= +github.com/0xPolygon/cdk-data-availability v0.0.9-0.20240815125053-230aa34389ca h1:UL6pfroUyI4HXNdZcbvBjfwrrwExoFlbFYUpQvk6u3c= +github.com/0xPolygon/cdk-data-availability v0.0.9-0.20240815125053-230aa34389ca/go.mod h1:5A+CU4FGeyG8zTDJc0khMzRxPzFzmpRydeEWmLztgh4= +github.com/0xPolygon/cdk-data-availability v0.0.9-0.20240815125241-f3d73dfba97a h1:LuPvswDi+86NGwDHITt3kroG1idrQYHLCjeFOTVGtgE= +github.com/0xPolygon/cdk-data-availability v0.0.9-0.20240815125241-f3d73dfba97a/go.mod h1:5A+CU4FGeyG8zTDJc0khMzRxPzFzmpRydeEWmLztgh4= +github.com/0xPolygon/cdk-data-availability v0.0.9 h1:KkP+hJH9nY5fljpSNtW2pfP5YQCJOsSRzfnl0yT78rI= +github.com/0xPolygon/cdk-data-availability v0.0.9/go.mod h1:5A+CU4FGeyG8zTDJc0khMzRxPzFzmpRydeEWmLztgh4= github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d h1:sxh6hZ2jF/sxxj2jd5o1vuNNCZjYmn4aRG9SRlVaEFs= github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d/go.mod h1:2scWqMMufrQXu7TikDgQ3BsyaKoX8qP26D6E262vSOg= github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3 h1:zJ06KCGLMDOap4slop/QmiMUO+VPsKSS3+944SY06ww= diff --git a/l1infotreesync/downloader.go b/l1infotreesync/downloader.go index e022b470..bc4305bc 100644 --- a/l1infotreesync/downloader.go +++ b/l1infotreesync/downloader.go @@ -3,8 +3,9 @@ package l1infotreesync import ( "fmt" - "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonzkevmglobalexitrootv2" + "github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonzkevmglobalexitrootv2" "github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonrollupmanager" + "github.com/0xPolygon/cdk/log" "github.com/0xPolygon/cdk/sync" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -14,9 +15,11 @@ import ( ) var ( - updateL1InfoTreeSignature = crypto.Keccak256Hash([]byte("UpdateL1InfoTree(bytes32,bytes32)")) + updateL1InfoTreeSignatureV1 = crypto.Keccak256Hash([]byte("UpdateL1InfoTree(bytes32,bytes32)")) + updateL1InfoTreeSignatureV2 = crypto.Keccak256Hash([]byte("UpdateL1InfoTreeV2(bytes32,uint32,uint256,uint64)")) verifyBatchesSignature = crypto.Keccak256Hash([]byte("VerifyBatches(uint32,uint64,bytes32,bytes32,address)")) verifyBatchesTrustedAggregatorSignature = crypto.Keccak256Hash([]byte("VerifyBatchesTrustedAggregator(uint32,uint64,bytes32,bytes32,address)")) + initL1InfoRootMapSignature = crypto.Keccak256Hash([]byte("InitL1InfoRootMap(uint32,bytes32)")) ) type EthClienter interface { @@ -36,7 +39,21 @@ func buildAppender(client EthClienter, globalExitRoot, rollupManager common.Addr return nil, err } appender := make(sync.LogAppenderMap) - appender[updateL1InfoTreeSignature] = func(b *sync.EVMBlock, l types.Log) error { + appender[initL1InfoRootMapSignature] = func(b *sync.EVMBlock, l types.Log) error { + init, err := ger.ParseInitL1InfoRootMap(l) + if err != nil { + return fmt.Errorf( + "error parsing log %+v using ger.ParseInitL1InfoRootMap: %v", + l, err, + ) + } + b.Events = append(b.Events, Event{InitL1InfoRootMap: &InitL1InfoRootMap{ + LeafCount: init.LeafCount, + CurrentL1InfoRoot: init.CurrentL1InfoRoot, + }}) + return nil + } + appender[updateL1InfoTreeSignatureV1] = func(b *sync.EVMBlock, l types.Log) error { l1InfoTreeUpdate, err := ger.ParseUpdateL1InfoTree(l) if err != nil { return fmt.Errorf( @@ -52,6 +69,19 @@ func buildAppender(client EthClienter, globalExitRoot, rollupManager common.Addr }}) return nil } + + // TODO: integrate this event to perform sanity checks + appender[updateL1InfoTreeSignatureV2] = func(b *sync.EVMBlock, l types.Log) error { + l1InfoTreeUpdate, err := ger.ParseUpdateL1InfoTreeV2(l) + if err != nil { + return fmt.Errorf( + "error parsing log %+v using ger.ParseUpdateL1InfoTreeV2: %v", + l, err, + ) + } + log.Infof("updateL1InfoTreeSignatureV2: expected root: %s", common.Bytes2Hex(l1InfoTreeUpdate.CurrentL1InfoRoot[:])) + return nil + } appender[verifyBatchesSignature] = func(b *sync.EVMBlock, l types.Log) error { verifyBatches, err := rm.ParseVerifyBatches(l) if err != nil { diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index f4d809ea..c1b16446 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/globalexitrootnopush0" + "github.com/0xPolygon/cdk-contracts-tooling/contracts/banana-paris/polygonzkevmglobalexitrootv2" "github.com/0xPolygon/cdk/etherman" "github.com/0xPolygon/cdk/l1infotreesync" "github.com/0xPolygon/cdk/reorgdetector" @@ -27,7 +27,7 @@ func newSimulatedClient(auth *bind.TransactOpts) ( client *simulated.Backend, gerAddr common.Address, verifyAddr common.Address, - gerContract *globalexitrootnopush0.Globalexitrootnopush0, + gerContract *polygonzkevmglobalexitrootv2.Polygonzkevmglobalexitrootv2, verifyContract *verifybatchesmock.Verifybatchesmock, err error, ) { @@ -53,7 +53,7 @@ func newSimulatedClient(auth *bind.TransactOpts) ( } client.Commit() - gerAddr, _, gerContract, err = globalexitrootnopush0.DeployGlobalexitrootnopush0(auth, client.Client(), verifyAddr, auth.From) + gerAddr, _, gerContract, err = polygonzkevmglobalexitrootv2.DeployPolygonzkevmglobalexitrootv2(auth, client.Client(), verifyAddr, auth.From) if err != nil { return } @@ -86,6 +86,8 @@ func TestE2E(t *testing.T) { tx, err := gerSc.UpdateExitRoot(auth, common.HexToHash(strconv.Itoa(i))) require.NoError(t, err) client.Commit() + g, err := gerSc.L1InfoRootMap(nil, uint32(i+1)) + require.NoError(t, err) // Let the processor catch up time.Sleep(time.Millisecond * 100) receipt, err := client.Client().TransactionReceipt(ctx, tx.Hash()) @@ -101,6 +103,7 @@ func TestE2E(t *testing.T) { expectedRoot, err := gerSc.GetRoot(&bind.CallOpts{Pending: false}) require.NoError(t, err) + require.Equal(t, g, expectedRoot) actualRoot, err := syncer.GetL1InfoTreeRootByIndex(ctx, uint32(i)) require.NoError(t, err) require.Equal(t, common.Hash(expectedRoot), actualRoot) @@ -118,7 +121,7 @@ func TestE2E(t *testing.T) { receipt, err := client.Client().TransactionReceipt(ctx, tx.Hash()) require.NoError(t, err) require.Equal(t, receipt.Status, types.ReceiptStatusSuccessful) - require.True(t, len(receipt.Logs) == 1+i%2) + require.True(t, len(receipt.Logs) == 1+i%2+i%2) expectedRollupExitRoot, err := verifySC.GetRollupExitRoot(&bind.CallOpts{Pending: false}) require.NoError(t, err) diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index 31b3f13f..2af812d2 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -66,9 +66,15 @@ type VerifyBatches struct { Aggregator ethCommon.Address } +type InitL1InfoRootMap struct { + LeafCount uint32 + CurrentL1InfoRoot ethCommon.Hash +} + type Event struct { - UpdateL1InfoTree *UpdateL1InfoTree - VerifyBatches *VerifyBatches + UpdateL1InfoTree *UpdateL1InfoTree + VerifyBatches *VerifyBatches + InitL1InfoRootMap *InitL1InfoRootMap } // L1InfoTreeLeaf representation of a leaf of the L1 Info tree @@ -389,6 +395,12 @@ func (p *processor) ProcessBlock(ctx context.Context, b sync.Block) error { Hash: event.VerifyBatches.ExitRoot, }) } + + if event.InitL1InfoRootMap != nil { + // TODO: indicate that l1 Info tree indexes before the one on this + // event are not safe to use + log.Debugf("TODO: handle InitL1InfoRootMap event") + } } if l1InfoLeavesAdded > 0 { bwl := blockWithLeafs{ @@ -428,7 +440,7 @@ func (p *processor) ProcessBlock(ctx context.Context, b sync.Block) error { rollback() return err } - log.Debugf("block %d processed with events: %+v", b.Num, events) + log.Infof("block %d processed with events: %+v", b.Num, events) return nil } diff --git a/sequencesender/config.go b/sequencesender/config.go index 9521a0c2..3e3fd1c0 100644 --- a/sequencesender/config.go +++ b/sequencesender/config.go @@ -64,6 +64,8 @@ type Config struct { // MaxBatchesForL1 is the maximum amount of batches to be sequenced in a single L1 tx MaxBatchesForL1 uint64 `mapstructure:"MaxBatchesForL1"` + // BlockFinality indicates the status of the blocks that will be queried in order to sync + BlockFinality string `jsonschema:"enum=LatestBlock, enum=SafeBlock, enum=PendingBlock, enum=FinalizedBlock, enum=EarliestBlock" mapstructure:"BlockFinality"` // SanityCheckRPCURL is the URL of the RPC server to perform sanity check regarding the number of blocks in a batch SanityCheckRPCURL string `mapstructure:"SanityCheckRPCURL"` diff --git a/sequencesender/sequencesender.go b/sequencesender/sequencesender.go index 2e116a1b..70f6e90e 100644 --- a/sequencesender/sequencesender.go +++ b/sequencesender/sequencesender.go @@ -477,8 +477,8 @@ func (s *SequenceSender) tryToSendSequence(ctx context.Context) { lastSequence := sequence.LastBatch() lastL2BlockTimestamp := lastSequence.LastL2BLockTimestamp() + log.Debugf(sequence.String()) log.Infof("sending sequences to L1. From batch %d to batch %d", firstSequence.BatchNumber(), lastSequence.BatchNumber()) - log.Infof(sequence.String()) // Wait until last L1 block timestamp is L1BlockTimestampMargin seconds above the timestamp of the last L2 block in the sequence timeMargin := int64(s.cfg.L1BlockTimestampMargin.Seconds()) @@ -522,8 +522,8 @@ func (s *SequenceSender) tryToSendSequence(ctx context.Context) { } // Send sequences to L1 + log.Debugf(sequence.String()) log.Infof("sending sequences to L1. From batch %d to batch %d", firstSequence.BatchNumber(), lastSequence.BatchNumber()) - log.Infof(sequence.String()) tx, err := s.TxBuilder.BuildSequenceBatchesTx(ctx, sequence) if err != nil { @@ -666,7 +666,7 @@ func (s *SequenceSender) getSequencesToSend(ctx context.Context) (seqsendertypes // If the coinbase changes, the sequence ends here if len(sequenceBatches) > 0 && batch.LastCoinbase() != prevCoinbase { log.Infof("batch with different coinbase (batch %v, sequence %v), sequence will be sent to this point", prevCoinbase, batch.LastCoinbase) - return s.TxBuilder.NewSequence(sequenceBatches, s.cfg.L2Coinbase) + return s.TxBuilder.NewSequence(ctx, sequenceBatches, s.cfg.L2Coinbase) } prevCoinbase = batch.LastCoinbase() @@ -684,7 +684,7 @@ func (s *SequenceSender) getSequencesToSend(ctx context.Context) (seqsendertypes // Check if the current batch is the last before a change to a new forkid, in this case we need to close and send the sequence to L1 if (s.cfg.ForkUpgradeBatchNumber != 0) && (batchNumber == (s.cfg.ForkUpgradeBatchNumber)) { log.Infof("sequence should be sent to L1, as we have reached the batch %d from which a new forkid is applied (upgrade)", s.cfg.ForkUpgradeBatchNumber) - return s.TxBuilder.NewSequence(sequenceBatches, s.cfg.L2Coinbase) + return s.TxBuilder.NewSequence(ctx, sequenceBatches, s.cfg.L2Coinbase) } } @@ -696,7 +696,7 @@ func (s *SequenceSender) getSequencesToSend(ctx context.Context) (seqsendertypes if s.latestVirtualTime.Before(time.Now().Add(-s.cfg.LastBatchVirtualizationTimeMaxWaitPeriod.Duration)) { log.Infof("sequence should be sent, too much time without sending anything to L1") - return s.TxBuilder.NewSequence(sequenceBatches, s.cfg.L2Coinbase) + return s.TxBuilder.NewSequence(ctx, sequenceBatches, s.cfg.L2Coinbase) } log.Infof("not enough time has passed since last batch was virtualized and the sequence could be bigger") diff --git a/sequencesender/txbuilder/banana_base.go b/sequencesender/txbuilder/banana_base.go index 382be8ce..15a25f56 100644 --- a/sequencesender/txbuilder/banana_base.go +++ b/sequencesender/txbuilder/banana_base.go @@ -1,15 +1,19 @@ package txbuilder import ( + "context" "fmt" + "math/big" cdkcommon "github.com/0xPolygon/cdk/common" "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/state/datastream" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ) type rollupBananaBaseContractor interface { @@ -21,18 +25,37 @@ type globalExitRootBananaContractor interface { String() string } +type l1InfoSyncer interface { + GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*l1infotreesync.L1InfoTreeLeaf, error) +} + +type l1Client interface { + HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) +} + type TxBuilderBananaBase struct { rollupContract rollupBananaBaseContractor globalExitRootContract globalExitRootBananaContractor + l1InfoTree l1InfoSyncer + ethClient l1Client + blockFinality *big.Int opts bind.TransactOpts } -func NewTxBuilderBananaBase(rollupContract rollupBananaBaseContractor, +func NewTxBuilderBananaBase( + rollupContract rollupBananaBaseContractor, gerContract globalExitRootBananaContractor, - opts bind.TransactOpts) *TxBuilderBananaBase { + l1InfoTree l1InfoSyncer, + ethClient l1Client, + blockFinality *big.Int, + opts bind.TransactOpts, +) *TxBuilderBananaBase { return &TxBuilderBananaBase{ rollupContract: rollupContract, globalExitRootContract: gerContract, + l1InfoTree: l1InfoTree, + ethClient: ethClient, + blockFinality: blockFinality, opts: opts, } @@ -49,14 +72,36 @@ func (t *TxBuilderBananaBase) NewBatchFromL2Block(l2Block *datastream.L2Block) s return NewBananaBatch(batch) } -func (t *TxBuilderBananaBase) NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) { +func (t *TxBuilderBananaBase) NewSequence(ctx context.Context, batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) { ethBatches, err := toEthermanBatches(batches) if err != nil { return nil, err } sequence := etherman.NewSequenceBanana(ethBatches, coinbase) + var greatestL1Index uint32 + for _, b := range sequence.Batches { + if greatestL1Index < b.L1InfoTreeIndex { + greatestL1Index = b.L1InfoTreeIndex + } + } + header, err := t.ethClient.HeaderByNumber(ctx, t.blockFinality) + if err != nil { + return nil, fmt.Errorf("error calling HeaderByNumber, with block finality %d: %v", t.blockFinality.Int64(), err) + } + info, err := t.l1InfoTree.GetLatestInfoUntilBlock(ctx, header.Number.Uint64()) + if err != nil { + return nil, fmt.Errorf("error calling GetLatestInfoUntilBlock with block num %d: %v", header.Number.Uint64(), err) + } + if info.L1InfoTreeIndex >= greatestL1Index { + sequence.CounterL1InfoRoot = info.L1InfoTreeIndex + 1 + } else { + return nil, fmt.Errorf( + "sequence contained an L1 Info tree index (%d) that is greater than the one synced with the desired finality (%d)", + greatestL1Index, info.L1InfoTreeIndex, + ) + } - l1InfoRoot, err := t.getL1InfoRoot(sequence.IndexL1InfoRoot) + l1InfoRoot, err := t.getL1InfoRoot(sequence.CounterL1InfoRoot) if err != nil { return nil, err } @@ -81,10 +126,7 @@ func (t *TxBuilderBananaBase) NewSequence(batches []seqsendertypes.Batch, coinba blockHash = batch.ForcedBlockHashL1 } - accInputHash, err = cdkcommon.CalculateAccInputHash(accInputHash, batch.L2Data, infoRootHash, timestamp, batch.LastCoinbase, blockHash) - if err != nil { - return nil, err - } + accInputHash = cdkcommon.CalculateAccInputHash(accInputHash, batch.L2Data, infoRootHash, timestamp, batch.LastCoinbase, blockHash) } sequence.OldAccInputHash = oldAccInputHash @@ -93,21 +135,8 @@ func (t *TxBuilderBananaBase) NewSequence(batches []seqsendertypes.Batch, coinba return res, nil } -func (t *TxBuilderBananaBase) getL1InfoRoot(indexL1InfoRoot uint32) (common.Hash, error) { - // Get lastL1InfoTreeRoot (if index==0 then root=0, no call is needed) - var ( - lastL1InfoTreeRoot common.Hash - err error - ) - - if indexL1InfoRoot > 0 { - lastL1InfoTreeRoot, err = t.globalExitRootContract.L1InfoRootMap(&bind.CallOpts{Pending: false}, indexL1InfoRoot) - if err != nil { - log.Errorf("error calling SC globalexitroot L1InfoLeafMap (%s) Err: %w", t.globalExitRootContract.String(), err) - } - } - - return lastL1InfoTreeRoot, err +func (t *TxBuilderBananaBase) getL1InfoRoot(counterL1InfoRoot uint32) (common.Hash, error) { + return t.globalExitRootContract.L1InfoRootMap(&bind.CallOpts{Pending: false}, counterL1InfoRoot) } func convertToSequenceBanana(sequences seqsendertypes.Sequence) (etherman.SequenceBanana, error) { @@ -122,7 +151,7 @@ func convertToSequenceBanana(sequences seqsendertypes.Sequence) (etherman.Sequen AccInputHash: seqEth.SequenceBanana.AccInputHash, L1InfoRoot: seqEth.SequenceBanana.L1InfoRoot, MaxSequenceTimestamp: seqEth.SequenceBanana.MaxSequenceTimestamp, - IndexL1InfoRoot: seqEth.SequenceBanana.IndexL1InfoRoot, + CounterL1InfoRoot: seqEth.SequenceBanana.CounterL1InfoRoot, L2Coinbase: seqEth.SequenceBanana.L2Coinbase, } diff --git a/sequencesender/txbuilder/banana_base_test.go b/sequencesender/txbuilder/banana_base_test.go index a2f54566..6ad08b80 100644 --- a/sequencesender/txbuilder/banana_base_test.go +++ b/sequencesender/txbuilder/banana_base_test.go @@ -1,23 +1,33 @@ package txbuilder_test import ( + "context" + "math/big" "testing" + "github.com/0xPolygon/cdk/l1infotreesync" "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/datastream" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) func TestBananaBaseNewSequenceEmpty(t *testing.T) { testData := newBananaBaseTestData(t) + testData.l1Client.On("HeaderByNumber", mock.Anything, mock.Anything). + Return(&types.Header{Number: big.NewInt(69)}, nil) + testData.getContract.On("L1InfoRootMap", mock.Anything, uint32(70)). + Return([32]byte{}, nil) + testData.l1InfoTreeSync.On("GetLatestInfoUntilBlock", mock.Anything, mock.Anything). + Return(&l1infotreesync.L1InfoTreeLeaf{L1InfoTreeIndex: 69}, nil) lastAcc := common.HexToHash("0x8aca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") testData.rollupContract.EXPECT().LastAccInputHash(mock.Anything).Return(lastAcc, nil) - seq, err := testData.sut.NewSequence(nil, common.Address{}) + seq, err := testData.sut.NewSequence(context.TODO(), nil, common.Address{}) require.NotNil(t, seq) require.NoError(t, err) // TODO check values @@ -44,6 +54,8 @@ func TestBananaBaseNewBatchFromL2Block(t *testing.T) { func TestBananaBaseNewSequenceBatch(t *testing.T) { testData := newBananaBaseTestData(t) + testData.l1Client.On("HeaderByNumber", mock.Anything, mock.Anything). + Return(&types.Header{Number: big.NewInt(69)}, nil) l2Block := &datastream.L2Block{ Timestamp: 1, BatchNumber: 2, @@ -56,9 +68,11 @@ func TestBananaBaseNewSequenceBatch(t *testing.T) { lastAcc := common.HexToHash("0x8aca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") testData.rollupContract.EXPECT().LastAccInputHash(mock.Anything).Return(lastAcc, nil) l1infoRoot := common.HexToHash("0x66ca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") - testData.getContract.EXPECT().L1InfoRootMap(mock.Anything, uint32(3)).Return(l1infoRoot, nil) + testData.l1InfoTreeSync.On("GetLatestInfoUntilBlock", mock.Anything, mock.Anything). + Return(&l1infotreesync.L1InfoTreeLeaf{L1InfoTreeIndex: 7}, nil) + testData.getContract.EXPECT().L1InfoRootMap(mock.Anything, uint32(8)).Return(l1infoRoot, nil) - seq, err := testData.sut.NewSequence(batches, common.Address{}) + seq, err := testData.sut.NewSequence(context.TODO(), batches, common.Address{}) require.NotNil(t, seq) require.NoError(t, err) // TODO: check that the seq have the right values @@ -69,18 +83,28 @@ type testDataBananaBase struct { getContract *mocks_txbuilder.GlobalExitRootBananaContractor opts bind.TransactOpts sut *txbuilder.TxBuilderBananaBase + l1InfoTreeSync *mocks_txbuilder.L1InfoSyncer + l1Client *mocks_txbuilder.L1Client } func newBananaBaseTestData(t *testing.T) *testDataBananaBase { zkevmContractMock := mocks_txbuilder.NewRollupBananaBaseContractor(t) gerContractMock := mocks_txbuilder.NewGlobalExitRootBananaContractor(t) opts := bind.TransactOpts{} - sut := txbuilder.NewTxBuilderBananaBase(zkevmContractMock, gerContractMock, opts) + l1Client := mocks_txbuilder.NewL1Client(t) + l1InfoSyncer := mocks_txbuilder.NewL1InfoSyncer(t) + sut := txbuilder.NewTxBuilderBananaBase( + zkevmContractMock, + gerContractMock, + l1InfoSyncer, l1Client, big.NewInt(0), opts, + ) require.NotNil(t, sut) return &testDataBananaBase{ rollupContract: zkevmContractMock, getContract: gerContractMock, opts: opts, sut: sut, + l1InfoTreeSync: l1InfoSyncer, + l1Client: l1Client, } } diff --git a/sequencesender/txbuilder/banana_types.go b/sequencesender/txbuilder/banana_types.go index ffa5d804..5a38cab0 100644 --- a/sequencesender/txbuilder/banana_types.go +++ b/sequencesender/txbuilder/banana_types.go @@ -25,7 +25,7 @@ func NewBananaSequence(ult etherman.SequenceBanana) *BananaSequence { } func (b *BananaSequence) IndexL1InfoRoot() uint32 { - return b.SequenceBanana.IndexL1InfoRoot + return b.SequenceBanana.CounterL1InfoRoot } func (b *BananaSequence) MaxSequenceTimestamp() uint64 { diff --git a/sequencesender/txbuilder/banana_validium.go b/sequencesender/txbuilder/banana_validium.go index c7309dfc..9ab1b929 100644 --- a/sequencesender/txbuilder/banana_validium.go +++ b/sequencesender/txbuilder/banana_validium.go @@ -28,11 +28,16 @@ type rollupBananaValidiumContractor interface { SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) } -func NewTxBuilderBananaValidium(rollupContract rollupBananaValidiumContractor, +func NewTxBuilderBananaValidium( + rollupContract rollupBananaValidiumContractor, gerContract globalExitRootBananaContractor, - da dataavailability.SequenceSenderBanana, opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderBananaValidium { + da dataavailability.SequenceSenderBanana, opts bind.TransactOpts, maxBatchesForL1 uint64, + l1InfoTree l1InfoSyncer, + ethClient l1Client, + blockFinality *big.Int, +) *TxBuilderBananaValidium { return &TxBuilderBananaValidium{ - TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), + TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, l1InfoTree, ethClient, blockFinality, opts), da: da, condNewSeq: NewConditionalNewSequenceNumBatches(maxBatchesForL1), rollupContract: rollupContract, @@ -111,7 +116,8 @@ func (t *TxBuilderBananaValidium) sequenceBatchesValidium(opts bind.TransactOpts } } - tx, err := t.rollupContract.SequenceBatchesValidium(&opts, batches, sequence.IndexL1InfoRoot, sequence.MaxSequenceTimestamp, sequence.AccInputHash, sequence.L2Coinbase, dataAvailabilityMessage) + log.Infof("building banana sequence tx. AccInputHash: %s", sequence.AccInputHash.Hex()) + tx, err := t.rollupContract.SequenceBatchesValidium(&opts, batches, sequence.CounterL1InfoRoot, sequence.MaxSequenceTimestamp, sequence.AccInputHash, sequence.L2Coinbase, dataAvailabilityMessage) if err != nil { log.Debugf("Batches to send: %+v", batches) log.Debug("l2CoinBase: ", sequence.L2Coinbase) diff --git a/sequencesender/txbuilder/banana_validium_test.go b/sequencesender/txbuilder/banana_validium_test.go index 5c6f0d50..97ec2286 100644 --- a/sequencesender/txbuilder/banana_validium_test.go +++ b/sequencesender/txbuilder/banana_validium_test.go @@ -3,16 +3,19 @@ package txbuilder_test import ( "context" "fmt" + "math/big" "strings" "testing" "github.com/0xPolygon/cdk/dataavailability/mocks_da" + "github.com/0xPolygon/cdk/l1infotreesync" "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/datastream" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -27,6 +30,10 @@ func TestBananaValidiumName(t *testing.T) { func TestBananaValidiumBuildSequenceBatchesTxSequenceErrorsFromDA(t *testing.T) { testData := newBananaValidiumTestData(t, txbuilder.MaxBatchesForL1Disabled) + testData.l1Client.On("HeaderByNumber", mock.Anything, mock.Anything). + Return(&types.Header{Number: big.NewInt(69)}, nil) + testData.l1InfoTreeSync.On("GetLatestInfoUntilBlock", mock.Anything, mock.Anything). + Return(&l1infotreesync.L1InfoTreeLeaf{L1InfoTreeIndex: 7}, nil) seq, err := newSequenceBananaValidiumForTest(testData) require.NoError(t, err) ctx := context.TODO() @@ -43,6 +50,10 @@ func TestBananaValidiumBuildSequenceBatchesTxSequenceErrorsFromDA(t *testing.T) func TestBananaValidiumBuildSequenceBatchesTxSequenceDAOk(t *testing.T) { testData := newBananaValidiumTestData(t, txbuilder.MaxBatchesForL1Disabled) + testData.l1Client.On("HeaderByNumber", mock.Anything, mock.Anything). + Return(&types.Header{Number: big.NewInt(69)}, nil) + testData.l1InfoTreeSync.On("GetLatestInfoUntilBlock", mock.Anything, mock.Anything). + Return(&l1infotreesync.L1InfoTreeLeaf{L1InfoTreeIndex: 7}, nil) seq, err := newSequenceBananaValidiumForTest(testData) require.NoError(t, err) ctx := context.TODO() @@ -65,6 +76,8 @@ type testDataBananaValidium struct { da *mocks_da.SequenceSenderBanana opts bind.TransactOpts sut *txbuilder.TxBuilderBananaValidium + l1InfoTreeSync *mocks_txbuilder.L1InfoSyncer + l1Client *mocks_txbuilder.L1Client } func newBananaValidiumTestData(t *testing.T, maxBatchesForL1 uint64) *testDataBananaValidium { @@ -72,9 +85,20 @@ func newBananaValidiumTestData(t *testing.T, maxBatchesForL1 uint64) *testDataBa gerContractMock := mocks_txbuilder.NewGlobalExitRootBananaContractor(t) condMock := mocks_txbuilder.NewCondNewSequence(t) daMock := mocks_da.NewSequenceSenderBanana(t) + l1Client := mocks_txbuilder.NewL1Client(t) + l1InfoSyncer := mocks_txbuilder.NewL1InfoSyncer(t) opts := bind.TransactOpts{} - sut := txbuilder.NewTxBuilderBananaValidium(zkevmContractMock, gerContractMock, daMock, opts, maxBatchesForL1) + sut := txbuilder.NewTxBuilderBananaValidium( + zkevmContractMock, + gerContractMock, + daMock, + opts, + maxBatchesForL1, + l1InfoSyncer, + l1Client, + big.NewInt(0), + ) require.NotNil(t, sut) sut.SetCondNewSeq(condMock) return &testDataBananaValidium{ @@ -84,6 +108,8 @@ func newBananaValidiumTestData(t *testing.T, maxBatchesForL1 uint64) *testDataBa da: daMock, opts: opts, sut: sut, + l1InfoTreeSync: l1InfoSyncer, + l1Client: l1Client, } } @@ -102,6 +128,6 @@ func newSequenceBananaValidiumForTest(testData *testDataBananaValidium) (seqsend lastAcc := common.HexToHash("0x8aca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") testData.rollupContract.EXPECT().LastAccInputHash(mock.Anything).Return(lastAcc, nil).Once() l1infoRoot := common.HexToHash("0x66ca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") - testData.getContract.EXPECT().L1InfoRootMap(mock.Anything, uint32(3)).Return(l1infoRoot, nil).Once() - return testData.sut.NewSequence(batches, common.Address{}) + testData.getContract.EXPECT().L1InfoRootMap(mock.Anything, uint32(8)).Return(l1infoRoot, nil).Once() + return testData.sut.NewSequence(context.TODO(), batches, common.Address{}) } diff --git a/sequencesender/txbuilder/banana_zkevm.go b/sequencesender/txbuilder/banana_zkevm.go index 3a95cdff..c0216d52 100644 --- a/sequencesender/txbuilder/banana_zkevm.go +++ b/sequencesender/txbuilder/banana_zkevm.go @@ -28,9 +28,17 @@ type globalExitRootBananaZKEVMContractor interface { globalExitRootBananaContractor } -func NewTxBuilderBananaZKEVM(rollupContract rollupBananaZKEVMContractor, gerContract globalExitRootBananaZKEVMContractor, opts bind.TransactOpts, maxTxSizeForL1 uint64) *TxBuilderBananaZKEVM { +func NewTxBuilderBananaZKEVM( + rollupContract rollupBananaZKEVMContractor, + gerContract globalExitRootBananaZKEVMContractor, + opts bind.TransactOpts, + maxTxSizeForL1 uint64, + l1InfoTree l1InfoSyncer, + ethClient l1Client, + blockFinality *big.Int, +) *TxBuilderBananaZKEVM { return &TxBuilderBananaZKEVM{ - TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), + TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, l1InfoTree, ethClient, blockFinality, opts), condNewSeq: NewConditionalNewSequenceMaxSize(maxTxSizeForL1), rollupContract: rollupContract, } @@ -86,7 +94,7 @@ func (t *TxBuilderBananaZKEVM) sequenceBatchesRollup(opts bind.TransactOpts, seq } } - tx, err := t.rollupContract.SequenceBatches(&opts, batches, sequence.IndexL1InfoRoot, sequence.MaxSequenceTimestamp, sequence.AccInputHash, sequence.L2Coinbase) + tx, err := t.rollupContract.SequenceBatches(&opts, batches, sequence.CounterL1InfoRoot, sequence.MaxSequenceTimestamp, sequence.AccInputHash, sequence.L2Coinbase) if err != nil { log.Debugf("Batches to send: %+v", batches) log.Debug("l2CoinBase: ", sequence.L2Coinbase) diff --git a/sequencesender/txbuilder/banana_zkevm_test.go b/sequencesender/txbuilder/banana_zkevm_test.go index 8653c504..10043b8a 100644 --- a/sequencesender/txbuilder/banana_zkevm_test.go +++ b/sequencesender/txbuilder/banana_zkevm_test.go @@ -3,15 +3,18 @@ package txbuilder_test import ( "context" "fmt" + "math/big" "strings" "testing" + "github.com/0xPolygon/cdk/l1infotreesync" "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/datastream" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -33,6 +36,10 @@ func TestBananaZkevmNewSequenceIfWorthToSend(t *testing.T) { func TestBananaZkevmBuildSequenceBatchesTxOk(t *testing.T) { testData := newBananaZKEVMTestData(t, txbuilder.MaxTxSizeForL1Disabled) + testData.l1Client.On("HeaderByNumber", mock.Anything, mock.Anything). + Return(&types.Header{Number: big.NewInt(69)}, nil) + testData.l1InfoTreeSync.On("GetLatestInfoUntilBlock", mock.Anything, mock.Anything). + Return(&l1infotreesync.L1InfoTreeLeaf{L1InfoTreeIndex: 7}, nil) seq, err := newSequenceBananaZKEVMForTest(testData) require.NoError(t, err) @@ -50,6 +57,10 @@ func TestBananaZkevmBuildSequenceBatchesTxOk(t *testing.T) { func TestBananaZkevmBuildSequenceBatchesTxErr(t *testing.T) { testData := newBananaZKEVMTestData(t, txbuilder.MaxTxSizeForL1Disabled) + testData.l1Client.On("HeaderByNumber", mock.Anything, mock.Anything). + Return(&types.Header{Number: big.NewInt(69)}, nil) + testData.l1InfoTreeSync.On("GetLatestInfoUntilBlock", mock.Anything, mock.Anything). + Return(&l1infotreesync.L1InfoTreeLeaf{L1InfoTreeIndex: 7}, nil) seq, err := newSequenceBananaZKEVMForTest(testData) require.NoError(t, err) @@ -66,6 +77,8 @@ type testDataBananaZKEVM struct { cond *mocks_txbuilder.CondNewSequence opts bind.TransactOpts sut *txbuilder.TxBuilderBananaZKEVM + l1InfoTreeSync *mocks_txbuilder.L1InfoSyncer + l1Client *mocks_txbuilder.L1Client } func newBananaZKEVMTestData(t *testing.T, maxTxSizeForL1 uint64) *testDataBananaZKEVM { @@ -73,7 +86,17 @@ func newBananaZKEVMTestData(t *testing.T, maxTxSizeForL1 uint64) *testDataBanana gerContractMock := mocks_txbuilder.NewGlobalExitRootBananaContractor(t) condMock := mocks_txbuilder.NewCondNewSequence(t) opts := bind.TransactOpts{} - sut := txbuilder.NewTxBuilderBananaZKEVM(zkevmContractMock, gerContractMock, opts, maxTxSizeForL1) + l1Client := mocks_txbuilder.NewL1Client(t) + l1InfoSyncer := mocks_txbuilder.NewL1InfoSyncer(t) + sut := txbuilder.NewTxBuilderBananaZKEVM( + zkevmContractMock, + gerContractMock, + opts, + maxTxSizeForL1, + l1InfoSyncer, + l1Client, + big.NewInt(0), + ) require.NotNil(t, sut) sut.SetCondNewSeq(condMock) return &testDataBananaZKEVM{ @@ -82,6 +105,8 @@ func newBananaZKEVMTestData(t *testing.T, maxTxSizeForL1 uint64) *testDataBanana cond: condMock, opts: opts, sut: sut, + l1InfoTreeSync: l1InfoSyncer, + l1Client: l1Client, } } @@ -100,6 +125,6 @@ func newSequenceBananaZKEVMForTest(testData *testDataBananaZKEVM) (seqsendertype lastAcc := common.HexToHash("0x8aca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") testData.rollupContract.EXPECT().LastAccInputHash(mock.Anything).Return(lastAcc, nil).Once() l1infoRoot := common.HexToHash("0x66ca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") - testData.getContract.EXPECT().L1InfoRootMap(mock.Anything, uint32(3)).Return(l1infoRoot, nil).Once() - return testData.sut.NewSequence(batches, common.Address{}) + testData.getContract.EXPECT().L1InfoRootMap(mock.Anything, uint32(8)).Return(l1infoRoot, nil).Once() + return testData.sut.NewSequence(context.TODO(), batches, common.Address{}) } diff --git a/sequencesender/txbuilder/elderberry_base.go b/sequencesender/txbuilder/elderberry_base.go index 23081b58..c076d7d9 100644 --- a/sequencesender/txbuilder/elderberry_base.go +++ b/sequencesender/txbuilder/elderberry_base.go @@ -1,6 +1,8 @@ package txbuilder import ( + "context" + "github.com/0xPolygon/cdk/etherman" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/0xPolygon/cdk/state/datastream" @@ -23,7 +25,7 @@ func (t *TxBuilderElderberryBase) SetAuth(auth *bind.TransactOpts) { t.opts = *auth } -func (t *TxBuilderElderberryBase) NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) { +func (t *TxBuilderElderberryBase) NewSequence(ctx context.Context, batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) { seq := ElderberrySequence{ l2Coinbase: coinbase, batches: batches, diff --git a/sequencesender/txbuilder/elderberry_base_test.go b/sequencesender/txbuilder/elderberry_base_test.go index 43141f22..c2507907 100644 --- a/sequencesender/txbuilder/elderberry_base_test.go +++ b/sequencesender/txbuilder/elderberry_base_test.go @@ -1,6 +1,7 @@ package txbuilder import ( + "context" "testing" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" @@ -14,7 +15,7 @@ func TestElderberryBaseNewSequence(t *testing.T) { opts := bind.TransactOpts{} sut := NewTxBuilderElderberryBase(opts) require.NotNil(t, sut) - seq, err := sut.NewSequence(nil, common.Address{}) + seq, err := sut.NewSequence(context.TODO(), nil, common.Address{}) require.NotNil(t, seq) require.NoError(t, err) } @@ -40,7 +41,7 @@ func TestElderberryBaseNewBatchFromL2Block(t *testing.T) { func TestElderberryBasegetLastSequencedBatchNumberEmpty(t *testing.T) { sut := newElderberryBaseSUT(t) - seq, err := sut.NewSequence(nil, common.Address{}) + seq, err := sut.NewSequence(context.TODO(), nil, common.Address{}) require.NoError(t, err) require.Equal(t, uint64(0), getLastSequencedBatchNumber(seq)) @@ -60,7 +61,7 @@ func TestElderberryBasegetLastSequencedBatch1Batch(t *testing.T) { batchElder, } - seq, err := sut.NewSequence(batches, common.Address{}) + seq, err := sut.NewSequence(context.TODO(), batches, common.Address{}) require.NoError(t, err) require.Equal(t, l2Block.BatchNumber-1, getLastSequencedBatchNumber(seq)) @@ -80,7 +81,7 @@ func TestElderberryBaseGetLastSequencedBatchFirstBatchIsZeroThrowAPanic(t *testi batchElder, } - seq, err := sut.NewSequence(batches, common.Address{}) + seq, err := sut.NewSequence(context.TODO(), batches, common.Address{}) require.NoError(t, err) defer func() { if r := recover(); r == nil { diff --git a/sequencesender/txbuilder/elderberry_validium.go b/sequencesender/txbuilder/elderberry_validium.go index 638ba3b1..c2acc649 100644 --- a/sequencesender/txbuilder/elderberry_validium.go +++ b/sequencesender/txbuilder/elderberry_validium.go @@ -15,7 +15,6 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" ) @@ -51,7 +50,7 @@ func (t *TxBuilderElderberryValidium) SetCondNewSeq(cond CondNewSequence) CondNe return previous } -func (t *TxBuilderElderberryValidium) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +func (t *TxBuilderElderberryValidium) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*types.Transaction, error) { if sequences == nil || sequences.Len() == 0 { return nil, fmt.Errorf("can't sequence an empty sequence") } diff --git a/sequencesender/txbuilder/elderberry_validium_test.go b/sequencesender/txbuilder/elderberry_validium_test.go index 1964867c..adc8456a 100644 --- a/sequencesender/txbuilder/elderberry_validium_test.go +++ b/sequencesender/txbuilder/elderberry_validium_test.go @@ -33,7 +33,7 @@ func TestElderberryValidiumBuildSequenceBatchesTxEmtpySequence(t *testing.T) { _, err := testData.sut.BuildSequenceBatchesTx(ctx, nil) require.Error(t, err) - seq, err := testData.sut.NewSequence(nil, common.Address{}) + seq, err := testData.sut.NewSequence(context.TODO(), nil, common.Address{}) require.NoError(t, err) _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err) @@ -53,7 +53,7 @@ func TestElderberryValidiumBuildSequenceBatchesTxSequenceErrorsFromDA(t *testing batches := []seqsendertypes.Batch{ batchElder, } - seq, err := testData.sut.NewSequence(batches, common.Address{}) + seq, err := testData.sut.NewSequence(context.TODO(), batches, common.Address{}) require.NoError(t, err) testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return(nil, nil) _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) @@ -77,7 +77,7 @@ func TestElderberryValidiumBuildSequenceBatchesTxSequenceDAOk(t *testing.T) { batches := []seqsendertypes.Batch{ batchElder, } - seq, err := testData.sut.NewSequence(batches, common.Address{}) + seq, err := testData.sut.NewSequence(context.TODO(), batches, common.Address{}) require.NoError(t, err) testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return([]byte{1}, nil) tx, err := testData.sut.BuildSequenceBatchesTx(ctx, seq) diff --git a/sequencesender/txbuilder/elderberry_zkevm.go b/sequencesender/txbuilder/elderberry_zkevm.go index 83e70971..870be1bb 100644 --- a/sequencesender/txbuilder/elderberry_zkevm.go +++ b/sequencesender/txbuilder/elderberry_zkevm.go @@ -12,7 +12,6 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - ethtypes "github.com/ethereum/go-ethereum/core/types" ) type TxBuilderElderberryZKEVM struct { @@ -44,7 +43,7 @@ func (t *TxBuilderElderberryZKEVM) SetCondNewSeq(cond CondNewSequence) CondNewSe return previous } -func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*types.Transaction, error) { newopts := t.opts newopts.NoSend = true diff --git a/sequencesender/txbuilder/elderberry_zkevm_test.go b/sequencesender/txbuilder/elderberry_zkevm_test.go index 9ed29823..94623048 100644 --- a/sequencesender/txbuilder/elderberry_zkevm_test.go +++ b/sequencesender/txbuilder/elderberry_zkevm_test.go @@ -31,7 +31,7 @@ func TestElderberryZkevmNewSequence(t *testing.T) { opts := bind.TransactOpts{} sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, 100) require.NotNil(t, sut) - seq, err := sut.NewSequence(nil, common.Address{}) + seq, err := sut.NewSequence(context.TODO(), nil, common.Address{}) require.NoError(t, err) require.NotNil(t, seq) } @@ -42,7 +42,7 @@ func TestElderberryZkevmBuildSequenceBatchesTxEmtpySequence(t *testing.T) { _, err := sut.BuildSequenceBatchesTx(ctx, nil) require.Error(t, err) - seq, err := sut.NewSequence(nil, common.Address{}) + seq, err := sut.NewSequence(context.TODO(), nil, common.Address{}) require.NoError(t, err) _, err = sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err) @@ -62,7 +62,7 @@ func TestElderberryZkevmBuildSequenceBatchesTxSequence1Batch(t *testing.T) { batches := []seqsendertypes.Batch{ batchElder, } - seq, err := sut.NewSequence(batches, common.Address{}) + seq, err := sut.NewSequence(context.TODO(), batches, common.Address{}) require.NoError(t, err) _, err = sut.BuildSequenceBatchesTx(ctx, seq) require.NoError(t, err) @@ -84,7 +84,7 @@ func TestElderberryZkevmBuildSequenceBatchesTxSequence1BatchError(t *testing.T) batches := []seqsendertypes.Batch{ batchElder, } - seq, err := sut.NewSequence(batches, common.Address{}) + seq, err := sut.NewSequence(context.TODO(), batches, common.Address{}) require.NoError(t, err) _, err = sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err) diff --git a/sequencesender/txbuilder/interface.go b/sequencesender/txbuilder/interface.go index 7bfa51be..bde8b634 100644 --- a/sequencesender/txbuilder/interface.go +++ b/sequencesender/txbuilder/interface.go @@ -13,7 +13,7 @@ type TxBuilder interface { // BuildSequenceBatchesTx Builds a sequence of batches transaction BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) // NewSequence Creates a new sequence - NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) + NewSequence(ctx context.Context, batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) // NewSequenceIfWorthToSend Creates a new sequence if it is worth sending NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) // NewBatchFromL2Block Creates a new batch from the L2 block from a datastream diff --git a/sequencesender/txbuilder/interface_test.go b/sequencesender/txbuilder/interface_test.go index 7a27e2f1..6db0216a 100644 --- a/sequencesender/txbuilder/interface_test.go +++ b/sequencesender/txbuilder/interface_test.go @@ -37,8 +37,8 @@ func testSequenceIfWorthToSendErr(t *testing.T, sut txbuilder.TxBuilder) { func testSetCondNewSeq(t *testing.T, sut txbuilder.TxBuilder) { cond := mocks_txbuilder.NewCondNewSequence(t) - previous := sut.SetCondNewSeq(cond) + sut.SetCondNewSeq(cond) cond2 := mocks_txbuilder.NewCondNewSequence(t) - previous = sut.SetCondNewSeq(cond2) + previous := sut.SetCondNewSeq(cond2) require.Equal(t, cond, previous) } diff --git a/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go b/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go index 26893fe1..ae818ce9 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go +++ b/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go @@ -31,6 +31,10 @@ func (_m *CondNewSequence) EXPECT() *CondNewSequence_Expecter { func (_m *CondNewSequence) NewSequenceIfWorthToSend(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { ret := _m.Called(ctx, txBuilder, sequenceBatches, l2Coinbase) + if len(ret) == 0 { + panic("no return value specified for NewSequenceIfWorthToSend") + } + var r0 seqsendertypes.Sequence var r1 error if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)); ok { @@ -84,13 +88,12 @@ func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) RunAndReturn(run func(c return _c } -type mockConstructorTestingTNewCondNewSequence interface { +// NewCondNewSequence creates a new instance of CondNewSequence. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCondNewSequence(t interface { mock.TestingT Cleanup(func()) -} - -// NewCondNewSequence creates a new instance of CondNewSequence. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewCondNewSequence(t mockConstructorTestingTNewCondNewSequence) *CondNewSequence { +}) *CondNewSequence { mock := &CondNewSequence{} mock.Mock.Test(t) diff --git a/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go index 7d2ff650..93dadeef 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go @@ -24,6 +24,10 @@ func (_m *GlobalExitRootBananaContractor) EXPECT() *GlobalExitRootBananaContract func (_m *GlobalExitRootBananaContractor) L1InfoRootMap(opts *bind.CallOpts, index uint32) ([32]byte, error) { ret := _m.Called(opts, index) + if len(ret) == 0 { + panic("no return value specified for L1InfoRootMap") + } + var r0 [32]byte var r1 error if rf, ok := ret.Get(0).(func(*bind.CallOpts, uint32) ([32]byte, error)); ok { @@ -79,6 +83,10 @@ func (_c *GlobalExitRootBananaContractor_L1InfoRootMap_Call) RunAndReturn(run fu func (_m *GlobalExitRootBananaContractor) String() string { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for String") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() @@ -116,13 +124,12 @@ func (_c *GlobalExitRootBananaContractor_String_Call) RunAndReturn(run func() st return _c } -type mockConstructorTestingTNewGlobalExitRootBananaContractor interface { +// NewGlobalExitRootBananaContractor creates a new instance of GlobalExitRootBananaContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewGlobalExitRootBananaContractor(t interface { mock.TestingT Cleanup(func()) -} - -// NewGlobalExitRootBananaContractor creates a new instance of GlobalExitRootBananaContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewGlobalExitRootBananaContractor(t mockConstructorTestingTNewGlobalExitRootBananaContractor) *GlobalExitRootBananaContractor { +}) *GlobalExitRootBananaContractor { mock := &GlobalExitRootBananaContractor{} mock.Mock.Test(t) diff --git a/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go index 33bb6c91..f7aed125 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go @@ -24,6 +24,10 @@ func (_m *GlobalExitRootBananaZKEVMContractor) EXPECT() *GlobalExitRootBananaZKE func (_m *GlobalExitRootBananaZKEVMContractor) L1InfoRootMap(opts *bind.CallOpts, index uint32) ([32]byte, error) { ret := _m.Called(opts, index) + if len(ret) == 0 { + panic("no return value specified for L1InfoRootMap") + } + var r0 [32]byte var r1 error if rf, ok := ret.Get(0).(func(*bind.CallOpts, uint32) ([32]byte, error)); ok { @@ -79,6 +83,10 @@ func (_c *GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call) RunAndReturn(r func (_m *GlobalExitRootBananaZKEVMContractor) String() string { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for String") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() @@ -116,13 +124,12 @@ func (_c *GlobalExitRootBananaZKEVMContractor_String_Call) RunAndReturn(run func return _c } -type mockConstructorTestingTNewGlobalExitRootBananaZKEVMContractor interface { +// NewGlobalExitRootBananaZKEVMContractor creates a new instance of GlobalExitRootBananaZKEVMContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewGlobalExitRootBananaZKEVMContractor(t interface { mock.TestingT Cleanup(func()) -} - -// NewGlobalExitRootBananaZKEVMContractor creates a new instance of GlobalExitRootBananaZKEVMContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewGlobalExitRootBananaZKEVMContractor(t mockConstructorTestingTNewGlobalExitRootBananaZKEVMContractor) *GlobalExitRootBananaZKEVMContractor { +}) *GlobalExitRootBananaZKEVMContractor { mock := &GlobalExitRootBananaZKEVMContractor{} mock.Mock.Test(t) diff --git a/sequencesender/txbuilder/mocks_txbuilder/l1_client.go b/sequencesender/txbuilder/mocks_txbuilder/l1_client.go new file mode 100644 index 00000000..853494f9 --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/l1_client.go @@ -0,0 +1,98 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + context "context" + big "math/big" + + mock "github.com/stretchr/testify/mock" + + types "github.com/ethereum/go-ethereum/core/types" +) + +// L1Client is an autogenerated mock type for the l1Client type +type L1Client struct { + mock.Mock +} + +type L1Client_Expecter struct { + mock *mock.Mock +} + +func (_m *L1Client) EXPECT() *L1Client_Expecter { + return &L1Client_Expecter{mock: &_m.Mock} +} + +// HeaderByNumber provides a mock function with given fields: ctx, number +func (_m *L1Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { + ret := _m.Called(ctx, number) + + if len(ret) == 0 { + panic("no return value specified for HeaderByNumber") + } + + var r0 *types.Header + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Header, error)); ok { + return rf(ctx, number) + } + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *types.Header); ok { + r0 = rf(ctx, number) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Header) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { + r1 = rf(ctx, number) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// L1Client_HeaderByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HeaderByNumber' +type L1Client_HeaderByNumber_Call struct { + *mock.Call +} + +// HeaderByNumber is a helper method to define mock.On call +// - ctx context.Context +// - number *big.Int +func (_e *L1Client_Expecter) HeaderByNumber(ctx interface{}, number interface{}) *L1Client_HeaderByNumber_Call { + return &L1Client_HeaderByNumber_Call{Call: _e.mock.On("HeaderByNumber", ctx, number)} +} + +func (_c *L1Client_HeaderByNumber_Call) Run(run func(ctx context.Context, number *big.Int)) *L1Client_HeaderByNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*big.Int)) + }) + return _c +} + +func (_c *L1Client_HeaderByNumber_Call) Return(_a0 *types.Header, _a1 error) *L1Client_HeaderByNumber_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *L1Client_HeaderByNumber_Call) RunAndReturn(run func(context.Context, *big.Int) (*types.Header, error)) *L1Client_HeaderByNumber_Call { + _c.Call.Return(run) + return _c +} + +// NewL1Client creates a new instance of L1Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewL1Client(t interface { + mock.TestingT + Cleanup(func()) +}) *L1Client { + mock := &L1Client{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/l1_info_syncer.go b/sequencesender/txbuilder/mocks_txbuilder/l1_info_syncer.go new file mode 100644 index 00000000..65bf9394 --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/l1_info_syncer.go @@ -0,0 +1,96 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + context "context" + + l1infotreesync "github.com/0xPolygon/cdk/l1infotreesync" + mock "github.com/stretchr/testify/mock" +) + +// L1InfoSyncer is an autogenerated mock type for the l1InfoSyncer type +type L1InfoSyncer struct { + mock.Mock +} + +type L1InfoSyncer_Expecter struct { + mock *mock.Mock +} + +func (_m *L1InfoSyncer) EXPECT() *L1InfoSyncer_Expecter { + return &L1InfoSyncer_Expecter{mock: &_m.Mock} +} + +// GetLatestInfoUntilBlock provides a mock function with given fields: ctx, blockNum +func (_m *L1InfoSyncer) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*l1infotreesync.L1InfoTreeLeaf, error) { + ret := _m.Called(ctx, blockNum) + + if len(ret) == 0 { + panic("no return value specified for GetLatestInfoUntilBlock") + } + + var r0 *l1infotreesync.L1InfoTreeLeaf + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uint64) (*l1infotreesync.L1InfoTreeLeaf, error)); ok { + return rf(ctx, blockNum) + } + if rf, ok := ret.Get(0).(func(context.Context, uint64) *l1infotreesync.L1InfoTreeLeaf); ok { + r0 = rf(ctx, blockNum) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*l1infotreesync.L1InfoTreeLeaf) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, uint64) error); ok { + r1 = rf(ctx, blockNum) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// L1InfoSyncer_GetLatestInfoUntilBlock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLatestInfoUntilBlock' +type L1InfoSyncer_GetLatestInfoUntilBlock_Call struct { + *mock.Call +} + +// GetLatestInfoUntilBlock is a helper method to define mock.On call +// - ctx context.Context +// - blockNum uint64 +func (_e *L1InfoSyncer_Expecter) GetLatestInfoUntilBlock(ctx interface{}, blockNum interface{}) *L1InfoSyncer_GetLatestInfoUntilBlock_Call { + return &L1InfoSyncer_GetLatestInfoUntilBlock_Call{Call: _e.mock.On("GetLatestInfoUntilBlock", ctx, blockNum)} +} + +func (_c *L1InfoSyncer_GetLatestInfoUntilBlock_Call) Run(run func(ctx context.Context, blockNum uint64)) *L1InfoSyncer_GetLatestInfoUntilBlock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint64)) + }) + return _c +} + +func (_c *L1InfoSyncer_GetLatestInfoUntilBlock_Call) Return(_a0 *l1infotreesync.L1InfoTreeLeaf, _a1 error) *L1InfoSyncer_GetLatestInfoUntilBlock_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *L1InfoSyncer_GetLatestInfoUntilBlock_Call) RunAndReturn(run func(context.Context, uint64) (*l1infotreesync.L1InfoTreeLeaf, error)) *L1InfoSyncer_GetLatestInfoUntilBlock_Call { + _c.Call.Return(run) + return _c +} + +// NewL1InfoSyncer creates a new instance of L1InfoSyncer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewL1InfoSyncer(t interface { + mock.TestingT + Cleanup(func()) +}) *L1InfoSyncer { + mock := &L1InfoSyncer{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go index 65eb380d..acd82a4e 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go @@ -24,6 +24,10 @@ func (_m *RollupBananaBaseContractor) EXPECT() *RollupBananaBaseContractor_Expec func (_m *RollupBananaBaseContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { ret := _m.Called(opts) + if len(ret) == 0 { + panic("no return value specified for LastAccInputHash") + } + var r0 [32]byte var r1 error if rf, ok := ret.Get(0).(func(*bind.CallOpts) ([32]byte, error)); ok { @@ -74,13 +78,12 @@ func (_c *RollupBananaBaseContractor_LastAccInputHash_Call) RunAndReturn(run fun return _c } -type mockConstructorTestingTNewRollupBananaBaseContractor interface { +// NewRollupBananaBaseContractor creates a new instance of RollupBananaBaseContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRollupBananaBaseContractor(t interface { mock.TestingT Cleanup(func()) -} - -// NewRollupBananaBaseContractor creates a new instance of RollupBananaBaseContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewRollupBananaBaseContractor(t mockConstructorTestingTNewRollupBananaBaseContractor) *RollupBananaBaseContractor { +}) *RollupBananaBaseContractor { mock := &RollupBananaBaseContractor{} mock.Mock.Test(t) diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go index e73e7838..a59b88dd 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go @@ -30,6 +30,10 @@ func (_m *RollupBananaValidiumContractor) EXPECT() *RollupBananaValidiumContract func (_m *RollupBananaValidiumContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { ret := _m.Called(opts) + if len(ret) == 0 { + panic("no return value specified for LastAccInputHash") + } + var r0 [32]byte var r1 error if rf, ok := ret.Get(0).(func(*bind.CallOpts) ([32]byte, error)); ok { @@ -84,6 +88,10 @@ func (_c *RollupBananaValidiumContractor_LastAccInputHash_Call) RunAndReturn(run func (_m *RollupBananaValidiumContractor) SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) { ret := _m.Called(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage) + if len(ret) == 0 { + panic("no return value specified for SequenceBatchesValidium") + } + var r0 *types.Transaction var r1 error if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint32, uint64, [32]byte, common.Address, []byte) (*types.Transaction, error)); ok { @@ -140,13 +148,12 @@ func (_c *RollupBananaValidiumContractor_SequenceBatchesValidium_Call) RunAndRet return _c } -type mockConstructorTestingTNewRollupBananaValidiumContractor interface { +// NewRollupBananaValidiumContractor creates a new instance of RollupBananaValidiumContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRollupBananaValidiumContractor(t interface { mock.TestingT Cleanup(func()) -} - -// NewRollupBananaValidiumContractor creates a new instance of RollupBananaValidiumContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewRollupBananaValidiumContractor(t mockConstructorTestingTNewRollupBananaValidiumContractor) *RollupBananaValidiumContractor { +}) *RollupBananaValidiumContractor { mock := &RollupBananaValidiumContractor{} mock.Mock.Test(t) diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go index 0d33f8ba..e29e3252 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go @@ -30,6 +30,10 @@ func (_m *RollupBananaZKEVMContractor) EXPECT() *RollupBananaZKEVMContractor_Exp func (_m *RollupBananaZKEVMContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { ret := _m.Called(opts) + if len(ret) == 0 { + panic("no return value specified for LastAccInputHash") + } + var r0 [32]byte var r1 error if rf, ok := ret.Get(0).(func(*bind.CallOpts) ([32]byte, error)); ok { @@ -84,6 +88,10 @@ func (_c *RollupBananaZKEVMContractor_LastAccInputHash_Call) RunAndReturn(run fu func (_m *RollupBananaZKEVMContractor) SequenceBatches(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address) (*types.Transaction, error) { ret := _m.Called(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase) + if len(ret) == 0 { + panic("no return value specified for SequenceBatches") + } + var r0 *types.Transaction var r1 error if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint32, uint64, [32]byte, common.Address) (*types.Transaction, error)); ok { @@ -139,13 +147,12 @@ func (_c *RollupBananaZKEVMContractor_SequenceBatches_Call) RunAndReturn(run fun return _c } -type mockConstructorTestingTNewRollupBananaZKEVMContractor interface { +// NewRollupBananaZKEVMContractor creates a new instance of RollupBananaZKEVMContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRollupBananaZKEVMContractor(t interface { mock.TestingT Cleanup(func()) -} - -// NewRollupBananaZKEVMContractor creates a new instance of RollupBananaZKEVMContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewRollupBananaZKEVMContractor(t mockConstructorTestingTNewRollupBananaZKEVMContractor) *RollupBananaZKEVMContractor { +}) *RollupBananaZKEVMContractor { mock := &RollupBananaZKEVMContractor{} mock.Mock.Test(t) diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go index 60a458d3..0d94c081 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go @@ -30,6 +30,10 @@ func (_m *RollupElderberryValidiumContractor) EXPECT() *RollupElderberryValidium func (_m *RollupElderberryValidiumContractor) SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) { ret := _m.Called(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage) + if len(ret) == 0 { + panic("no return value specified for SequenceBatchesValidium") + } + var r0 *types.Transaction var r1 error if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint64, uint64, common.Address, []byte) (*types.Transaction, error)); ok { @@ -85,13 +89,12 @@ func (_c *RollupElderberryValidiumContractor_SequenceBatchesValidium_Call) RunAn return _c } -type mockConstructorTestingTNewRollupElderberryValidiumContractor interface { +// NewRollupElderberryValidiumContractor creates a new instance of RollupElderberryValidiumContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRollupElderberryValidiumContractor(t interface { mock.TestingT Cleanup(func()) -} - -// NewRollupElderberryValidiumContractor creates a new instance of RollupElderberryValidiumContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewRollupElderberryValidiumContractor(t mockConstructorTestingTNewRollupElderberryValidiumContractor) *RollupElderberryValidiumContractor { +}) *RollupElderberryValidiumContractor { mock := &RollupElderberryValidiumContractor{} mock.Mock.Test(t) diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go index b96e46e2..1ed208ab 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go @@ -30,6 +30,10 @@ func (_m *RollupElderberryZKEVMContractor) EXPECT() *RollupElderberryZKEVMContra func (_m *RollupElderberryZKEVMContractor) SequenceBatches(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address) (*types.Transaction, error) { ret := _m.Called(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase) + if len(ret) == 0 { + panic("no return value specified for SequenceBatches") + } + var r0 *types.Transaction var r1 error if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint64, uint64, common.Address) (*types.Transaction, error)); ok { @@ -84,13 +88,12 @@ func (_c *RollupElderberryZKEVMContractor_SequenceBatches_Call) RunAndReturn(run return _c } -type mockConstructorTestingTNewRollupElderberryZKEVMContractor interface { +// NewRollupElderberryZKEVMContractor creates a new instance of RollupElderberryZKEVMContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRollupElderberryZKEVMContractor(t interface { mock.TestingT Cleanup(func()) -} - -// NewRollupElderberryZKEVMContractor creates a new instance of RollupElderberryZKEVMContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewRollupElderberryZKEVMContractor(t mockConstructorTestingTNewRollupElderberryZKEVMContractor) *RollupElderberryZKEVMContractor { +}) *RollupElderberryZKEVMContractor { mock := &RollupElderberryZKEVMContractor{} mock.Mock.Test(t) diff --git a/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go index 150e9cff..846437db 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go +++ b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go @@ -35,6 +35,10 @@ func (_m *TxBuilder) EXPECT() *TxBuilder_Expecter { func (_m *TxBuilder) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*types.Transaction, error) { ret := _m.Called(ctx, sequences) + if len(ret) == 0 { + panic("no return value specified for BuildSequenceBatchesTx") + } + var r0 *types.Transaction var r1 error if rf, ok := ret.Get(0).(func(context.Context, seqsendertypes.Sequence) (*types.Transaction, error)); ok { @@ -90,6 +94,10 @@ func (_c *TxBuilder_BuildSequenceBatchesTx_Call) RunAndReturn(run func(context.C func (_m *TxBuilder) NewBatchFromL2Block(l2Block *datastream.L2Block) seqsendertypes.Batch { ret := _m.Called(l2Block) + if len(ret) == 0 { + panic("no return value specified for NewBatchFromL2Block") + } + var r0 seqsendertypes.Batch if rf, ok := ret.Get(0).(func(*datastream.L2Block) seqsendertypes.Batch); ok { r0 = rf(l2Block) @@ -130,25 +138,29 @@ func (_c *TxBuilder_NewBatchFromL2Block_Call) RunAndReturn(run func(*datastream. return _c } -// NewSequence provides a mock function with given fields: batches, coinbase -func (_m *TxBuilder) NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) { - ret := _m.Called(batches, coinbase) +// NewSequence provides a mock function with given fields: ctx, batches, coinbase +func (_m *TxBuilder) NewSequence(ctx context.Context, batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) { + ret := _m.Called(ctx, batches, coinbase) + + if len(ret) == 0 { + panic("no return value specified for NewSequence") + } var r0 seqsendertypes.Sequence var r1 error - if rf, ok := ret.Get(0).(func([]seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)); ok { - return rf(batches, coinbase) + if rf, ok := ret.Get(0).(func(context.Context, []seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)); ok { + return rf(ctx, batches, coinbase) } - if rf, ok := ret.Get(0).(func([]seqsendertypes.Batch, common.Address) seqsendertypes.Sequence); ok { - r0 = rf(batches, coinbase) + if rf, ok := ret.Get(0).(func(context.Context, []seqsendertypes.Batch, common.Address) seqsendertypes.Sequence); ok { + r0 = rf(ctx, batches, coinbase) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(seqsendertypes.Sequence) } } - if rf, ok := ret.Get(1).(func([]seqsendertypes.Batch, common.Address) error); ok { - r1 = rf(batches, coinbase) + if rf, ok := ret.Get(1).(func(context.Context, []seqsendertypes.Batch, common.Address) error); ok { + r1 = rf(ctx, batches, coinbase) } else { r1 = ret.Error(1) } @@ -162,15 +174,16 @@ type TxBuilder_NewSequence_Call struct { } // NewSequence is a helper method to define mock.On call +// - ctx context.Context // - batches []seqsendertypes.Batch // - coinbase common.Address -func (_e *TxBuilder_Expecter) NewSequence(batches interface{}, coinbase interface{}) *TxBuilder_NewSequence_Call { - return &TxBuilder_NewSequence_Call{Call: _e.mock.On("NewSequence", batches, coinbase)} +func (_e *TxBuilder_Expecter) NewSequence(ctx interface{}, batches interface{}, coinbase interface{}) *TxBuilder_NewSequence_Call { + return &TxBuilder_NewSequence_Call{Call: _e.mock.On("NewSequence", ctx, batches, coinbase)} } -func (_c *TxBuilder_NewSequence_Call) Run(run func(batches []seqsendertypes.Batch, coinbase common.Address)) *TxBuilder_NewSequence_Call { +func (_c *TxBuilder_NewSequence_Call) Run(run func(ctx context.Context, batches []seqsendertypes.Batch, coinbase common.Address)) *TxBuilder_NewSequence_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]seqsendertypes.Batch), args[1].(common.Address)) + run(args[0].(context.Context), args[1].([]seqsendertypes.Batch), args[2].(common.Address)) }) return _c } @@ -180,7 +193,7 @@ func (_c *TxBuilder_NewSequence_Call) Return(_a0 seqsendertypes.Sequence, _a1 er return _c } -func (_c *TxBuilder_NewSequence_Call) RunAndReturn(run func([]seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)) *TxBuilder_NewSequence_Call { +func (_c *TxBuilder_NewSequence_Call) RunAndReturn(run func(context.Context, []seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)) *TxBuilder_NewSequence_Call { _c.Call.Return(run) return _c } @@ -189,6 +202,10 @@ func (_c *TxBuilder_NewSequence_Call) RunAndReturn(run func([]seqsendertypes.Bat func (_m *TxBuilder) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { ret := _m.Called(ctx, sequenceBatches, l2Coinbase, batchNumber) + if len(ret) == 0 { + panic("no return value specified for NewSequenceIfWorthToSend") + } + var r0 seqsendertypes.Sequence var r1 error if rf, ok := ret.Get(0).(func(context.Context, []seqsendertypes.Batch, common.Address, uint64) (seqsendertypes.Sequence, error)); ok { @@ -246,6 +263,10 @@ func (_c *TxBuilder_NewSequenceIfWorthToSend_Call) RunAndReturn(run func(context func (_m *TxBuilder) SetCondNewSeq(cond txbuilder.CondNewSequence) txbuilder.CondNewSequence { ret := _m.Called(cond) + if len(ret) == 0 { + panic("no return value specified for SetCondNewSeq") + } + var r0 txbuilder.CondNewSequence if rf, ok := ret.Get(0).(func(txbuilder.CondNewSequence) txbuilder.CondNewSequence); ok { r0 = rf(cond) @@ -290,6 +311,10 @@ func (_c *TxBuilder_SetCondNewSeq_Call) RunAndReturn(run func(txbuilder.CondNewS func (_m *TxBuilder) String() string { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for String") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() @@ -327,13 +352,12 @@ func (_c *TxBuilder_String_Call) RunAndReturn(run func() string) *TxBuilder_Stri return _c } -type mockConstructorTestingTNewTxBuilder interface { +// NewTxBuilder creates a new instance of TxBuilder. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTxBuilder(t interface { mock.TestingT Cleanup(func()) -} - -// NewTxBuilder creates a new instance of TxBuilder. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewTxBuilder(t mockConstructorTestingTNewTxBuilder) *TxBuilder { +}) *TxBuilder { mock := &TxBuilder{} mock.Mock.Test(t) diff --git a/sequencesender/txbuilder/validium_cond_num_batches.go b/sequencesender/txbuilder/validium_cond_num_batches.go index 93755c9b..11329a06 100644 --- a/sequencesender/txbuilder/validium_cond_num_batches.go +++ b/sequencesender/txbuilder/validium_cond_num_batches.go @@ -26,7 +26,7 @@ func (c *ConditionalNewSequenceNumBatches) NewSequenceIfWorthToSend(ctx context. "sequence should be sent to L1, because MaxBatchesForL1 (%d) has been reached", c.maxBatchesForL1, ) - return txBuilder.NewSequence(sequenceBatches, l2Coinbase) + return txBuilder.NewSequence(ctx, sequenceBatches, l2Coinbase) } return nil, nil } diff --git a/sequencesender/txbuilder/validium_cond_num_batches_test.go b/sequencesender/txbuilder/validium_cond_num_batches_test.go index c449f161..0f8b275e 100644 --- a/sequencesender/txbuilder/validium_cond_num_batches_test.go +++ b/sequencesender/txbuilder/validium_cond_num_batches_test.go @@ -1,6 +1,7 @@ package txbuilder_test import ( + "context" "testing" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" @@ -15,7 +16,7 @@ func TestConditionalNumBatchesDisabled(t *testing.T) { mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) sut := txbuilder.NewConditionalNewSequenceNumBatches(0) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(context.TODO(), mockTxBuilder, nil, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } @@ -26,7 +27,7 @@ func TestConditionalNumBatchesDontFulfillCondition(t *testing.T) { sut := txbuilder.NewConditionalNewSequenceNumBatches(2) var sequenceBatches []seqsendertypes.Batch sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(context.TODO(), mockTxBuilder, sequenceBatches, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } @@ -38,8 +39,8 @@ func TestConditionalNumBatchesFulfillCondition(t *testing.T) { var sequenceBatches []seqsendertypes.Batch sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) - mockTxBuilder.EXPECT().NewSequence(mock.Anything, mock.Anything).Return(nil, nil) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) + mockTxBuilder.EXPECT().NewSequence(context.TODO(), mock.Anything, mock.Anything).Return(nil, nil) + tx, err := sut.NewSequenceIfWorthToSend(context.TODO(), mockTxBuilder, sequenceBatches, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } diff --git a/sequencesender/txbuilder/zkevm_cond_max_size.go b/sequencesender/txbuilder/zkevm_cond_max_size.go index 98267e17..5c931f8e 100644 --- a/sequencesender/txbuilder/zkevm_cond_max_size.go +++ b/sequencesender/txbuilder/zkevm_cond_max_size.go @@ -32,7 +32,7 @@ func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Con log.Debugf("maxTxSizeForL1 is %d, so is disabled", MaxTxSizeForL1Disabled) return nil, nil } - sequence, err := txBuilder.NewSequence(sequenceBatches, l2Coinbase) + sequence, err := txBuilder.NewSequence(ctx, sequenceBatches, l2Coinbase) if err != nil { return nil, err } @@ -60,7 +60,7 @@ func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Con if sequenceBatches != nil { // Handling the error gracefully, re-processing the sequence as a sanity check //sequence, err = s.newSequenceBanana(sequenceBatches, s.cfg.L2Coinbase) - sequence, err = txBuilder.NewSequence(sequenceBatches, l2Coinbase) + sequence, err = txBuilder.NewSequence(ctx, sequenceBatches, l2Coinbase) if err != nil { return nil, err } diff --git a/sequencesender/txbuilder/zkevm_cond_max_size_test.go b/sequencesender/txbuilder/zkevm_cond_max_size_test.go index 32e49eed..bc382698 100644 --- a/sequencesender/txbuilder/zkevm_cond_max_size_test.go +++ b/sequencesender/txbuilder/zkevm_cond_max_size_test.go @@ -18,7 +18,7 @@ func TestConditionalMaxSizeDisabled(t *testing.T) { mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) sut := txbuilder.NewConditionalNewSequenceMaxSize(txbuilder.MaxTxSizeForL1Disabled) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(context.TODO(), mockTxBuilder, nil, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } @@ -28,8 +28,8 @@ func TestConditionalMaxSizeTxBuilderNewSequenceReturnsNil(t *testing.T) { sut := txbuilder.NewConditionalNewSequenceMaxSize(1024) var sequenceBatches []seqsendertypes.Batch sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) - mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(nil, nil) - _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) + mockTxBuilder.EXPECT().NewSequence(context.TODO(), sequenceBatches, common.Address{}).Return(nil, nil) + _, err := sut.NewSequenceIfWorthToSend(context.TODO(), mockTxBuilder, sequenceBatches, common.Address{}) require.Error(t, err) } @@ -39,9 +39,9 @@ func TestConditionalMaxSizeTxBuilderBuildSequenceBatchesTxReturnsNil(t *testing. var sequenceBatches []seqsendertypes.Batch sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) seq := &txbuilder.ElderberrySequence{} - mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(seq, nil) + mockTxBuilder.EXPECT().NewSequence(context.TODO(), sequenceBatches, common.Address{}).Return(seq, nil) mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything).Return(nil, nil) - _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) + _, err := sut.NewSequenceIfWorthToSend(context.TODO(), mockTxBuilder, sequenceBatches, common.Address{}) require.Error(t, err) } @@ -51,12 +51,12 @@ func TestConditionalMaxSizeTxBuilderDontFulFill(t *testing.T) { var sequenceBatches []seqsendertypes.Batch sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) seq := &txbuilder.ElderberrySequence{} - mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(seq, nil) + mockTxBuilder.EXPECT().NewSequence(context.TODO(), sequenceBatches, common.Address{}).Return(seq, nil) inner := ðtypes.LegacyTx{} tx := ethtypes.NewTx(inner) mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything).Return(tx, nil) - res, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) + res, err := sut.NewSequenceIfWorthToSend(context.TODO(), mockTxBuilder, sequenceBatches, common.Address{}) require.NoError(t, err) require.Nil(t, res) @@ -69,7 +69,7 @@ func TestConditionalMaxSizeTxBuilderFulFill(t *testing.T) { ctx := context.TODO() newSeq := newTestSeq(3, 100, l2coinbase) - mockTxBuilder.EXPECT().NewSequence(newSeq.Batches(), l2coinbase).Return(newSeq, nil) + mockTxBuilder.EXPECT().NewSequence(context.TODO(), newSeq.Batches(), l2coinbase).Return(newSeq, nil) inner := ðtypes.LegacyTx{ Data: []byte{0x01, 0x02, 0x03, 0x04}, } @@ -77,7 +77,7 @@ func TestConditionalMaxSizeTxBuilderFulFill(t *testing.T) { mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, newSeq).Return(tx, nil) // The size of result Tx is 14 that is > 10, so it reduce 1 batch newSeqReduced := newTestSeq(2, 100, l2coinbase) - mockTxBuilder.EXPECT().NewSequence(newSeqReduced.Batches(), l2coinbase).Return(newSeqReduced, nil) + mockTxBuilder.EXPECT().NewSequence(context.TODO(), newSeqReduced.Batches(), l2coinbase).Return(newSeqReduced, nil) mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, newSeqReduced).Return(tx, nil) res, err := sut.NewSequenceIfWorthToSend(ctx, mockTxBuilder, newSeq.Batches(), l2coinbase) diff --git a/tree/appendonlytree.go b/tree/appendonlytree.go index 7e33d3a4..da828d0a 100644 --- a/tree/appendonlytree.go +++ b/tree/appendonlytree.go @@ -135,13 +135,14 @@ func (t *AppendOnlyTree) initLastLeftCacheAndLastDepositCount(ctx context.Contex } func (t *AppendOnlyTree) initLastIndex(tx kv.Tx) (common.Hash, error) { - ldc, root, err := t.getLastIndexAndRootWithTx(tx) + lastIndex, root, err := t.getLastIndexAndRootWithTx(tx) if err != nil { return common.Hash{}, err } - t.lastIndex = ldc + t.lastIndex = lastIndex return root, nil } + func (t *AppendOnlyTree) initLastLeftCache(tx kv.Tx, lastIndex int64, lastRoot common.Hash) error { siblings := make([]common.Hash, t.height, t.height) if lastIndex == -1 {