@@ -45,6 +45,8 @@ type partialMessageManager struct {
45
45
pendingDiscoveredChains chan * discoveredChain
46
46
// pendingChainBroadcasts is a channel of chains that are pending to be broadcasted.
47
47
pendingChainBroadcasts chan chainexchange.Message
48
+ // pendingInstanceRemoval is a channel of instances that are pending to be removed.
49
+ pendingInstanceRemoval chan uint64
48
50
// rebroadcastInterval is the interval at which chains are re-broadcasted.
49
51
rebroadcastInterval time.Duration
50
52
@@ -58,6 +60,7 @@ func newPartialMessageManager(progress gpbft.Progress, ps *pubsub.PubSub, m *man
58
60
pendingDiscoveredChains : make (chan * discoveredChain , 100 ), // TODO: parameterize buffer size.
59
61
pendingPartialMessages : make (chan * PartiallyValidatedMessage , 100 ), // TODO: parameterize buffer size.
60
62
pendingChainBroadcasts : make (chan chainexchange.Message , 100 ), // TODO: parameterize buffer size.
63
+ pendingInstanceRemoval : make (chan uint64 , 10 ),
61
64
rebroadcastInterval : m .ChainExchange .RebroadcastInterval ,
62
65
}
63
66
var err error
@@ -150,6 +153,23 @@ func (pmm *partialMessageManager) Start(ctx context.Context) (<-chan *PartiallyV
150
153
// TODO: Add equivocation metrics: check if the message is different and if so
151
154
// increment the equivocations counter tagged by phase.
152
155
// See: https://github.com/filecoin-project/go-f3/issues/812
156
+ case instance , ok := <- pmm .pendingInstanceRemoval :
157
+ if ! ok {
158
+ return
159
+ }
160
+ for i := range pmm .pmByInstance {
161
+ if i < instance {
162
+ delete (pmm .pmByInstance , i )
163
+ }
164
+ }
165
+ for i := range pmm .pmkByInstanceByChainKey {
166
+ if i < instance {
167
+ delete (pmm .pmkByInstanceByChainKey , i )
168
+ }
169
+ }
170
+ if err := pmm .chainex .RemoveChainsByInstance (ctx , instance ); err != nil {
171
+ log .Errorw ("Failed to remove chains by instance form chainexchange." , "instance" , instance , "error" , err )
172
+ }
153
173
}
154
174
}
155
175
}()
@@ -366,6 +386,16 @@ func inferJustificationVoteValue(pgmsg *PartialGMessage) {
366
386
}
367
387
}
368
388
389
+ func (pmm * partialMessageManager ) RemoveMessagesBeforeInstance (ctx context.Context , instance uint64 ) {
390
+ select {
391
+ case <- ctx .Done ():
392
+ return
393
+ case pmm .pendingInstanceRemoval <- instance :
394
+ default :
395
+ log .Warnw ("Dropped instance removal request as partial message manager is too slow." , "instance" , instance )
396
+ }
397
+ }
398
+
369
399
func (pmm * partialMessageManager ) Shutdown (ctx context.Context ) error {
370
400
if pmm .stop != nil {
371
401
pmm .stop ()
0 commit comments