Skip to content

Commit f2a2164

Browse files
committed
Merge pull request #990 from zsfelfoldi/gasprice
eth: add GasPriceOracle
2 parents f475a01 + 1e3f487 commit f2a2164

File tree

8 files changed

+319
-59
lines changed

8 files changed

+319
-59
lines changed

cmd/geth/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
256256
utils.PProfEanbledFlag,
257257
utils.PProfPortFlag,
258258
utils.SolcPathFlag,
259+
utils.GpoMinGasPriceFlag,
260+
utils.GpoMaxGasPriceFlag,
261+
utils.GpoFullBlockRatioFlag,
262+
utils.GpobaseStepDownFlag,
263+
utils.GpobaseStepUpFlag,
264+
utils.GpobaseCorrectionFactorFlag,
259265
}
260266
app.Before = func(ctx *cli.Context) error {
261267
utils.SetupLogger(ctx)

cmd/utils/flags.go

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
"github.com/ethereum/go-ethereum/logger/glog"
2424
"github.com/ethereum/go-ethereum/p2p/nat"
2525
"github.com/ethereum/go-ethereum/rpc"
26-
"github.com/ethereum/go-ethereum/xeth"
2726
"github.com/ethereum/go-ethereum/rpc/api"
28-
"github.com/ethereum/go-ethereum/rpc/comms"
2927
"github.com/ethereum/go-ethereum/rpc/codec"
28+
"github.com/ethereum/go-ethereum/rpc/comms"
29+
"github.com/ethereum/go-ethereum/xeth"
3030
)
3131

3232
func init() {
@@ -132,7 +132,7 @@ var (
132132
GasPriceFlag = cli.StringFlag{
133133
Name: "gasprice",
134134
Usage: "Sets the minimal gasprice when mining transactions",
135-
Value: new(big.Int).Mul(big.NewInt(10), common.Szabo).String(),
135+
Value: new(big.Int).Mul(big.NewInt(1), common.Szabo).String(),
136136
}
137137

138138
UnlockedAccountFlag = cli.StringFlag{
@@ -276,6 +276,36 @@ var (
276276
Usage: "solidity compiler to be used",
277277
Value: "solc",
278278
}
279+
GpoMinGasPriceFlag = cli.StringFlag{
280+
Name: "gpomin",
281+
Usage: "Minimum suggested gas price",
282+
Value: new(big.Int).Mul(big.NewInt(1), common.Szabo).String(),
283+
}
284+
GpoMaxGasPriceFlag = cli.StringFlag{
285+
Name: "gpomax",
286+
Usage: "Maximum suggested gas price",
287+
Value: new(big.Int).Mul(big.NewInt(100), common.Szabo).String(),
288+
}
289+
GpoFullBlockRatioFlag = cli.IntFlag{
290+
Name: "gpofull",
291+
Usage: "Full block threshold for gas price calculation (%)",
292+
Value: 80,
293+
}
294+
GpobaseStepDownFlag = cli.IntFlag{
295+
Name: "gpobasedown",
296+
Usage: "Suggested gas price base step down ratio (1/1000)",
297+
Value: 10,
298+
}
299+
GpobaseStepUpFlag = cli.IntFlag{
300+
Name: "gpobaseup",
301+
Usage: "Suggested gas price base step up ratio (1/1000)",
302+
Value: 100,
303+
}
304+
GpobaseCorrectionFactorFlag = cli.IntFlag{
305+
Name: "gpobasecf",
306+
Usage: "Suggested gas price base correction factor (%)",
307+
Value: 110,
308+
}
279309
)
280310

281311
// MakeNAT creates a port mapper from set command line flags.
@@ -313,33 +343,39 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
313343
clientID += "/" + customName
314344
}
315345
return &eth.Config{
316-
Name: common.MakeName(clientID, version),
317-
DataDir: ctx.GlobalString(DataDirFlag.Name),
318-
ProtocolVersion: ctx.GlobalInt(ProtocolVersionFlag.Name),
319-
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
320-
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
321-
SkipBcVersionCheck: false,
322-
NetworkId: ctx.GlobalInt(NetworkIdFlag.Name),
323-
LogFile: ctx.GlobalString(LogFileFlag.Name),
324-
Verbosity: ctx.GlobalInt(VerbosityFlag.Name),
325-
LogJSON: ctx.GlobalString(LogJSONFlag.Name),
326-
Etherbase: ctx.GlobalString(EtherbaseFlag.Name),
327-
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
328-
AccountManager: MakeAccountManager(ctx),
329-
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
330-
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
331-
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
332-
Port: ctx.GlobalString(ListenPortFlag.Name),
333-
NAT: MakeNAT(ctx),
334-
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
335-
Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name),
336-
NodeKey: MakeNodeKey(ctx),
337-
Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
338-
Dial: true,
339-
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
340-
GasPrice: common.String2Big(ctx.GlobalString(GasPriceFlag.Name)),
341-
SolcPath: ctx.GlobalString(SolcPathFlag.Name),
342-
AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name),
346+
Name: common.MakeName(clientID, version),
347+
DataDir: ctx.GlobalString(DataDirFlag.Name),
348+
ProtocolVersion: ctx.GlobalInt(ProtocolVersionFlag.Name),
349+
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
350+
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
351+
SkipBcVersionCheck: false,
352+
NetworkId: ctx.GlobalInt(NetworkIdFlag.Name),
353+
LogFile: ctx.GlobalString(LogFileFlag.Name),
354+
Verbosity: ctx.GlobalInt(VerbosityFlag.Name),
355+
LogJSON: ctx.GlobalString(LogJSONFlag.Name),
356+
Etherbase: ctx.GlobalString(EtherbaseFlag.Name),
357+
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
358+
AccountManager: MakeAccountManager(ctx),
359+
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
360+
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
361+
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
362+
Port: ctx.GlobalString(ListenPortFlag.Name),
363+
NAT: MakeNAT(ctx),
364+
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
365+
Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name),
366+
NodeKey: MakeNodeKey(ctx),
367+
Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
368+
Dial: true,
369+
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
370+
GasPrice: common.String2Big(ctx.GlobalString(GasPriceFlag.Name)),
371+
GpoMinGasPrice: common.String2Big(ctx.GlobalString(GpoMinGasPriceFlag.Name)),
372+
GpoMaxGasPrice: common.String2Big(ctx.GlobalString(GpoMaxGasPriceFlag.Name)),
373+
GpoFullBlockRatio: ctx.GlobalInt(GpoFullBlockRatioFlag.Name),
374+
GpobaseStepDown: ctx.GlobalInt(GpobaseStepDownFlag.Name),
375+
GpobaseStepUp: ctx.GlobalInt(GpobaseStepUpFlag.Name),
376+
GpobaseCorrectionFactor: ctx.GlobalInt(GpobaseCorrectionFactorFlag.Name),
377+
SolcPath: ctx.GlobalString(SolcPathFlag.Name),
378+
AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name),
343379
}
344380
}
345381

@@ -396,7 +432,7 @@ func IpcSocketPath(ctx *cli.Context) (ipcpath string) {
396432
if ctx.GlobalString(IPCPathFlag.Name) != common.DefaultIpcPath() {
397433
ipcpath = ctx.GlobalString(IPCPathFlag.Name)
398434
} else if ctx.GlobalString(DataDirFlag.Name) != "" &&
399-
ctx.GlobalString(DataDirFlag.Name) != common.DefaultDataDir() {
435+
ctx.GlobalString(DataDirFlag.Name) != common.DefaultDataDir() {
400436
ipcpath = filepath.Join(ctx.GlobalString(DataDirFlag.Name), "geth.ipc")
401437
}
402438
}

core/block_processor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
260260
putTx(sm.extraDb, tx, block, uint64(i))
261261
}
262262

263+
receiptsRlp := receipts.RlpEncode()
264+
/*if len(receipts) > 0 {
265+
glog.V(logger.Info).Infof("Saving %v receipts, rlp len is %v\n", len(receipts), len(receiptsRlp))
266+
}*/
267+
sm.extraDb.Put(append(receiptsPre, block.Hash().Bytes()...), receiptsRlp)
268+
263269
return state.Logs(), nil
264270
}
265271

@@ -404,6 +410,8 @@ func getBlockReceipts(db common.Database, bhash common.Hash) (receipts types.Rec
404410

405411
if err == nil {
406412
err = rlp.DecodeBytes(rdata, &receipts)
413+
} else {
414+
glog.V(logger.Detail).Infof("getBlockReceipts error %v\n", err)
407415
}
408416
return
409417
}

eth/backend.go

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ type Config struct {
9393
AccountManager *accounts.Manager
9494
SolcPath string
9595

96+
GpoMinGasPrice *big.Int
97+
GpoMaxGasPrice *big.Int
98+
GpoFullBlockRatio int
99+
GpobaseStepDown int
100+
GpobaseStepUp int
101+
GpobaseCorrectionFactor int
102+
96103
// NewDB is used to create databases.
97104
// If nil, the default is to create leveldb databases on disk.
98105
NewDB func(path string) (common.Database, error)
@@ -196,6 +203,13 @@ type Ethereum struct {
196203
SolcPath string
197204
solc *compiler.Solidity
198205

206+
GpoMinGasPrice *big.Int
207+
GpoMaxGasPrice *big.Int
208+
GpoFullBlockRatio int
209+
GpobaseStepDown int
210+
GpobaseStepUp int
211+
GpobaseCorrectionFactor int
212+
199213
net *p2p.Server
200214
eventMux *event.TypeMux
201215
miner *miner.Miner
@@ -265,22 +279,28 @@ func New(config *Config) (*Ethereum, error) {
265279
glog.V(logger.Info).Infof("Blockchain DB Version: %d", config.BlockChainVersion)
266280

267281
eth := &Ethereum{
268-
shutdownChan: make(chan bool),
269-
databasesClosed: make(chan bool),
270-
blockDb: blockDb,
271-
stateDb: stateDb,
272-
extraDb: extraDb,
273-
eventMux: &event.TypeMux{},
274-
accountManager: config.AccountManager,
275-
DataDir: config.DataDir,
276-
etherbase: common.HexToAddress(config.Etherbase),
277-
clientVersion: config.Name, // TODO should separate from Name
278-
ethVersionId: config.ProtocolVersion,
279-
netVersionId: config.NetworkId,
280-
NatSpec: config.NatSpec,
281-
MinerThreads: config.MinerThreads,
282-
SolcPath: config.SolcPath,
283-
AutoDAG: config.AutoDAG,
282+
shutdownChan: make(chan bool),
283+
databasesClosed: make(chan bool),
284+
blockDb: blockDb,
285+
stateDb: stateDb,
286+
extraDb: extraDb,
287+
eventMux: &event.TypeMux{},
288+
accountManager: config.AccountManager,
289+
DataDir: config.DataDir,
290+
etherbase: common.HexToAddress(config.Etherbase),
291+
clientVersion: config.Name, // TODO should separate from Name
292+
ethVersionId: config.ProtocolVersion,
293+
netVersionId: config.NetworkId,
294+
NatSpec: config.NatSpec,
295+
MinerThreads: config.MinerThreads,
296+
SolcPath: config.SolcPath,
297+
AutoDAG: config.AutoDAG,
298+
GpoMinGasPrice: config.GpoMinGasPrice,
299+
GpoMaxGasPrice: config.GpoMaxGasPrice,
300+
GpoFullBlockRatio: config.GpoFullBlockRatio,
301+
GpobaseStepDown: config.GpobaseStepDown,
302+
GpobaseStepUp: config.GpobaseStepUp,
303+
GpobaseCorrectionFactor: config.GpobaseCorrectionFactor,
284304
}
285305

286306
eth.pow = ethash.New()

0 commit comments

Comments
 (0)