File tree 1 file changed +22
-3
lines changed
1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -199,10 +199,29 @@ func (cnc *CosignerNonceCache) getUuids(n int) []uuid.UUID {
199
199
}
200
200
201
201
func (cnc * CosignerNonceCache ) target (noncesPerMinute float64 ) int {
202
- t := int ((noncesPerMinute / 60 ) *
203
- ((cnc .getNoncesInterval .Seconds () * nonceOverallocation ) + cnc .getNoncesTimeout .Seconds ()))
202
+ // Nonces needed per block:
203
+ // - 1 for proposal
204
+ // - 1 for prevote
205
+ // - 1 for precommit
206
+ // - 1 for vote extension (if enabled)
207
+ const (
208
+ noncesPerBlock = 4 // proposal + prevote + precommit + extension
209
+ blockTime = 0.5 // block time in seconds
210
+ )
211
+
212
+ // Calculate nonces needed per second based on either:
213
+ // - Actual usage (noncesPerMinute converted to per second)
214
+ // - Theoretical usage (noncesPerBlock / blockTime)
215
+ noncesPerSecond := max (noncesPerMinute / 60 , float64 (noncesPerBlock )/ blockTime )
216
+
217
+ // Calculate target number of nonces to maintain in cache:
218
+ // noncesPerSecond * (interval * overallocation + timeout)
219
+ t := int (noncesPerSecond * ((cnc .getNoncesInterval .Seconds () * nonceOverallocation ) +
220
+ cnc .getNoncesTimeout .Seconds ()))
221
+
222
+ // Always maintain at least one nonce
204
223
if t <= 0 {
205
- return 1 // always target at least one nonce ready
224
+ return 1
206
225
}
207
226
return t
208
227
}
You can’t perform that action at this time.
0 commit comments