Skip to content

Commit

Permalink
fix concurrent map write
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Jun 20, 2023
1 parent 518446a commit 742518c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 6 additions & 0 deletions signer/cosigner_security_ecies.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ type CosignerSecurityECIES struct {
eciesPubKeys map[int]CosignerECIESPubKey
}

// CosignerECIESKey is a cosigner's ECIES public key.
type CosignerECIESPubKey struct {
ID int
PublicKey *ecies.PublicKey
}

// NewCosignerSecurityECIES creates a new CosignerSecurityECIES.
func NewCosignerSecurityECIES(key CosignerECIESKey, eciesPubKeys []CosignerECIESPubKey) *CosignerSecurityECIES {
c := &CosignerSecurityECIES{
Expand Down
6 changes: 6 additions & 0 deletions signer/cosigner_security_rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ type CosignerSecurityRSA struct {
rsaPubKeys map[int]CosignerRSAPubKey
}

// CosignerRSAKey is a cosigner's RSA public key.
type CosignerRSAPubKey struct {
ID int
PublicKey rsa.PublicKey
}

// NewCosignerSecurityRSA creates a new CosignerSecurityRSA.
func NewCosignerSecurityRSA(key CosignerRSAKey, rsaPubKeys []CosignerRSAPubKey) *CosignerSecurityRSA {
c := &CosignerSecurityRSA{
Expand Down
14 changes: 2 additions & 12 deletions signer/local_cosigner.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package signer

import (
"crypto/rsa"
"errors"
"fmt"
"sync"
"time"

cometcrypto "github.com/cometbft/cometbft/crypto"
cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519"
ecies "github.com/ecies/go/v2"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -104,16 +102,6 @@ func (hrst *HRSTKey) Less(other HRSTKey) bool {
return false
}

type CosignerRSAPubKey struct {
ID int
PublicKey rsa.PublicKey
}

type CosignerECIESPubKey struct {
ID int
PublicKey *ecies.PublicKey
}

type CosignerGetNonceRequest struct {
ChainID string
ID int
Expand Down Expand Up @@ -278,13 +266,15 @@ func (cosigner *LocalCosigner) sign(req CosignerSignRequest) (CosignerSignRespon
}
}

ccs.mu.Lock()
for existingKey := range ccs.nonces {
// delete any HRS lower than our signed level
// we will not be providing parts for any lower HRS
if existingKey.Less(hrst) {
delete(ccs.nonces, existingKey)
}
}
ccs.mu.Unlock()

res.Signature = sig

Expand Down

0 comments on commit 742518c

Please sign in to comment.