diff options
author | bojie <bojie@dexon.org> | 2019-01-14 20:42:15 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-01-14 20:42:15 +0800 |
commit | 899022022f7f922b43e739e844800362587d5d56 (patch) | |
tree | 9719615c15a7964cd503fd0156189a366ad85eb9 /core/tx_pool.go | |
parent | 5823540202423aed2cbdf8c125e95d8b1a20e245 (diff) | |
download | dexon-899022022f7f922b43e739e844800362587d5d56.tar dexon-899022022f7f922b43e739e844800362587d5d56.tar.gz dexon-899022022f7f922b43e739e844800362587d5d56.tar.bz2 dexon-899022022f7f922b43e739e844800362587d5d56.tar.lz dexon-899022022f7f922b43e739e844800362587d5d56.tar.xz dexon-899022022f7f922b43e739e844800362587d5d56.tar.zst dexon-899022022f7f922b43e739e844800362587d5d56.zip |
app: remove pending block logic (#149)
Diffstat (limited to 'core/tx_pool.go')
-rw-r--r-- | core/tx_pool.go | 73 |
1 files changed, 22 insertions, 51 deletions
diff --git a/core/tx_pool.go b/core/tx_pool.go index f4961a034..d1827257e 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -37,9 +37,6 @@ 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 ( @@ -121,7 +118,6 @@ type blockChain interface { 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. @@ -186,18 +182,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 - blockConfirmedCh chan BlockConfirmedEvent - blockConfirmedSub event.Subscription - signer types.Signer - mu sync.RWMutex + 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 currentState *state.StateDB // Current state in the blockchain head pendingState *state.ManagedState // Pending state tracking virtual nonces @@ -226,18 +220,17 @@ 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), - blockConfirmedCh: make(chan BlockConfirmedEvent, blockConfirmedChanSize), - gasPrice: new(big.Int).SetUint64(config.PriceLimit), - isBlockProposer: isBlockProposer, + 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), + isBlockProposer: isBlockProposer, } pool.locals = newAccountSet(pool.signer) for _, addr := range config.Locals { @@ -259,7 +252,6 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block } } // Subscribe events from blockchain - pool.blockConfirmedSub = pool.chain.SubscribeBlockConfirmedEvent(pool.blockConfirmedCh) pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh) // Start the event loop and return @@ -295,9 +287,6 @@ func (pool *TxPool) loop() { select { // Handle ChainHeadEvent case ev := <-pool.chainHeadCh: - if pool.isBlockProposer { - break - } if ev.Block != nil { pool.mu.Lock() if pool.chainconfig.IsHomestead(ev.Block.Number()) { @@ -311,24 +300,6 @@ func (pool *TxPool) loop() { // Be unsubscribed due to system stopped case <-pool.chainHeadSub.Err(): return - // Handle BlockConfirmedEvent - case ev := <-pool.blockConfirmedCh: - if !pool.isBlockProposer { - break - } - 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 - - pool.mu.Unlock() - } - // Be unsubscribed due to system stopped - case <-pool.blockConfirmedSub.Err(): - return // Handle stats reporting ticks case <-report.C: @@ -419,7 +390,7 @@ func (pool *TxPool) Stop() { pool.scope.Close() // Unsubscribe subscriptions registered from blockchain - pool.blockConfirmedSub.Unsubscribe() + pool.chainHeadSub.Unsubscribe() pool.wg.Wait() if pool.journal != nil { |