miner: implement prioritized addresses (reuse --txpool.locals)

pull/30559/head
Martin Holst Swende 2 months ago
parent 7d50a821fb
commit 887d51b900
No known key found for this signature in database
GPG Key ID: 683B438C05A5DDF0
  1. 1
      eth/backend.go
  2. 7
      miner/miner.go
  3. 31
      miner/worker.go

@ -264,6 +264,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
eth.miner = miner.New(eth, config.Miner, eth.engine) eth.miner = miner.New(eth, config.Miner, eth.engine)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData)) eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
eth.miner.SetPrioAddresses(config.TxPool.Locals)
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil} eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
if eth.APIBackend.allowUnprotectedTxs { if eth.APIBackend.allowUnprotectedTxs {

@ -70,6 +70,7 @@ type Miner struct {
chainConfig *params.ChainConfig chainConfig *params.ChainConfig
engine consensus.Engine engine consensus.Engine
txpool *txpool.TxPool txpool *txpool.TxPool
prio []common.Address // A list of senders to prioritize
chain *core.BlockChain chain *core.BlockChain
pending *pending pending *pending
pendingMu sync.Mutex // Lock protects the pending block pendingMu sync.Mutex // Lock protects the pending block
@ -109,6 +110,12 @@ func (miner *Miner) SetExtra(extra []byte) error {
return nil return nil
} }
func (miner *Miner) SetPrioAddresses(prio []common.Address) {
miner.confMu.Lock()
miner.prio = prio
miner.confMu.Unlock()
}
// SetGasCeil sets the gaslimit to strive for when mining blocks post 1559. // SetGasCeil sets the gaslimit to strive for when mining blocks post 1559.
// For pre-1559 blocks, it sets the ceiling. // For pre-1559 blocks, it sets the ceiling.
func (miner *Miner) SetGasCeil(ceil uint64) { func (miner *Miner) SetGasCeil(ceil uint64) {

@ -428,6 +428,7 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran
func (miner *Miner) fillTransactions(interrupt *atomic.Int32, env *environment) error { func (miner *Miner) fillTransactions(interrupt *atomic.Int32, env *environment) error {
miner.confMu.RLock() miner.confMu.RLock()
tip := miner.config.GasPrice tip := miner.config.GasPrice
prio := miner.prio
miner.confMu.RUnlock() miner.confMu.RUnlock()
// Retrieve the pending transactions pre-filtered by the 1559/4844 dynamic fees // Retrieve the pending transactions pre-filtered by the 1559/4844 dynamic fees
@ -447,31 +448,31 @@ func (miner *Miner) fillTransactions(interrupt *atomic.Int32, env *environment)
pendingBlobTxs := miner.txpool.Pending(filter) pendingBlobTxs := miner.txpool.Pending(filter)
// Split the pending transactions into locals and remotes. // Split the pending transactions into locals and remotes.
localPlainTxs, remotePlainTxs := make(map[common.Address][]*txpool.LazyTransaction), pendingPlainTxs prioPlainTxs, normalPlainTxs := make(map[common.Address][]*txpool.LazyTransaction), pendingPlainTxs
localBlobTxs, remoteBlobTxs := make(map[common.Address][]*txpool.LazyTransaction), pendingBlobTxs prioBlobTxs, normalBlobTxs := make(map[common.Address][]*txpool.LazyTransaction), pendingBlobTxs
for _, account := range miner.txpool.Locals() { for _, account := range prio {
if txs := remotePlainTxs[account]; len(txs) > 0 { if txs := normalPlainTxs[account]; len(txs) > 0 {
delete(remotePlainTxs, account) delete(normalPlainTxs, account)
localPlainTxs[account] = txs prioPlainTxs[account] = txs
} }
if txs := remoteBlobTxs[account]; len(txs) > 0 { if txs := normalBlobTxs[account]; len(txs) > 0 {
delete(remoteBlobTxs, account) delete(normalBlobTxs, account)
localBlobTxs[account] = txs prioBlobTxs[account] = txs
} }
} }
// Fill the block with all available pending transactions. // Fill the block with all available pending transactions.
if len(localPlainTxs) > 0 || len(localBlobTxs) > 0 { if len(prioPlainTxs) > 0 || len(prioBlobTxs) > 0 {
plainTxs := newTransactionsByPriceAndNonce(env.signer, localPlainTxs, env.header.BaseFee) plainTxs := newTransactionsByPriceAndNonce(env.signer, prioPlainTxs, env.header.BaseFee)
blobTxs := newTransactionsByPriceAndNonce(env.signer, localBlobTxs, env.header.BaseFee) blobTxs := newTransactionsByPriceAndNonce(env.signer, prioBlobTxs, env.header.BaseFee)
if err := miner.commitTransactions(env, plainTxs, blobTxs, interrupt); err != nil { if err := miner.commitTransactions(env, plainTxs, blobTxs, interrupt); err != nil {
return err return err
} }
} }
if len(remotePlainTxs) > 0 || len(remoteBlobTxs) > 0 { if len(normalPlainTxs) > 0 || len(normalBlobTxs) > 0 {
plainTxs := newTransactionsByPriceAndNonce(env.signer, remotePlainTxs, env.header.BaseFee) plainTxs := newTransactionsByPriceAndNonce(env.signer, normalPlainTxs, env.header.BaseFee)
blobTxs := newTransactionsByPriceAndNonce(env.signer, remoteBlobTxs, env.header.BaseFee) blobTxs := newTransactionsByPriceAndNonce(env.signer, normalBlobTxs, env.header.BaseFee)
if err := miner.commitTransactions(env, plainTxs, blobTxs, interrupt); err != nil { if err := miner.commitTransactions(env, plainTxs, blobTxs, interrupt); err != nil {
return err return err

Loading…
Cancel
Save