core, eth, les: polish txpool API around local/remote txs

This commit is contained in:
Péter Szilágyi
2017-07-05 16:51:55 +03:00
parent a633a2d7ea
commit 48ee7f9de7
9 changed files with 153 additions and 149 deletions

View File

@ -420,7 +420,7 @@ func (l *txPricedList) Removed() {
heap.Init(l.items)
}
// Discard finds all the transactions below the given price threshold, drops them
// Cap finds all the transactions below the given price threshold, drops them
// from the priced list and returs them for further removal from the entire pool.
func (l *txPricedList) Cap(threshold *big.Int, local *accountSet) types.Transactions {
drop := make(types.Transactions, 0, 128) // Remote underpriced transactions to drop
@ -429,9 +429,7 @@ func (l *txPricedList) Cap(threshold *big.Int, local *accountSet) types.Transact
for len(*l.items) > 0 {
// Discard stale transactions if found during cleanup
tx := heap.Pop(l.items).(*types.Transaction)
hash := tx.Hash()
if _, ok := (*l.all)[hash]; !ok {
if _, ok := (*l.all)[tx.Hash()]; !ok {
l.stales--
continue
}
@ -440,7 +438,7 @@ func (l *txPricedList) Cap(threshold *big.Int, local *accountSet) types.Transact
break
}
// Non stale transaction found, discard unless local
if local.contains(tx) {
if local.containsTx(tx) {
save = append(save, tx)
} else {
drop = append(drop, tx)
@ -456,7 +454,7 @@ func (l *txPricedList) Cap(threshold *big.Int, local *accountSet) types.Transact
// lowest priced transaction currently being tracked.
func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) bool {
// Local transactions cannot be underpriced
if local.contains(tx) {
if local.containsTx(tx) {
return false
}
// Discard stale price points if found at the heap start
@ -487,14 +485,12 @@ func (l *txPricedList) Discard(count int, local *accountSet) types.Transactions
for len(*l.items) > 0 && count > 0 {
// Discard stale transactions if found during cleanup
tx := heap.Pop(l.items).(*types.Transaction)
hash := tx.Hash()
if _, ok := (*l.all)[hash]; !ok {
if _, ok := (*l.all)[tx.Hash()]; !ok {
l.stales--
continue
}
// Non stale transaction found, discard unless local
if local.contains(tx) {
if local.containsTx(tx) {
save = append(save, tx)
} else {
drop = append(drop, tx)