Reset tx pool when there is a new block

pull/1806/head
Rongjian Lan 5 years ago
parent d21ce08309
commit 2c9f2135cd
  1. 2
      core/blockchain.go
  2. 27
      core/tx_pool.go
  3. 3
      node/node_newblock.go

@ -1155,7 +1155,6 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
// After insertion is done, all accumulated events will be fired.
func (bc *BlockChain) InsertChain(chain types.Blocks, verifyHeaders bool) (int, error) {
n, events, logs, err := bc.insertChain(chain, verifyHeaders)
bc.PostChainEvents(events, logs)
if err == nil {
for idx, block := range chain {
header := block.Header()
@ -1197,6 +1196,7 @@ func (bc *BlockChain) InsertChain(chain types.Blocks, verifyHeaders bool) (int,
}
}
bc.PostChainEvents(events, logs)
return n, err
}

@ -292,7 +292,7 @@ func (pool *TxPool) loop() {
defer journal.Stop()
// Track the previous head headers for transaction reorgs
//head := pool.chain.CurrentBlock()
head := pool.chain.CurrentBlock()
// Keep waiting for and reacting to the various events
for {
@ -301,12 +301,25 @@ func (pool *TxPool) loop() {
case ev := <-pool.chainHeadCh:
if ev.Block != nil {
pool.mu.Lock()
//if pool.chainconfig.IsHomestead(ev.Block.Number()) {
// pool.homestead = true
//}
//pool.reset(head.Header(), ev.Block.Header())
//head = ev.Block
if pool.chainconfig.IsS3(ev.Block.Epoch()) {
pool.homestead = true
}
pool.reset(head.Header(), ev.Block.Header())
head = ev.Block
// DEBUG-
pending, queued := pool.stats()
stales := pool.priced.stales
if pending != prevPending || queued != prevQueued || stales != prevStales {
utils.Logger().Debug().
Int("executable", pending).
Int("queued", queued).
Int("stales", stales).
Msg("Transaction pool status report")
prevPending, prevQueued, prevStales = pending, queued, stales
}
// -
pool.mu.Unlock()
}
// Be unsubscribed due to system stopped

@ -82,6 +82,7 @@ func (node *Node) proposeNewBlock() (*types.Block, error) {
// Update worker's current header and state data in preparation to propose/process new transactions
coinbase := node.Consensus.SelfAddress
utils.Logger().Info().Msg("11111111111")
// Prepare transactions including staking transactions\
pending, err := node.TxPool.Pending()
if err != nil {
@ -89,6 +90,7 @@ func (node *Node) proposeNewBlock() (*types.Block, error) {
return nil, err
}
utils.Logger().Info().Msg("222222222222")
// TODO: integrate staking transaction into tx pool
pendingStakingTransactions := types2.StakingTransactions{}
for _, tx := range node.pendingStakingTransactions {
@ -102,6 +104,7 @@ func (node *Node) proposeNewBlock() (*types.Block, error) {
return nil, err
}
utils.Logger().Info().Msg("33333333333333")
// Prepare cross shard transaction receipts
receiptsList := node.proposeReceiptsProof()
if len(receiptsList) != 0 {

Loading…
Cancel
Save