Skip to content

Commit

Permalink
GPO tracks down correctly. Also GPO can be set to always offer zero i… (
Browse files Browse the repository at this point in the history
ethereum#94)

* GPO tracks down correctly. Also GPO can be set to always offer zero if miner.gasprice=0

* Rename GPO param floor -> defaultPrice
  • Loading branch information
timmoreton committed Nov 12, 2018
1 parent 9afedf5 commit 8d226e8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
Binary file removed build/bin/geth.aar
Binary file not shown.
2 changes: 1 addition & 1 deletion build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func doTest(cmdline []string) {
// Test a single package at a time. CI builders are slow
// and some tests run into timeouts under load.
gotest := goTool("test", buildFlags(env)...)
gotest.Args = append(gotest.Args, "-p", "1", "-timeout", "5m")
gotest.Args = append(gotest.Args, "-p", "1", "-timeout", "5m", "-v")
if *coverage {
gotest.Args = append(gotest.Args, "-covermode=atomic", "-cover")
}
Expand Down
6 changes: 3 additions & 3 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,22 +625,22 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
}
// If the transaction fails basic validation, discard it
if err := pool.validateTx(tx, local); err != nil {
log.Trace("Discarding invalid transaction", "hash", hash, "err", err)
log.Debug("Discarding invalid transaction", "hash", hash, "err", err)
invalidTxCounter.Inc(1)
return false, err
}
// If the transaction pool is full, discard underpriced transactions
if uint64(pool.all.Count()) >= pool.config.GlobalSlots+pool.config.GlobalQueue {
// If the new transaction is underpriced, don't accept it
if !local && pool.priced.Underpriced(tx, pool.locals) {
log.Trace("Discarding underpriced transaction", "hash", hash, "price", tx.GasPrice())
log.Debug("Discarding underpriced transaction", "hash", hash, "price", tx.GasPrice())
underpricedTxCounter.Inc(1)
return false, ErrUnderpriced
}
// New transaction is better than our worse ones, make room for it
drop := pool.priced.Discard(pool.all.Count()-int(pool.config.GlobalSlots+pool.config.GlobalQueue-1), pool.locals)
for _, tx := range drop {
log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "price", tx.GasPrice())
log.Debug("Discarding freshly underpriced transaction", "hash", tx.Hash(), "price", tx.GasPrice())
underpricedTxCounter.Inc(1)
pool.removeTx(tx.Hash(), false)
}
Expand Down
3 changes: 2 additions & 1 deletion eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ var DefaultConfig = Config{
TrieTimeout: 60 * time.Minute,
MinerGasFloor: 8000000,
MinerGasCeil: 8000000,
MinerGasPrice: big.NewInt(0), // params.GWei
MinerGasPrice: big.NewInt(0), // Always free gas
MinerRecommit: 3 * time.Second,
MinerVerificationServiceUrl: "https://mining-pool.celo.org/v0.1/sms",

TxPool: core.DefaultTxPoolConfig,
GPO: gasprice.Config{
Blocks: 20,
Percentile: 60,
AlwaysZero: true, // Always free gas
},
}

Expand Down
24 changes: 17 additions & 7 deletions eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Config struct {
Blocks int
Percentile int
Default *big.Int `toml:",omitempty"`
AlwaysZero bool
}

// Oracle recommends gas prices based on the content of recent
Expand All @@ -48,6 +49,8 @@ type Oracle struct {

checkBlocks, maxEmpty, maxBlocks int
percentile int
defaultPrice *big.Int
alwaysZero bool
}

// NewOracle returns a new oracle.
Expand All @@ -64,17 +67,24 @@ func NewOracle(backend ethapi.Backend, params Config) *Oracle {
percent = 100
}
return &Oracle{
backend: backend,
lastPrice: params.Default,
checkBlocks: blocks,
maxEmpty: blocks / 2,
maxBlocks: blocks * 5,
percentile: percent,
backend: backend,
lastPrice: params.Default,
checkBlocks: blocks,
maxEmpty: blocks / 2,
maxBlocks: blocks * 5,
percentile: percent,
defaultPrice: params.Default,
alwaysZero: params.AlwaysZero,
}
}

// SuggestPrice returns the recommended gas price.
func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {

if gpo.alwaysZero {
return big.NewInt(0), nil
}

gpo.cacheLock.RLock()
lastHead := gpo.lastHead
lastPrice := gpo.lastPrice
Expand Down Expand Up @@ -131,7 +141,7 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
blockNum--
}
}
price := lastPrice
price := gpo.defaultPrice
if len(blockPrices) > 0 {
sort.Sort(bigIntArray(blockPrices))
price = blockPrices[(len(blockPrices)-1)*gpo.percentile/100]
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
)

const (
defaultGasPrice = params.GWei
defaultGasPrice = uint64(0) // Always free gas
)

// PublicEthereumAPI provides an API to access Ethereum related information.
Expand Down

0 comments on commit 8d226e8

Please sign in to comment.