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: reorg detector and syncer issues v0.4.2 #271

Merged
merged 6 commits into from
Jan 23, 2025
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
1 change: 0 additions & 1 deletion aggsender/aggsender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func TestConfigString(t *testing.T) {
"BlockGetInterval: 10s\n" +
"CheckSettledInterval: 20s\n" +
"AggsenderPrivateKeyPath: /path/to/key\n" +
"AggsenderPrivateKeyPassword: password\n" +
"URLRPCL2: http://l2.rpc.url\n" +
"BlockFinality: latestBlock\n" +
"EpochNotificationPercentage: 50\n" +
Expand Down
1 change: 0 additions & 1 deletion aggsender/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (c Config) String() string {
"BlockGetInterval: " + c.BlockGetInterval.String() + "\n" +
"CheckSettledInterval: " + c.CheckSettledInterval.String() + "\n" +
"AggsenderPrivateKeyPath: " + c.AggsenderPrivateKey.Path + "\n" +
"AggsenderPrivateKeyPassword: " + c.AggsenderPrivateKey.Password + "\n" +
"URLRPCL2: " + c.URLRPCL2 + "\n" +
"BlockFinality: " + c.BlockFinality + "\n" +
"EpochNotificationPercentage: " + fmt.Sprintf("%d", c.EpochNotificationPercentage) + "\n" +
Expand Down
6 changes: 6 additions & 0 deletions bridgesync/bridgesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func NewL1(
retryAfterErrorPeriod time.Duration,
maxRetryAttemptsAfterError int,
originNetwork uint32,
finalizedBlockType etherman.BlockNumberFinality,
) (*BridgeSync, error) {
return newBridgeSync(
ctx,
Expand All @@ -59,6 +60,7 @@ func NewL1(
maxRetryAttemptsAfterError,
originNetwork,
false,
finalizedBlockType,
)
}

Expand All @@ -76,6 +78,7 @@ func NewL2(
retryAfterErrorPeriod time.Duration,
maxRetryAttemptsAfterError int,
originNetwork uint32,
finalizedBlockType etherman.BlockNumberFinality,
) (*BridgeSync, error) {
return newBridgeSync(
ctx,
Expand All @@ -92,6 +95,7 @@ func NewL2(
maxRetryAttemptsAfterError,
originNetwork,
true,
finalizedBlockType,
)
}

Expand All @@ -110,6 +114,7 @@ func newBridgeSync(
maxRetryAttemptsAfterError int,
originNetwork uint32,
syncFullClaims bool,
finalizedBlockType etherman.BlockNumberFinality,
) (*BridgeSync, error) {
processor, err := newProcessor(dbPath, l1OrL2ID)
if err != nil {
Expand Down Expand Up @@ -147,6 +152,7 @@ func newBridgeSync(
appender,
[]common.Address{bridge},
rh,
finalizedBlockType,
)
if err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions bridgesync/bridgesync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestNewLx(t *testing.T) {
retryAfterErrorPeriod,
maxRetryAttemptsAfterError,
originNetwork,
blockFinalityType,
)

assert.NoError(t, err)
Expand All @@ -72,6 +73,7 @@ func TestNewLx(t *testing.T) {
retryAfterErrorPeriod,
maxRetryAttemptsAfterError,
originNetwork,
blockFinalityType,
)

assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion bridgesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestBridgeEventE2E(t *testing.T) {
go rd.Start(ctx) //nolint:errcheck

testClient := helpers.TestClient{ClientRenamed: client.Client()}
syncer, err := bridgesync.NewL1(ctx, dbPathSyncer, setup.EBZkevmBridgeAddr, 10, etherman.LatestBlock, rd, testClient, 0, time.Millisecond*10, 0, 0, 1)
syncer, err := bridgesync.NewL1(ctx, dbPathSyncer, setup.EBZkevmBridgeAddr, 10, etherman.LatestBlock, rd, testClient, 0, time.Millisecond*10, 0, 0, 1, etherman.SafeBlock)
require.NoError(t, err)

go syncer.Start(ctx)
Expand Down
2 changes: 1 addition & 1 deletion claimsponsor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestE2EL1toEVML2(t *testing.T) {
env := aggoraclehelpers.SetupAggoracleWithEVMChain(t)
dbPathBridgeSyncL1 := path.Join(t.TempDir(), "file::memory:?cache=shared")
testClient := helpers.TestClient{ClientRenamed: env.L1Client.Client()}
bridgeSyncL1, err := bridgesync.NewL1(ctx, dbPathBridgeSyncL1, env.BridgeL1Addr, 10, etherman.LatestBlock, env.ReorgDetector, testClient, 0, time.Millisecond*10, 0, 0, 1)
bridgeSyncL1, err := bridgesync.NewL1(ctx, dbPathBridgeSyncL1, env.BridgeL1Addr, 10, etherman.LatestBlock, env.ReorgDetector, testClient, 0, time.Millisecond*10, 0, 0, 1, etherman.SafeBlock)
require.NoError(t, err)
go bridgeSyncL1.Start(ctx)

Expand Down
3 changes: 3 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ func runL1InfoTreeSyncerIfNeeded(
cfg.L1InfoTreeSync.RetryAfterErrorPeriod.Duration,
cfg.L1InfoTreeSync.MaxRetryAttemptsAfterError,
l1infotreesync.FlagNone,
etherman.FinalizedBlock,
)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -731,6 +732,7 @@ func runBridgeSyncL1IfNeeded(
cfg.RetryAfterErrorPeriod.Duration,
cfg.MaxRetryAttemptsAfterError,
cfg.OriginNetwork,
etherman.FinalizedBlock,
)
if err != nil {
log.Fatalf("error creating bridgeSyncL1: %s", err)
Expand Down Expand Up @@ -764,6 +766,7 @@ func runBridgeSyncL2IfNeeded(
cfg.RetryAfterErrorPeriod.Duration,
cfg.MaxRetryAttemptsAfterError,
cfg.OriginNetwork,
etherman.LatestBlock,
)
if err != nil {
log.Fatalf("error creating bridgeSyncL2: %s", err)
Expand Down
4 changes: 4 additions & 0 deletions etherman/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const (
EarliestBlock = BlockNumberFinality("EarliestBlock")
)

func (b BlockNumberFinality) IsFinalized() bool {
return b == FinalizedBlock
}

func (b *BlockNumberFinality) ToBlockNum() (*big.Int, error) {
switch *b {
case FinalizedBlock:
Expand Down
18 changes: 8 additions & 10 deletions l1infotreesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func TestE2E(t *testing.T) {
rdm.On("AddBlockToTrack", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)

client, auth, gerAddr, verifyAddr, gerSc, verifySC := newSimulatedClient(t)
syncer, err := l1infotreesync.New(ctx, dbPath, gerAddr, verifyAddr, 10, etherman.LatestBlock, rdm, client.Client(), time.Millisecond, 0, 100*time.Millisecond, 3,
l1infotreesync.FlagAllowWrongContractsAddrs)
syncer, err := l1infotreesync.New(ctx, dbPath, gerAddr, verifyAddr, 10, etherman.LatestBlock, rdm, client.Client(), time.Millisecond, 0, 100*time.Millisecond, 25,
l1infotreesync.FlagAllowWrongContractsAddrs, etherman.SafeBlock)
require.NoError(t, err)

go syncer.Start(ctx)
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestWithReorgs(t *testing.T) {
require.NoError(t, rd.Start(ctx))

syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerAddr, verifyAddr, 10, etherman.LatestBlock, rd, client.Client(), time.Millisecond, 0, time.Second, 25,
l1infotreesync.FlagAllowWrongContractsAddrs)
l1infotreesync.FlagAllowWrongContractsAddrs, etherman.SafeBlock)
require.NoError(t, err)
go syncer.Start(ctx)

Expand Down Expand Up @@ -228,9 +228,6 @@ func TestWithReorgs(t *testing.T) {
// Block 4, 5, 6 after the fork
commitBlocks(t, client, 3, time.Millisecond*500)

// Make sure syncer is up to date
waitForSyncerToCatchUp(ctx, t, syncer, client)

// Assert rollup exit root after the fork - should be zero since there are no events in the block after the fork
expectedRollupExitRoot, err = verifySC.GetRollupExitRoot(&bind.CallOpts{Pending: false})
require.NoError(t, err)
Expand All @@ -244,11 +241,12 @@ func TestWithReorgs(t *testing.T) {
require.NoError(t, err)
time.Sleep(time.Millisecond * 500)

commitBlocks(t, client, 1, time.Millisecond*100)

// create some events and update the trees
updateL1InfoTreeAndRollupExitTree(2, 1)

// Block 4, 5, 6, 7 after the fork
commitBlocks(t, client, 4, time.Millisecond*100)
commitBlocks(t, client, 1, time.Millisecond*100)

// Make sure syncer is up to date
waitForSyncerToCatchUp(ctx, t, syncer, client)
Expand Down Expand Up @@ -283,7 +281,7 @@ func TestStressAndReorgs(t *testing.T) {
require.NoError(t, rd.Start(ctx))

syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerAddr, verifyAddr, 10, etherman.LatestBlock, rd, client.Client(), time.Millisecond, 0, time.Second, 100,
l1infotreesync.FlagAllowWrongContractsAddrs)
l1infotreesync.FlagAllowWrongContractsAddrs, etherman.SafeBlock)
require.NoError(t, err)
go syncer.Start(ctx)

Expand Down Expand Up @@ -323,7 +321,7 @@ func TestStressAndReorgs(t *testing.T) {
}
}

commitBlocks(t, client, 1, time.Millisecond*10)
commitBlocks(t, client, 11, time.Millisecond*10)

waitForSyncerToCatchUp(ctx, t, syncer, client)

Expand Down
2 changes: 2 additions & 0 deletions l1infotreesync/l1infotreesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func New(
retryAfterErrorPeriod time.Duration,
maxRetryAttemptsAfterError int,
flags CreationFlags,
finalizedBlockType etherman.BlockNumberFinality,
) (*L1InfoTreeSync, error) {
processor, err := newProcessor(dbPath)
if err != nil {
Expand Down Expand Up @@ -83,6 +84,7 @@ func New(
appender,
[]common.Address{globalExitRoot, rollupManager},
rh,
finalizedBlockType,
)
if err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions l1infotreesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ func (p *processor) Reorg(ctx context.Context, firstReorgedBlock uint64) error {
p.halted = false
p.haltedReason = ""
}

shouldRollback = false

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion lastgersync/evmdownloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func newDownloader(

return &downloader{
EVMDownloaderImplementation: sync.NewEVMDownloaderImplementation(
"lastgersync", l2Client, blockFinality, waitForNewBlocksPeriod, nil, nil, nil, rh,
"lastgersync", l2Client, blockFinality, waitForNewBlocksPeriod, nil, nil, nil, rh, blockFinality,
),
l2Client: l2Client,
gerContract: gerContract,
Expand Down
Loading
Loading