mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 22:56:43 +00:00
Add mutex for currentState in TxPool
This commit is contained in:
parent
560620fa89
commit
75fe9c6c84
1 changed files with 13 additions and 3 deletions
|
|
@ -279,9 +279,10 @@ type TxPool struct {
|
||||||
eip1559 atomic.Bool // Fork indicator whether we are using EIP-1559 type transactions.
|
eip1559 atomic.Bool // Fork indicator whether we are using EIP-1559 type transactions.
|
||||||
shanghai atomic.Bool // Fork indicator whether we are in the Shanghai stage.
|
shanghai atomic.Bool // Fork indicator whether we are in the Shanghai stage.
|
||||||
|
|
||||||
currentState *state.StateDB // Current state in the blockchain head
|
currentState *state.StateDB // Current state in the blockchain head
|
||||||
pendingNonces *noncer // Pending state tracking virtual nonces
|
currentStateMutex sync.Mutex // Mutex to protect currentState
|
||||||
currentMaxGas atomic.Uint64 // Current gas limit for transaction caps
|
pendingNonces *noncer // Pending state tracking virtual nonces
|
||||||
|
currentMaxGas atomic.Uint64 // Current gas limit for transaction caps
|
||||||
|
|
||||||
locals *accountSet // Set of local transaction to exempt from eviction rules
|
locals *accountSet // Set of local transaction to exempt from eviction rules
|
||||||
journal *journal // Journal of local transaction to back up to disk
|
journal *journal // Journal of local transaction to back up to disk
|
||||||
|
|
@ -745,6 +746,9 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
|
||||||
// and does not require the pool mutex to be held.
|
// and does not require the pool mutex to be held.
|
||||||
// nolint:gocognit
|
// nolint:gocognit
|
||||||
func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {
|
func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {
|
||||||
|
pool.currentStateMutex.Lock()
|
||||||
|
defer pool.currentStateMutex.Unlock()
|
||||||
|
|
||||||
// Accept only legacy transactions until EIP-2718/2930 activates.
|
// Accept only legacy transactions until EIP-2718/2930 activates.
|
||||||
if !pool.eip2718.Load() && tx.Type() != types.LegacyTxType {
|
if !pool.eip2718.Load() && tx.Type() != types.LegacyTxType {
|
||||||
return core.ErrTxTypeNotSupported
|
return core.ErrTxTypeNotSupported
|
||||||
|
|
@ -1915,6 +1919,9 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
|
||||||
|
|
||||||
balance := uint256.NewInt(0)
|
balance := uint256.NewInt(0)
|
||||||
|
|
||||||
|
pool.currentStateMutex.Lock()
|
||||||
|
defer pool.currentStateMutex.Unlock()
|
||||||
|
|
||||||
// Iterate over all accounts and promote any executable transactions
|
// Iterate over all accounts and promote any executable transactions
|
||||||
for _, addr := range accounts {
|
for _, addr := range accounts {
|
||||||
list = pool.queue[addr]
|
list = pool.queue[addr]
|
||||||
|
|
@ -2252,6 +2259,9 @@ func (pool *TxPool) demoteUnexecutables() {
|
||||||
// Iterate over all accounts and demote any non-executable transactions
|
// Iterate over all accounts and demote any non-executable transactions
|
||||||
pool.pendingMu.RLock()
|
pool.pendingMu.RLock()
|
||||||
|
|
||||||
|
pool.currentStateMutex.Lock()
|
||||||
|
defer pool.currentStateMutex.Unlock()
|
||||||
|
|
||||||
for addr, list := range pool.pending {
|
for addr, list := range pool.pending {
|
||||||
nonce := pool.currentState.GetNonce(addr)
|
nonce := pool.currentState.GetNonce(addr)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue