Skip to content

Commit 11d742c

Browse files
committed
use max instead of addition
1 parent 3593b3c commit 11d742c

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

signer/cosigner_nonce_cache.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,27 @@ func (cnc *CosignerNonceCache) getUuids(n int) []uuid.UUID {
199199
}
200200

201201
func (cnc *CosignerNonceCache) target(noncesPerMinute float64) int {
202-
buffer := 60
203-
t := int((noncesPerMinute / 60) *
204-
((cnc.getNoncesInterval.Seconds() * nonceOverallocation) + cnc.getNoncesTimeout.Seconds()))
205-
if t <= 0 {
206-
t = 0
207-
}
208-
return t + buffer
202+
// Calculate for 10s window (nonce expiration period)
203+
activeBlocksPer10s := 20 // (10 seconds / 0.5 second blocks)
204+
205+
// Nonces needed per block:
206+
// - 1 for proposal
207+
// - 1 for prevote
208+
// - 1 for precommit
209+
// - 1 for vote extension (if enabled)
210+
noncesPerBlock := 4 // proposal + prevote + precommit + extension
211+
212+
// Total nonces needed for 10s window with overallocation
213+
activeNoncesPer10s := int(float64(activeBlocksPer10s) *
214+
float64(noncesPerBlock) *
215+
nonceOverallocation) // Using the standard 1.5 overallocation
216+
217+
// Calculate based on current usage with buffer (adjusted for 10s window)
218+
currentUsageTarget := int((noncesPerMinute / 6) * // Convert per-minute to per-10-seconds
219+
((cnc.getNoncesInterval.Seconds() * nonceOverallocation) +
220+
cnc.getNoncesTimeout.Seconds()))
221+
222+
return max(currentUsageTarget, activeNoncesPer10s)
209223
}
210224

211225
func (cnc *CosignerNonceCache) reconcile(ctx context.Context) {

0 commit comments

Comments
 (0)