Skip to content

Commit 4f7a380

Browse files
authored
Merge pull request #14737 from holiman/txpool_localaccounts
Txpool localaccounts
2 parents 65f0e90 + 34ec991 commit 4f7a380

File tree

13 files changed

+390
-285
lines changed

13 files changed

+390
-285
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var (
6666
utils.EthashDatasetDirFlag,
6767
utils.EthashDatasetsInMemoryFlag,
6868
utils.EthashDatasetsOnDiskFlag,
69+
utils.TxPoolNoLocalsFlag,
6970
utils.TxPoolPriceLimitFlag,
7071
utils.TxPoolPriceBumpFlag,
7172
utils.TxPoolAccountSlotsFlag,

cmd/geth/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ var AppHelpFlagGroups = []flagGroup{
9595
{
9696
Name: "TRANSACTION POOL",
9797
Flags: []cli.Flag{
98+
utils.TxPoolNoLocalsFlag,
9899
utils.TxPoolPriceLimitFlag,
99100
utils.TxPoolPriceBumpFlag,
100101
utils.TxPoolAccountSlotsFlag,

cmd/utils/flags.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ var (
209209
Value: eth.DefaultConfig.EthashDatasetsOnDisk,
210210
}
211211
// Transaction pool settings
212+
TxPoolNoLocalsFlag = cli.BoolFlag{
213+
Name: "txpool.nolocals",
214+
Usage: "Disables price exemptions for locally submitted transactions",
215+
}
212216
TxPoolPriceLimitFlag = cli.Uint64Flag{
213217
Name: "txpool.pricelimit",
214218
Usage: "Minimum gas price limit to enforce for acceptance into the pool",
@@ -831,6 +835,9 @@ func setGPO(ctx *cli.Context, cfg *gasprice.Config) {
831835
}
832836

833837
func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
838+
if ctx.GlobalIsSet(TxPoolNoLocalsFlag.Name) {
839+
cfg.NoLocals = ctx.GlobalBool(TxPoolNoLocalsFlag.Name)
840+
}
834841
if ctx.GlobalIsSet(TxPoolPriceLimitFlag.Name) {
835842
cfg.PriceLimit = ctx.GlobalUint64(TxPoolPriceLimitFlag.Name)
836843
}

core/tx_list.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -420,18 +420,16 @@ func (l *txPricedList) Removed() {
420420
heap.Init(l.items)
421421
}
422422

423-
// Discard finds all the transactions below the given price threshold, drops them
423+
// Cap finds all the transactions below the given price threshold, drops them
424424
// from the priced list and returs them for further removal from the entire pool.
425-
func (l *txPricedList) Cap(threshold *big.Int, local *txSet) types.Transactions {
425+
func (l *txPricedList) Cap(threshold *big.Int, local *accountSet) types.Transactions {
426426
drop := make(types.Transactions, 0, 128) // Remote underpriced transactions to drop
427427
save := make(types.Transactions, 0, 64) // Local underpriced transactions to keep
428428

429429
for len(*l.items) > 0 {
430430
// Discard stale transactions if found during cleanup
431431
tx := heap.Pop(l.items).(*types.Transaction)
432-
433-
hash := tx.Hash()
434-
if _, ok := (*l.all)[hash]; !ok {
432+
if _, ok := (*l.all)[tx.Hash()]; !ok {
435433
l.stales--
436434
continue
437435
}
@@ -440,7 +438,7 @@ func (l *txPricedList) Cap(threshold *big.Int, local *txSet) types.Transactions
440438
break
441439
}
442440
// Non stale transaction found, discard unless local
443-
if local.contains(hash) {
441+
if local.containsTx(tx) {
444442
save = append(save, tx)
445443
} else {
446444
drop = append(drop, tx)
@@ -454,9 +452,9 @@ func (l *txPricedList) Cap(threshold *big.Int, local *txSet) types.Transactions
454452

455453
// Underpriced checks whether a transaction is cheaper than (or as cheap as) the
456454
// lowest priced transaction currently being tracked.
457-
func (l *txPricedList) Underpriced(tx *types.Transaction, local *txSet) bool {
455+
func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) bool {
458456
// Local transactions cannot be underpriced
459-
if local.contains(tx.Hash()) {
457+
if local.containsTx(tx) {
460458
return false
461459
}
462460
// Discard stale price points if found at the heap start
@@ -479,22 +477,20 @@ func (l *txPricedList) Underpriced(tx *types.Transaction, local *txSet) bool {
479477
}
480478

481479
// Discard finds a number of most underpriced transactions, removes them from the
482-
// priced list and returs them for further removal from the entire pool.
483-
func (l *txPricedList) Discard(count int, local *txSet) types.Transactions {
480+
// priced list and returns them for further removal from the entire pool.
481+
func (l *txPricedList) Discard(count int, local *accountSet) types.Transactions {
484482
drop := make(types.Transactions, 0, count) // Remote underpriced transactions to drop
485483
save := make(types.Transactions, 0, 64) // Local underpriced transactions to keep
486484

487485
for len(*l.items) > 0 && count > 0 {
488486
// Discard stale transactions if found during cleanup
489487
tx := heap.Pop(l.items).(*types.Transaction)
490-
491-
hash := tx.Hash()
492-
if _, ok := (*l.all)[hash]; !ok {
488+
if _, ok := (*l.all)[tx.Hash()]; !ok {
493489
l.stales--
494490
continue
495491
}
496492
// Non stale transaction found, discard unless local
497-
if local.contains(hash) {
493+
if local.containsTx(tx) {
498494
save = append(save, tx)
499495
} else {
500496
drop = append(drop, tx)

0 commit comments

Comments
 (0)