diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-31 18:21:55 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | 8b555ae56c581718077891974b0606bc32e6488b (patch) | |
tree | 58789d7ed6803e8539e2797aac6be7f188f85b9e /core/blockchain.go | |
parent | 38b34914c47a994754006adf6cef8463f5f3315a (diff) | |
download | dexon-8b555ae56c581718077891974b0606bc32e6488b.tar dexon-8b555ae56c581718077891974b0606bc32e6488b.tar.gz dexon-8b555ae56c581718077891974b0606bc32e6488b.tar.bz2 dexon-8b555ae56c581718077891974b0606bc32e6488b.tar.lz dexon-8b555ae56c581718077891974b0606bc32e6488b.tar.xz dexon-8b555ae56c581718077891974b0606bc32e6488b.tar.zst dexon-8b555ae56c581718077891974b0606bc32e6488b.zip |
core: tx_pool: remove transactions on BlockConfirmed event
Diffstat (limited to 'core/blockchain.go')
-rw-r--r-- | core/blockchain.go | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index af975f81a..201b53d74 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -104,14 +104,15 @@ type BlockChain struct { triegc *prque.Prque // Priority queue mapping block numbers to tries to gc gcproc time.Duration // Accumulates canonical block processing for trie dumping - hc *HeaderChain - rmLogsFeed event.Feed - chainFeed event.Feed - chainSideFeed event.Feed - chainHeadFeed event.Feed - logsFeed event.Feed - scope event.SubscriptionScope - genesisBlock *types.Block + hc *HeaderChain + rmLogsFeed event.Feed + chainFeed event.Feed + chainSideFeed event.Feed + chainHeadFeed event.Feed + blockConfirmedFeed event.Feed + logsFeed event.Feed + scope event.SubscriptionScope + genesisBlock *types.Block mu sync.RWMutex // global mutex for locking chain operations chainmu sync.RWMutex // blockchain insertion lock @@ -1610,6 +1611,7 @@ func (bc *BlockChain) processPendingBlock(block *types.Block, witness *coreTypes // add into pending blocks bc.addPendingBlock(newPendingBlock, receipts) + events = append(events, BlockConfirmedEvent{newPendingBlock}) // start insert available pending blocks into db for pendingHeight := bc.CurrentBlock().NumberU64() + 1; pendingHeight <= witness.Height; pendingHeight++ { @@ -1830,6 +1832,9 @@ func (bc *BlockChain) PostChainEvents(events []interface{}, logs []*types.Log) { case ChainHeadEvent: bc.chainHeadFeed.Send(ev) + case BlockConfirmedEvent: + bc.blockConfirmedFeed.Send(ev) + case ChainSideEvent: bc.chainSideFeed.Send(ev) } @@ -2022,6 +2027,11 @@ func (bc *BlockChain) SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Su return bc.scope.Track(bc.chainHeadFeed.Subscribe(ch)) } +// SubscribeBlockConfirmedEvent registers a subscription of ChainHeadEvent. +func (bc *BlockChain) SubscribeBlockConfirmedEvent(ch chan<- BlockConfirmedEvent) event.Subscription { + return bc.scope.Track(bc.blockConfirmedFeed.Subscribe(ch)) +} + // SubscribeChainSideEvent registers a subscription of ChainSideEvent. func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- ChainSideEvent) event.Subscription { return bc.scope.Track(bc.chainSideFeed.Subscribe(ch)) |