From 1b42762a541837112750dbf0782a62305d423e96 Mon Sep 17 00:00:00 2001 From: Arnau Date: Tue, 12 Nov 2024 11:10:43 -0600 Subject: [PATCH 01/11] change to run gha --- crates/cdk/versions.json | 2 +- l1infotreesync/downloader_test.go | 6 ++++++ l1infotreesync/e2e_test.go | 1 - 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/cdk/versions.json b/crates/cdk/versions.json index bafbd00b..0d7f3daf 100644 --- a/crates/cdk/versions.json +++ b/crates/cdk/versions.json @@ -5,7 +5,7 @@ "cdk_validium_node_image": "0xpolygon/cdk-validium-node:0.7.0-cdk", "zkevm_bridge_proxy_image": "haproxy:3.0-bookworm", "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC1", - "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network-2", + "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network", "zkevm_contracts_image": "leovct/zkevm-contracts:v8.0.0-rc.4-fork.12", "zkevm_da_image": "0xpolygon/cdk-data-availability:0.0.10", "zkevm_node_image": "hermeznetwork/zkevm-node:v0.7.3", diff --git a/l1infotreesync/downloader_test.go b/l1infotreesync/downloader_test.go index 6007a3d6..a4885ae9 100644 --- a/l1infotreesync/downloader_test.go +++ b/l1infotreesync/downloader_test.go @@ -10,6 +10,7 @@ import ( mocks_l1infotreesync "github.com/0xPolygon/cdk/l1infotreesync/mocks" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -53,3 +54,8 @@ func TestBuildAppenderVerifiedContractAddr(t *testing.T) { _, err = buildAppender(l1Client, globalExitRoot, rollupManager, flags) require.NoError(t, err) } + +func TestFoo(t *testing.T) { + updateL1InfoTreeSignatureV1 = crypto.Keccak256Hash([]byte("VerifyBatchesTrustedAggregator(uint32,uint64,bytes32,bytes32,address)")) + require.Equal(t, "", updateL1InfoTreeSignatureV1.Hex()) +} diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index 132f563f..0ac050d6 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -36,7 +36,6 @@ func newSimulatedClient(t *testing.T) ( *verifybatchesmock.Verifybatchesmock, ) { t.Helper() - ctx := context.Background() client, setup := helpers.SimulatedBackend(t, nil, 0) From 1a3109bbb71195248bf188162d6909c8f08fead9 Mon Sep 17 00:00:00 2001 From: Arnau Date: Tue, 12 Nov 2024 11:30:47 -0600 Subject: [PATCH 02/11] better wait for processot --- l1infotreesync/downloader_test.go | 6 ------ l1infotreesync/e2e_test.go | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/l1infotreesync/downloader_test.go b/l1infotreesync/downloader_test.go index a4885ae9..6007a3d6 100644 --- a/l1infotreesync/downloader_test.go +++ b/l1infotreesync/downloader_test.go @@ -10,7 +10,6 @@ import ( mocks_l1infotreesync "github.com/0xPolygon/cdk/l1infotreesync/mocks" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -54,8 +53,3 @@ func TestBuildAppenderVerifiedContractAddr(t *testing.T) { _, err = buildAppender(l1Client, globalExitRoot, rollupManager, flags) require.NoError(t, err) } - -func TestFoo(t *testing.T) { - updateL1InfoTreeSignatureV1 = crypto.Keccak256Hash([]byte("VerifyBatchesTrustedAggregator(uint32,uint64,bytes32,bytes32,address)")) - require.Equal(t, "", updateL1InfoTreeSignatureV1.Hex()) -} diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index 0ac050d6..d8b82de3 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -78,11 +78,21 @@ func TestE2E(t *testing.T) { 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()) require.NoError(t, err) require.Equal(t, receipt.Status, types.ReceiptStatusSuccessful) + // Let the processor catch up + processorUpdated := false + for i := 0; i < 60; i++ { + lpb, err := syncer.GetLastProcessedBlock(ctx) + require.NoError(t, err) + if receipt.BlockNumber.Uint64() == lpb { + processorUpdated = true + break + } + time.Sleep(time.Millisecond * 10) + } + require.True(t, processorUpdated) expectedGER, err := gerSc.GetLastGlobalExitRoot(&bind.CallOpts{Pending: false}) require.NoError(t, err) @@ -118,7 +128,7 @@ func TestE2E(t *testing.T) { // Let the processor catch processorUpdated := false - for i := 0; i < 30; i++ { + for i := 0; i < 60; i++ { lpb, err := syncer.GetLastProcessedBlock(ctx) require.NoError(t, err) if receipt.BlockNumber.Uint64() == lpb { From f2d99e121be54a1736d750d6ba8b025573b7164b Mon Sep 17 00:00:00 2001 From: Arnau Date: Tue, 12 Nov 2024 12:05:06 -0600 Subject: [PATCH 03/11] handle context cancel --- crates/cdk/versions.json | 2 +- sync/evmdownloader.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/cdk/versions.json b/crates/cdk/versions.json index 0d7f3daf..bafbd00b 100644 --- a/crates/cdk/versions.json +++ b/crates/cdk/versions.json @@ -5,7 +5,7 @@ "cdk_validium_node_image": "0xpolygon/cdk-validium-node:0.7.0-cdk", "zkevm_bridge_proxy_image": "haproxy:3.0-bookworm", "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC1", - "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network", + "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network-2", "zkevm_contracts_image": "leovct/zkevm-contracts:v8.0.0-rc.4-fork.12", "zkevm_da_image": "0xpolygon/cdk-data-availability:0.0.10", "zkevm_node_image": "hermeznetwork/zkevm-node:v0.7.3", diff --git a/sync/evmdownloader.go b/sync/evmdownloader.go index 13539f2f..25663fe1 100644 --- a/sync/evmdownloader.go +++ b/sync/evmdownloader.go @@ -163,9 +163,13 @@ func (d *EVMDownloaderImplementation) WaitForNewBlocks( case <-ticker.C: header, err := d.ethClient.HeaderByNumber(ctx, d.blockFinality) if err != nil { - attempts++ - d.log.Error("error getting last block num from eth client: ", err) - d.rh.Handle("waitForNewBlocks", attempts) + if errors.Is(err, context.Canceled) { + attempts++ + d.log.Error("error getting last block num from eth client: ", err) + d.rh.Handle("waitForNewBlocks", attempts) + } else { + d.log.Warn("context has been canceled while trying to get header by number") + } continue } if header.Number.Uint64() > lastBlockSeen { From 44593c9a7bf335e0fa6bb32a80fabefe7aaea0d5 Mon Sep 17 00:00:00 2001 From: Arnau Date: Tue, 12 Nov 2024 12:39:55 -0600 Subject: [PATCH 04/11] handle context cancel --- sync/evmdownloader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync/evmdownloader.go b/sync/evmdownloader.go index 25663fe1..74b8ec7c 100644 --- a/sync/evmdownloader.go +++ b/sync/evmdownloader.go @@ -163,7 +163,7 @@ func (d *EVMDownloaderImplementation) WaitForNewBlocks( case <-ticker.C: header, err := d.ethClient.HeaderByNumber(ctx, d.blockFinality) if err != nil { - if errors.Is(err, context.Canceled) { + if ctx.Err() == nil { attempts++ d.log.Error("error getting last block num from eth client: ", err) d.rh.Handle("waitForNewBlocks", attempts) From 10792e78cef026509292c290623ff9f94a3b9281 Mon Sep 17 00:00:00 2001 From: Arnau Date: Tue, 12 Nov 2024 13:29:20 -0600 Subject: [PATCH 05/11] add mutex to halt --- l1infotreesync/l1infotreesync.go | 38 ++++++++++++++++---------------- l1infotreesync/processor.go | 15 +++++++++++++ 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/l1infotreesync/l1infotreesync.go b/l1infotreesync/l1infotreesync.go index 9719fcd7..e6262ffb 100644 --- a/l1infotreesync/l1infotreesync.go +++ b/l1infotreesync/l1infotreesync.go @@ -106,7 +106,7 @@ func (s *L1InfoTreeSync) Start(ctx context.Context) { // GetL1InfoTreeMerkleProof creates a merkle proof for the L1 Info tree func (s *L1InfoTreeSync) GetL1InfoTreeMerkleProof(ctx context.Context, index uint32) (types.Proof, types.Root, error) { - if s.processor.halted { + if s.processor.isHalted() { return types.Proof{}, types.Root{}, sync.ErrInconsistentState } return s.processor.GetL1InfoTreeMerkleProof(ctx, index) @@ -118,7 +118,7 @@ func (s *L1InfoTreeSync) GetRollupExitTreeMerkleProof( networkID uint32, root common.Hash, ) (types.Proof, error) { - if s.processor.halted { + if s.processor.isHalted() { return types.Proof{}, sync.ErrInconsistentState } if networkID == 0 { @@ -141,7 +141,7 @@ func translateError(err error) error { // - ErrBlockNotProcessed, // - ErrNotFound func (s *L1InfoTreeSync) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*L1InfoTreeLeaf, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } leaf, err := s.processor.GetLatestInfoUntilBlock(ctx, blockNum) @@ -150,7 +150,7 @@ func (s *L1InfoTreeSync) GetLatestInfoUntilBlock(ctx context.Context, blockNum u // GetInfoByIndex returns the value of a leaf (not the hash) of the L1 info tree func (s *L1InfoTreeSync) GetInfoByIndex(ctx context.Context, index uint32) (*L1InfoTreeLeaf, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } return s.processor.GetInfoByIndex(ctx, index) @@ -158,7 +158,7 @@ func (s *L1InfoTreeSync) GetInfoByIndex(ctx context.Context, index uint32) (*L1I // GetL1InfoTreeRootByIndex returns the root of the L1 info tree at the moment the leaf with the given index was added func (s *L1InfoTreeSync) GetL1InfoTreeRootByIndex(ctx context.Context, index uint32) (types.Root, error) { - if s.processor.halted { + if s.processor.isHalted() { return types.Root{}, sync.ErrInconsistentState } return s.processor.l1InfoTree.GetRootByIndex(ctx, index) @@ -166,7 +166,7 @@ func (s *L1InfoTreeSync) GetL1InfoTreeRootByIndex(ctx context.Context, index uin // GetLastRollupExitRoot return the last rollup exit root processed func (s *L1InfoTreeSync) GetLastRollupExitRoot(ctx context.Context) (types.Root, error) { - if s.processor.halted { + if s.processor.isHalted() { return types.Root{}, sync.ErrInconsistentState } return s.processor.rollupExitTree.GetLastRoot(nil) @@ -174,7 +174,7 @@ func (s *L1InfoTreeSync) GetLastRollupExitRoot(ctx context.Context) (types.Root, // GetLastL1InfoTreeRoot return the last root and index processed from the L1 Info tree func (s *L1InfoTreeSync) GetLastL1InfoTreeRoot(ctx context.Context) (types.Root, error) { - if s.processor.halted { + if s.processor.isHalted() { return types.Root{}, sync.ErrInconsistentState } return s.processor.l1InfoTree.GetLastRoot(nil) @@ -182,7 +182,7 @@ func (s *L1InfoTreeSync) GetLastL1InfoTreeRoot(ctx context.Context) (types.Root, // GetLastProcessedBlock return the last processed block func (s *L1InfoTreeSync) GetLastProcessedBlock(ctx context.Context) (uint64, error) { - if s.processor.halted { + if s.processor.isHalted() { return 0, sync.ErrInconsistentState } return s.processor.GetLastProcessedBlock(ctx) @@ -191,7 +191,7 @@ func (s *L1InfoTreeSync) GetLastProcessedBlock(ctx context.Context) (uint64, err func (s *L1InfoTreeSync) GetLocalExitRoot( ctx context.Context, networkID uint32, rollupExitRoot common.Hash, ) (common.Hash, error) { - if s.processor.halted { + if s.processor.isHalted() { return common.Hash{}, sync.ErrInconsistentState } if networkID == 0 { @@ -202,56 +202,56 @@ func (s *L1InfoTreeSync) GetLocalExitRoot( } func (s *L1InfoTreeSync) GetLastVerifiedBatches(rollupID uint32) (*VerifyBatches, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } return s.processor.GetLastVerifiedBatches(rollupID) } func (s *L1InfoTreeSync) GetFirstVerifiedBatches(rollupID uint32) (*VerifyBatches, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } return s.processor.GetFirstVerifiedBatches(rollupID) } func (s *L1InfoTreeSync) GetFirstVerifiedBatchesAfterBlock(rollupID uint32, blockNum uint64) (*VerifyBatches, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } return s.processor.GetFirstVerifiedBatchesAfterBlock(rollupID, blockNum) } func (s *L1InfoTreeSync) GetFirstL1InfoWithRollupExitRoot(rollupExitRoot common.Hash) (*L1InfoTreeLeaf, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } return s.processor.GetFirstL1InfoWithRollupExitRoot(rollupExitRoot) } func (s *L1InfoTreeSync) GetLastInfo() (*L1InfoTreeLeaf, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } return s.processor.GetLastInfo() } func (s *L1InfoTreeSync) GetFirstInfo() (*L1InfoTreeLeaf, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } return s.processor.GetFirstInfo() } func (s *L1InfoTreeSync) GetFirstInfoAfterBlock(blockNum uint64) (*L1InfoTreeLeaf, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } return s.processor.GetFirstInfoAfterBlock(blockNum) } func (s *L1InfoTreeSync) GetInfoByGlobalExitRoot(ger common.Hash) (*L1InfoTreeLeaf, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } return s.processor.GetInfoByGlobalExitRoot(ger) @@ -261,7 +261,7 @@ func (s *L1InfoTreeSync) GetInfoByGlobalExitRoot(ger common.Hash) (*L1InfoTreeLe func (s *L1InfoTreeSync) GetL1InfoTreeMerkleProofFromIndexToRoot( ctx context.Context, index uint32, root common.Hash, ) (types.Proof, error) { - if s.processor.halted { + if s.processor.isHalted() { return types.Proof{}, sync.ErrInconsistentState } return s.processor.l1InfoTree.GetProof(ctx, index, root) @@ -269,7 +269,7 @@ func (s *L1InfoTreeSync) GetL1InfoTreeMerkleProofFromIndexToRoot( // GetInitL1InfoRootMap returns the initial L1 info root map, nil if no root map has been set func (s *L1InfoTreeSync) GetInitL1InfoRootMap(ctx context.Context) (*L1InfoTreeInitial, error) { - if s.processor.halted { + if s.processor.isHalted() { return nil, sync.ErrInconsistentState } return s.processor.GetInitL1InfoRootMap(nil) diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index ee94e829..5b84ff69 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -6,6 +6,7 @@ import ( "encoding/binary" "errors" "fmt" + mutex "sync" "github.com/0xPolygon/cdk/db" "github.com/0xPolygon/cdk/l1infotreesync/migrations" @@ -28,6 +29,7 @@ type processor struct { db *sql.DB l1InfoTree *tree.AppendOnlyTree rollupExitTree *tree.UpdatableTree + mu mutex.RWMutex halted bool haltedReason string } @@ -267,6 +269,8 @@ func (p *processor) Reorg(ctx context.Context, firstReorgedBlock uint64) error { return err } if rowsAffected > 0 { + p.mu.Lock() + defer p.mu.Unlock() p.halted = false p.haltedReason = "" } @@ -277,10 +281,13 @@ func (p *processor) Reorg(ctx context.Context, firstReorgedBlock uint64) error { // ProcessBlock process the events of the block to build the rollup exit tree and the l1 info tree // and updates the last processed block (can be called without events for that purpose) func (p *processor) ProcessBlock(ctx context.Context, block sync.Block) error { + p.mu.RLock() if p.halted { log.Errorf("processor is halted due to: %s", p.haltedReason) + p.mu.RUnlock() return sync.ErrInconsistentState } + p.mu.RUnlock() tx, err := db.NewTx(ctx, p.db) if err != nil { return err @@ -361,8 +368,10 @@ func (p *processor) ProcessBlock(ctx context.Context, block sync.Block) error { block.Num, ) log.Error(errStr) + p.mu.Lock() p.haltedReason = errStr p.halted = true + p.mu.Unlock() return sync.ErrInconsistentState } } @@ -464,3 +473,9 @@ func (p *processor) getDBQuerier(tx db.Txer) db.Querier { } return p.db } + +func (p *processor) isHalted() bool { + p.mu.RLock() + p.mu.RUnlock() + return p.halted +} From 2080ef0cd7d32ad03d7046f0fec5032cd323becc Mon Sep 17 00:00:00 2001 From: Arnau Date: Tue, 12 Nov 2024 14:52:26 -0600 Subject: [PATCH 06/11] add mutex to halt --- reorgdetector/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reorgdetector/types.go b/reorgdetector/types.go index 20d4562c..2c860277 100644 --- a/reorgdetector/types.go +++ b/reorgdetector/types.go @@ -93,9 +93,9 @@ func (hl *headersList) get(num uint64) *header { // getSorted returns headers in sorted order func (hl *headersList) getSorted() []header { + hl.RLock() sortedBlocks := make([]header, 0, len(hl.headers)) - hl.RLock() for _, b := range hl.headers { sortedBlocks = append(sortedBlocks, b) } From cddbe8a7196eb8ad282201170fefb1727fba71c8 Mon Sep 17 00:00:00 2001 From: Arnau Date: Wed, 13 Nov 2024 08:14:24 -0600 Subject: [PATCH 07/11] better wait --- bridgesync/e2e_test.go | 19 +--------------- crates/cdk/versions.json | 6 ++--- go.mod | 1 - go.sum | 11 ++-------- l1infotreesync/e2e_test.go | 45 +++++--------------------------------- lastgersync/e2e_test.go | 20 ++++------------- test/helpers/wait.go | 27 +++++++++++++++++++++++ 7 files changed, 42 insertions(+), 87 deletions(-) create mode 100644 test/helpers/wait.go diff --git a/bridgesync/e2e_test.go b/bridgesync/e2e_test.go index 6f1e10c4..0b350006 100644 --- a/bridgesync/e2e_test.go +++ b/bridgesync/e2e_test.go @@ -2,7 +2,6 @@ package bridgesync_test import ( "context" - "fmt" "math/big" "path" "testing" @@ -63,25 +62,9 @@ func TestBridgeEventE2E(t *testing.T) { } // Wait for syncer to catch up - syncerUpToDate := false - - var errMsg string lb, err := client.Client().BlockNumber(ctx) require.NoError(t, err) - - for i := 0; i < 10; i++ { - lpb, err := syncer.GetLastProcessedBlock(ctx) - require.NoError(t, err) - if lpb == lb { - syncerUpToDate = true - - break - } - - time.Sleep(time.Millisecond * 100) - errMsg = fmt.Sprintf("last block from client: %d, last block from syncer: %d", lb, lpb) - } - require.True(t, syncerUpToDate, errMsg) + helpers.RequireProcessorUpdated(t, syncer, lb) // Get bridges lastBlock, err := client.Client().BlockNumber(ctx) diff --git a/crates/cdk/versions.json b/crates/cdk/versions.json index bafbd00b..39bfb4dc 100644 --- a/crates/cdk/versions.json +++ b/crates/cdk/versions.json @@ -1,15 +1,15 @@ { "agglayer_image": "ghcr.io/agglayer/agglayer:0.2.0-rc.5", "cdk_erigon_node_image": "hermeznetwork/cdk-erigon:v2.1.2", - "cdk_node_image": "ghcr.io/0xpolygon/cdk:0.4.0-beta5", + "cdk_node_image": "ghcr.io/0xpolygon/cdk:0.4.0-beta8", "cdk_validium_node_image": "0xpolygon/cdk-validium-node:0.7.0-cdk", "zkevm_bridge_proxy_image": "haproxy:3.0-bookworm", "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC1", - "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network-2", + "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network", "zkevm_contracts_image": "leovct/zkevm-contracts:v8.0.0-rc.4-fork.12", "zkevm_da_image": "0xpolygon/cdk-data-availability:0.0.10", "zkevm_node_image": "hermeznetwork/zkevm-node:v0.7.3", - "zkevm_pool_manager_image": "hermeznetwork/zkevm-pool-manager:v0.1.1", + "zkevm_pool_manager_image": "hermeznetwork/zkevm-pool-manager:v0.1.2", "zkevm_prover_image": "hermeznetwork/zkevm-prover:v8.0.0-RC14-fork.12", "zkevm_sequence_sender_image": "hermeznetwork/zkevm-sequence-sender:v0.2.4" } diff --git a/go.mod b/go.mod index 430e8326..c42bb806 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,6 @@ require ( ) require ( - github.com/0xPolygonHermez/zkevm-data-streamer v0.2.7 // indirect github.com/DataDog/zstd v1.5.6 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/StackExchange/wmi v1.2.1 // indirect diff --git a/go.sum b/go.sum index 3ad80938..d6cbdb2b 100644 --- a/go.sum +++ b/go.sum @@ -6,7 +6,6 @@ github.com/0xPolygon/cdk-rpc v0.0.0-20241004114257-6c3cb6eebfb6 h1:FXL/rcO7/GtZ3 github.com/0xPolygon/cdk-rpc v0.0.0-20241004114257-6c3cb6eebfb6/go.mod h1:2scWqMMufrQXu7TikDgQ3BsyaKoX8qP26D6E262vSOg= github.com/0xPolygon/zkevm-ethtx-manager v0.2.1 h1:2Yb+KdJFMpVrS9LIkd658XiWuN+MCTs7SgeWaopXScg= github.com/0xPolygon/zkevm-ethtx-manager v0.2.1/go.mod h1:lqQmzSo2OXEZItD0R4Cd+lqKFxphXEWgqHefVcGDZZc= -github.com/0xPolygonHermez/zkevm-data-streamer v0.2.7/go.mod h1:7nM7Ihk+fTG1TQPwdZoGOYd3wprqqyIyjtS514uHzWE= github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.5 h1:YmnhuCl349MoNASN0fMeGKU1o9HqJhiZkfMsA/1cTRA= github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.5/go.mod h1:X4Su/M/+hSISqdl9yomKlRsbTyuZHsRohporyHsP8gg= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -481,8 +480,6 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= -golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= -golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo= golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -490,9 +487,8 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= -golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -512,8 +508,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -575,9 +569,8 @@ golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= -golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o= +golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index d8b82de3..719a79fa 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -82,17 +82,7 @@ func TestE2E(t *testing.T) { require.NoError(t, err) require.Equal(t, receipt.Status, types.ReceiptStatusSuccessful) // Let the processor catch up - processorUpdated := false - for i := 0; i < 60; i++ { - lpb, err := syncer.GetLastProcessedBlock(ctx) - require.NoError(t, err) - if receipt.BlockNumber.Uint64() == lpb { - processorUpdated = true - break - } - time.Sleep(time.Millisecond * 10) - } - require.True(t, processorUpdated) + helpers.RequireProcessorUpdated(t, syncer, receipt.BlockNumber.Uint64()) expectedGER, err := gerSc.GetLastGlobalExitRoot(&bind.CallOpts{Pending: false}) require.NoError(t, err) @@ -127,17 +117,7 @@ func TestE2E(t *testing.T) { require.True(t, len(receipt.Logs) == 1+i%2+i%2) // Let the processor catch - processorUpdated := false - for i := 0; i < 60; i++ { - lpb, err := syncer.GetLastProcessedBlock(ctx) - require.NoError(t, err) - if receipt.BlockNumber.Uint64() == lpb { - processorUpdated = true - break - } - time.Sleep(time.Millisecond * 10) - } - require.True(t, processorUpdated) + helpers.RequireProcessorUpdated(t, syncer, receipt.BlockNumber.Uint64()) // Assert rollup exit root expectedRollupExitRoot, err := verifySC.GetRollupExitRoot(&bind.CallOpts{Pending: false}) @@ -360,24 +340,9 @@ func TestStressAndReorgs(t *testing.T) { func waitForSyncerToCatchUp(ctx context.Context, t *testing.T, syncer *l1infotreesync.L1InfoTreeSync, client *simulated.Backend) { t.Helper() - - syncerUpToDate := false - var errMsg string - - for i := 0; i < 200; i++ { - lpb, err := syncer.GetLastProcessedBlock(ctx) - require.NoError(t, err) - lb, err := client.Client().BlockNumber(ctx) - require.NoError(t, err) - if lpb == lb { - syncerUpToDate = true - break - } - time.Sleep(time.Second / 2) - errMsg = fmt.Sprintf("last block from client: %d, last block from syncer: %d", lb, lpb) - } - - require.True(t, syncerUpToDate, errMsg) + lastBlockNum, err := client.Client().BlockNumber(ctx) + require.NoError(t, err) + helpers.RequireProcessorUpdated(t, syncer, lastBlockNum) } // commitBlocks commits the specified number of blocks with the given client and waits for the specified duration after each block diff --git a/lastgersync/e2e_test.go b/lastgersync/e2e_test.go index 9b9a6f36..6f62f12d 100644 --- a/lastgersync/e2e_test.go +++ b/lastgersync/e2e_test.go @@ -11,6 +11,7 @@ import ( "github.com/0xPolygon/cdk/etherman" "github.com/0xPolygon/cdk/lastgersync" "github.com/0xPolygon/cdk/test/aggoraclehelpers" + "github.com/0xPolygon/cdk/test/helpers" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" @@ -49,22 +50,9 @@ func TestE2E(t *testing.T) { require.True(t, isInjected, fmt.Sprintf("iteration %d, GER: %s", i, common.Bytes2Hex(expectedGER[:]))) // Wait for syncer to catch up - syncerUpToDate := false - var errMsg string - for i := 0; i < 10; i++ { - lpb, err := syncer.GetLastProcessedBlock(ctx) - require.NoError(t, err) - lb, err := env.L2Client.Client().BlockNumber(ctx) - require.NoError(t, err) - if lpb == lb { - syncerUpToDate = true - - break - } - time.Sleep(time.Millisecond * 100) - errMsg = fmt.Sprintf("last block from client: %d, last block from syncer: %d", lb, lpb) - } - require.True(t, syncerUpToDate, errMsg) + lb, err := env.L2Client.Client().BlockNumber(ctx) + require.NoError(t, err) + helpers.RequireProcessorUpdated(t, syncer, lb) e, err := syncer.GetFirstGERAfterL1InfoTreeIndex(ctx, uint32(i)) require.NoError(t, err, fmt.Sprint("iteration: ", i)) diff --git a/test/helpers/wait.go b/test/helpers/wait.go new file mode 100644 index 00000000..85a947a2 --- /dev/null +++ b/test/helpers/wait.go @@ -0,0 +1,27 @@ +package helpers + +import ( + "context" + "errors" + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +type Processorer interface { + GetLastProcessedBlock(ctx context.Context) (uint64, error) +} + +func RequireProcessorUpdated(t *testing.T, processor Processorer, targetBlock uint64) { + ctx := context.Background() + for i := 0; i < 100; i++ { + lpb, err := processor.GetLastProcessedBlock(ctx) + require.NoError(t, err) + if targetBlock <= lpb { + return + } + time.Sleep(time.Millisecond * 10) + } + require.NoError(t, errors.New("processor not updated")) +} From 3d2fbe5151770fc24418e79b14d1624b6edde9fc Mon Sep 17 00:00:00 2001 From: Arnau Date: Wed, 13 Nov 2024 08:17:27 -0600 Subject: [PATCH 08/11] better mutex for halted --- l1infotreesync/processor.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index 5b84ff69..ac58fb5c 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -281,13 +281,10 @@ func (p *processor) Reorg(ctx context.Context, firstReorgedBlock uint64) error { // ProcessBlock process the events of the block to build the rollup exit tree and the l1 info tree // and updates the last processed block (can be called without events for that purpose) func (p *processor) ProcessBlock(ctx context.Context, block sync.Block) error { - p.mu.RLock() - if p.halted { + if p.isHalted() { log.Errorf("processor is halted due to: %s", p.haltedReason) - p.mu.RUnlock() return sync.ErrInconsistentState } - p.mu.RUnlock() tx, err := db.NewTx(ctx, p.db) if err != nil { return err @@ -476,6 +473,6 @@ func (p *processor) getDBQuerier(tx db.Txer) db.Querier { func (p *processor) isHalted() bool { p.mu.RLock() - p.mu.RUnlock() + defer p.mu.RUnlock() return p.halted } From ce0b8510030777ff2e50a5ca4d29c03f708a911a Mon Sep 17 00:00:00 2001 From: Arnau Date: Wed, 13 Nov 2024 11:05:24 -0600 Subject: [PATCH 09/11] lint --- l1infotreesync/e2e_test.go | 2 +- test/helpers/wait.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index 719a79fa..ece2de0d 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -312,7 +312,7 @@ func TestStressAndReorgs(t *testing.T) { } } - commitBlocks(t, client, 1, time.Millisecond*10) + commitBlocks(t, client, 2, time.Millisecond*10) waitForSyncerToCatchUp(ctx, t, syncer, client) diff --git a/test/helpers/wait.go b/test/helpers/wait.go index 85a947a2..86a6f9fb 100644 --- a/test/helpers/wait.go +++ b/test/helpers/wait.go @@ -14,14 +14,19 @@ type Processorer interface { } func RequireProcessorUpdated(t *testing.T, processor Processorer, targetBlock uint64) { + t.Helper() + const ( + maxIterations = 100 + sleepTimePerIteration = time.Millisecond * 10 + ) ctx := context.Background() - for i := 0; i < 100; i++ { + for i := 0; i < maxIterations; i++ { lpb, err := processor.GetLastProcessedBlock(ctx) require.NoError(t, err) if targetBlock <= lpb { return } - time.Sleep(time.Millisecond * 10) + time.Sleep(sleepTimePerIteration) } require.NoError(t, errors.New("processor not updated")) } From c9950df5516efb2c4fa823fa56c7286cc745102f Mon Sep 17 00:00:00 2001 From: Arnau Date: Wed, 13 Nov 2024 11:41:01 -0600 Subject: [PATCH 10/11] fix wait --- l1infotreesync/e2e_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index ece2de0d..be683e25 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -312,7 +312,7 @@ func TestStressAndReorgs(t *testing.T) { } } - commitBlocks(t, client, 2, time.Millisecond*10) + commitBlocks(t, client, 1, time.Millisecond*10) waitForSyncerToCatchUp(ctx, t, syncer, client) @@ -340,9 +340,17 @@ func TestStressAndReorgs(t *testing.T) { func waitForSyncerToCatchUp(ctx context.Context, t *testing.T, syncer *l1infotreesync.L1InfoTreeSync, client *simulated.Backend) { t.Helper() - lastBlockNum, err := client.Client().BlockNumber(ctx) - require.NoError(t, err) - helpers.RequireProcessorUpdated(t, syncer, lastBlockNum) + for { + lastBlockNum, err := client.Client().BlockNumber(ctx) + require.NoError(t, err) + helpers.RequireProcessorUpdated(t, syncer, lastBlockNum) + lastBlockNum2, err := client.Client().BlockNumber(ctx) + require.NoError(t, err) + time.Sleep(time.Second / 2) + if lastBlockNum == lastBlockNum2 { + return + } + } } // commitBlocks commits the specified number of blocks with the given client and waits for the specified duration after each block From 0dc616352421d1f2278e628df44ed3616b0ee47e Mon Sep 17 00:00:00 2001 From: Arnau Date: Wed, 13 Nov 2024 11:41:27 -0600 Subject: [PATCH 11/11] fix wait --- l1infotreesync/e2e_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index be683e25..ffb00e35 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -344,9 +344,9 @@ func waitForSyncerToCatchUp(ctx context.Context, t *testing.T, syncer *l1infotre lastBlockNum, err := client.Client().BlockNumber(ctx) require.NoError(t, err) helpers.RequireProcessorUpdated(t, syncer, lastBlockNum) + time.Sleep(time.Second / 2) lastBlockNum2, err := client.Client().BlockNumber(ctx) require.NoError(t, err) - time.Sleep(time.Second / 2) if lastBlockNum == lastBlockNum2 { return }