From 843277870e2b2d3b1e5c7a3c6acf98f0a1d62378 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:59:30 +0100 Subject: [PATCH 01/10] fix: blockNotifier estimate next block --- aggsender/block_notifier_polling.go | 2 +- aggsender/block_notifier_polling_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aggsender/block_notifier_polling.go b/aggsender/block_notifier_polling.go index dbae1a38f..42b942248 100644 --- a/aggsender/block_notifier_polling.go +++ b/aggsender/block_notifier_polling.go @@ -164,7 +164,7 @@ func (b *BlockNotifierPolling) step(ctx context.Context, func (b *BlockNotifierPolling) nextBlockRequestDelay(status *blockNotifierPollingInternalStatus, err error) time.Duration { - if b.config.CheckNewBlockInterval == AutomaticBlockInterval { + if b.config.CheckNewBlockInterval != AutomaticBlockInterval { return b.config.CheckNewBlockInterval } // Initial stages wait the minimum interval to increas accuracy diff --git a/aggsender/block_notifier_polling_test.go b/aggsender/block_notifier_polling_test.go index e4f15ad79..9cbbd4478 100644 --- a/aggsender/block_notifier_polling_test.go +++ b/aggsender/block_notifier_polling_test.go @@ -193,7 +193,7 @@ func newBlockNotifierPollingTestData(t *testing.T, config *ConfigBlockNotifierPo if config == nil { config = &ConfigBlockNotifierPolling{ BlockFinalityType: etherman.LatestBlock, - CheckNewBlockInterval: time.Second, + CheckNewBlockInterval: 0, } } EthClientMock := mocks.NewEthClient(t) From 986d092b5e2df8460bba224ba2ef61de113e1457 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:25:29 +0100 Subject: [PATCH 02/10] fix: e2e updating agglayer image to agglayer:0.2.0-rc.21 --- test/combinations/fork12-pessimistic.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/combinations/fork12-pessimistic.yml b/test/combinations/fork12-pessimistic.yml index a3734f6ab..67cc51f8b 100644 --- a/test/combinations/fork12-pessimistic.yml +++ b/test/combinations/fork12-pessimistic.yml @@ -1,5 +1,5 @@ args: - agglayer_image: ghcr.io/agglayer/agglayer:0.2.0-rc.12 + agglayer_image: ghcr.io/agglayer/agglayer:0.2.0-rc.21 cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.60.0-beta8 cdk_node_image: cdk zkevm_bridge_proxy_image: haproxy:3.0-bookworm From 0eb921d120e602f766125db6af1acc551cb62318 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:25:48 +0100 Subject: [PATCH 03/10] fix: e2e updating agglayer image to agglayer:0.2.0-rc.20 --- test/combinations/fork12-pessimistic.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/combinations/fork12-pessimistic.yml b/test/combinations/fork12-pessimistic.yml index 67cc51f8b..c7714e45b 100644 --- a/test/combinations/fork12-pessimistic.yml +++ b/test/combinations/fork12-pessimistic.yml @@ -1,5 +1,5 @@ args: - agglayer_image: ghcr.io/agglayer/agglayer:0.2.0-rc.21 + agglayer_image: ghcr.io/agglayer/agglayer:0.2.0-rc.20 cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.60.0-beta8 cdk_node_image: cdk zkevm_bridge_proxy_image: haproxy:3.0-bookworm From 8fdc4287ff9bd09a39bafbc595c62c7216b506c3 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:58:23 +0100 Subject: [PATCH 04/10] feat: warning if block number decrease --- aggsender/block_notifier_polling.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aggsender/block_notifier_polling.go b/aggsender/block_notifier_polling.go index 42b942248..2694d73de 100644 --- a/aggsender/block_notifier_polling.go +++ b/aggsender/block_notifier_polling.go @@ -147,8 +147,15 @@ func (b *BlockNotifierPolling) step(ctx context.Context, BlockNumber: currentBlock.Number.Uint64(), BlockFinalityType: b.config.BlockFinalityType, } + if currentBlock.Number.Uint64()-previousState.lastBlockSeen < 0 { + b.logger.Warnf("Block number decreased [finality:%s]: %d -> %d", + b.config.BlockFinalityType, previousState.lastBlockSeen, currentBlock.Number.Uint64()) + // It start from scratch because something fails in calculation of block period + newState := previousState.intialBlock(currentBlock.Number.Uint64()) + return b.nextBlockRequestDelay(nil, nil), newState, eventToEmit + } - if currentBlock.Number.Uint64()-previousState.lastBlockSeen != 1 { + if currentBlock.Number.Uint64()-previousState.lastBlockSeen > 1 { b.logger.Warnf("Missed block(s) [finality:%s]: %d -> %d", b.config.BlockFinalityType, previousState.lastBlockSeen, currentBlock.Number.Uint64()) // It start from scratch because something fails in calculation of block period From b44d01ffa0845b0ee116b3c708c82cd74ca0bb99 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:58:28 +0100 Subject: [PATCH 05/10] feat: warning if block number decrease --- aggsender/block_notifier_polling.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aggsender/block_notifier_polling.go b/aggsender/block_notifier_polling.go index 2694d73de..105c9e0c6 100644 --- a/aggsender/block_notifier_polling.go +++ b/aggsender/block_notifier_polling.go @@ -147,7 +147,7 @@ func (b *BlockNotifierPolling) step(ctx context.Context, BlockNumber: currentBlock.Number.Uint64(), BlockFinalityType: b.config.BlockFinalityType, } - if currentBlock.Number.Uint64()-previousState.lastBlockSeen < 0 { + if previousState.lastBlockSeen-currentBlock.Number.Uint64() > 1 { b.logger.Warnf("Block number decreased [finality:%s]: %d -> %d", b.config.BlockFinalityType, previousState.lastBlockSeen, currentBlock.Number.Uint64()) // It start from scratch because something fails in calculation of block period From dc335e444bed4995ca6202b3d40bf0d5c28577c8 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:15:26 +0100 Subject: [PATCH 06/10] feat: warning decrease blockNumber --- aggsender/block_notifier_polling.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aggsender/block_notifier_polling.go b/aggsender/block_notifier_polling.go index 105c9e0c6..c9fec72e8 100644 --- a/aggsender/block_notifier_polling.go +++ b/aggsender/block_notifier_polling.go @@ -147,7 +147,7 @@ func (b *BlockNotifierPolling) step(ctx context.Context, BlockNumber: currentBlock.Number.Uint64(), BlockFinalityType: b.config.BlockFinalityType, } - if previousState.lastBlockSeen-currentBlock.Number.Uint64() > 1 { + if previousState.lastBlockSeen > currentBlock.Number.Uint64() { b.logger.Warnf("Block number decreased [finality:%s]: %d -> %d", b.config.BlockFinalityType, previousState.lastBlockSeen, currentBlock.Number.Uint64()) // It start from scratch because something fails in calculation of block period @@ -155,7 +155,7 @@ func (b *BlockNotifierPolling) step(ctx context.Context, return b.nextBlockRequestDelay(nil, nil), newState, eventToEmit } - if currentBlock.Number.Uint64()-previousState.lastBlockSeen > 1 { + if currentBlock.Number.Uint64()-previousState.lastBlockSeen != 1 { b.logger.Warnf("Missed block(s) [finality:%s]: %d -> %d", b.config.BlockFinalityType, previousState.lastBlockSeen, currentBlock.Number.Uint64()) // It start from scratch because something fails in calculation of block period From 5f80d3fc5453698c2df5618ff5b0ffd72bc78387 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:19:18 +0100 Subject: [PATCH 07/10] fix: PR comments --- aggsender/block_notifier_polling.go | 5 +++-- aggsender/block_notifier_polling_test.go | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/aggsender/block_notifier_polling.go b/aggsender/block_notifier_polling.go index c9fec72e8..8224a4f79 100644 --- a/aggsender/block_notifier_polling.go +++ b/aggsender/block_notifier_polling.go @@ -12,7 +12,8 @@ import ( ) var ( - timeNowFunc = time.Now + timeNowFunc = time.Now + percentForNextInterval = 80 ) const ( @@ -186,7 +187,7 @@ func (b *BlockNotifierPolling) nextBlockRequestDelay(status *blockNotifierPollin now := timeNowFunc() expectedTimeNextBlock := status.lastBlockTime.Add(*status.previousBlockTime) distanceToNextBlock := expectedTimeNextBlock.Sub(now) - interval := distanceToNextBlock * 4 / 5 //nolint:mnd // 80% of for reach the next block + interval := distanceToNextBlock * time.Duration(percentForNextInterval) / 100 //nolint:mnd // 80% of for reach the next block return max(minBlockInterval, min(maxBlockInterval, interval)) } diff --git a/aggsender/block_notifier_polling_test.go b/aggsender/block_notifier_polling_test.go index 9cbbd4478..b4c4e6296 100644 --- a/aggsender/block_notifier_polling_test.go +++ b/aggsender/block_notifier_polling_test.go @@ -196,13 +196,13 @@ func newBlockNotifierPollingTestData(t *testing.T, config *ConfigBlockNotifierPo CheckNewBlockInterval: 0, } } - EthClientMock := mocks.NewEthClient(t) + ethClientMock := mocks.NewEthClient(t) logger := log.WithFields("test", "BlockNotifierPolling") - sut, err := NewBlockNotifierPolling(EthClientMock, *config, logger, nil) + sut, err := NewBlockNotifierPolling(ethClientMock, *config, logger, nil) require.NoError(t, err) return blockNotifierPollingTestData{ sut: sut, - ethClientMock: EthClientMock, + ethClientMock: ethClientMock, ctx: context.TODO(), } } From 46b807ec2723dd5c445fa6721df3c03f8a8a1bc2 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:20:12 +0100 Subject: [PATCH 08/10] fix: PR comments --- aggsender/block_notifier_polling.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aggsender/block_notifier_polling.go b/aggsender/block_notifier_polling.go index 8224a4f79..6e39920a0 100644 --- a/aggsender/block_notifier_polling.go +++ b/aggsender/block_notifier_polling.go @@ -12,8 +12,8 @@ import ( ) var ( - timeNowFunc = time.Now - percentForNextInterval = 80 + timeNowFunc = time.Now + percentForNextBlock = 80 ) const ( @@ -187,7 +187,7 @@ func (b *BlockNotifierPolling) nextBlockRequestDelay(status *blockNotifierPollin now := timeNowFunc() expectedTimeNextBlock := status.lastBlockTime.Add(*status.previousBlockTime) distanceToNextBlock := expectedTimeNextBlock.Sub(now) - interval := distanceToNextBlock * time.Duration(percentForNextInterval) / 100 //nolint:mnd // 80% of for reach the next block + interval := distanceToNextBlock * time.Duration(percentForNextInterval) / 100 //nolint:mnd // percent periodfor reach the next block return max(minBlockInterval, min(maxBlockInterval, interval)) } From f96eba2352c01ee0f888d4a2837fa3ae20c53dcf Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:20:38 +0100 Subject: [PATCH 09/10] fix: PR comments --- aggsender/block_notifier_polling.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/aggsender/block_notifier_polling.go b/aggsender/block_notifier_polling.go index 6e39920a0..d93ce413e 100644 --- a/aggsender/block_notifier_polling.go +++ b/aggsender/block_notifier_polling.go @@ -12,8 +12,7 @@ import ( ) var ( - timeNowFunc = time.Now - percentForNextBlock = 80 + timeNowFunc = time.Now ) const ( @@ -22,6 +21,8 @@ const ( minBlockInterval = time.Second // maxBlockInterval is the maximum interval at which the AggSender will check for new blocks maxBlockInterval = time.Minute + // Percentage period of reach the next block + percentForNextBlock = 80 ) type ConfigBlockNotifierPolling struct { @@ -187,7 +188,7 @@ func (b *BlockNotifierPolling) nextBlockRequestDelay(status *blockNotifierPollin now := timeNowFunc() expectedTimeNextBlock := status.lastBlockTime.Add(*status.previousBlockTime) distanceToNextBlock := expectedTimeNextBlock.Sub(now) - interval := distanceToNextBlock * time.Duration(percentForNextInterval) / 100 //nolint:mnd // percent periodfor reach the next block + interval := distanceToNextBlock * time.Duration(percentForNextInterval) / 100 //nolint:mnd // percent period for reach the next block return max(minBlockInterval, min(maxBlockInterval, interval)) } From 96426157f795de875fa3796e234e17f9c5033df5 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:21:01 +0100 Subject: [PATCH 10/10] fix: PR comments --- aggsender/block_notifier_polling.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aggsender/block_notifier_polling.go b/aggsender/block_notifier_polling.go index d93ce413e..dce860e85 100644 --- a/aggsender/block_notifier_polling.go +++ b/aggsender/block_notifier_polling.go @@ -188,7 +188,7 @@ func (b *BlockNotifierPolling) nextBlockRequestDelay(status *blockNotifierPollin now := timeNowFunc() expectedTimeNextBlock := status.lastBlockTime.Add(*status.previousBlockTime) distanceToNextBlock := expectedTimeNextBlock.Sub(now) - interval := distanceToNextBlock * time.Duration(percentForNextInterval) / 100 //nolint:mnd // percent period for reach the next block + interval := distanceToNextBlock * percentForNextBlock / 100 //nolint:mnd // percent period for reach the next block return max(minBlockInterval, min(maxBlockInterval, interval)) }