Skip to content

Commit 8d226e8

Browse files
authored
GPO tracks down correctly. Also GPO can be set to always offer zero i… (ethereum#94)
* GPO tracks down correctly. Also GPO can be set to always offer zero if miner.gasprice=0 * Rename GPO param floor -> defaultPrice
1 parent 9afedf5 commit 8d226e8

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

build/bin/geth.aar

-30.3 MB
Binary file not shown.

build/ci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func doTest(cmdline []string) {
359359
// Test a single package at a time. CI builders are slow
360360
// and some tests run into timeouts under load.
361361
gotest := goTool("test", buildFlags(env)...)
362-
gotest.Args = append(gotest.Args, "-p", "1", "-timeout", "5m")
362+
gotest.Args = append(gotest.Args, "-p", "1", "-timeout", "5m", "-v")
363363
if *coverage {
364364
gotest.Args = append(gotest.Args, "-covermode=atomic", "-cover")
365365
}

core/tx_pool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,22 +625,22 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
625625
}
626626
// If the transaction fails basic validation, discard it
627627
if err := pool.validateTx(tx, local); err != nil {
628-
log.Trace("Discarding invalid transaction", "hash", hash, "err", err)
628+
log.Debug("Discarding invalid transaction", "hash", hash, "err", err)
629629
invalidTxCounter.Inc(1)
630630
return false, err
631631
}
632632
// If the transaction pool is full, discard underpriced transactions
633633
if uint64(pool.all.Count()) >= pool.config.GlobalSlots+pool.config.GlobalQueue {
634634
// If the new transaction is underpriced, don't accept it
635635
if !local && pool.priced.Underpriced(tx, pool.locals) {
636-
log.Trace("Discarding underpriced transaction", "hash", hash, "price", tx.GasPrice())
636+
log.Debug("Discarding underpriced transaction", "hash", hash, "price", tx.GasPrice())
637637
underpricedTxCounter.Inc(1)
638638
return false, ErrUnderpriced
639639
}
640640
// New transaction is better than our worse ones, make room for it
641641
drop := pool.priced.Discard(pool.all.Count()-int(pool.config.GlobalSlots+pool.config.GlobalQueue-1), pool.locals)
642642
for _, tx := range drop {
643-
log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "price", tx.GasPrice())
643+
log.Debug("Discarding freshly underpriced transaction", "hash", tx.Hash(), "price", tx.GasPrice())
644644
underpricedTxCounter.Inc(1)
645645
pool.removeTx(tx.Hash(), false)
646646
}

eth/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ var DefaultConfig = Config{
4949
TrieTimeout: 60 * time.Minute,
5050
MinerGasFloor: 8000000,
5151
MinerGasCeil: 8000000,
52-
MinerGasPrice: big.NewInt(0), // params.GWei
52+
MinerGasPrice: big.NewInt(0), // Always free gas
5353
MinerRecommit: 3 * time.Second,
5454
MinerVerificationServiceUrl: "https://mining-pool.celo.org/v0.1/sms",
5555

5656
TxPool: core.DefaultTxPoolConfig,
5757
GPO: gasprice.Config{
5858
Blocks: 20,
5959
Percentile: 60,
60+
AlwaysZero: true, // Always free gas
6061
},
6162
}
6263

eth/gasprice/gasprice.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Config struct {
3535
Blocks int
3636
Percentile int
3737
Default *big.Int `toml:",omitempty"`
38+
AlwaysZero bool
3839
}
3940

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

4950
checkBlocks, maxEmpty, maxBlocks int
5051
percentile int
52+
defaultPrice *big.Int
53+
alwaysZero bool
5154
}
5255

5356
// NewOracle returns a new oracle.
@@ -64,17 +67,24 @@ func NewOracle(backend ethapi.Backend, params Config) *Oracle {
6467
percent = 100
6568
}
6669
return &Oracle{
67-
backend: backend,
68-
lastPrice: params.Default,
69-
checkBlocks: blocks,
70-
maxEmpty: blocks / 2,
71-
maxBlocks: blocks * 5,
72-
percentile: percent,
70+
backend: backend,
71+
lastPrice: params.Default,
72+
checkBlocks: blocks,
73+
maxEmpty: blocks / 2,
74+
maxBlocks: blocks * 5,
75+
percentile: percent,
76+
defaultPrice: params.Default,
77+
alwaysZero: params.AlwaysZero,
7378
}
7479
}
7580

7681
// SuggestPrice returns the recommended gas price.
7782
func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
83+
84+
if gpo.alwaysZero {
85+
return big.NewInt(0), nil
86+
}
87+
7888
gpo.cacheLock.RLock()
7989
lastHead := gpo.lastHead
8090
lastPrice := gpo.lastPrice
@@ -131,7 +141,7 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
131141
blockNum--
132142
}
133143
}
134-
price := lastPrice
144+
price := gpo.defaultPrice
135145
if len(blockPrices) > 0 {
136146
sort.Sort(bigIntArray(blockPrices))
137147
price = blockPrices[(len(blockPrices)-1)*gpo.percentile/100]

internal/ethapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import (
4747
)
4848

4949
const (
50-
defaultGasPrice = params.GWei
50+
defaultGasPrice = uint64(0) // Always free gas
5151
)
5252

5353
// PublicEthereumAPI provides an API to access Ethereum related information.

0 commit comments

Comments
 (0)