Skip to content

Commit

Permalink
Start Snowman++ after Avalanche is Linearized (ava-labs#2478)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Mar 17, 2023
1 parent 69863d9 commit 3268a81
Show file tree
Hide file tree
Showing 21 changed files with 662 additions and 248 deletions.
80 changes: 80 additions & 0 deletions chains/linearizable_vm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package chains

import (
"context"

"github.com/ava-labs/avalanchego/api/metrics"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"

dbManager "github.com/ava-labs/avalanchego/database/manager"
)

var (
_ vertex.LinearizableVM = (*initializeOnLinearizeVM)(nil)
_ block.ChainVM = (*linearizeOnInitializeVM)(nil)
)

// initializeOnLinearizeVM transforms the consensus engine's call to Linearize
// into a call to Initialize. This enables the proposervm to be initialized by
// the call to Linearize. This also provides the stopVertexID to the
// linearizeOnInitializeVM.
type initializeOnLinearizeVM struct {
vertex.DAGVM
vmToInitialize common.VM
vmToLinearize *linearizeOnInitializeVM

registerer metrics.OptionalGatherer
ctx *snow.Context
dbManager dbManager.Manager
genesisBytes []byte
upgradeBytes []byte
configBytes []byte
toEngine chan<- common.Message
fxs []*common.Fx
appSender common.AppSender
}

func (vm *initializeOnLinearizeVM) Linearize(ctx context.Context, stopVertexID ids.ID) error {
vm.vmToLinearize.stopVertexID = stopVertexID
vm.ctx.Metrics = vm.registerer
return vm.vmToInitialize.Initialize(
ctx,
vm.ctx,
vm.dbManager,
vm.genesisBytes,
vm.upgradeBytes,
vm.configBytes,
vm.toEngine,
vm.fxs,
vm.appSender,
)
}

// linearizeOnInitializeVM transforms the proposervm's call to Initialize into a
// call to Linearize. This enables the proposervm to provide its toEngine
// channel to the VM that is being linearized.
type linearizeOnInitializeVM struct {
vertex.LinearizableVMWithEngine
stopVertexID ids.ID
}

func (vm *linearizeOnInitializeVM) Initialize(
ctx context.Context,
_ *snow.Context,
_ dbManager.Manager,
_ []byte,
_ []byte,
_ []byte,
toEngine chan<- common.Message,
_ []*common.Fx,
_ common.AppSender,
) error {
return vm.Linearize(ctx, vm.stopVertexID, toEngine)
}
Loading

0 comments on commit 3268a81

Please sign in to comment.