-
Notifications
You must be signed in to change notification settings - Fork 699
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
[Proposal] - Version Proposal Blocks #2439
Closed
Closed
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7f44ca5
wip: scaffolding
abi87 0632c28
wip: fixing UTs
abi87 69ade2b
wip: some more UTs fixing
abi87 41be5b9
wip: some more UTs fixing
abi87 d4c25dc
Merge branch 'dev' into version_proposal_blocks
abi87 1170933
fix metrics
abi87 8ddbef5
nit
abi87 323587f
nits
abi87 5eef147
nits
abi87 a5a25e8
nit
abi87 861ac12
fixed acceptor
abi87 48b5a81
nit
abi87 bbc4b58
Merge branch 'dev' into version_proposal_blocks
abi87 b69ec52
Merge branch 'dev' into version_proposal_blocks
abi87 0496520
Merge branch 'dev' into version_proposal_blocks
abi87 b75f688
Merge branch 'dev' into version_proposal_blocks
abi87 9eb48f2
Merge branch 'dev' into version_proposal_blocks
abi87 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 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 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ package executor | |
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
|
@@ -135,7 +136,7 @@ func TestAcceptorVisitAtomicBlock(t *testing.T) { | |
childOnCommitState := state.NewMockDiff(ctrl) | ||
childState := &blockState{ | ||
onAcceptState: childOnAcceptState, | ||
proposalBlockState: proposalBlockState{ | ||
optionsState: optionsState{ | ||
onAbortState: childOnAbortState, | ||
onCommitState: childOnCommitState, | ||
}, | ||
|
@@ -224,7 +225,7 @@ func TestAcceptorVisitStandardBlock(t *testing.T) { | |
childOnCommitState := state.NewMockDiff(ctrl) | ||
childState := &blockState{ | ||
onAcceptState: childOnAcceptState, | ||
proposalBlockState: proposalBlockState{ | ||
optionsState: optionsState{ | ||
onAbortState: childOnAbortState, | ||
onCommitState: childOnCommitState, | ||
}, | ||
|
@@ -254,7 +255,12 @@ func TestAcceptorVisitCommitBlock(t *testing.T) { | |
s := state.NewMockState(ctrl) | ||
sharedMemory := atomic.NewMockSharedMemory(ctrl) | ||
|
||
parentID := ids.GenerateTestID() | ||
var ( | ||
parentID = ids.GenerateTestID() | ||
parentHeight = uint64(10) | ||
blkTime = time.Now().Truncate(time.Second) | ||
) | ||
|
||
acceptor := &acceptor{ | ||
backend: &backend{ | ||
lastAccepted: parentID, | ||
|
@@ -270,72 +276,55 @@ func TestAcceptorVisitCommitBlock(t *testing.T) { | |
bootstrapped: &utils.Atomic[bool]{}, | ||
} | ||
|
||
blk, err := block.NewApricotCommitBlock(parentID, 1 /*height*/) | ||
blk, err := block.NewBanffCommitBlock(blkTime, parentID, parentHeight+1) | ||
require.NoError(err) | ||
|
||
err = acceptor.ApricotCommitBlock(blk) | ||
require.ErrorIs(err, state.ErrMissingParentState) | ||
|
||
// Set [blk]'s parent in the state map. | ||
parentOnAcceptState := state.NewMockDiff(ctrl) | ||
parentOnAbortState := state.NewMockDiff(ctrl) | ||
parentOnCommitState := state.NewMockDiff(ctrl) | ||
parentStatelessBlk := block.NewMockBlock(ctrl) | ||
parentState := &blockState{ | ||
statelessBlock: parentStatelessBlk, | ||
onAcceptState: parentOnAcceptState, | ||
proposalBlockState: proposalBlockState{ | ||
onAbortState: parentOnAbortState, | ||
onCommitState: parentOnCommitState, | ||
}, | ||
} | ||
acceptor.backend.blkIDToState[parentID] = parentState | ||
|
||
blkID := blk.ID() | ||
// Set expected calls on dependencies. | ||
// Make sure the parent is accepted first. | ||
gomock.InOrder( | ||
parentStatelessBlk.EXPECT().ID().Return(parentID).Times(2), | ||
s.EXPECT().SetLastAccepted(parentID).Times(1), | ||
parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1), | ||
s.EXPECT().SetHeight(blk.Height()-1).Times(1), | ||
s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1), | ||
|
||
s.EXPECT().SetLastAccepted(blkID).Times(1), | ||
s.EXPECT().SetHeight(blk.Height()).Times(1), | ||
s.EXPECT().AddStatelessBlock(blk).Times(1), | ||
) | ||
|
||
err = acceptor.ApricotCommitBlock(blk) | ||
require.ErrorIs(err, errMissingBlockState) | ||
|
||
// Set [blk]'s state in the map as though it had been verified. | ||
acceptor.backend.blkIDToState[parentID] = parentState | ||
onAcceptState := state.NewMockDiff(ctrl) | ||
acceptor.backend.blkIDToState[blkID] = &blockState{ | ||
onAcceptState: onAcceptState, | ||
{ | ||
err = acceptor.BanffCommitBlock(blk) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated to BanffCommitBlock here. There is not much difference in the logic and it's better to test options currently created on mainnet rather than deprecated versions |
||
require.ErrorIs(err, errMissingBlockState) | ||
} | ||
|
||
// Set expected calls on dependencies. | ||
// Make sure the parent is accepted first. | ||
gomock.InOrder( | ||
parentStatelessBlk.EXPECT().ID().Return(parentID).Times(2), | ||
s.EXPECT().SetLastAccepted(parentID).Times(1), | ||
parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1), | ||
s.EXPECT().SetHeight(blk.Height()-1).Times(1), | ||
s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1), | ||
|
||
s.EXPECT().SetLastAccepted(blkID).Times(1), | ||
s.EXPECT().SetHeight(blk.Height()).Times(1), | ||
s.EXPECT().AddStatelessBlock(blk).Times(1), | ||
|
||
onAcceptState.EXPECT().Apply(s).Times(1), | ||
s.EXPECT().Commit().Return(nil).Times(1), | ||
s.EXPECT().Checksum().Return(ids.Empty).Times(1), | ||
) | ||
|
||
require.NoError(acceptor.ApricotCommitBlock(blk)) | ||
require.Equal(blk.ID(), acceptor.backend.lastAccepted) | ||
{ | ||
// Set [blk]'s parent in the state map. | ||
// We don't bother setting options state since | ||
// it's not relevant when accepting the block | ||
parentOnAcceptState := state.NewMockDiff(ctrl) | ||
parentStatelessBlk := block.NewMockBlock(ctrl) | ||
parentStatelessBlk.EXPECT().ID().Return(parentID).AnyTimes() | ||
parentStatelessBlk.EXPECT().Height().Return(parentHeight).AnyTimes() | ||
|
||
parentState := &blockState{ | ||
statelessBlock: parentStatelessBlk, | ||
onAcceptState: parentOnAcceptState, | ||
} | ||
acceptor.backend.blkIDToState[parentID] = parentState | ||
|
||
onAcceptState := state.NewMockDiff(ctrl) | ||
acceptor.backend.blkIDToState[blkID] = &blockState{ | ||
onAcceptState: onAcceptState, | ||
} | ||
|
||
// Set expected calls on dependencies. | ||
// Make sure the parent is accepted first. | ||
gomock.InOrder( | ||
s.EXPECT().SetLastAccepted(parentStatelessBlk.ID()).Times(1), | ||
s.EXPECT().SetHeight(parentStatelessBlk.Height()).Times(1), | ||
s.EXPECT().AddStatelessBlock(parentStatelessBlk).Times(1), | ||
parentOnAcceptState.EXPECT().Apply(s).Times(1), | ||
|
||
s.EXPECT().SetLastAccepted(blkID).Times(1), | ||
s.EXPECT().SetHeight(blk.Height()).Times(1), | ||
s.EXPECT().AddStatelessBlock(blk).Times(1), | ||
|
||
onAcceptState.EXPECT().Apply(s).Times(1), | ||
s.EXPECT().Commit().Return(nil).Times(1), | ||
s.EXPECT().Checksum().Return(ids.Empty).Times(1), | ||
) | ||
|
||
require.NoError(acceptor.BanffCommitBlock(blk)) | ||
require.Equal(blk.ID(), acceptor.backend.lastAccepted) | ||
} | ||
} | ||
|
||
func TestAcceptorVisitAbortBlock(t *testing.T) { | ||
|
@@ -345,7 +334,11 @@ func TestAcceptorVisitAbortBlock(t *testing.T) { | |
s := state.NewMockState(ctrl) | ||
sharedMemory := atomic.NewMockSharedMemory(ctrl) | ||
|
||
parentID := ids.GenerateTestID() | ||
var ( | ||
parentID = ids.GenerateTestID() | ||
parentHeight = uint64(10) | ||
blkTime = time.Now().Truncate(time.Second) | ||
) | ||
acceptor := &acceptor{ | ||
backend: &backend{ | ||
lastAccepted: parentID, | ||
|
@@ -361,71 +354,53 @@ func TestAcceptorVisitAbortBlock(t *testing.T) { | |
bootstrapped: &utils.Atomic[bool]{}, | ||
} | ||
|
||
blk, err := block.NewApricotAbortBlock(parentID, 1 /*height*/) | ||
blk, err := block.NewBanffAbortBlock(blkTime, parentID, parentHeight+1) | ||
require.NoError(err) | ||
|
||
err = acceptor.ApricotAbortBlock(blk) | ||
require.ErrorIs(err, state.ErrMissingParentState) | ||
|
||
// Set [blk]'s parent in the state map. | ||
parentOnAcceptState := state.NewMockDiff(ctrl) | ||
parentOnAbortState := state.NewMockDiff(ctrl) | ||
parentOnCommitState := state.NewMockDiff(ctrl) | ||
parentStatelessBlk := block.NewMockBlock(ctrl) | ||
parentState := &blockState{ | ||
statelessBlock: parentStatelessBlk, | ||
onAcceptState: parentOnAcceptState, | ||
proposalBlockState: proposalBlockState{ | ||
onAbortState: parentOnAbortState, | ||
onCommitState: parentOnCommitState, | ||
}, | ||
} | ||
acceptor.backend.blkIDToState[parentID] = parentState | ||
|
||
blkID := blk.ID() | ||
// Set expected calls on dependencies. | ||
// Make sure the parent is accepted first. | ||
gomock.InOrder( | ||
parentStatelessBlk.EXPECT().ID().Return(parentID).Times(2), | ||
s.EXPECT().SetLastAccepted(parentID).Times(1), | ||
parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1), | ||
s.EXPECT().SetHeight(blk.Height()-1).Times(1), | ||
s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1), | ||
|
||
s.EXPECT().SetLastAccepted(blkID).Times(1), | ||
s.EXPECT().SetHeight(blk.Height()).Times(1), | ||
s.EXPECT().AddStatelessBlock(blk).Times(1), | ||
) | ||
|
||
err = acceptor.ApricotAbortBlock(blk) | ||
require.ErrorIs(err, errMissingBlockState) | ||
|
||
// Set [blk]'s state in the map as though it had been verified. | ||
acceptor.backend.blkIDToState[parentID] = parentState | ||
|
||
onAcceptState := state.NewMockDiff(ctrl) | ||
acceptor.backend.blkIDToState[blkID] = &blockState{ | ||
onAcceptState: onAcceptState, | ||
{ | ||
err = acceptor.BanffAbortBlock(blk) | ||
require.ErrorIs(err, errMissingBlockState) | ||
} | ||
|
||
// Set expected calls on dependencies. | ||
// Make sure the parent is accepted first. | ||
gomock.InOrder( | ||
parentStatelessBlk.EXPECT().ID().Return(parentID).Times(2), | ||
s.EXPECT().SetLastAccepted(parentID).Times(1), | ||
parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1), | ||
s.EXPECT().SetHeight(blk.Height()-1).Times(1), | ||
s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1), | ||
|
||
s.EXPECT().SetLastAccepted(blkID).Times(1), | ||
s.EXPECT().SetHeight(blk.Height()).Times(1), | ||
s.EXPECT().AddStatelessBlock(blk).Times(1), | ||
|
||
onAcceptState.EXPECT().Apply(s).Times(1), | ||
s.EXPECT().Commit().Return(nil).Times(1), | ||
s.EXPECT().Checksum().Return(ids.Empty).Times(1), | ||
) | ||
|
||
require.NoError(acceptor.ApricotAbortBlock(blk)) | ||
require.Equal(blk.ID(), acceptor.backend.lastAccepted) | ||
{ | ||
// Set [blk]'s parent in the state map. | ||
// We don't bother setting options state since | ||
// it's not relevant when accepting the block | ||
parentOnAcceptState := state.NewMockDiff(ctrl) | ||
parentStatelessBlk := block.NewMockBlock(ctrl) | ||
parentStatelessBlk.EXPECT().ID().Return(parentID).AnyTimes() | ||
parentStatelessBlk.EXPECT().Height().Return(parentHeight).AnyTimes() | ||
|
||
parentState := &blockState{ | ||
statelessBlock: parentStatelessBlk, | ||
onAcceptState: parentOnAcceptState, | ||
} | ||
acceptor.backend.blkIDToState[parentID] = parentState | ||
|
||
onAcceptState := state.NewMockDiff(ctrl) | ||
acceptor.backend.blkIDToState[blkID] = &blockState{ | ||
onAcceptState: onAcceptState, | ||
} | ||
|
||
// Set expected calls on dependencies. | ||
// Make sure the parent is accepted first. | ||
gomock.InOrder( | ||
s.EXPECT().SetLastAccepted(parentStatelessBlk.ID()).Times(1), | ||
s.EXPECT().SetHeight(parentStatelessBlk.Height()).Times(1), | ||
s.EXPECT().AddStatelessBlock(parentStatelessBlk).Times(1), | ||
parentOnAcceptState.EXPECT().Apply(s).Times(1), | ||
|
||
s.EXPECT().SetLastAccepted(blkID).Times(1), | ||
s.EXPECT().SetHeight(blk.Height()).Times(1), | ||
s.EXPECT().AddStatelessBlock(blk).Times(1), | ||
|
||
onAcceptState.EXPECT().Apply(s).Times(1), | ||
s.EXPECT().Commit().Return(nil).Times(1), | ||
s.EXPECT().Checksum().Return(ids.Empty).Times(1), | ||
) | ||
|
||
require.NoError(acceptor.BanffAbortBlock(blk)) | ||
require.Equal(blk.ID(), acceptor.backend.lastAccepted) | ||
} | ||
} |
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.
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.
when we verified the option we copied over option's blockState the preference. Hence we can lookup the option blockState now, instead of its parent's one