Skip to content

Make AVM implement block.HeightIndexedChainVM #1699

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
merged 12 commits into from
Jul 13, 2023

Conversation

dhrubabasu
Copy link
Contributor

@dhrubabasu dhrubabasu commented Jul 5, 2023

Why this should be merged

We use both GetBlockID and GetBlockIDAtHeight in different places in the repo. This standardizes all of these calls to GetBlockIDAtHeight.

Additionally, implements block.HeightIndexedChainVM on the AVM to kick off the X-chain proposervm height index (https://github.com/ava-labs/avalanchego/blob/master/vms/proposervm/vm.go#L341)

How this works

Find + replace + implement interface

How this was tested

CI

@dhrubabasu dhrubabasu added the vm This involves virtual machines label Jul 5, 2023
@dhrubabasu dhrubabasu added this to the v1.10.4 milestone Jul 5, 2023
@dhrubabasu dhrubabasu requested a review from abi87 as a code owner July 5, 2023 22:11
@dhrubabasu dhrubabasu self-assigned this Jul 5, 2023
@dhrubabasu dhrubabasu force-pushed the avm-standardize-getblockidatheight branch from 7558d33 to 4bc89d1 Compare July 5, 2023 22:11
darioush
darioush previously approved these changes Jul 5, 2023
abi87
abi87 previously approved these changes Jul 6, 2023
@StephenButtolph StephenButtolph modified the milestones: v1.10.4, v1.10.5 Jul 6, 2023
@dhrubabasu dhrubabasu changed the title GetBlockID -> GetBlockIDAtHeight Make AVM implement block.HeightIndexedChainVM Jul 7, 2023
coffeeavax
coffeeavax previously approved these changes Jul 9, 2023
@StephenButtolph StephenButtolph dismissed stale reviews from coffeeavax, abi87, and darioush July 12, 2023 15:21

stale

stopVertexID ids.ID
}

func NewLinearizeOnInitializeVM(vm vertex.LinearizableVMWithEngine) *linearizeOnInitializeVM {
hVM, _ := vm.(block.HeightIndexedChainVM)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this ever not be ok?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it would just be nil then and we handle that below...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in our usage but it could not be okay by somebody implementing a linearizable vm (definitely not advised haha).

return vm.state.GetBlockIDAtHeight(height)
}

func (*VM) VerifyHeightIndex(context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is never called because it is wrapped by the HeightIndexedVM?

(if so, may make sense to clarify that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The vm itself implements HeightIndexedVM, it doesn't wrap it. This function is called here when we're generating the proposervm height index.

Reason why it's nil is because the AVM has always had a height index so we don't need to verify it.

Copy link
Contributor

@patrick-ogrady patrick-ogrady Jul 13, 2023

Choose a reason for hiding this comment

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

How does it always have it if it is performed async (and could be interrupted)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The AVM height index is not performed async. Since we linearized, each block was included in the height index on accept.

This is different than the P-chain where there is a period of time where both the inner vm and the proposervm height indexes are incomplete so we cannot simply return nil there.

Signed-off-by: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
@StephenButtolph StephenButtolph merged commit 535c123 into dev Jul 13, 2023
@StephenButtolph StephenButtolph deleted the avm-standardize-getblockidatheight branch July 13, 2023 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm This involves virtual machines
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants