|
|
@ -444,9 +444,9 @@ func (pool *TxPool) Stop() { |
|
|
|
log.Info("Transaction pool stopped") |
|
|
|
log.Info("Transaction pool stopped") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SubscribeTxPreEvent registers a subscription of TxsPreEvent and
|
|
|
|
// SubscribeNewTxsEvent registers a subscription of NewTxsEvent and
|
|
|
|
// starts sending event to the given channel.
|
|
|
|
// starts sending event to the given channel.
|
|
|
|
func (pool *TxPool) SubscribeTxPreEvent(ch chan<- TxsPreEvent) event.Subscription { |
|
|
|
func (pool *TxPool) SubscribeNewTxsEvent(ch chan<- NewTxsEvent) event.Subscription { |
|
|
|
return pool.scope.Track(pool.txFeed.Subscribe(ch)) |
|
|
|
return pool.scope.Track(pool.txFeed.Subscribe(ch)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -653,7 +653,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) { |
|
|
|
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()) |
|
|
|
|
|
|
|
|
|
|
|
// We've directly injected a replacement transaction, notify subsystems
|
|
|
|
// We've directly injected a replacement transaction, notify subsystems
|
|
|
|
go pool.txFeed.Send(TxsPreEvent{types.Transactions{tx}}) |
|
|
|
go pool.txFeed.Send(NewTxsEvent{types.Transactions{tx}}) |
|
|
|
|
|
|
|
|
|
|
|
return old != nil, nil |
|
|
|
return old != nil, nil |
|
|
|
} |
|
|
|
} |
|
|
@ -712,7 +712,8 @@ func (pool *TxPool) journalTx(from common.Address, tx *types.Transaction) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// promoteTx adds a transaction to the pending (processable) list of transactions.
|
|
|
|
// promoteTx adds a transaction to the pending (processable) list of transactions
|
|
|
|
|
|
|
|
// and returns whether it was inserted or an older was better.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Note, this method assumes the pool lock is held!
|
|
|
|
// Note, this method assumes the pool lock is held!
|
|
|
|
func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.Transaction) bool { |
|
|
|
func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.Transaction) bool { |
|
|
@ -746,6 +747,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() |
|
|
|
pool.pendingState.SetNonce(addr, tx.Nonce()+1) |
|
|
|
pool.pendingState.SetNonce(addr, tx.Nonce()+1) |
|
|
|
|
|
|
|
|
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -906,7 +908,9 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) { |
|
|
|
// future queue to the set of pending transactions. During this process, all
|
|
|
|
// future queue to the set of pending transactions. During this process, all
|
|
|
|
// invalidated transactions (low nonce, low balance) are deleted.
|
|
|
|
// invalidated transactions (low nonce, low balance) are deleted.
|
|
|
|
func (pool *TxPool) promoteExecutables(accounts []common.Address) { |
|
|
|
func (pool *TxPool) promoteExecutables(accounts []common.Address) { |
|
|
|
var promotedTxs types.Transactions |
|
|
|
// Track the promoted transactions to broadcast them at once
|
|
|
|
|
|
|
|
var promoted []*types.Transaction |
|
|
|
|
|
|
|
|
|
|
|
// Gather all the accounts potentially needing updates
|
|
|
|
// Gather all the accounts potentially needing updates
|
|
|
|
if accounts == nil { |
|
|
|
if accounts == nil { |
|
|
|
accounts = make([]common.Address, 0, len(pool.queue)) |
|
|
|
accounts = make([]common.Address, 0, len(pool.queue)) |
|
|
@ -937,16 +941,13 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) { |
|
|
|
queuedNofundsCounter.Inc(1) |
|
|
|
queuedNofundsCounter.Inc(1) |
|
|
|
} |
|
|
|
} |
|
|
|
// Gather all executable transactions and promote them
|
|
|
|
// Gather all executable transactions and promote them
|
|
|
|
txs := list.Ready(pool.pendingState.GetNonce(addr)) |
|
|
|
for _, tx := range list.Ready(pool.pendingState.GetNonce(addr)) { |
|
|
|
for _, tx := range txs { |
|
|
|
|
|
|
|
hash := tx.Hash() |
|
|
|
hash := tx.Hash() |
|
|
|
inserted := pool.promoteTx(addr, hash, tx) |
|
|
|
if pool.promoteTx(addr, hash, tx) { |
|
|
|
if inserted { |
|
|
|
|
|
|
|
log.Trace("Promoting queued transaction", "hash", hash) |
|
|
|
log.Trace("Promoting queued transaction", "hash", hash) |
|
|
|
promotedTxs = append(promotedTxs, tx) |
|
|
|
promoted = append(promoted, tx) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Drop all transactions over the allowed limit
|
|
|
|
// Drop all transactions over the allowed limit
|
|
|
|
if !pool.locals.contains(addr) { |
|
|
|
if !pool.locals.contains(addr) { |
|
|
|
for _, tx := range list.Cap(int(pool.config.AccountQueue)) { |
|
|
|
for _, tx := range list.Cap(int(pool.config.AccountQueue)) { |
|
|
@ -963,10 +964,9 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Notify subsystem for new promoted transactions.
|
|
|
|
// Notify subsystem for new promoted transactions.
|
|
|
|
if promotedTxs.Len() > 0 { |
|
|
|
if len(promoted) > 0 { |
|
|
|
pool.txFeed.Send(TxsPreEvent{promotedTxs}) |
|
|
|
pool.txFeed.Send(NewTxsEvent{promoted}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If the pending limit is overflown, start equalizing allowances
|
|
|
|
// If the pending limit is overflown, start equalizing allowances
|
|
|
|
pending := uint64(0) |
|
|
|
pending := uint64(0) |
|
|
|
for _, list := range pool.pending { |
|
|
|
for _, list := range pool.pending { |
|
|
|