Skip to content

Commit

Permalink
txpool: replace by atomic lock;
Browse files Browse the repository at this point in the history
  • Loading branch information
galaio committed Apr 30, 2024
1 parent d4a2b8a commit 2113824
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
11 changes: 4 additions & 7 deletions core/txpool/blobpool/blobpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path/filepath"
"sort"
"sync"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -305,7 +306,7 @@ type BlobPool struct {
head *types.Header // Current head of the chain
state *state.StateDB // Current state at the head of the chain
gasTip *uint256.Int // Currently accepted minimum gas tip
maxGas uint64 // Currently accepted max gas, it will be modified by MinerAPI
maxGas atomic.Uint64 // Currently accepted max gas, it will be modified by MinerAPI

lookup map[common.Hash]uint64 // Lookup table mapping hashes to tx billy entries
index map[common.Address][]*blobTxMeta // Blob transactions grouped by accounts, sorted by nonce
Expand Down Expand Up @@ -1675,13 +1676,9 @@ func (p *BlobPool) Status(hash common.Hash) txpool.TxStatus {
}

func (p *BlobPool) SetMaxGas(maxGas uint64) {
p.lock.Lock()
defer p.lock.Unlock()
p.maxGas = maxGas
p.maxGas.Store(maxGas)
}

func (p *BlobPool) GetMaxGas() uint64 {
p.lock.RLock()
defer p.lock.RUnlock()
return p.maxGas
return p.maxGas.Load()
}
10 changes: 3 additions & 7 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ type LegacyPool struct {
scope event.SubscriptionScope
signer types.Signer
mu sync.RWMutex
maxGas uint64 // Currently accepted max gas, it will be modified by MinerAPI
maxGas atomic.Uint64 // Currently accepted max gas, it will be modified by MinerAPI

currentHead atomic.Pointer[types.Header] // Current head of the blockchain
currentState *state.StateDB // Current state in the blockchain head
Expand Down Expand Up @@ -1772,15 +1772,11 @@ func (pool *LegacyPool) demoteUnexecutables() {
}

func (pool *LegacyPool) GetMaxGas() uint64 {
pool.mu.RLock()
defer pool.mu.RUnlock()
return pool.maxGas
return pool.maxGas.Load()
}

func (pool *LegacyPool) SetMaxGas(maxGas uint64) {
pool.mu.Lock()
defer pool.mu.Unlock()
pool.maxGas = maxGas
pool.maxGas.Store(maxGas)
}

// addressByHeartbeat is an account address tagged with its last activity timestamp.
Expand Down

0 comments on commit 2113824

Please sign in to comment.