-
Notifications
You must be signed in to change notification settings - Fork 159
ACP-226: Apply Min Block Delay to Block Builder #1310
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
Merged
+239
−31
Merged
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
ef12dfb
add is retry logic
ceyonur ef76b58
Merge branch 'master' into ceyonur/wait-for-event-refactor
ceyonur cf66f59
update waitForEvent by using parent hash + last build time
ceyonur 9c0d64c
Merge branch 'ceyonur/wait-for-event-refactor' of github.com:ava-labs…
ceyonur da7a8cb
rename var
ceyonur 5402155
pass current header to waitForEvent
ceyonur a35d6fb
add delay tests
ceyonur 4f5b78b
add tests
ceyonur 27da7a6
Merge branch 'master' into ceyonur/wait-for-event-refactor
ceyonur 3c2d944
ensure mempool is empty
ceyonur 67c62cd
Merge branch 'ceyonur/wait-for-event-refactor' of github.com:ava-labs…
ceyonur eef3650
comment
ceyonur 49d1a78
remove reduntant and flaky test
ceyonur e998652
use timeout for no-delay return test
ceyonur ac83a0c
Merge branch 'master' into ceyonur/wait-for-event-refactor
ceyonur 10e3bc0
add acp-226 constraints to builder
ceyonur 6d05981
nit comments
ceyonur 3385ef1
refactor GetNextTimestamp and add test for same sec different ms
ceyonur a2a6946
Merge branch 'master' into ceyonur/acp-226-min-block-delay-builder
ceyonur 76111f5
nits
ceyonur 049aefa
nits
ceyonur ce38349
revert worker changes
ceyonur aa9a2cc
apply min blok delay to block builder
ceyonur 29aee71
Merge branch 'master' into ceyonur/acp-226-min-block-delay-builder
ceyonur 1503d87
Update RELEASES.md
ceyonur cf2697e
Merge branch 'ceyonur/acp-226-min-block-delay-builder' of github.com:…
ceyonur d96886b
comments
ceyonur 8e8205b
use a single retry delay
ceyonur 42be3f3
simplify var
ceyonur c447907
check for negative as well
ceyonur d55eba3
refactor block delay calculations
ceyonur 68c33a4
Merge branch 'master' into ceyonur/acp-226-min-block-delay-builder
ceyonur 50a0628
use excess from parent directly
ceyonur 5a22df5
add comment
ceyonur 29c102a
Merge branch 'ceyonur/acp-226-min-block-delay-builder' of github.com:…
ceyonur d5b5e6d
linter
ceyonur 49a28d8
Update plugin/evm/block_builder.go
ceyonur e722c53
Merge branch 'master' into ceyonur/acp-226-min-block-delay-builder
ceyonur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package evm | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/ava-labs/avalanchego/utils/timer/mockable" | ||
| "github.com/ava-labs/avalanchego/vms/evm/acp226" | ||
| "github.com/ava-labs/libevm/common" | ||
| "github.com/ava-labs/libevm/core/types" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/ava-labs/coreth/params/extras" | ||
| "github.com/ava-labs/coreth/plugin/evm/customtypes" | ||
| ) | ||
|
|
||
| func TestCalculateBlockBuildingDelay(t *testing.T) { | ||
| now := time.UnixMilli(10000) | ||
| nowSecUint64 := uint64(now.Unix()) | ||
| nowMilliUint64 := uint64(now.UnixMilli()) | ||
| clock := &mockable.Clock{} | ||
| clock.Set(now) | ||
| tests := []struct { | ||
| name string | ||
| config *extras.ChainConfig | ||
| currentHeader *types.Header | ||
| lastBuildTime time.Time | ||
| lastBuildParentHash common.Hash | ||
| expectedTimeToWait time.Duration | ||
| }{ | ||
| { | ||
| name: "pre_granite_returns_build_immediately_zero_time", | ||
| config: extras.TestFortunaChainConfig, // Pre-Granite config | ||
| currentHeader: &types.Header{ | ||
| ParentHash: common.Hash{1}, | ||
| Time: nowSecUint64, | ||
| }, | ||
| lastBuildTime: time.Time{}, // Zero time means not a retry | ||
| lastBuildParentHash: common.Hash{1}, | ||
| expectedTimeToWait: 0, | ||
| }, | ||
| { | ||
| name: "pre_granite_returns_build_immediately_different_parent_hash", | ||
| config: extras.TestFortunaChainConfig, // Pre-Granite config | ||
| currentHeader: &types.Header{ | ||
| ParentHash: common.Hash{2}, | ||
| Time: nowSecUint64, | ||
| }, | ||
| lastBuildTime: now, | ||
| lastBuildParentHash: common.Hash{1}, | ||
| expectedTimeToWait: 0, | ||
| }, | ||
| { | ||
| name: "pre_granite_returns_build_delays_with_same_parent_hash", | ||
| config: extras.TestFortunaChainConfig, // Pre-Granite config | ||
| currentHeader: &types.Header{ | ||
| ParentHash: common.Hash{1}, | ||
| Time: nowSecUint64, | ||
| }, | ||
| lastBuildTime: now, | ||
| lastBuildParentHash: common.Hash{1}, | ||
| expectedTimeToWait: RetryDelay, | ||
| }, | ||
| { | ||
| name: "pre_granite_returns_build_returns_immediately_if_enough_time_passed", | ||
| config: extras.TestFortunaChainConfig, // Pre-Granite config | ||
| currentHeader: &types.Header{ | ||
| ParentHash: common.Hash{1}, | ||
| Time: nowSecUint64, | ||
| }, | ||
| lastBuildTime: now.Add(-RetryDelay), // Less than retry delay ago | ||
| lastBuildParentHash: common.Hash{1}, // Same as current parent | ||
| expectedTimeToWait: 0, | ||
| }, | ||
| { | ||
| name: "pre_granite_returns_build_delays_only_remaining_min_delay", | ||
| config: extras.TestFortunaChainConfig, // Pre-Granite config | ||
| currentHeader: &types.Header{ | ||
| ParentHash: common.Hash{1}, | ||
| Time: nowSecUint64, | ||
| }, | ||
| lastBuildTime: now.Add(-RetryDelay / 2), // Less than retry delay ago | ||
| lastBuildParentHash: common.Hash{1}, | ||
| expectedTimeToWait: RetryDelay / 2, | ||
| }, | ||
| { | ||
| name: "first_granite_block_build_immediately", | ||
| config: extras.TestGraniteChainConfig, | ||
| currentHeader: &types.Header{ | ||
| ParentHash: common.Hash{1}, | ||
| Time: nowSecUint64, | ||
| }, | ||
| lastBuildTime: now, | ||
| lastBuildParentHash: common.Hash{2}, | ||
| expectedTimeToWait: 0, | ||
| }, | ||
| { | ||
| name: "granite_block_with_now_time", | ||
| config: extras.TestGraniteChainConfig, | ||
| currentHeader: createGraniteTestHeader(common.Hash{1}, nowMilliUint64, acp226.InitialDelayExcess), | ||
| lastBuildTime: time.Time{}, | ||
| lastBuildParentHash: common.Hash{1}, | ||
| expectedTimeToWait: 2000 * time.Millisecond, // should wait for initial delay | ||
| }, | ||
| { | ||
| name: "granite_block_with_2_seconds_before_clock_no_retry", | ||
| config: extras.TestGraniteChainConfig, | ||
| currentHeader: createGraniteTestHeader(common.Hash{1}, nowMilliUint64-2000, acp226.InitialDelayExcess), | ||
| lastBuildTime: time.Time{}, // Zero time means not a retry | ||
| lastBuildParentHash: common.Hash{1}, | ||
| expectedTimeToWait: 0, // should not wait for initial delay | ||
| }, | ||
| { | ||
| name: "granite_block_with_2_seconds_before_clock_with_retry", | ||
| config: extras.TestGraniteChainConfig, | ||
| currentHeader: createGraniteTestHeader(common.Hash{1}, nowMilliUint64-2000, acp226.InitialDelayExcess), | ||
| lastBuildTime: now, | ||
| lastBuildParentHash: common.Hash{1}, | ||
| expectedTimeToWait: RetryDelay, | ||
| }, | ||
| { | ||
| name: "granite_with_2_seconds_before_clock_only_waits_for_retry_delay", | ||
| config: extras.TestGraniteChainConfig, | ||
| currentHeader: createGraniteTestHeader(common.Hash{1}, nowMilliUint64-2000, 0), // 0 means min delay excess which is 1 | ||
| lastBuildTime: now, | ||
| lastBuildParentHash: common.Hash{1}, | ||
| expectedTimeToWait: RetryDelay, | ||
| }, | ||
| { | ||
| name: "granite_with_2_seconds_before_clock_only_waits_for_remaining_retry_delay", | ||
| config: extras.TestGraniteChainConfig, | ||
| currentHeader: createGraniteTestHeader(common.Hash{1}, nowMilliUint64-2000, 0), // 0 means min delay excess which is 1 | ||
| lastBuildTime: now.Add(-RetryDelay / 2), // Less than retry delay ago | ||
| lastBuildParentHash: common.Hash{1}, | ||
| expectedTimeToWait: RetryDelay / 2, | ||
| }, | ||
| { | ||
| name: "granite_with_2_seconds_after_clock", | ||
| config: extras.TestGraniteChainConfig, | ||
| currentHeader: createGraniteTestHeader(common.Hash{1}, nowMilliUint64+2000, acp226.InitialDelayExcess), | ||
| lastBuildTime: time.Time{}, // Zero time means not a retry | ||
| lastBuildParentHash: common.Hash{1}, | ||
| expectedTimeToWait: 4000 * time.Millisecond, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| b := &blockBuilder{ | ||
| clock: clock, | ||
| chainConfig: tt.config, | ||
| } | ||
|
|
||
| timeToWait, err := b.calculateBlockBuildingDelay( | ||
| tt.lastBuildTime, | ||
| tt.lastBuildParentHash, | ||
| tt.currentHeader, | ||
| ) | ||
|
|
||
| require.NoError(t, err) | ||
| require.Equal(t, tt.expectedTimeToWait, timeToWait) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func createGraniteTestHeader(parentHash common.Hash, timeMilliseconds uint64, minDelayExcess acp226.DelayExcess) *types.Header { | ||
| header := &types.Header{ | ||
| Time: timeMilliseconds / 1000, | ||
| } | ||
| header.ParentHash = parentHash | ||
|
|
||
| extra := &customtypes.HeaderExtra{ | ||
| TimeMilliseconds: &timeMilliseconds, | ||
| MinDelayExcess: &minDelayExcess, | ||
| } | ||
| customtypes.SetHeaderExtra(header, extra) | ||
|
|
||
| return header | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.