@@ -199,26 +199,31 @@ func (cnc *CosignerNonceCache) getUuids(n int) []uuid.UUID {
199
199
}
200
200
201
201
func (cnc * CosignerNonceCache ) target (noncesPerMinute float64 ) int {
202
- // Calculate for nonce expiration window
203
- blocksPerExpirationWindow := int (cnc .nonceExpiration .Seconds () / 0.5 ) // 0.5 second blocks
204
-
205
202
// Nonces needed per block:
206
203
// - 1 for proposal
207
204
// - 1 for prevote
208
205
// - 1 for precommit
209
206
// - 1 for vote extension (if enabled)
210
- noncesPerBlock := 4 // proposal + prevote + precommit + extension
207
+ const (
208
+ noncesPerBlock = 4 // proposal + prevote + precommit + extension
209
+ blockTime = 0.5 // block time in seconds
210
+ )
211
211
212
- // Total nonces needed for expiration window with overallocation
213
- activeNoncesPerWindow := int ( float64 ( blocksPerExpirationWindow ) *
214
- float64 (noncesPerBlock ) *
215
- nonceOverallocation )
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
216
217
- // Calculate based on current usage with buffer
218
- currentUsageTarget := int ((noncesPerMinute / 60 ) *
219
- ((cnc .getNoncesInterval .Seconds () * nonceOverallocation ) + cnc .getNoncesTimeout .Seconds ()))
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 ()))
220
221
221
- return max (currentUsageTarget , activeNoncesPerWindow )
222
+ // Always maintain at least one nonce
223
+ if t <= 0 {
224
+ return 1
225
+ }
226
+ return t
222
227
}
223
228
224
229
func (cnc * CosignerNonceCache ) reconcile (ctx context.Context ) {
0 commit comments