@@ -75,6 +75,8 @@ type Node struct {
75
75
startCtx context.Context
76
76
77
77
closer io.Closer
78
+
79
+ roundRepublishCache * lru.Cache
78
80
}
79
81
80
82
type NewNodeOptions struct {
@@ -116,6 +118,11 @@ func NewNode(ctx context.Context, opts *NewNodeOptions) (*Node, error) {
116
118
return nil , fmt .Errorf ("error creating cache: %w" , err )
117
119
}
118
120
121
+ roundRepublishCache , err := lru .New (3 )
122
+ if err != nil {
123
+ return nil , fmt .Errorf ("error creating cache: %w" , err )
124
+ }
125
+
119
126
nodeName := opts .Name
120
127
if nodeName == "" {
121
128
nodeName = fmt .Sprintf ("node-%d" , signerIndex )
@@ -128,18 +135,19 @@ func NewNode(ctx context.Context, opts *NewNodeOptions) (*Node, error) {
128
135
dagStore := opts .DagStore
129
136
130
137
n := & Node {
131
- name : nodeName ,
132
- p2pNode : opts .P2PNode ,
133
- signKey : opts .SignKey ,
134
- notaryGroup : opts .NotaryGroup ,
135
- dagStore : dagStore ,
136
- hamtStore : hamtStore ,
137
- dataStore : dataStore ,
138
- signerIndex : signerIndex ,
139
- inflight : cache ,
140
- mempool : newMempool (),
141
- rootContext : opts .RootActorContext ,
142
- logger : logger ,
138
+ name : nodeName ,
139
+ p2pNode : opts .P2PNode ,
140
+ signKey : opts .SignKey ,
141
+ notaryGroup : opts .NotaryGroup ,
142
+ dagStore : dagStore ,
143
+ hamtStore : hamtStore ,
144
+ dataStore : dataStore ,
145
+ signerIndex : signerIndex ,
146
+ inflight : cache ,
147
+ mempool : newMempool (),
148
+ rootContext : opts .RootActorContext ,
149
+ logger : logger ,
150
+ roundRepublishCache : roundRepublishCache ,
143
151
}
144
152
145
153
err = n .initRoundHolder ()
@@ -243,7 +251,7 @@ func (n *Node) maybeRepublish(ctx context.Context) {
243
251
244
252
if found && previousRound != nil && previousRound .published {
245
253
n .logger .Debugf ("republishing round: %d" , previousRound .height )
246
- n .publishCompletedRound (ctx , previousRound )
254
+ n .republishCompletedRound (ctx , previousRound )
247
255
}
248
256
}
249
257
}
@@ -451,9 +459,20 @@ func (n *Node) publishCompletedRound(ctx context.Context, round *round) error {
451
459
452
460
defer func () { round .published = true }()
453
461
462
+ n .roundRepublishCache .Add (round .height , conf .Data ())
463
+
454
464
return n .pubsub .Publish (n .notaryGroup .ID , conf .Data ())
455
465
}
456
466
467
+ func (n * Node ) republishCompletedRound (ctx context.Context , round * round ) error {
468
+ roundConfPayload , ok := n .roundRepublishCache .Peek (round ) // Peek acts as FIFO based on insert above
469
+ if ok {
470
+ n .logger .Debugf ("republishing round confirmed to: %s" , n .notaryGroup .ID )
471
+ return n .pubsub .Publish (n .notaryGroup .ID , roundConfPayload .([]byte ))
472
+ }
473
+ return n .publishCompletedRound (ctx , round )
474
+ }
475
+
457
476
func (n * Node ) storeCompletedRound (round * types.RoundWrapper ) error {
458
477
heightBytes := make ([]byte , binary .MaxVarintLen64 )
459
478
binary .PutUvarint (heightBytes , round .Height ())
0 commit comments