-
Notifications
You must be signed in to change notification settings - Fork 669
/
manager.go
84 lines (73 loc) · 2.06 KB
/
manager.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
83
84
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package executor
import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/vms/platformvm/blocks"
"github.com/ava-labs/avalanchego/vms/platformvm/metrics"
"github.com/ava-labs/avalanchego/vms/platformvm/state"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool"
"github.com/ava-labs/avalanchego/vms/platformvm/validators"
)
var _ Manager = (*manager)(nil)
type Manager interface {
state.Versions
// Returns the ID of the most recently accepted block.
LastAccepted() ids.ID
GetBlock(blkID ids.ID) (snowman.Block, error)
GetStatelessBlock(blkID ids.ID) (blocks.Block, error)
NewBlock(blocks.Block) snowman.Block
}
func NewManager(
mempool mempool.Mempool,
metrics metrics.Metrics,
s state.State,
txExecutorBackend *executor.Backend,
validatorManager validators.Manager,
) Manager {
backend := &backend{
Mempool: mempool,
lastAccepted: s.GetLastAccepted(),
state: s,
ctx: txExecutorBackend.Ctx,
blkIDToState: map[ids.ID]*blockState{},
}
return &manager{
backend: backend,
verifier: &verifier{
backend: backend,
txExecutorBackend: txExecutorBackend,
},
acceptor: &acceptor{
backend: backend,
metrics: metrics,
validators: validatorManager,
bootstrapped: txExecutorBackend.Bootstrapped,
},
rejector: &rejector{backend: backend},
}
}
type manager struct {
*backend
verifier blocks.Visitor
acceptor blocks.Visitor
rejector blocks.Visitor
}
func (m *manager) GetBlock(blkID ids.ID) (snowman.Block, error) {
blk, err := m.backend.GetBlock(blkID)
if err != nil {
return nil, err
}
return m.NewBlock(blk), nil
}
func (m *manager) GetStatelessBlock(blkID ids.ID) (blocks.Block, error) {
return m.backend.GetBlock(blkID)
}
func (m *manager) NewBlock(blk blocks.Block) snowman.Block {
return &Block{
manager: m,
Block: blk,
}
}