forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
batched_vm.go
57 lines (49 loc) · 1.34 KB
/
batched_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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package metervm
import (
"context"
"time"
"github.com/MetalBlockchain/metalgo/ids"
"github.com/MetalBlockchain/metalgo/snow/consensus/snowman"
"github.com/MetalBlockchain/metalgo/snow/engine/snowman/block"
)
func (vm *blockVM) GetAncestors(
ctx context.Context,
blkID ids.ID,
maxBlocksNum int,
maxBlocksSize int,
maxBlocksRetrivalTime time.Duration,
) ([][]byte, error) {
if vm.batchedVM == nil {
return nil, block.ErrRemoteVMNotImplemented
}
start := vm.clock.Time()
ancestors, err := vm.batchedVM.GetAncestors(
ctx,
blkID,
maxBlocksNum,
maxBlocksSize,
maxBlocksRetrivalTime,
)
end := vm.clock.Time()
vm.blockMetrics.getAncestors.Observe(float64(end.Sub(start)))
return ancestors, err
}
func (vm *blockVM) BatchedParseBlock(ctx context.Context, blks [][]byte) ([]snowman.Block, error) {
if vm.batchedVM == nil {
return nil, block.ErrRemoteVMNotImplemented
}
start := vm.clock.Time()
blocks, err := vm.batchedVM.BatchedParseBlock(ctx, blks)
end := vm.clock.Time()
vm.blockMetrics.batchedParseBlock.Observe(float64(end.Sub(start)))
wrappedBlocks := make([]snowman.Block, len(blocks))
for i, block := range blocks {
wrappedBlocks[i] = &meterBlock{
Block: block,
vm: vm,
}
}
return wrappedBlocks, err
}