@ -98,6 +98,7 @@ var (
queuedReplaceMeter = metrics . NewRegisteredMeter ( "txpool/queued/replace" , nil )
queuedReplaceMeter = metrics . NewRegisteredMeter ( "txpool/queued/replace" , nil )
queuedRateLimitMeter = metrics . NewRegisteredMeter ( "txpool/queued/ratelimit" , nil ) // Dropped due to rate limiting
queuedRateLimitMeter = metrics . NewRegisteredMeter ( "txpool/queued/ratelimit" , nil ) // Dropped due to rate limiting
queuedNofundsMeter = metrics . NewRegisteredMeter ( "txpool/queued/nofunds" , nil ) // Dropped due to out-of-funds
queuedNofundsMeter = metrics . NewRegisteredMeter ( "txpool/queued/nofunds" , nil ) // Dropped due to out-of-funds
queuedEvictionMeter = metrics . NewRegisteredMeter ( "txpool/queued/eviction" , nil ) // Dropped due to lifetime
// General tx metrics
// General tx metrics
knownTxMeter = metrics . NewRegisteredMeter ( "txpool/known" , nil )
knownTxMeter = metrics . NewRegisteredMeter ( "txpool/known" , nil )
@ -234,6 +235,7 @@ type TxPool struct {
pending map [ common . Address ] * txList // All currently processable transactions
pending map [ common . Address ] * txList // All currently processable transactions
queue map [ common . Address ] * txList // Queued but non-processable transactions
queue map [ common . Address ] * txList // Queued but non-processable transactions
beats map [ common . Address ] time . Time // Last heartbeat from each known account
beats map [ common . Address ] time . Time // Last heartbeat from each known account
queuedTs map [ common . Hash ] time . Time // Timestamp for when queued transactions were added
all * txLookup // All transactions to allow lookups
all * txLookup // All transactions to allow lookups
priced * txPricedList // All transactions sorted by price
priced * txPricedList // All transactions sorted by price
@ -266,6 +268,7 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
pending : make ( map [ common . Address ] * txList ) ,
pending : make ( map [ common . Address ] * txList ) ,
queue : make ( map [ common . Address ] * txList ) ,
queue : make ( map [ common . Address ] * txList ) ,
beats : make ( map [ common . Address ] time . Time ) ,
beats : make ( map [ common . Address ] time . Time ) ,
queuedTs : make ( map [ common . Hash ] time . Time ) ,
all : newTxLookup ( ) ,
all : newTxLookup ( ) ,
chainHeadCh : make ( chan ChainHeadEvent , chainHeadChanSize ) ,
chainHeadCh : make ( chan ChainHeadEvent , chainHeadChanSize ) ,
reqResetCh : make ( chan * txpoolResetRequest ) ,
reqResetCh : make ( chan * txpoolResetRequest ) ,
@ -363,10 +366,13 @@ func (pool *TxPool) loop() {
// Any non-locals old enough should be removed
// Any non-locals old enough should be removed
if time . Since ( pool . beats [ addr ] ) > pool . config . Lifetime {
if time . Since ( pool . beats [ addr ] ) > pool . config . Lifetime {
for _ , tx := range pool . queue [ addr ] . Flatten ( ) {
for _ , tx := range pool . queue [ addr ] . Flatten ( ) {
if time . Since ( pool . queuedTs [ tx . Hash ( ) ] ) > pool . config . Lifetime {
queuedEvictionMeter . Mark ( 1 )
pool . removeTx ( tx . Hash ( ) , true )
pool . removeTx ( tx . Hash ( ) , true )
}
}
}
}
}
}
}
pool . mu . Unlock ( )
pool . mu . Unlock ( )
// Handle local transaction journal rotation
// Handle local transaction journal rotation
@ -616,6 +622,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
pool . all . Add ( tx )
pool . all . Add ( tx )
pool . priced . Put ( tx )
pool . priced . Put ( tx )
pool . journalTx ( from , tx )
pool . journalTx ( from , tx )
pool . beats [ from ] = time . Now ( )
pool . queueTxEvent ( tx )
pool . queueTxEvent ( tx )
log . Trace ( "Pooled new executable transaction" , "hash" , hash , "from" , from , "to" , tx . To ( ) )
log . Trace ( "Pooled new executable transaction" , "hash" , hash , "from" , from , "to" , tx . To ( ) )
return old != nil , nil
return old != nil , nil
@ -658,16 +665,20 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) (bool, er
}
}
// Discard any previous transaction and mark this
// Discard any previous transaction and mark this
if old != nil {
if old != nil {
pool . all . Remove ( old . Hash ( ) )
old_hash := old . Hash ( )
pool . all . Remove ( old_hash )
pool . priced . Removed ( 1 )
pool . priced . Removed ( 1 )
delete ( pool . queuedTs , old_hash )
queuedReplaceMeter . Mark ( 1 )
queuedReplaceMeter . Mark ( 1 )
} else {
} else {
// Nothing was replaced, bump the queued counter
// Nothing was replaced, bump the queued counter
queuedGauge . Inc ( 1 )
queuedGauge . Inc ( 1 )
pool . queuedTs [ hash ] = time . Now ( )
}
}
if pool . all . Get ( hash ) == nil {
if pool . all . Get ( hash ) == nil {
pool . all . Add ( tx )
pool . all . Add ( tx )
pool . priced . Put ( tx )
pool . priced . Put ( tx )
pool . queuedTs [ hash ] = time . Now ( )
}
}
return old != nil , nil
return old != nil , nil
}
}
@ -700,7 +711,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
// An older transaction was better, discard this
// An older transaction was better, discard this
pool . all . Remove ( hash )
pool . all . Remove ( hash )
pool . priced . Removed ( 1 )
pool . priced . Removed ( 1 )
delete ( pool . queuedTs , hash )
pendingDiscardMeter . Mark ( 1 )
pendingDiscardMeter . Mark ( 1 )
return false
return false
}
}
@ -708,7 +719,6 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
if old != nil {
if old != nil {
pool . all . Remove ( old . Hash ( ) )
pool . all . Remove ( old . Hash ( ) )
pool . priced . Removed ( 1 )
pool . priced . Removed ( 1 )
pendingReplaceMeter . Mark ( 1 )
pendingReplaceMeter . Mark ( 1 )
} else {
} else {
// Nothing was replaced, bump the pending counter
// Nothing was replaced, bump the pending counter
@ -721,6 +731,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
}
}
// Set the potentially new pending nonce and notify any subsystems of the new tx
// Set the potentially new pending nonce and notify any subsystems of the new tx
pool . beats [ addr ] = time . Now ( )
pool . beats [ addr ] = time . Now ( )
delete ( pool . queuedTs , hash )
pool . pendingNonces . set ( addr , tx . Nonce ( ) + 1 )
pool . pendingNonces . set ( addr , tx . Nonce ( ) + 1 )
return true
return true
@ -895,7 +906,6 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
// If no more pending transactions are left, remove the list
// If no more pending transactions are left, remove the list
if pending . Empty ( ) {
if pending . Empty ( ) {
delete ( pool . pending , addr )
delete ( pool . pending , addr )
delete ( pool . beats , addr )
}
}
// Postpone any invalidated transactions
// Postpone any invalidated transactions
for _ , tx := range invalids {
for _ , tx := range invalids {
@ -913,6 +923,7 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
if removed , _ := future . Remove ( tx ) ; removed {
if removed , _ := future . Remove ( tx ) ; removed {
// Reduce the queued counter
// Reduce the queued counter
queuedGauge . Dec ( 1 )
queuedGauge . Dec ( 1 )
delete ( pool . queuedTs , hash )
}
}
if future . Empty ( ) {
if future . Empty ( ) {
delete ( pool . queue , addr )
delete ( pool . queue , addr )
@ -1191,6 +1202,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
for _ , tx := range forwards {
for _ , tx := range forwards {
hash := tx . Hash ( )
hash := tx . Hash ( )
pool . all . Remove ( hash )
pool . all . Remove ( hash )
delete ( pool . queuedTs , hash )
}
}
log . Trace ( "Removed old queued transactions" , "count" , len ( forwards ) )
log . Trace ( "Removed old queued transactions" , "count" , len ( forwards ) )
// Drop all transactions that are too costly (low balance or out of gas)
// Drop all transactions that are too costly (low balance or out of gas)
@ -1198,6 +1210,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
for _ , tx := range drops {
for _ , tx := range drops {
hash := tx . Hash ( )
hash := tx . Hash ( )
pool . all . Remove ( hash )
pool . all . Remove ( hash )
delete ( pool . queuedTs , hash )
}
}
log . Trace ( "Removed unpayable queued transactions" , "count" , len ( drops ) )
log . Trace ( "Removed unpayable queued transactions" , "count" , len ( drops ) )
queuedNofundsMeter . Mark ( int64 ( len ( drops ) ) )
queuedNofundsMeter . Mark ( int64 ( len ( drops ) ) )
@ -1220,6 +1233,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
for _ , tx := range caps {
for _ , tx := range caps {
hash := tx . Hash ( )
hash := tx . Hash ( )
pool . all . Remove ( hash )
pool . all . Remove ( hash )
delete ( pool . queuedTs , hash )
log . Trace ( "Removed cap-exceeding queued transaction" , "hash" , hash )
log . Trace ( "Removed cap-exceeding queued transaction" , "hash" , hash )
}
}
queuedRateLimitMeter . Mark ( int64 ( len ( caps ) ) )
queuedRateLimitMeter . Mark ( int64 ( len ( caps ) ) )
@ -1414,7 +1428,7 @@ func (pool *TxPool) demoteUnexecutables() {
}
}
pendingGauge . Dec ( int64 ( len ( gapped ) ) )
pendingGauge . Dec ( int64 ( len ( gapped ) ) )
}
}
// Delete the entire queue entry if it became empty.
// Delete the entire pending entry if it became empty.
if list . Empty ( ) {
if list . Empty ( ) {
delete ( pool . pending , addr )
delete ( pool . pending , addr )
delete ( pool . beats , addr )
delete ( pool . beats , addr )