Skip to content

Commit

Permalink
mitigate unexpected state (#233)
Browse files Browse the repository at this point in the history
* mitigate unexpected state

remove ClearAllNonces

* use string constant
  • Loading branch information
agouin authored Dec 12, 2023
1 parent 60760f2 commit 8e01923
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions signer/cosigner_nonce_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,23 @@ func TestClearNonces(t *testing.T) {

for _, n := range cnc.cache.cache {
require.Len(t, n.Nonces, 2)
oneFound := false
twoFound := false
for _, cnr := range n.Nonces {
if cnr.Cosigner == cosigners[1] {
oneFound = true
}
if cnr.Cosigner == cosigners[2] {
twoFound = true
}
}
require.True(t, oneFound)
require.True(t, twoFound)
}

cnc.ClearNonces(cosigners[1])

require.Equal(t, 0, cnc.cache.Size())
}

type mockPruner struct {
Expand Down
5 changes: 4 additions & 1 deletion signer/local_cosigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ func (cosigner *LocalCosigner) getNonce(
return nonce, nil
}

const errUnexpectedState = "unexpected state, metadata does not exist for U:"

// setNonce stores a nonce provided by another cosigner
func (cosigner *LocalCosigner) setNonce(uuid uuid.UUID, nonce CosignerNonce) error {
// Verify the source signature
Expand All @@ -456,7 +458,8 @@ func (cosigner *LocalCosigner) setNonce(uuid uuid.UUID, nonce CosignerNonce) err
// generate metadata placeholder
if !ok {
return fmt.Errorf(
"unexpected state, metadata does not exist for U: %s",
"%s %s",
errUnexpectedState,
uuid,
)
}
Expand Down
5 changes: 5 additions & 0 deletions signer/threshold_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"os"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -734,6 +735,10 @@ func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Bl
"err", err.Error(),
)

if strings.Contains(err.Error(), errUnexpectedState) {
pv.nonceCache.ClearNonces(cosigner)
}

if cosigner.GetID() == pv.myCosigner.GetID() {
return err
}
Expand Down

0 comments on commit 8e01923

Please sign in to comment.