mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 10:20:44 +00:00
lookup txPool before listening to imcoming tx
This commit is contained in:
parent
b955291388
commit
b8cb19732f
1 changed files with 22 additions and 3 deletions
|
|
@ -209,9 +209,28 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if eth.etherbase != m2 {
|
if eth.etherbase != m2 {
|
||||||
//wait until signTx from m2 comes into txPool
|
// firstly, look into txPool
|
||||||
|
pendingMap, err := eth.txPool.Pending()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Fail to get txPool pending", "err", err)
|
||||||
|
//reset pendingMap
|
||||||
|
pendingMap = map[common.Address]types.Transactions{}
|
||||||
|
}
|
||||||
|
txsSentFromM2 := pendingMap[m2]
|
||||||
|
if len(txsSentFromM2) > 0 {
|
||||||
|
for _, tx := range txsSentFromM2 {
|
||||||
|
if tx.To().String() == common.BlockSigners {
|
||||||
|
if err := contracts.CreateTransactionSign(chainConfig, eth.txPool, eth.accountManager, block, chainDb); err != nil {
|
||||||
|
log.Error("Fail to create tx sign for imported block", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//then wait until signTx from m2 comes into txPool
|
||||||
txCh := make(chan core.TxPreEvent, txChanSize)
|
txCh := make(chan core.TxPreEvent, txChanSize)
|
||||||
eth.txPool.SubscribeTxPreEvent(txCh)
|
subEvent := eth.txPool.SubscribeTxPreEvent(txCh)
|
||||||
G:
|
G:
|
||||||
select {
|
select {
|
||||||
case event := <-txCh:
|
case event := <-txCh:
|
||||||
|
|
@ -226,7 +245,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
case <-time.After(time.Duration(10) * time.Second):
|
case <-time.After(time.Duration(10) * time.Second):
|
||||||
break G
|
break G
|
||||||
}
|
}
|
||||||
close(txCh)
|
subEvent.Unsubscribe()
|
||||||
} else if err := contracts.CreateTransactionSign(chainConfig, eth.txPool, eth.accountManager, block, chainDb); err != nil {
|
} else if err := contracts.CreateTransactionSign(chainConfig, eth.txPool, eth.accountManager, block, chainDb); err != nil {
|
||||||
log.Error("Fail to create tx sign for imported block", "error", err)
|
log.Error("Fail to create tx sign for imported block", "error", err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue