From 99e23b48807515dade142c6bbbeb327847c155f4 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Thu, 16 Nov 2023 13:23:30 -0700 Subject: [PATCH] make local cosigner nonce cache expiration twice the leader nonce cache --- signer/cosigner_nonce_cache.go | 3 ++- signer/local_cosigner.go | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/signer/cosigner_nonce_cache.go b/signer/cosigner_nonce_cache.go index 6184e26b..eac24d92 100644 --- a/signer/cosigner_nonce_cache.go +++ b/signer/cosigner_nonce_cache.go @@ -14,6 +14,7 @@ const ( defaultGetNoncesInterval = 3 * time.Second defaultGetNoncesTimeout = 4 * time.Second cachePreSize = 10000 + nonceCacheExpiration = 10 * time.Second // half of the local cosigner cache expiration ) type CosignerNonceCache struct { @@ -201,7 +202,7 @@ func (cnc *CosignerNonceCache) LoadN(ctx context.Context, n int) { var wg sync.WaitGroup wg.Add(len(cnc.cosigners)) - expiration := time.Now().Add(nonceExpiration) + expiration := time.Now().Add(nonceCacheExpiration) for i, p := range cnc.cosigners { i := i diff --git a/signer/local_cosigner.go b/signer/local_cosigner.go index 38404a30..5251b3f7 100644 --- a/signer/local_cosigner.go +++ b/signer/local_cosigner.go @@ -16,7 +16,9 @@ import ( var _ Cosigner = &LocalCosigner{} -const nonceExpiration = 10 * time.Second +// double the CosignerNonceCache expiration so that sign requests from the leader +// never reference nonces which have expired here in the LocalCosigner. +const nonceExpiration = 20 * time.Second // LocalCosigner responds to sign requests. // It maintains a high watermark to avoid double-signing.