Skip to content

Commit 292c050

Browse files
authored
core/txpool, eth: refactor function IsSigner (#1889)
1 parent 1394ea0 commit 292c050

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

core/txpool/lending_pool.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ type LendingPool struct {
143143
all map[common.Hash]*types.LendingTransaction // All transactions to allow lookups
144144
wg sync.WaitGroup // for shutdown sync
145145
homestead bool
146-
IsSigner func(address common.Address) bool
147146
}
148147

149148
// NewLendingPool creates a new transaction pool to gather, sort and filter inbound

core/txpool/order_pool.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ type OrderPool struct {
152152
all map[common.Hash]*types.OrderTransaction // All transactions to allow lookups
153153
wg sync.WaitGroup // for shutdown sync
154154
homestead bool
155-
IsSigner func(address common.Address) bool
156155
}
157156

158157
// NewOrderPool creates a new transaction pool to gather, sort and filter inbound

core/txpool/txpool.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ type TxPool struct {
289289

290290
changesSinceReorg int // A counter for how many drops we've performed in-between reorg.
291291

292-
IsSigner func(address common.Address) bool
292+
isSigner func(address common.Address) bool
293293
trc21FeeCapacity map[common.Address]*big.Int
294294
}
295295

@@ -623,7 +623,7 @@ func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {
623623
MaxSize: txMaxSize,
624624
MinTip: pool.gasTip.Load(),
625625
NotSigner: func(from common.Address) bool {
626-
return pool.IsSigner != nil && !pool.IsSigner(from)
626+
return pool.IsNotSigner(from)
627627
},
628628
}
629629
if local {
@@ -718,7 +718,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
718718

719719
// already validated
720720
from, _ := types.Sender(pool.signer, tx)
721-
if tx.IsSpecialTransaction() && pool.IsSigner != nil && pool.IsSigner(from) && pool.pendingNonces.get(from) == tx.Nonce() {
721+
if tx.IsSpecialTransaction() && pool.IsSigner(from) && pool.pendingNonces.get(from) == tx.Nonce() {
722722
return pool.promoteSpecialTx(from, tx, isLocal)
723723
}
724724

@@ -1707,6 +1707,18 @@ func (pool *TxPool) demoteUnexecutables() {
17071707
}
17081708
}
17091709

1710+
func (pool *TxPool) SetSigner(f func(address common.Address) bool) {
1711+
pool.isSigner = f
1712+
}
1713+
1714+
func (pool *TxPool) IsSigner(addr common.Address) bool {
1715+
return pool.isSigner != nil && pool.isSigner(addr)
1716+
}
1717+
1718+
func (pool *TxPool) IsNotSigner(addr common.Address) bool {
1719+
return pool.isSigner != nil && !pool.isSigner(addr)
1720+
}
1721+
17101722
// addressByHeartbeat is an account address tagged with its last activity timestamp.
17111723
type addressByHeartbeat struct {
17121724
address common.Address

eth/backend.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
302302
log.Error("Cannot get etherbase for append m2 header", "err", err)
303303
return fmt.Errorf("etherbase missing: %v", err)
304304
}
305-
ok := eth.txPool.IsSigner != nil && eth.txPool.IsSigner(eb)
305+
ok := eth.txPool.IsSigner(eb)
306306
if !ok {
307307
return nil
308308
}
@@ -355,9 +355,10 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
355355
hooks.AttachConsensusV1Hooks(c, eth.blockchain, chainConfig)
356356
hooks.AttachConsensusV2Hooks(c, eth.blockchain, chainConfig)
357357

358-
eth.txPool.IsSigner = func(address common.Address) bool {
358+
isSigner := func(address common.Address) bool {
359359
return c.IsAuthorisedAddress(eth.blockchain, eth.blockchain.CurrentHeader(), address)
360360
}
361+
eth.txPool.SetSigner(isSigner)
361362
}
362363
// Start the RPC service
363364
eth.netRPCService = ethapi.NewNetAPI(eth.p2pServer, eth.NetVersion())

0 commit comments

Comments
 (0)