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

Snow VM #1831

Draft
wants to merge 59 commits into
base: main
Choose a base branch
from
Draft

Snow VM #1831

wants to merge 59 commits into from

Conversation

aaronbuchwald
Copy link
Collaborator

This refactor is intended to separate out maintenance of the AvalancheGo specific invariants and initialization from the VM package.

Prior to this PR, the VM package:

  • initializes all of the required components of the chain with the params supplied by AvalancheGo
  • Implements the snowman.Block, block.ChainVM, and block.StateSyncableVM interfaces

This PR aims to reduce the responsibilities of the VM package as much as possible. Note: #1744 moved the StatefulBlock type out of the chain package and into VM. This continues to remove AvalancheGo specific functionality from the HyperVM specific components.

The goal of this refactor is to get to a point where:

  • snow package implements snowman.Block and block.ChainVM and maintains invariants required by consensus engine
  • snow package can be tested independently of HyperSDK chain logic that it correctly maintains those invariants
  • snow package "decomposes" the AvalancheGo VM interface into components with given defaults and can be overridden by an individual chain (currently Options, but should be renamed as it doesn't quite fit under this pattern)
  • rename vm package to hypervm
  • vm package plays the role of initializing all of the required components and implementing a simpler interface that handles the required block state transitions
  • can write integration tests for the vm package that do not need to cover consensus engine edge cases
  • makes it possible to implement both DSMR and non-DSMR version of HyperSDK (use DSMR block type and produce chain.OutputBlock after accept that can be sent to relevant APIs)

@aaronbuchwald aaronbuchwald added the DO NOT MERGE This PR is not meant to be merged in its current state label Dec 10, 2024
snow/vm.go Fixed Show fixed Hide fixed
vm/vm.go Fixed Show fixed Hide fixed
vm/vm.go Fixed Show fixed Hide fixed
vm/vm.go Fixed Show fixed Hide fixed
vm/vm.go Fixed Show fixed Hide fixed
vm/vm.go Fixed Show fixed Hide fixed
vm/vm.go Fixed Show fixed Hide fixed
vm/vm.go Fixed Show fixed Hide fixed
vm/vm.go Fixed Show fixed Hide fixed
vm/vm.go Fixed Show fixed Hide fixed
@aaronbuchwald
Copy link
Collaborator Author

aaronbuchwald commented Dec 11, 2024

Next steps:

  1. Clean up dynamic state sync and write snow dynamic state sync tests
  2. Move general purpose config out of snow package and replace with "context" that can either be a singleton or passed around similar to require.Equal(t, a, b) or r.Equal(a, b)
  3. Update out of date comments
  4. Replace "Options" misnomer (Configuration?)
  5. Handle cyclic dependency with chain index (chain must currently return last accepted block and potentially re-process blocks)
  6. Update VM package + rename to HyperVM + add HyperVM integration tests

Most importantly break this PR up

vm/vm.go Fixed Show fixed Hide fixed
Comment on lines +56 to +60
res.Errors = make([]string, len(errs))
for i, err := range errs {
if err != nil {
res.Errors[i] = err.Error()
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixes a bug discovered in a newly added test. If the error was nil, then the previous code triggered a panic.

Comment on lines +38 to +40
return fmt.Errorf("%w: tx timestamp (%d) < block timestamp (%d)", ErrTimestampTooLate, b.Timestamp, timestamp)
case b.Timestamp > timestamp+r.GetValidityWindow(): // tx: 100 block 10
return ErrTimestampTooEarly
return fmt.Errorf("%w: tx timestamp (%d) > block timestamp (%d) + validity window (%d)", ErrTimestampTooEarly, b.Timestamp, timestamp, r.GetValidityWindow())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added details while debugging newly added tests. These errors are much more helpful with the added information.

@@ -72,10 +71,8 @@ func (p *PreExecutor) PreExecute(
}

// Verify auth if not already verified by caller
if verifyAuth {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was never false previously.

Comment on lines +157 to +158
// NewTransaction creates a Transaction and initializes the private fields.
func NewTransaction(base *Base, actions Actions, auth Auth) (*Transaction, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need this exported for newly added tests

Comment on lines +55 to +59
authFactories := testingNetworkConfig.AuthFactories()
spamKey := authFactories[0]
generator := workload.NewTxGenerator(authFactories[1])
tc := e2e.NewTestContext()
he2e.SetWorkload(testingNetworkConfig, generator, expectedABI, &spamHelper, firstAuthFactory)
he2e.SetWorkload(testingNetworkConfig, generator, expectedABI, &spamHelper, spamKey)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Throughput and workflow tests should not share the same pre-funded key

Comment on lines -17 to -19
type Ready interface {
IsReady() bool
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove the need for IsReady and register the gossip handler when it's ready instead

@@ -8,10 +8,10 @@ import (
"testing"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/trace"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

remove need for HyperSDK defined trace package

@@ -1,666 +0,0 @@
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: add integration testing harness for VMs and use for MorpheusVM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE This PR is not meant to be merged in its current state
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant