Skip to content

Commit

Permalink
Merge pull request #21 from 0xcary/kcc
Browse files Browse the repository at this point in the history
set minimum gas price
  • Loading branch information
viaweb3 authored Jun 28, 2022
2 parents 260973e + ea8e729 commit a4ba265
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Docker Image CI

on:
push:
-tags:
- v1.2.0
workflow_dispatch:


jobs:
Expand Down Expand Up @@ -39,7 +37,7 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}

- name: Copy binary out of image
run: mkdir -p build/bin && docker create --name binContainer wyblockchain/kcc:latest && docker cp binContainer:/usr/local/bin/geth build/bin/geth && ls -la build/bin/geth
run: mkdir -p build/bin && docker create --name binContainer kucoincommunitychain/kcc:latest && docker cp binContainer:/usr/local/bin/geth build/bin/geth && ls -la build/bin/geth

- uses: "marvinpinto/action-automatic-releases@latest"
with:
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ var (
utils.GpoBlocksFlag,
utils.GpoPercentileFlag,
utils.GpoMaxGasPriceFlag,
utils.GpoMinGasPriceFlag,
utils.EWASMInterpreterFlag,
utils.EVMInterpreterFlag,
configFileFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.GpoBlocksFlag,
utils.GpoPercentileFlag,
utils.GpoMaxGasPriceFlag,
utils.GpoMinGasPriceFlag,
},
},
{
Expand Down
8 changes: 8 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,11 @@ var (
Usage: "Maximum gas price will be recommended by gpo",
Value: ethconfig.Defaults.GPO.MaxPrice.Int64(),
}
GpoMinGasPriceFlag = cli.Int64Flag{
Name: "gpo.minprice",
Usage: "Minimum gas price will be recommended by gpo",
Value: ethconfig.Defaults.GPO.MinPrice.Int64(),
}

// Metrics flags
MetricsEnabledFlag = cli.BoolFlag{
Expand Down Expand Up @@ -1238,6 +1243,9 @@ func setGPO(ctx *cli.Context, cfg *gasprice.Config, light bool) {
if ctx.GlobalIsSet(GpoMaxGasPriceFlag.Name) {
cfg.MaxPrice = big.NewInt(ctx.GlobalInt64(GpoMaxGasPriceFlag.Name))
}
if ctx.GlobalIsSet(GpoMinGasPriceFlag.Name) {
cfg.MinPrice = big.NewInt(ctx.GlobalInt64(GpoMinGasPriceFlag.Name))
}
}

func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
Expand Down
2 changes: 2 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ var FullNodeGPO = gasprice.Config{
Blocks: 20,
Percentile: 60,
MaxPrice: gasprice.DefaultMaxPrice,
MinPrice: gasprice.DefaultMinPrice,
}

// LightClientGPO contains default gasprice oracle settings for light client.
var LightClientGPO = gasprice.Config{
Blocks: 2,
Percentile: 60,
MaxPrice: gasprice.DefaultMaxPrice,
MinPrice: gasprice.DefaultMinPrice,
}

// Defaults contains default settings for use on the Ethereum main net.
Expand Down
14 changes: 14 additions & 0 deletions eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ import (
const sampleNumber = 3 // Number of transactions sampled in a block

var DefaultMaxPrice = big.NewInt(500 * params.GWei)
var DefaultMinPrice = big.NewInt(3 * params.GWei)

type Config struct {
Blocks int
Percentile int
Default *big.Int `toml:",omitempty"`
MaxPrice *big.Int `toml:",omitempty"`
MinPrice *big.Int `toml:",omitempty"`
}

// OracleBackend includes all necessary background APIs for oracle.
Expand All @@ -54,6 +56,7 @@ type Oracle struct {
lastHead common.Hash
lastPrice *big.Int
maxPrice *big.Int
minPrice *big.Int
cacheLock sync.RWMutex
fetchLock sync.Mutex

Expand Down Expand Up @@ -83,10 +86,16 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
maxPrice = DefaultMaxPrice
log.Warn("Sanitizing invalid gasprice oracle price cap", "provided", params.MaxPrice, "updated", maxPrice)
}
minPrice := params.MinPrice
if minPrice == nil || minPrice.Int64() <= 0 {
minPrice = DefaultMinPrice
log.Warn("Sanitizing invalid gasprice oracle price floor", "provided", params.MinPrice, "updated", minPrice)
}
return &Oracle{
backend: backend,
lastPrice: params.Default,
maxPrice: maxPrice,
minPrice: minPrice,
checkBlocks: blocks,
percentile: percent,
}
Expand Down Expand Up @@ -161,6 +170,11 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
if price.Cmp(gpo.maxPrice) > 0 {
price = new(big.Int).Set(gpo.maxPrice)
}

if price.Cmp(gpo.minPrice) < 0 {
price = new(big.Int).Set(gpo.minPrice)
}

gpo.cacheLock.Lock()
gpo.lastHead = headHash
gpo.lastPrice = price
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
const (
VersionMajor = 1 // Major version component of the current release
VersionMinor = 2 // Minor version component of the current release
VersionPatch = 0 // Patch version component of the current release
VersionPatch = 1 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string
)

Expand Down

0 comments on commit a4ba265

Please sign in to comment.