promoteExecutables moves transactions that have become processable from the future queue to the set of pending transactions. During this process, all invalidated transactions (low nonce, low balance) are deleted.
(accounts []common.Address)
| 1037 | // future queue to the set of pending transactions. During this process, all |
| 1038 | // invalidated transactions (low nonce, low balance) are deleted. |
| 1039 | func (pool *TxPool) promoteExecutables(accounts []common.Address) { |
| 1040 | // Track the promoted transactions to broadcast them at once |
| 1041 | var promoted []*types.Transaction |
| 1042 | |
| 1043 | // Gather all the accounts potentially needing updates |
| 1044 | if accounts == nil { |
| 1045 | accounts = make([]common.Address, 0, len(pool.queue)) |
| 1046 | for addr := range pool.queue { |
| 1047 | accounts = append(accounts, addr) |
| 1048 | } |
| 1049 | } |
| 1050 | // Iterate over all accounts and promote any executable transactions |
| 1051 | for _, addr := range accounts { |
| 1052 | list := pool.getQueueTxList(addr) |
| 1053 | if list == nil { |
| 1054 | continue // Just in case someone calls with a non existing account |
| 1055 | } |
| 1056 | // Drop all transactions that are deemed too old (low nonce) |
| 1057 | oldQueuedTransaction := list.Forward(pool.currentState.GetNonce(addr)) |
| 1058 | if len(oldQueuedTransaction) > 0 { |
| 1059 | log.Debug("Removed old queued transaction", "old queued tx len", oldQueuedTransaction.Len()) |
| 1060 | } |
| 1061 | for _, tx := range oldQueuedTransaction { |
| 1062 | hash := tx.Hash() |
| 1063 | log.Debug("Removed old queued transaction", "hash", hash.Hex()) |
| 1064 | pool.all.Remove(hash) |
| 1065 | pool.priced.Removed() |
| 1066 | } |
| 1067 | // Drop all transactions that are too costly (low balance or out of gas) |
| 1068 | drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas) |
| 1069 | if len(drops) > 0 { |
| 1070 | log.Debug("Removed unpayable queued transaction", "unpayable tx len", drops.Len()) |
| 1071 | } |
| 1072 | for _, tx := range drops { |
| 1073 | hash := tx.Hash() |
| 1074 | log.Debug("Removed unpayable queued transaction", "hash", hash.Hex()) |
| 1075 | pool.all.Remove(hash) |
| 1076 | pool.priced.Removed() |
| 1077 | queuedNofundsCounter.Inc(1) |
| 1078 | } |
| 1079 | // Gather all executable transactions and promote them |
| 1080 | readyTxs := list.Ready(pool.pendingState.GetNonce(addr)) |
| 1081 | if len(readyTxs) > 0 { |
| 1082 | log.Debug("readyTxs", "length", readyTxs.Len()) |
| 1083 | } |
| 1084 | for _, tx := range readyTxs { |
| 1085 | hash := tx.Hash() |
| 1086 | if pool.promoteTx(addr, hash, tx) { |
| 1087 | log.Debug("Promoting queued transaction", "hash", hash.Hex()) |
| 1088 | promoted = append(promoted, tx) |
| 1089 | } |
| 1090 | } |
| 1091 | // Drop all transactions over the allowed limit |
| 1092 | if !pool.locals.contains(addr) { |
| 1093 | capExceedingTxToRemove := list.Cap(int(pool.config.AccountQueue)) |
| 1094 | if len(capExceedingTxToRemove) > 0 { |
| 1095 | log.Debug("Removed cap-exceeding queued transaction", "addr", addr.Hex(), "len", capExceedingTxToRemove.Len()) |
| 1096 | } |