diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-31 18:21:55 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2018-12-19 20:54:27 +0800 |
commit | 10511980f4e0d5d5330b2fd619e6d805c65938fd (patch) | |
tree | 6ad951518926a50e11e0c9ae98f6fb4a664d38e1 /core/tx_pool.go | |
parent | 26b7d6403b713717d46fef1fa2bed273722a4ce8 (diff) | |
download | dexon-10511980f4e0d5d5330b2fd619e6d805c65938fd.tar dexon-10511980f4e0d5d5330b2fd619e6d805c65938fd.tar.gz dexon-10511980f4e0d5d5330b2fd619e6d805c65938fd.tar.bz2 dexon-10511980f4e0d5d5330b2fd619e6d805c65938fd.tar.lz dexon-10511980f4e0d5d5330b2fd619e6d805c65938fd.tar.xz dexon-10511980f4e0d5d5330b2fd619e6d805c65938fd.tar.zst dexon-10511980f4e0d5d5330b2fd619e6d805c65938fd.zip |
core: tx_pool: remove transactions on BlockConfirmed event
Diffstat (limited to 'core/tx_pool.go')
-rw-r--r-- | core/tx_pool.go | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/core/tx_pool.go b/core/tx_pool.go index db9a6b9f9..6a9fa45c3 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -36,8 +36,8 @@ import ( ) const ( - // chainHeadChanSize is the size of channel listening to ChainHeadEvent. - chainHeadChanSize = 10 + // blockConfirmedChanSize is the size of channel listening to BlockConfirmedEvent. + blockConfirmedChanSize = 10 ) var ( @@ -118,7 +118,7 @@ type blockChain interface { GetBlock(hash common.Hash, number uint64) *types.Block StateAt(root common.Hash) (*state.StateDB, error) - SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Subscription + SubscribeBlockConfirmedEvent(ch chan<- BlockConfirmedEvent) event.Subscription } // TxPoolConfig are the configuration parameters of the transaction pool. @@ -183,16 +183,16 @@ func (config *TxPoolConfig) sanitize() TxPoolConfig { // current state) and future transactions. Transactions move between those // two states over time as they are received and processed. type TxPool struct { - config TxPoolConfig - chainconfig *params.ChainConfig - chain blockChain - gasPrice *big.Int - txFeed event.Feed - scope event.SubscriptionScope - chainHeadCh chan ChainHeadEvent - chainHeadSub event.Subscription - signer types.Signer - mu sync.RWMutex + config TxPoolConfig + chainconfig *params.ChainConfig + chain blockChain + gasPrice *big.Int + txFeed event.Feed + scope event.SubscriptionScope + blockConfirmedCh chan BlockConfirmedEvent + blockConfirmedSub event.Subscription + signer types.Signer + mu sync.RWMutex currentState *state.StateDB // Current state in the blockchain head pendingState *state.ManagedState // Pending state tracking virtual nonces @@ -220,16 +220,16 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block // Create the transaction pool with its initial settings pool := &TxPool{ - config: config, - chainconfig: chainconfig, - chain: chain, - signer: types.NewEIP155Signer(chainconfig.ChainID), - pending: make(map[common.Address]*txList), - queue: make(map[common.Address]*txList), - beats: make(map[common.Address]time.Time), - all: newTxLookup(), - chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize), - gasPrice: new(big.Int).SetUint64(config.PriceLimit), + config: config, + chainconfig: chainconfig, + chain: chain, + signer: types.NewEIP155Signer(chainconfig.ChainID), + pending: make(map[common.Address]*txList), + queue: make(map[common.Address]*txList), + beats: make(map[common.Address]time.Time), + all: newTxLookup(), + blockConfirmedCh: make(chan BlockConfirmedEvent, blockConfirmedChanSize), + gasPrice: new(big.Int).SetUint64(config.PriceLimit), } pool.locals = newAccountSet(pool.signer) for _, addr := range config.Locals { @@ -251,7 +251,7 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block } } // Subscribe events from blockchain - pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh) + pool.blockConfirmedSub = pool.chain.SubscribeBlockConfirmedEvent(pool.blockConfirmedCh) // Start the event loop and return pool.wg.Add(1) @@ -284,8 +284,8 @@ func (pool *TxPool) loop() { // Keep waiting for and reacting to the various events for { select { - // Handle ChainHeadEvent - case ev := <-pool.chainHeadCh: + // Handle BlockConfirmedEvent + case ev := <-pool.blockConfirmedCh: if ev.Block != nil { pool.mu.Lock() if pool.chainconfig.IsHomestead(ev.Block.Number()) { @@ -297,7 +297,7 @@ func (pool *TxPool) loop() { pool.mu.Unlock() } // Be unsubscribed due to system stopped - case <-pool.chainHeadSub.Err(): + case <-pool.blockConfirmedSub.Err(): return // Handle stats reporting ticks @@ -441,7 +441,7 @@ func (pool *TxPool) Stop() { pool.scope.Close() // Unsubscribe subscriptions registered from blockchain - pool.chainHeadSub.Unsubscribe() + pool.blockConfirmedSub.Unsubscribe() pool.wg.Wait() if pool.journal != nil { |