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

cmd, eth, internal, les: add gasprice cap #21212

Merged
merged 5 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ var (
utils.IPCPathFlag,
utils.InsecureUnlockAllowedFlag,
utils.RPCGlobalGasCap,
utils.RPCGlobalGasPriceCap,
}

whisperFlags = []cli.Flag{
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.GraphQLCORSDomainFlag,
utils.GraphQLVirtualHostsFlag,
utils.RPCGlobalGasCap,
utils.RPCGlobalGasPriceCap,
utils.JSpathFlag,
utils.ExecFlag,
utils.PreloadJSFlag,
Expand Down
7 changes: 7 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ var (
Name: "rpc.gascap",
Usage: "Sets a cap on gas that can be used in eth_call/estimateGas",
}
RPCGlobalGasPriceCap = cli.Uint64Flag{
Name: "rpc.gaspricecap",
Usage: "Sets a cap on gasprice that can be used in sendTransaction/sendRawTransaction",
}
// Logging and debug settings
EthStatsURLFlag = cli.StringFlag{
Name: "ethstats",
Expand Down Expand Up @@ -1560,6 +1564,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
if ctx.GlobalIsSet(RPCGlobalGasCap.Name) {
cfg.RPCGasCap = new(big.Int).SetUint64(ctx.GlobalUint64(RPCGlobalGasCap.Name))
}
if ctx.GlobalIsSet(RPCGlobalGasPriceCap.Name) {
cfg.RPCGasPriceCap = new(big.Int).SetUint64(ctx.GlobalUint64(RPCGlobalGasPriceCap.Name))
}
if ctx.GlobalIsSet(DNSDiscoveryFlag.Name) {
urls := ctx.GlobalString(DNSDiscoveryFlag.Name)
if urls == "" {
Expand Down
4 changes: 4 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ func (b *EthAPIBackend) RPCGasCap() *big.Int {
return b.eth.config.RPCGasCap
}

func (b *EthAPIBackend) RPCGasPriceCap() *big.Int {
return b.eth.config.RPCGasPriceCap
}

func (b *EthAPIBackend) BloomStatus() (uint64, uint64) {
sections, _, _ := b.eth.bloomIndexer.Sections()
return params.BloomBitsBlocks, sections
Expand Down
3 changes: 3 additions & 0 deletions eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ type Config struct {
// RPCGasCap is the global gas cap for eth-call variants.
RPCGasCap *big.Int `toml:",omitempty"`

// RPCGasPriceCap is the global gasprice cap for send-transction variants.
RPCGasPriceCap *big.Int `toml:",omitempty"`

// Checkpoint is a hardcoded checkpoint which can be nil.
Checkpoint *params.TrustedCheckpoint `toml:",omitempty"`

Expand Down
5 changes: 5 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,11 @@ func (args *SendTxArgs) toTransaction() *types.Transaction {

// SubmitTransaction is a helper function that submits tx to txPool and logs a message.
func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (common.Hash, error) {
// If the gasprice cap is already specified, ensure the
// gasprice of given transaction is _reasonable_.
if b.RPCGasPriceCap() != nil && tx.GasPrice().Cmp(b.RPCGasPriceCap()) > 0 {
return common.Hash{}, fmt.Errorf("gasprice(%s) exceeds the maximum setting(%s)", hexutil.EncodeBig(tx.GasPrice()), hexutil.EncodeBig(b.RPCGasPriceCap()))
}
if err := b.SendTx(ctx, tx); err != nil {
return common.Hash{}, err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ type Backend interface {
ChainDb() ethdb.Database
AccountManager() *accounts.Manager
ExtRPCEnabled() bool
RPCGasCap() *big.Int // global gas cap for eth_call over rpc: DoS protection
RPCGasCap() *big.Int // global gas cap for eth_call over rpc: DoS protection
RPCGasPriceCap() *big.Int // global gas price cap for all transaction related APIs

// Blockchain API
SetHead(number uint64)
Expand Down
4 changes: 4 additions & 0 deletions les/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ func (b *LesApiBackend) RPCGasCap() *big.Int {
return b.eth.config.RPCGasCap
}

func (b *LesApiBackend) RPCGasPriceCap() *big.Int {
return b.eth.config.RPCGasPriceCap
}

func (b *LesApiBackend) BloomStatus() (uint64, uint64) {
if b.eth.bloomIndexer == nil {
return 0, 0
Expand Down