Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: miner minimum gas price #33

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main

import (
"fmt"
"math/big"
"os"
"sort"
"strconv"
Expand Down Expand Up @@ -428,6 +429,18 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isCon
}()
}

// CHANGE(MXC)
gasprice := flags.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
if gasprice.Cmp(big.NewInt(0)) > 0 {
ethBackend, ok := backend.(*eth.EthAPIBackend)
if !ok {
utils.Fatalf("Ethereum service not running")
}
// Set the gas price to the limits from the CLI and start mining
gasprice := flags.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
ethBackend.TxPool().SetGasPrice(gasprice)
}

// Start auxiliary services if enabled
if ctx.Bool(utils.MiningEnabledFlag.Name) || ctx.Bool(utils.DeveloperFlag.Name) {
// Mining only makes sense if a full Ethereum node is running
Expand Down
7 changes: 7 additions & 0 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,13 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
// the sender is marked as local previously, treat it as the local transaction.
isLocal := local || pool.locals.containsTx(tx)

// CHANGE(MXC): check if the transaction gas price is less than the minimum gas price
if tx.GasPrice().Cmp(pool.gasPrice) < 0 {
log.Trace("Discarding underpriced transaction", "hash", hash, "gasPrice", tx.GasPrice(), "local", isLocal)
underpricedTxMeter.Mark(1)
return false, ErrUnderpriced
}

// If the transaction fails basic validation, discard it
if err := pool.validateTx(tx, isLocal); err != nil {
log.Trace("Discarding invalid transaction", "hash", hash, "err", err)
Expand Down
Loading