@@ -238,7 +238,7 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
238238 if ! config .NoLocals && config .Journal != "" {
239239 pool .journal = newTxJournal (config .Journal )
240240
241- if err := pool .journal .load (pool .AddLocal ); err != nil {
241+ if err := pool .journal .load (pool .AddLocals ); err != nil {
242242 log .Warn ("Failed to load transaction journal" , "err" , err )
243243 }
244244 if err := pool .journal .rotate (pool .local ()); err != nil {
@@ -444,9 +444,9 @@ func (pool *TxPool) Stop() {
444444 log .Info ("Transaction pool stopped" )
445445}
446446
447- // SubscribeTxPreEvent registers a subscription of TxPreEvent and
447+ // SubscribeNewTxsEvent registers a subscription of NewTxsEvent and
448448// starts sending event to the given channel.
449- func (pool * TxPool ) SubscribeTxPreEvent (ch chan <- TxPreEvent ) event.Subscription {
449+ func (pool * TxPool ) SubscribeNewTxsEvent (ch chan <- NewTxsEvent ) event.Subscription {
450450 return pool .scope .Track (pool .txFeed .Subscribe (ch ))
451451}
452452
@@ -653,7 +653,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
653653 log .Trace ("Pooled new executable transaction" , "hash" , hash , "from" , from , "to" , tx .To ())
654654
655655 // We've directly injected a replacement transaction, notify subsystems
656- go pool .txFeed .Send (TxPreEvent { tx })
656+ go pool .txFeed .Send (NewTxsEvent {types. Transactions { tx } })
657657
658658 return old != nil , nil
659659 }
@@ -712,10 +712,11 @@ func (pool *TxPool) journalTx(from common.Address, tx *types.Transaction) {
712712 }
713713}
714714
715- // promoteTx adds a transaction to the pending (processable) list of transactions.
715+ // promoteTx adds a transaction to the pending (processable) list of transactions
716+ // and returns whether it was inserted or an older was better.
716717//
717718// Note, this method assumes the pool lock is held!
718- func (pool * TxPool ) promoteTx (addr common.Address , hash common.Hash , tx * types.Transaction ) {
719+ func (pool * TxPool ) promoteTx (addr common.Address , hash common.Hash , tx * types.Transaction ) bool {
719720 // Try to insert the transaction into the pending queue
720721 if pool .pending [addr ] == nil {
721722 pool .pending [addr ] = newTxList (true )
@@ -729,7 +730,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
729730 pool .priced .Removed ()
730731
731732 pendingDiscardCounter .Inc (1 )
732- return
733+ return false
733734 }
734735 // Otherwise discard any previous transaction and mark this
735736 if old != nil {
@@ -747,7 +748,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
747748 pool .beats [addr ] = time .Now ()
748749 pool .pendingState .SetNonce (addr , tx .Nonce ()+ 1 )
749750
750- go pool . txFeed . Send ( TxPreEvent { tx })
751+ return true
751752}
752753
753754// AddLocal enqueues a single transaction into the pool if it is valid, marking
@@ -907,6 +908,9 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
907908// future queue to the set of pending transactions. During this process, all
908909// invalidated transactions (low nonce, low balance) are deleted.
909910func (pool * TxPool ) promoteExecutables (accounts []common.Address ) {
911+ // Track the promoted transactions to broadcast them at once
912+ var promoted []* types.Transaction
913+
910914 // Gather all the accounts potentially needing updates
911915 if accounts == nil {
912916 accounts = make ([]common.Address , 0 , len (pool .queue ))
@@ -939,8 +943,10 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
939943 // Gather all executable transactions and promote them
940944 for _ , tx := range list .Ready (pool .pendingState .GetNonce (addr )) {
941945 hash := tx .Hash ()
942- log .Trace ("Promoting queued transaction" , "hash" , hash )
943- pool .promoteTx (addr , hash , tx )
946+ if pool .promoteTx (addr , hash , tx ) {
947+ log .Trace ("Promoting queued transaction" , "hash" , hash )
948+ promoted = append (promoted , tx )
949+ }
944950 }
945951 // Drop all transactions over the allowed limit
946952 if ! pool .locals .contains (addr ) {
@@ -957,6 +963,10 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
957963 delete (pool .queue , addr )
958964 }
959965 }
966+ // Notify subsystem for new promoted transactions.
967+ if len (promoted ) > 0 {
968+ pool .txFeed .Send (NewTxsEvent {promoted })
969+ }
960970 // If the pending limit is overflown, start equalizing allowances
961971 pending := uint64 (0 )
962972 for _ , list := range pool .pending {
0 commit comments