-
Notifications
You must be signed in to change notification settings - Fork 671
/
vertex_vm.go
73 lines (61 loc) · 1.68 KB
/
vertex_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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package tracedvm
import (
"context"
"go.opentelemetry.io/otel/attribute"
oteltrace "go.opentelemetry.io/otel/trace"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/consensus/snowstorm"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/trace"
)
var _ vertex.LinearizableVMWithEngine = (*vertexVM)(nil)
type vertexVM struct {
vertex.LinearizableVMWithEngine
tracer trace.Tracer
}
func NewVertexVM(vm vertex.LinearizableVMWithEngine, tracer trace.Tracer) vertex.LinearizableVMWithEngine {
return &vertexVM{
LinearizableVMWithEngine: vm,
tracer: tracer,
}
}
func (vm *vertexVM) Initialize(
ctx context.Context,
chainCtx *snow.Context,
db database.Database,
genesisBytes,
upgradeBytes,
configBytes []byte,
toEngine chan<- common.Message,
fxs []*common.Fx,
appSender common.AppSender,
) error {
ctx, span := vm.tracer.Start(ctx, "vertexVM.Initialize")
defer span.End()
return vm.LinearizableVMWithEngine.Initialize(
ctx,
chainCtx,
db,
genesisBytes,
upgradeBytes,
configBytes,
toEngine,
fxs,
appSender,
)
}
func (vm *vertexVM) ParseTx(ctx context.Context, txBytes []byte) (snowstorm.Tx, error) {
ctx, span := vm.tracer.Start(ctx, "vertexVM.ParseTx", oteltrace.WithAttributes(
attribute.Int("txLen", len(txBytes)),
))
defer span.End()
tx, err := vm.LinearizableVMWithEngine.ParseTx(ctx, txBytes)
return &tracedTx{
Tx: tx,
tracer: vm.tracer,
}, err
}