From 6bb85c3d8774cfaab07ac69d6029e64623ed3e1c Mon Sep 17 00:00:00 2001 From: artheraone <126314488+artheraone@users.noreply.github.com> Date: Tue, 18 Jul 2023 21:23:19 +0300 Subject: [PATCH] fix tx sender caching --- core/types/transaction_signing.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index 33522c873..8ac2b5210 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -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 {