Skip to content

Commit

Permalink
Moved local flag check to the top of Add function
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-imx committed Nov 14, 2023
1 parent 01fa6d9 commit 5927f62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ var DefaultConfig = Config{
Lifetime: 3 * time.Hour,
}

func (config *Config) PrioritizeLocals() bool {
return !config.NoLocals
}

// sanitize checks the provided user configurations and changes anything that's
// unreasonable or unworkable.
func (config *Config) sanitize() Config {
Expand Down Expand Up @@ -600,7 +596,7 @@ func (pool *LegacyPool) validateTxBasics(tx *types.Transaction, local bool) erro
MaxSize: txMaxSize,
MinTip: pool.gasTip.Load(),
}
if local && pool.config.PrioritizeLocals() {
if local {
opts.MinTip = new(big.Int)
}
if err := txpool.ValidateTransaction(tx, pool.currentHead.Load(), pool.signer, opts); err != nil {
Expand Down Expand Up @@ -963,6 +959,9 @@ func (pool *LegacyPool) addRemoteSync(tx *types.Transaction) error {
// If sync is set, the method will block until all internal maintenance related
// to the add is finished. Only use this during tests for determinism!
func (pool *LegacyPool) Add(txs []*types.Transaction, local, sync bool) []error {
// Do not treat as local if local transactions have been disabled
local = local && !pool.config.NoLocals

// Filter out known ones without obtaining the pool lock or recovering signatures
var (
errs = make([]error, len(txs))
Expand Down
4 changes: 2 additions & 2 deletions core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ func TestMinGasPriceEnforced(t *testing.T) {
t.Fatalf("Min tip not enforced")
}

if err := pool.Add([]*txpool.Transaction{{Tx: tx}}, true, false)[0]; !errors.Is(err, txpool.ErrUnderpriced) {
if err := pool.Add([]*types.Transaction{tx}, true, false)[0]; !errors.Is(err, txpool.ErrUnderpriced) {
t.Fatalf("Min tip not enforced")
}

Expand All @@ -1526,7 +1526,7 @@ func TestMinGasPriceEnforced(t *testing.T) {
t.Fatalf("Min tip not enforced")
}

if err := pool.Add([]*txpool.Transaction{{Tx: tx}}, true, false)[0]; !errors.Is(err, txpool.ErrUnderpriced) {
if err := pool.Add([]*types.Transaction{tx}, true, false)[0]; !errors.Is(err, txpool.ErrUnderpriced) {
t.Fatalf("Min tip not enforced")
}
}
Expand Down

0 comments on commit 5927f62

Please sign in to comment.