forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
linearizable_vm.go
82 lines (72 loc) · 2.19 KB
/
linearizable_vm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package chains
import (
"context"
"github.com/MetalBlockchain/metalgo/database"
"github.com/MetalBlockchain/metalgo/ids"
"github.com/MetalBlockchain/metalgo/snow"
"github.com/MetalBlockchain/metalgo/snow/engine/avalanche/vertex"
"github.com/MetalBlockchain/metalgo/snow/engine/common"
"github.com/MetalBlockchain/metalgo/snow/engine/snowman/block"
)
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
ctx *snow.Context
db database.Database
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
return vm.vmToInitialize.Initialize(
ctx,
vm.ctx,
vm.db,
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 NewLinearizeOnInitializeVM(vm vertex.LinearizableVMWithEngine) *linearizeOnInitializeVM {
return &linearizeOnInitializeVM{
LinearizableVMWithEngine: vm,
}
}
func (vm *linearizeOnInitializeVM) Initialize(
ctx context.Context,
_ *snow.Context,
_ database.Database,
_ []byte,
_ []byte,
_ []byte,
toEngine chan<- common.Message,
_ []*common.Fx,
_ common.AppSender,
) error {
return vm.Linearize(ctx, vm.stopVertexID, toEngine)
}