-
Notifications
You must be signed in to change notification settings - Fork 4
Don't restart non-validators that are behind #475
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
Draft
samliok
wants to merge
22
commits into
main
Choose a base branch
from
cleanup-instance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
309860d
cleanup instance
samliok bb2bbce
fix test
samliok 3e30d78
update test
samliok 980ea63
add regression test
samliok 094683b
fix race
samliok 61fa350
clarify is validator
samliok 450a411
flake skip
samliok 0607c66
undo test
samliok 56b15ea
Merge branch 'main' into cleanup-instance
samliok 9f38f44
compiler issues
samliok d733a2a
Merge branch 'main' into cleanup-instance
samliok ba18050
race + deadlock
samliok f50c2be
Merge branch 'main' into cleanup-instance
samliok 0a391a9
fix compiler error
samliok 9f3f930
Merge branch 'main' into cleanup-instance
yacovm b76cebf
compiler
samliok 7bf7199
comment
samliok a4019fd
Merge branch 'main' into cleanup-instance
samliok 08ca82f
testing refactor
samliok 36e2a03
save
samliok dec3b97
save lookup
samliok 75a3538
working tests
samliok 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,176 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package simplex | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "sync" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/ava-labs/simplex/common" | ||
| metadata "github.com/ava-labs/simplex/msm" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestValidatorIndexes(t *testing.T) { | ||
| validatorID := generateNodeIDMapping() | ||
|
|
||
| genesisSet := []metadata.NodeBLSMapping{validatorID} | ||
|
|
||
| pChain := newTestPChain(genesisSet) | ||
| chain := newChain(t, pChain) | ||
| chain.addNode(validatorID.NodeID[:]) | ||
|
|
||
| _, err := chain.index() | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| func TestNonValidatorSyncs(t *testing.T) { | ||
| validatorID := generateNodeIDMapping() | ||
| nonValidatorID := generateNodeIDMapping() | ||
|
|
||
| genesisSet := []metadata.NodeBLSMapping{validatorID} | ||
|
|
||
| pChain := newTestPChain(genesisSet) | ||
| chain := newChain(t, pChain) | ||
| chain.addNode(validatorID.NodeID[:]) | ||
|
|
||
| _, err := chain.index() | ||
| require.NoError(t, err) | ||
| _, err = chain.index() | ||
| require.NoError(t, err) | ||
|
|
||
| chain.addNode(nonValidatorID.NodeID[:]) | ||
| } | ||
|
|
||
| func TestNonValidator_BecomesValidator(t *testing.T) { | ||
| validatorID := generateNodeIDMapping() | ||
| upcomingValidator := generateNodeIDMapping() | ||
|
|
||
| genesisSet := []metadata.NodeBLSMapping{validatorID} | ||
|
|
||
| pChain := newTestPChain(genesisSet) | ||
| chain := newChain(t, pChain) | ||
| chain.addNode(validatorID.NodeID[:]) | ||
|
|
||
| _, err := chain.index() | ||
| require.NoError(t, err) | ||
| _, err = chain.index() | ||
| require.NoError(t, err) | ||
|
|
||
| chain.addNode(upcomingValidator.NodeID[:]) | ||
|
|
||
| fmt.Println("advancing height") | ||
| // initiate an epoch change | ||
| pChain.setValidatorSetAt(10, []metadata.NodeBLSMapping{validatorID, upcomingValidator}) | ||
| pChain.advanceHeight(10) | ||
|
|
||
| // now that we advanced the height the validator will keep building empty blocks until the upcoming validator sends an approval | ||
| time.Sleep(5 * time.Second) | ||
| } | ||
|
|
||
| func TestValidator_ValidatorSetNotChanged(t *testing.T) { | ||
| validatorID := generateNodeIDMapping() | ||
|
|
||
| genesisSet := []metadata.NodeBLSMapping{validatorID} | ||
|
|
||
| pChain := newTestPChain(genesisSet) | ||
| chain := newChain(t, pChain) | ||
| chain.addNode(validatorID.NodeID[:]) | ||
|
|
||
| _, err := chain.index() | ||
| require.NoError(t, err) | ||
|
|
||
| // initiate an epoch change | ||
| pChain.setValidatorSetAt(10, []metadata.NodeBLSMapping{validatorID}) | ||
| pChain.advanceHeight(10) | ||
|
|
||
| // potential time to propose blocks | ||
| time.Sleep(3 * time.Second) | ||
|
|
||
| block, err := chain.index() | ||
| require.NoError(t, err) | ||
| require.Equal(t, uint64(1), block.BlockHeader().Epoch) | ||
| } | ||
|
|
||
| func TestValidator_ValidatorSetDecreased(t *testing.T) { | ||
| validatorID := generateNodeIDMapping([20]byte{1}) | ||
| leavingValidatorID := generateNodeIDMapping([20]byte{2}) | ||
|
|
||
| genesisSet := []metadata.NodeBLSMapping{validatorID, leavingValidatorID} | ||
|
|
||
| pChain := newTestPChain(genesisSet) | ||
| chain := newChain(t, pChain) | ||
| wg := sync.WaitGroup{} | ||
|
|
||
| wg.Add(1) | ||
| go func() { | ||
| chain.addNode(validatorID.NodeID[:]) | ||
| wg.Done() | ||
| }() | ||
| chain.addNode(leavingValidatorID.NodeID[:]) | ||
|
|
||
| // all nodes have synced the first every simplex block | ||
| wg.Wait() | ||
|
|
||
| // time.Sleep(1 * time.Second) | ||
| block, err := chain.index() | ||
| require.NoError(t, err) | ||
| require.Equal(t, uint64(2), block.BlockHeader().Round) | ||
|
|
||
| // initiate an epoch change | ||
| pChain.setValidatorSetAt(10, []metadata.NodeBLSMapping{validatorID}) | ||
| pChain.advanceHeight(10) | ||
|
|
||
| sealing := chain.waitUntilSealingBlock() | ||
| require.Contains(t, sealing.SealingBlockInfo().ValidatorSet.NodeIDs(), common.NodeID(validatorID.NodeID[:])) | ||
| require.NotContains(t, sealing.SealingBlockInfo().ValidatorSet.NodeIDs(), common.NodeID(leavingValidatorID.NodeID[:])) | ||
| } | ||
|
|
||
| // Tests a non-validator converts to a validator when the epoch admitting it is committed, | ||
| // proven by the finalization of the next block carrying both nodes' signatures. | ||
| // func TestNonValidatorJoins(t *testing.T) { | ||
| // chain := newChain(t) | ||
|
|
||
| // // The initial validator set is just currentValidator, so futureValidator comes up as a | ||
| // // non-validator that tracks the chain. | ||
| // currentValidator := chain.newNode(nodeConfig{Name: "current-validator", Validator: true}) | ||
| // futureValidator := chain.newNode(nodeConfig{Name: "future-validator"}) | ||
|
|
||
| // chain.AddNodes(currentValidator, futureValidator) | ||
|
|
||
| // chain.IndexBlock() | ||
|
|
||
| // // The new validator set is current + future. | ||
| // chain.IndexSealing(currentValidator, futureValidator) | ||
|
|
||
| // block := chain.IndexBlock() | ||
|
|
||
| // // A quorum of the new epoch needs both nodes, so both signing the finalization proves the | ||
| // // joined node takes part in consensus rather than merely tracking the chain. | ||
| // chain.RequireFinalizedBy(block, currentValidator, futureValidator) | ||
| // } | ||
|
|
||
| // // Tests that a non-validator joining a chain that has already sealed an epoch syncs across | ||
| // // every epoch up to the tip. | ||
| // func TestNonValidatorSyncs(t *testing.T) { | ||
| // chain := newChain(t, chainConfig{}) | ||
|
|
||
| // // The initial validator set is just currentValidator. | ||
| // currentValidator := chain.newNode(nodeConfig{Name: "current-validator", Validator: true}) | ||
| // syncingNonValidator := chain.newNode(nodeConfig{Name: "syncing-non-validator"}) | ||
|
|
||
| // chain.AddNodes(currentValidator) | ||
|
|
||
| // chain.IndexBlock() | ||
| // chain.IndexBlock() | ||
| // chain.IndexSealing(currentValidator) | ||
| // latestBlock := chain.IndexBlock() | ||
|
|
||
| // chain.AddNodes(syncingNonValidator) | ||
|
|
||
| // syncingNonValidator.WaitForCommit(latestBlock) | ||
| // syncingNonValidator.RequireNonValidator() | ||
| // } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this file belongs to the PR