mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
improve txSenderCacher init
This commit is contained in:
parent
864e717b56
commit
d078ad321c
3 changed files with 20 additions and 4 deletions
|
|
@ -1616,7 +1616,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool, makeWitness
|
||||||
return nil, 0, nil
|
return nil, 0, nil
|
||||||
}
|
}
|
||||||
// Start a parallel signature recovery (signer will fluke on fork transition, minimal perf loss)
|
// Start a parallel signature recovery (signer will fluke on fork transition, minimal perf loss)
|
||||||
SenderCacher.RecoverFromBlocks(types.MakeSigner(bc.chainConfig, chain[0].Number(), chain[0].Time()), chain)
|
GetSenderCacher().RecoverFromBlocks(types.MakeSigner(bc.chainConfig, chain[0].Number(), chain[0].Time()), chain)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
stats = insertStats{startTime: mclock.Now()}
|
stats = insertStats{startTime: mclock.Now()}
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,28 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SenderCacher is a concurrent transaction sender recoverer and cacher.
|
var (
|
||||||
var SenderCacher = newTxSenderCacher(runtime.NumCPU())
|
// senderCacherOnce is used to ensure that the SenderCacher is initialized only once.
|
||||||
|
// It leverages sync.Once to provide thread-safe lazy initialization.
|
||||||
|
senderCacherOnce sync.Once
|
||||||
|
// senderCacherInstance is a concurrent transaction sender recoverer and cacher.
|
||||||
|
senderCacherInstance = newTxSenderCacher(runtime.NumCPU())
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetSenderCacher returns the singleton instance of SenderCacher.
|
||||||
|
// If the instance has not been initialized yet, it will be created using newTxSenderCacher.
|
||||||
|
// This function is thread-safe and ensures that initialization happens only once.
|
||||||
|
func GetSenderCacher() *txSenderCacher {
|
||||||
|
senderCacherOnce.Do(func() {
|
||||||
|
senderCacherInstance = newTxSenderCacher(runtime.NumCPU())
|
||||||
|
})
|
||||||
|
return senderCacherInstance
|
||||||
|
}
|
||||||
|
|
||||||
// txSenderCacherRequest is a request for recovering transaction senders with a
|
// txSenderCacherRequest is a request for recovering transaction senders with a
|
||||||
// specific signature scheme and caching it into the transactions themselves.
|
// specific signature scheme and caching it into the transactions themselves.
|
||||||
|
|
|
||||||
|
|
@ -1440,7 +1440,7 @@ func (pool *LegacyPool) reset(oldHead, newHead *types.Header) {
|
||||||
|
|
||||||
// Inject any transactions discarded due to reorgs
|
// Inject any transactions discarded due to reorgs
|
||||||
log.Debug("Reinjecting stale transactions", "count", len(reinject))
|
log.Debug("Reinjecting stale transactions", "count", len(reinject))
|
||||||
core.SenderCacher.Recover(pool.signer, reinject)
|
core.GetSenderCacher().Recover(pool.signer, reinject)
|
||||||
pool.addTxsLocked(reinject, false)
|
pool.addTxsLocked(reinject, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue