addTx enqueues a single transaction into the pool if it is valid.
(tx *types.Transaction, local bool)
| 911 | |
| 912 | // addTx enqueues a single transaction into the pool if it is valid. |
| 913 | func (pool *TxPool) addTx(tx *types.Transaction, local bool) error { |
| 914 | pool.mu.Lock() |
| 915 | defer pool.mu.Unlock() |
| 916 | |
| 917 | // Try to inject the transaction and update any state |
| 918 | start := time.Now() |
| 919 | replace, err := pool.add(tx, local) |
| 920 | log.Debug("add tx to pool", "tx", tx.Hash(), "elapsed", common.PrettyDuration(time.Since(start))) |
| 921 | if err != nil { |
| 922 | return err |
| 923 | } |
| 924 | // If we added a new transaction, run promotion checks and return |
| 925 | if !replace { |
| 926 | start := time.Now() |
| 927 | from, _ := types.Sender(pool.signer, tx) // already validated |
| 928 | pool.promoteExecutables([]common.Address{from}) |
| 929 | log.Debug("promoteExecutables", "elapsed", common.PrettyDuration(time.Since(start))) |
| 930 | } |
| 931 | return nil |
| 932 | } |
| 933 | |
| 934 | // addTxs attempts to queue a batch of transactions if they are valid. |
| 935 | func (pool *TxPool) addTxs(txs []*types.Transaction, local bool) []error { |