-
Notifications
You must be signed in to change notification settings - Fork 670
/
block.go
62 lines (50 loc) · 1.45 KB
/
block.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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package executor
import (
"context"
"time"
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/vms/platformvm/block"
)
var (
_ snowman.Block = (*Block)(nil)
_ snowman.OracleBlock = (*Block)(nil)
)
// Exported for testing in platformvm package.
type Block struct {
block.Block
manager *manager
}
func (b *Block) Verify(context.Context) error {
blkID := b.ID()
if _, ok := b.manager.blkIDToState[blkID]; ok {
// This block has already been verified.
return nil
}
return b.Visit(b.manager.verifier)
}
func (b *Block) Accept(context.Context) error {
return b.Visit(b.manager.acceptor)
}
func (b *Block) Reject(context.Context) error {
return b.Visit(b.manager.rejector)
}
func (b *Block) Timestamp() time.Time {
return b.manager.getTimestamp(b.ID())
}
func (b *Block) Options(context.Context) ([2]snowman.Block, error) {
options := options{
log: b.manager.ctx.Log,
primaryUptimePercentage: b.manager.txExecutorBackend.Config.UptimePercentage,
uptimes: b.manager.txExecutorBackend.Uptimes,
state: b.manager.backend.state,
}
if err := b.Block.Visit(&options); err != nil {
return [2]snowman.Block{}, err
}
return [2]snowman.Block{
b.manager.NewBlock(options.preferredBlock),
b.manager.NewBlock(options.alternateBlock),
}, nil
}