mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-07-09 14:22:33 +00:00
[NOD-1551] Remove lock in SigCache (#1161)
This commit is contained in:
parent
f407c44a8d
commit
3b6eb73e53
@ -6,7 +6,6 @@ package txscript
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kaspanet/go-secp256k1"
|
"github.com/kaspanet/go-secp256k1"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// sigCacheEntry represents an entry in the SigCache. Entries within the
|
// sigCacheEntry represents an entry in the SigCache. Entries within the
|
||||||
@ -31,7 +30,6 @@ type sigCacheEntry struct {
|
|||||||
// optimization which speeds up the validation of transactions within a block,
|
// optimization which speeds up the validation of transactions within a block,
|
||||||
// if they've already been seen and verified within the mempool.
|
// if they've already been seen and verified within the mempool.
|
||||||
type SigCache struct {
|
type SigCache struct {
|
||||||
sync.RWMutex
|
|
||||||
validSigs map[secp256k1.Hash]sigCacheEntry
|
validSigs map[secp256k1.Hash]sigCacheEntry
|
||||||
maxEntries uint
|
maxEntries uint
|
||||||
}
|
}
|
||||||
@ -54,8 +52,6 @@ func NewSigCache(maxEntries uint) *SigCache {
|
|||||||
// NOTE: This function is safe for concurrent access. Readers won't be blocked
|
// NOTE: This function is safe for concurrent access. Readers won't be blocked
|
||||||
// unless there exists a writer, adding an entry to the SigCache.
|
// unless there exists a writer, adding an entry to the SigCache.
|
||||||
func (s *SigCache) Exists(sigHash secp256k1.Hash, sig *secp256k1.SchnorrSignature, pubKey *secp256k1.SchnorrPublicKey) bool {
|
func (s *SigCache) Exists(sigHash secp256k1.Hash, sig *secp256k1.SchnorrSignature, pubKey *secp256k1.SchnorrPublicKey) bool {
|
||||||
s.RLock()
|
|
||||||
defer s.RUnlock()
|
|
||||||
entry, ok := s.validSigs[sigHash]
|
entry, ok := s.validSigs[sigHash]
|
||||||
|
|
||||||
return ok && entry.pubKey.IsEqual(pubKey) && entry.sig.IsEqual(sig)
|
return ok && entry.pubKey.IsEqual(pubKey) && entry.sig.IsEqual(sig)
|
||||||
@ -69,9 +65,6 @@ func (s *SigCache) Exists(sigHash secp256k1.Hash, sig *secp256k1.SchnorrSignatur
|
|||||||
// NOTE: This function is safe for concurrent access. Writers will block
|
// NOTE: This function is safe for concurrent access. Writers will block
|
||||||
// simultaneous readers until function execution has concluded.
|
// simultaneous readers until function execution has concluded.
|
||||||
func (s *SigCache) Add(sigHash secp256k1.Hash, sig *secp256k1.SchnorrSignature, pubKey *secp256k1.SchnorrPublicKey) {
|
func (s *SigCache) Add(sigHash secp256k1.Hash, sig *secp256k1.SchnorrSignature, pubKey *secp256k1.SchnorrPublicKey) {
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
|
|
||||||
if s.maxEntries == 0 {
|
if s.maxEntries == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user