Skip to content

Commit

Permalink
Merge pull request #34 from MXCzkEVM/feat-minerMininumGasprice
Browse files Browse the repository at this point in the history
feat: miner minimum gas price
  • Loading branch information
luanxu-mxc authored Jul 21, 2023
2 parents 6b06da4 + 4789a5f commit b27846f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit b27846f

Please sign in to comment.