Skip to content

Commit

Permalink
fix tx sender caching
Browse files Browse the repository at this point in the history
  • Loading branch information
artheraone committed Jul 18, 2023
1 parent 14a49e6 commit 6bb85c3
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,27 @@ type CachedSigner struct {
cache SenderCache
}

func WrapWithCachedSigner(signer Signer, cache SenderCache) *CachedSigner {
return &CachedSigner{
func WrapWithCachedSigner(signer Signer, cache SenderCache) CachedSigner {
return CachedSigner{
Signer: signer,
cache: cache,
}
}

func (cs CachedSigner) Equal(s2 Signer) bool {
cs2, ok := s2.(CachedSigner)
if ok {
// unwrap the signer
return cs.Signer.Equal(cs2.Signer)
}
return cs.Signer.Equal(s2)
}

func (cs CachedSigner) Sender(tx *Transaction) (common.Address, error) {
if tx.from.Load() == nil {
// try to load the sender from the global cache
cached := cs.cache.Get(tx.Hash())
if cached != nil && cached.Signer.Equal(cs.Signer) {
return cached.From, nil
}
// try to load the sender from the global cache
cached := cs.cache.Get(tx.Hash())
if cached != nil && cached.Signer.Equal(cs.Signer) {
return cached.From, nil
}
from, err := cs.Signer.Sender(tx)
if err != nil {
Expand Down

0 comments on commit 6bb85c3

Please sign in to comment.