Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: l1infotree flaky test #182

Merged
merged 11 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions bridgesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bridgesync_test

import (
"context"
"fmt"
"math/big"
"path"
"testing"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions crates/cdk/versions.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -481,18 +480,15 @@ 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=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
38 changes: 10 additions & 28 deletions l1infotreesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func newSimulatedClient(t *testing.T) (
*verifybatchesmock.Verifybatchesmock,
) {
t.Helper()

ctx := context.Background()
client, setup := helpers.SimulatedBackend(t, nil, 0)

Expand Down Expand Up @@ -79,11 +78,11 @@ 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
helpers.RequireProcessorUpdated(t, syncer, receipt.BlockNumber.Uint64())

expectedGER, err := gerSc.GetLastGlobalExitRoot(&bind.CallOpts{Pending: false})
require.NoError(t, err)
Expand Down Expand Up @@ -118,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 < 30; 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})
Expand Down Expand Up @@ -351,24 +340,17 @@ 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)
for {
lastBlockNum, err := client.Client().BlockNumber(ctx)
require.NoError(t, err)
lb, err := client.Client().BlockNumber(ctx)
helpers.RequireProcessorUpdated(t, syncer, lastBlockNum)
time.Sleep(time.Second / 2)
lastBlockNum2, err := client.Client().BlockNumber(ctx)
require.NoError(t, err)
if lpb == lb {
syncerUpToDate = true
break
if lastBlockNum == lastBlockNum2 {
return
}
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)
}

// commitBlocks commits the specified number of blocks with the given client and waits for the specified duration after each block
Expand Down
38 changes: 19 additions & 19 deletions l1infotreesync/l1infotreesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -150,39 +150,39 @@ 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)
}

// 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)
}

// 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)
}

// 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)
}

// 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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -261,15 +261,15 @@ 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)
}

// 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)
Expand Down
Loading
Loading