core/txpool, eth: refactor function IsSigner (#1889)

This commit is contained in:
Daniel Liu 2025-12-25 11:57:37 +08:00 committed by GitHub
parent 1394ea09f0
commit 292c0506c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 7 deletions

View file

@ -143,7 +143,6 @@ type LendingPool struct {
all map[common.Hash]*types.LendingTransaction // All transactions to allow lookups all map[common.Hash]*types.LendingTransaction // All transactions to allow lookups
wg sync.WaitGroup // for shutdown sync wg sync.WaitGroup // for shutdown sync
homestead bool homestead bool
IsSigner func(address common.Address) bool
} }
// NewLendingPool creates a new transaction pool to gather, sort and filter inbound // NewLendingPool creates a new transaction pool to gather, sort and filter inbound

View file

@ -152,7 +152,6 @@ type OrderPool struct {
all map[common.Hash]*types.OrderTransaction // All transactions to allow lookups all map[common.Hash]*types.OrderTransaction // All transactions to allow lookups
wg sync.WaitGroup // for shutdown sync wg sync.WaitGroup // for shutdown sync
homestead bool homestead bool
IsSigner func(address common.Address) bool
} }
// NewOrderPool creates a new transaction pool to gather, sort and filter inbound // NewOrderPool creates a new transaction pool to gather, sort and filter inbound

View file

@ -289,7 +289,7 @@ type TxPool struct {
changesSinceReorg int // A counter for how many drops we've performed in-between reorg. changesSinceReorg int // A counter for how many drops we've performed in-between reorg.
IsSigner func(address common.Address) bool isSigner func(address common.Address) bool
trc21FeeCapacity map[common.Address]*big.Int trc21FeeCapacity map[common.Address]*big.Int
} }
@ -623,7 +623,7 @@ func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {
MaxSize: txMaxSize, MaxSize: txMaxSize,
MinTip: pool.gasTip.Load(), MinTip: pool.gasTip.Load(),
NotSigner: func(from common.Address) bool { NotSigner: func(from common.Address) bool {
return pool.IsSigner != nil && !pool.IsSigner(from) return pool.IsNotSigner(from)
}, },
} }
if local { if local {
@ -718,7 +718,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
// already validated // already validated
from, _ := types.Sender(pool.signer, tx) from, _ := types.Sender(pool.signer, tx)
if tx.IsSpecialTransaction() && pool.IsSigner != nil && pool.IsSigner(from) && pool.pendingNonces.get(from) == tx.Nonce() { if tx.IsSpecialTransaction() && pool.IsSigner(from) && pool.pendingNonces.get(from) == tx.Nonce() {
return pool.promoteSpecialTx(from, tx, isLocal) return pool.promoteSpecialTx(from, tx, isLocal)
} }
@ -1707,6 +1707,18 @@ func (pool *TxPool) demoteUnexecutables() {
} }
} }
func (pool *TxPool) SetSigner(f func(address common.Address) bool) {
pool.isSigner = f
}
func (pool *TxPool) IsSigner(addr common.Address) bool {
return pool.isSigner != nil && pool.isSigner(addr)
}
func (pool *TxPool) IsNotSigner(addr common.Address) bool {
return pool.isSigner != nil && !pool.isSigner(addr)
}
// addressByHeartbeat is an account address tagged with its last activity timestamp. // addressByHeartbeat is an account address tagged with its last activity timestamp.
type addressByHeartbeat struct { type addressByHeartbeat struct {
address common.Address address common.Address

View file

@ -302,7 +302,7 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
log.Error("Cannot get etherbase for append m2 header", "err", err) log.Error("Cannot get etherbase for append m2 header", "err", err)
return fmt.Errorf("etherbase missing: %v", err) return fmt.Errorf("etherbase missing: %v", err)
} }
ok := eth.txPool.IsSigner != nil && eth.txPool.IsSigner(eb) ok := eth.txPool.IsSigner(eb)
if !ok { if !ok {
return nil return nil
} }
@ -355,9 +355,10 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
hooks.AttachConsensusV1Hooks(c, eth.blockchain, chainConfig) hooks.AttachConsensusV1Hooks(c, eth.blockchain, chainConfig)
hooks.AttachConsensusV2Hooks(c, eth.blockchain, chainConfig) hooks.AttachConsensusV2Hooks(c, eth.blockchain, chainConfig)
eth.txPool.IsSigner = func(address common.Address) bool { isSigner := func(address common.Address) bool {
return c.IsAuthorisedAddress(eth.blockchain, eth.blockchain.CurrentHeader(), address) return c.IsAuthorisedAddress(eth.blockchain, eth.blockchain.CurrentHeader(), address)
} }
eth.txPool.SetSigner(isSigner)
} }
// Start the RPC service // Start the RPC service
eth.netRPCService = ethapi.NewNetAPI(eth.p2pServer, eth.NetVersion()) eth.netRPCService = ethapi.NewNetAPI(eth.p2pServer, eth.NetVersion())