Add tries to insert a new transaction into the list, returning whether the transaction was accepted, and if yes, any previous transaction it replaced. If the new transaction is accepted into the list, the lists' cost and gas thresholds are also potentially updated.
(tx *types.Transaction, priceBump uint64)
| 300 | // If the new transaction is accepted into the list, the lists' cost and gas |
| 301 | // thresholds are also potentially updated. |
| 302 | func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transaction) { |
| 303 | // If there's an older better transaction, abort |
| 304 | old := l.txs.Get(tx.Nonce()) |
| 305 | if old != nil { |
| 306 | threshold := new(big.Int).Div(new(big.Int).Mul(old.GasPrice(), big.NewInt(100+int64(priceBump))), big.NewInt(100)) |
| 307 | // Have to ensure that the new gas price is higher than the old gas |
| 308 | // price as well as checking the percentage threshold to ensure that |
| 309 | // this is accurate for low (Wei-level) gas price replacements |
| 310 | if old.GasPrice().Cmp(tx.GasPrice()) >= 0 || threshold.Cmp(tx.GasPrice()) > 0 { |
| 311 | return false, nil |
| 312 | } |
| 313 | } |
| 314 | // Otherwise overwrite the old transaction with the current one |
| 315 | l.txs.Put(tx) |
| 316 | if cost := tx.Cost(); l.costcap.Cmp(cost) < 0 { |
| 317 | l.costcap = cost |
| 318 | } |
| 319 | if gas := tx.Gas(); l.gascap < gas { |
| 320 | l.gascap = gas |
| 321 | } |
| 322 | return true, old |
| 323 | } |
| 324 | |
| 325 | // Forward removes all transactions from the list with a nonce lower than the |
| 326 | // provided threshold. Every removed transaction is returned for any post-removal |