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

[Proposal] - Version Proposal Blocks #2439

Closed
wants to merge 17 commits into from
Closed

Conversation

abi87
Copy link
Contributor

@abi87 abi87 commented Dec 6, 2023

Why this should be merged

This is a refactoring to enable decision txs inclusion in proposal blocks.
For now we just change the way we store proposal blocks state changes in memory.
Specifically we store all changes common to both commit and abort options (timestamp advance time post fork, inputs consumption of the proposal tx) in proposal block state and we explicitly index proposal block state by itself.
Previously no change was index under proposal block; all changes were indexed under the options.

Followed by #2442

How this works

Split changes related to proposal + options blocks into two chucks:

  1. Advance time tx + tx input consumptions changes indexed as proposal block changes
  2. proposal tx changes + tx output generation changes indexes as either commit or abort changes

Changes are still kept in memory while block is verified; they are flushed to state and stored to disk when the option is accepted so that proposal block and accepted option changes are stored atomically.

How this was tested

CI + mainnet sync

@abi87 abi87 force-pushed the version_proposal_blocks branch from ba8df67 to d88d397 Compare December 7, 2023 00:33
@abi87 abi87 force-pushed the version_proposal_blocks branch from d88d397 to 0632c28 Compare December 7, 2023 00:42
@abi87 abi87 force-pushed the version_proposal_blocks branch from 2c4e517 to 41be5b9 Compare December 7, 2023 08:53
@abi87 abi87 self-assigned this Dec 7, 2023
Comment on lines 160 to 161
// Note: we assume this block's sibling doesn't
// need the parent's state when it's rejected.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: check whether this comment is still true

s.EXPECT().SetHeight(blk.Height()).Times(1),
s.EXPECT().AddStatelessBlock(blk).Times(1),

onAcceptState.EXPECT().Apply(gomock.Any()).Return(nil),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notably commit is not called here. Deferred to the accepted option

@@ -121,7 +126,7 @@ func (e *ProposalTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error {

onAbortOuts, err := verifyAddValidatorTx(
e.Backend,
e.OnCommitState,
e.OnProposalBlockState,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in all of these verify methods OnProposalBlockState should never be modified. Consider carving out of state.Chain interface into a state.ReadOnlyChain containing only getters. It won't actually enforce any constness of proposalBlockState, but it'd be more expressive.
Deferred to a future PR to keep scope reduced.

//
// Invariant: Both [OnCommitState] and [OnAbortState] are built on
// top of OnProposalBlockState when provided to the executor.
OnProposalBlockState state.Diff
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we used to lookup state quantities from OnCommitState. Imma change this to do lookups/verifications from OnProposalBlockState

Comment on lines +139 to +141
// Consume the input UTXOs whether we accept commit or abort blocks
avax.Consume(e.OnProposalBlockState, tx.Ins)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably blurs a bit the distinction of what state changes go in proposal block state and what goes in options block states.
However it should be marginally more efficient to do this once, in proposal block state, rather than twice in options blocks.

@abi87 abi87 marked this pull request as ready for review December 7, 2023 10:29
@abi87 abi87 linked an issue Dec 7, 2023 that may be closed by this pull request
@abi87
Copy link
Contributor Author

abi87 commented Dec 8, 2023

There seems to be an issue around block building. See logs from a mainnet sync with partial sync activated. Looking at this.

[12-07|18:49:33.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "2oMiw4C94CxuUYkShic55fRotWwRYPQvz4BvMnwMijcfJ7QiGq", "lastAcceptedID": "36dVGoziVQZDzqEg4AZkQA3QWFTCEBhS9L6EmZVHsJVB73ZeY", "error": "missing parent state: 2tjmANc3GQ6DnbFsk2qAXX9JUaCp1Hf4NXeLNGVgqe7v27yZYv"}
[12-07|19:26:11.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "2nR3aw5KuFLHJ9UotXppE5mfvxdFSYheCW1V3JUSFJWc4os4b2", "lastAcceptedID": "2cx2Y5QbnSQruCW9NbyLFVn72in6P8jSj8FxKpqP8HdCZAJVXp", "error": "missing parent state: 2dofa7MT7dmS7DgrF86AyjXRYQ9BZzVdS8UsakTFy7MWuqVFSj"}
[12-07|20:01:30.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "2kHwo3M5D22HUKFTnVfnbkw7UAD7YqRqiPsmkVBDtH3dXVt2FA", "lastAcceptedID": "LufbRrCEKFSFLN7pEChoDsscEs83xtsiqZ9FLsKj88FCMv4au", "error": "missing parent state: 2ufX8ypJmVr2sBEa1ecehHLAQX1VhmT5f1e6NFtgMQCYA4LCff"}
[12-07|20:31:02.001] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "HEv7inZWefnzAaqyaS9uhLaHSRSPQjsxq3KquPk32F7swd8BA", "lastAcceptedID": "23ZHgZdyXk3Pds8PLvUVPFsTjqmLTqu131CdEixATfoRQoZXzK", "error": "missing parent state: 2f6pBaTBfquVuH5cc2XHagNvtdsRrCfzxhqJFQ6QQs2NF7KLFU"}
[12-07|20:34:45.386] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "C8bp1uZABH5zWzoEUVQGcpXwf4uMegHSPX14VVxbKgYZh8c74", "lastAcceptedID": "2114fzdhc4HnPj4HJcipHJMLEe7ycQB59yFPR6uLrtwacqAqAW", "error": "missing parent state: 2NTEWPD88UPcR9PFDaKknzj9VqNGdf3A61PUCHRdop2ZGXEnM8"}
[12-07|21:09:23.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "i4tuRNxz2jmos8viDS7BVfkC9ZXHAphR5sb6MgV16KF2HQgnw", "lastAcceptedID": "2sjU76XzQG5YJBLJt7JKMhCoeNKdsxpqzmuEapESHo6PrvkgLX", "error": "missing parent state: 2T6EdSyhF4gCrV1auzEs1Z27bgyanEJrciwkC9a5WuhnWDEyFx"}
[12-07|22:20:32.001] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "hmcMqLVqvhc1yrEVi6z7ABXLYDzx9iQCSRpwXnt1DPCLtYZix", "lastAcceptedID": "2U63MdAXNMvoQXHbS6fNjNHpJaZVASrVjdF8PkrsuG7xjFBKB2", "error": "missing parent state: tRG221rWh3FCJEz3oojwbGsaZPfYvwc1dpNN61KKSP65Uet9u"}
[12-07|22:22:49.506] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "7XpS1S9A31UK2fVbwyCL9mTdJnuJQszaLBh5re9FQYCPzF9yF", "lastAcceptedID": "UKe6tsttKDh5SUPxPfmkJb4NuWXCZ9fnFcjX56H6coBGuyaAx", "error": "missing parent state: 26xZ128fLBeeAJf7sydqznkrFAFfUpsuDEEyghctYNZudzoabJ"}
[12-08|00:55:49.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "a2st2fMPj8opMcYPRRhu1DeSoQiyJF1u6fbTJgncaLUZPzMfR", "lastAcceptedID": "2UHwmcXfDoewbD82XjaniuhtdmtL1CJ9LCFq7KcLHSubsqwurk", "error": "missing parent state: 2aTbz27zDPK34B3htjsRs6WyMk362J4ibsQkX3yNNA2N6oWymt"}
[12-08|05:12:15.012] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "jukSniLfwFXh8w5zKdp5bRhy22xDK7wrxwD1AQoTE9N5V1Pue", "lastAcceptedID": "kJkBcHZ5dnHj11yUdHoFsTuaPivyAhFpnjGSWL3k4joeSFVtP", "error": "missing parent state: KwueaXPDvWyqshMkJtBwaVE2nqgLVCPEc8qLvZvAQdPDm8S3d"}
[12-08|05:29:21.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "yQEXbbs661SKxoqj63U9UuDYjFpUT1DaGsUCnTMC1xKsnYfmR", "lastAcceptedID": "9UzL3xHoXbWbnJo7AGmDEhbDAE3Ar2gWN2KnNUCWgFXQ1bzv4", "error": "missing parent state: fGed5aSEK6XxDE5gk3TKdrh5UbPef5Fc8d8KZhBR9RCqmnwhE"}
[12-08|06:08:02.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "JddzNQyLqge6sfpqxZiCfJYU1wApya4XHehiYzkDi6pCHS6ew", "lastAcceptedID": "2GSkyRMYB33TaPhHN1zSpPw4jZnHacVVHEXDRkhznvRosiE3GG", "error": "missing parent state: 2Nmo7BSK3BfpzuopKtGDuw1GSnE341YsH3RWjm7TJ3t3JHUaCu"}
[12-08|06:23:13.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "iCMXEY5vHmbaVBXavVLWQqWAJc9HHbUhMv7ncxJ2FC9KCLzbi", "lastAcceptedID": "26s4kyA3ywwXp24AdBJmkcGGDsUmCGXEaPTBN8TmN9Ff8ohzGD", "error": "missing parent state: PS6uzpmiqKBntdvjCe6MyyJ9YGMmqT6Jy6XXsGfJdh279hhpN"}
[12-08|06:56:11.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "5LNZjZykZa2q9RoM4wesjngqAeeocm4WP32twdnFZnHbdTBZH", "lastAcceptedID": "7H8YD7wWgL5H4zvtyoeSsbbK428qz34q57aztyppELcbuq6b9", "error": "missing parent state: yF36DPzQK3qhVY4DdVxf4obr7nF1wSqofxGuQFeh9fvxGxp84"}

@@ -117,57 +117,71 @@ func (a *acceptor) ApricotAtomicBlock(b *block.ApricotAtomicBlock) error {
}

func (a *acceptor) abortBlock(b block.Block, blockType string) error {
parentID := b.Parent()
parentState, ok := a.blkIDToState[parentID]
blkID := b.ID()
Copy link
Contributor Author

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

acceptor.backend.blkIDToState[blkID] = &blockState{
onAcceptState: onAcceptState,
{
err = acceptor.BanffCommitBlock(blk)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

@abi87
Copy link
Contributor Author

abi87 commented Dec 8, 2023

There seems to be an issue around block building. See logs from a mainnet sync with partial sync activated. Looking at this.

[12-07|18:49:33.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "2oMiw4C94CxuUYkShic55fRotWwRYPQvz4BvMnwMijcfJ7QiGq", "lastAcceptedID": "36dVGoziVQZDzqEg4AZkQA3QWFTCEBhS9L6EmZVHsJVB73ZeY", "error": "missing parent state: 2tjmANc3GQ6DnbFsk2qAXX9JUaCp1Hf4NXeLNGVgqe7v27yZYv"}
[12-07|19:26:11.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "2nR3aw5KuFLHJ9UotXppE5mfvxdFSYheCW1V3JUSFJWc4os4b2", "lastAcceptedID": "2cx2Y5QbnSQruCW9NbyLFVn72in6P8jSj8FxKpqP8HdCZAJVXp", "error": "missing parent state: 2dofa7MT7dmS7DgrF86AyjXRYQ9BZzVdS8UsakTFy7MWuqVFSj"}
[12-07|20:01:30.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "2kHwo3M5D22HUKFTnVfnbkw7UAD7YqRqiPsmkVBDtH3dXVt2FA", "lastAcceptedID": "LufbRrCEKFSFLN7pEChoDsscEs83xtsiqZ9FLsKj88FCMv4au", "error": "missing parent state: 2ufX8ypJmVr2sBEa1ecehHLAQX1VhmT5f1e6NFtgMQCYA4LCff"}
[12-07|20:31:02.001] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "HEv7inZWefnzAaqyaS9uhLaHSRSPQjsxq3KquPk32F7swd8BA", "lastAcceptedID": "23ZHgZdyXk3Pds8PLvUVPFsTjqmLTqu131CdEixATfoRQoZXzK", "error": "missing parent state: 2f6pBaTBfquVuH5cc2XHagNvtdsRrCfzxhqJFQ6QQs2NF7KLFU"}
[12-07|20:34:45.386] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "C8bp1uZABH5zWzoEUVQGcpXwf4uMegHSPX14VVxbKgYZh8c74", "lastAcceptedID": "2114fzdhc4HnPj4HJcipHJMLEe7ycQB59yFPR6uLrtwacqAqAW", "error": "missing parent state: 2NTEWPD88UPcR9PFDaKknzj9VqNGdf3A61PUCHRdop2ZGXEnM8"}
[12-07|21:09:23.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "i4tuRNxz2jmos8viDS7BVfkC9ZXHAphR5sb6MgV16KF2HQgnw", "lastAcceptedID": "2sjU76XzQG5YJBLJt7JKMhCoeNKdsxpqzmuEapESHo6PrvkgLX", "error": "missing parent state: 2T6EdSyhF4gCrV1auzEs1Z27bgyanEJrciwkC9a5WuhnWDEyFx"}
[12-07|22:20:32.001] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "hmcMqLVqvhc1yrEVi6z7ABXLYDzx9iQCSRpwXnt1DPCLtYZix", "lastAcceptedID": "2U63MdAXNMvoQXHbS6fNjNHpJaZVASrVjdF8PkrsuG7xjFBKB2", "error": "missing parent state: tRG221rWh3FCJEz3oojwbGsaZPfYvwc1dpNN61KKSP65Uet9u"}
[12-07|22:22:49.506] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "7XpS1S9A31UK2fVbwyCL9mTdJnuJQszaLBh5re9FQYCPzF9yF", "lastAcceptedID": "UKe6tsttKDh5SUPxPfmkJb4NuWXCZ9fnFcjX56H6coBGuyaAx", "error": "missing parent state: 26xZ128fLBeeAJf7sydqznkrFAFfUpsuDEEyghctYNZudzoabJ"}
[12-08|00:55:49.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "a2st2fMPj8opMcYPRRhu1DeSoQiyJF1u6fbTJgncaLUZPzMfR", "lastAcceptedID": "2UHwmcXfDoewbD82XjaniuhtdmtL1CJ9LCFq7KcLHSubsqwurk", "error": "missing parent state: 2aTbz27zDPK34B3htjsRs6WyMk362J4ibsQkX3yNNA2N6oWymt"}
[12-08|05:12:15.012] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "jukSniLfwFXh8w5zKdp5bRhy22xDK7wrxwD1AQoTE9N5V1Pue", "lastAcceptedID": "kJkBcHZ5dnHj11yUdHoFsTuaPivyAhFpnjGSWL3k4joeSFVtP", "error": "missing parent state: KwueaXPDvWyqshMkJtBwaVE2nqgLVCPEc8qLvZvAQdPDm8S3d"}
[12-08|05:29:21.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "yQEXbbs661SKxoqj63U9UuDYjFpUT1DaGsUCnTMC1xKsnYfmR", "lastAcceptedID": "9UzL3xHoXbWbnJo7AGmDEhbDAE3Ar2gWN2KnNUCWgFXQ1bzv4", "error": "missing parent state: fGed5aSEK6XxDE5gk3TKdrh5UbPef5Fc8d8KZhBR9RCqmnwhE"}
[12-08|06:08:02.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "JddzNQyLqge6sfpqxZiCfJYU1wApya4XHehiYzkDi6pCHS6ew", "lastAcceptedID": "2GSkyRMYB33TaPhHN1zSpPw4jZnHacVVHEXDRkhznvRosiE3GG", "error": "missing parent state: 2Nmo7BSK3BfpzuopKtGDuw1GSnE341YsH3RWjm7TJ3t3JHUaCu"}
[12-08|06:23:13.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "iCMXEY5vHmbaVBXavVLWQqWAJc9HHbUhMv7ncxJ2FC9KCLzbi", "lastAcceptedID": "26s4kyA3ywwXp24AdBJmkcGGDsUmCGXEaPTBN8TmN9Ff8ohzGD", "error": "missing parent state: PS6uzpmiqKBntdvjCe6MyyJ9YGMmqT6Jy6XXsGfJdh279hhpN"}
[12-08|06:56:11.000] ERROR <P Chain> builder/builder.go:194 couldn't get next staker change time {"preferredID": "5LNZjZykZa2q9RoM4wesjngqAeeocm4WP32twdnFZnHbdTBZH", "lastAcceptedID": "7H8YD7wWgL5H4zvtyoeSsbbK428qz34q57aztyppELcbuq6b9", "error": "missing parent state: yF36DPzQK3qhVY4DdVxf4obr7nF1wSqofxGuQFeh9fvxGxp84"}

So failure were happening when proposal block was the accepted one; it's parent block state was missing when trying to iterator over current stakers. Note that the iteration is done by recursively fetching all diffs till state.State and building the iterator by merging these diffs.
I believe the issue was the following: in a previous version I was:

  1. applying proposal block state to state.State without committing it;
  2. applying the accepted option state and doing the commit.

This is wrong because when applying the proposal block I was overwriting the last Accepted block ID.
So when trying to loop over stakers and building recursivelly the staker iterator I would:

  1. end up looking at proposal block diff, which was not removed despite it's state being applied
  2. because last layer was a diff, trying and go down to it's parent in state.State
  3. state.State has last accepted block overwritten to be proposalBlkID, not its parent ID. Hence ther error

This is fixed by deferring proposal state application to when option block is accepted.

@dhrubabasu
Copy link
Contributor

Superseded by #2451

@abi87 abi87 changed the title Version Proposal Blocks [Proposal] - Version Proposal Blocks Dec 11, 2023
@dhrubabasu dhrubabasu closed this Dec 11, 2023
@abi87 abi87 added the Durango durango fork label Dec 11, 2023
@dhrubabasu dhrubabasu deleted the version_proposal_blocks branch December 11, 2023 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Durango durango fork
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants