Commit d300fa1 1 parent 8ea8e63 commit d300fa1 Copy full SHA for d300fa1
File tree 2 files changed +24
-9
lines changed
2 files changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -141,20 +141,28 @@ func (fff *F3) runSigningLoop(ctx context.Context) {
141
141
142
142
msgCh := fff .inner .MessagesToSign ()
143
143
144
- loop:
144
+ var mb * gpbft.MessageBuilder
145
+ alreadyParticipated := make (map [uint64 ]struct {})
145
146
for ctx .Err () == nil {
146
147
select {
147
148
case <- ctx .Done ():
148
149
return
149
- case mb , ok := <- msgCh :
150
- if ! ok {
151
- continue loop
150
+ case <- fff . leaser . notifyParticipation :
151
+ if mb == nil {
152
+ continue
152
153
}
153
- participants := fff .leaser .getParticipantsByInstance (mb .Payload .Instance )
154
- for _ , id := range participants {
155
- if err := participateOnce (ctx , mb , id ); err != nil {
156
- log .Errorf ("while participating for miner f0%d: %+v" , id , err )
157
- }
154
+ case mb = <- msgCh : // never closed
155
+ clear (alreadyParticipated )
156
+ }
157
+
158
+ participants := fff .leaser .getParticipantsByInstance (mb .Payload .Instance )
159
+ for _ , id := range participants {
160
+ if _ , ok := alreadyParticipated [id ]; ok {
161
+ continue
162
+ } else if err := participateOnce (ctx , mb , id ); err != nil {
163
+ log .Errorf ("while participating for miner f0%d: %+v" , id , err )
164
+ } else {
165
+ alreadyParticipated [id ] = struct {}{}
158
166
}
159
167
}
160
168
}
Original file line number Diff line number Diff line change @@ -23,13 +23,16 @@ type leaser struct {
23
23
issuer peer.ID
24
24
status f3Status
25
25
maxLeasableInstances uint64
26
+ // Signals that a lease was created and/or updated.
27
+ notifyParticipation chan struct {}
26
28
}
27
29
28
30
func newParticipationLeaser (nodeId peer.ID , status f3Status , maxLeasedInstances uint64 ) * leaser {
29
31
return & leaser {
30
32
leases : make (map [uint64 ]api.F3ParticipationLease ),
31
33
issuer : nodeId ,
32
34
status : status ,
35
+ notifyParticipation : make (chan struct {}, 1 ),
33
36
maxLeasableInstances : maxLeasedInstances ,
34
37
}
35
38
}
@@ -102,6 +105,10 @@ func (l *leaser) participate(ticket api.F3ParticipationTicket) (api.F3Participat
102
105
log .Infof ("started participating in F3 for miner %d" , newLease .MinerID )
103
106
}
104
107
l .leases [newLease .MinerID ] = newLease
108
+ select {
109
+ case l .notifyParticipation <- struct {}{}:
110
+ default :
111
+ }
105
112
return newLease , nil
106
113
}
107
114
You can’t perform that action at this time.
0 commit comments