Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: use channel for promoted transactions to improve order during high volume #16673

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ type TxPool struct {
chainHeadSub event.Subscription
signer types.Signer
mu sync.RWMutex
promotedTxCh chan TxPreEvent

currentState *state.StateDB // Current state in the blockchain head
pendingState *state.ManagedState // Pending state tracking virtual nonces
Expand Down Expand Up @@ -219,16 +220,17 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block

// Create the transaction pool with its initial settings
pool := &TxPool{
config: config,
chainconfig: chainconfig,
chain: chain,
signer: types.NewEIP155Signer(chainconfig.ChainId),
pending: make(map[common.Address]*txList),
queue: make(map[common.Address]*txList),
beats: make(map[common.Address]time.Time),
all: make(map[common.Hash]*types.Transaction),
chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize),
gasPrice: new(big.Int).SetUint64(config.PriceLimit),
config: config,
chainconfig: chainconfig,
chain: chain,
signer: types.NewEIP155Signer(chainconfig.ChainId),
pending: make(map[common.Address]*txList),
queue: make(map[common.Address]*txList),
beats: make(map[common.Address]time.Time),
all: make(map[common.Hash]*types.Transaction),
chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize),
gasPrice: new(big.Int).SetUint64(config.PriceLimit),
promotedTxCh: make(chan TxPreEvent, config.GlobalSlots),
}
pool.locals = newAccountSet(pool.signer)
pool.priced = newTxPricedList(&pool.all)
Expand Down Expand Up @@ -333,6 +335,10 @@ func (pool *TxPool) loop() {
}
pool.mu.Unlock()
}

// Handle promoted transaction
case txPreEvent := <-pool.promotedTxCh:
pool.txFeed.Send(txPreEvent)
}
}
}
Expand Down Expand Up @@ -653,7 +659,9 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
log.Trace("Pooled new executable transaction", "hash", hash, "from", from, "to", tx.To())

// We've directly injected a replacement transaction, notify subsystems
go pool.txFeed.Send(TxPreEvent{tx})
go func(tx *types.Transaction) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to just send on the same goroutine.

pool.promotedTxCh <- TxPreEvent{tx}
}(tx)

return old != nil, nil
}
Expand Down Expand Up @@ -747,7 +755,9 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
pool.beats[addr] = time.Now()
pool.pendingState.SetNonce(addr, tx.Nonce()+1)

go pool.txFeed.Send(TxPreEvent{tx})
go func(tx *types.Transaction) {
pool.promotedTxCh <- TxPreEvent{tx}
}(tx)
}

// AddLocal enqueues a single transaction into the pool if it is valid, marking
Expand Down