forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start Snowman++ after Avalanche is Linearized (ava-labs#2478)
- Loading branch information
1 parent
69863d9
commit 3268a81
Showing
21 changed files
with
662 additions
and
248 deletions.
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
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) | ||
} |
Oops, something went wrong.