1
1
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
2
2
// See the file LICENSE for licensing terms.
3
3
4
- package vm
4
+ package validators
5
5
6
6
import (
7
7
"context"
@@ -11,6 +11,7 @@ import (
11
11
12
12
"github.com/ava-labs/avalanchego/cache"
13
13
"github.com/ava-labs/avalanchego/ids"
14
+ "github.com/ava-labs/avalanchego/snow"
14
15
"github.com/ava-labs/avalanchego/snow/validators"
15
16
"github.com/ava-labs/avalanchego/utils/crypto/bls"
16
17
"github.com/ava-labs/avalanchego/utils/set"
@@ -23,8 +24,13 @@ const (
23
24
proposerMonitorLRUSize = 60
24
25
)
25
26
27
+ type Backend interface {
28
+ PreferredHeight (ctx context.Context ) (uint64 , error )
29
+ }
30
+
26
31
type ProposerMonitor struct {
27
- vm * VM
32
+ backend Backend
33
+ snowCtx * snow.Context
28
34
proposer proposer.Windower
29
35
30
36
currentPHeight uint64
@@ -37,13 +43,14 @@ type ProposerMonitor struct {
37
43
rl sync.Mutex
38
44
}
39
45
40
- func NewProposerMonitor (vm * VM ) * ProposerMonitor {
46
+ func NewProposerMonitor (backend Backend , snowCtx * snow. Context ) * ProposerMonitor {
41
47
return & ProposerMonitor {
42
- vm : vm ,
48
+ backend : backend ,
49
+ snowCtx : snowCtx ,
43
50
proposer : proposer .New (
44
- vm . snowCtx .ValidatorState ,
45
- vm . snowCtx .SubnetID ,
46
- vm . snowCtx .ChainID ,
51
+ snowCtx .ValidatorState ,
52
+ snowCtx .SubnetID ,
53
+ snowCtx .ChainID ,
47
54
),
48
55
proposerCache : & cache.LRU [string , []ids.NodeID ]{Size : proposerMonitorLRUSize },
49
56
}
@@ -58,14 +65,14 @@ func (p *ProposerMonitor) refresh(ctx context.Context) error {
58
65
return nil
59
66
}
60
67
start := time .Now ()
61
- pHeight , err := p .vm . snowCtx .ValidatorState .GetCurrentHeight (ctx )
68
+ pHeight , err := p .snowCtx .ValidatorState .GetCurrentHeight (ctx )
62
69
if err != nil {
63
70
return err
64
71
}
65
- p .validators , err = p .vm . snowCtx .ValidatorState .GetValidatorSet (
72
+ p .validators , err = p .snowCtx .ValidatorState .GetValidatorSet (
66
73
ctx ,
67
74
pHeight ,
68
- p .vm . snowCtx .SubnetID ,
75
+ p .snowCtx .SubnetID ,
69
76
)
70
77
if err != nil {
71
78
return err
@@ -78,7 +85,7 @@ func (p *ProposerMonitor) refresh(ctx context.Context) error {
78
85
pks [string (bls .PublicKeyToCompressedBytes (v .PublicKey ))] = struct {}{}
79
86
}
80
87
p .validatorPublicKeys = pks
81
- p .vm . snowCtx .Log .Info (
88
+ p .snowCtx .Log .Info (
82
89
"refreshed proposer monitor" ,
83
90
zap .Uint64 ("previous" , p .currentPHeight ),
84
91
zap .Uint64 ("new" , pHeight ),
@@ -105,14 +112,14 @@ func (p *ProposerMonitor) Proposers(
105
112
if err := p .refresh (ctx ); err != nil {
106
113
return nil , err
107
114
}
108
- preferredBlk , err := p .vm . GetStatefulBlock (ctx , p . vm . preferred )
115
+ preferredHeight , err := p .backend . PreferredHeight (ctx )
109
116
if err != nil {
110
117
return nil , err
111
118
}
112
119
proposersToGossip := set.NewSet [ids.NodeID ](diff * depth )
113
120
udepth := uint64 (depth )
114
121
for i := uint64 (1 ); i <= uint64 (diff ); i ++ {
115
- height := preferredBlk . Hght + i
122
+ height := preferredHeight + i
116
123
key := fmt .Sprintf ("%d-%d" , height , p .currentPHeight )
117
124
var proposers []ids.NodeID
118
125
if v , ok := p .proposerCache .Get (key ); ok {
0 commit comments