From 3f94d09c1f07538c3fc72c72609037c47c04c4b5 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Tue, 26 May 2015 14:17:43 +0200 Subject: [PATCH 1/9] fixed saving receipts --- cmd/geth/main.go | 6 +++ cmd/utils/flags.go | 90 ++++++++++++++++++++++++++++------------- core/block_processor.go | 22 ++++++++++ eth/backend.go | 52 ++++++++++++++++-------- rpc/api.go | 2 +- xeth/xeth.go | 26 +++++++----- 6 files changed, 144 insertions(+), 54 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 0f2438cfd..1739fbc6b 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -256,6 +256,12 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.PProfEanbledFlag, utils.PProfPortFlag, utils.SolcPathFlag, + utils.GpoMinGasPriceFlag, + utils.GpoMaxGasPriceFlag, + utils.GpoFullBlockRatioFlag, + utils.GpobaseStepDownFlag, + utils.GpobaseStepUpFlag, + utils.GpobaseCorrectionFactorFlag, } app.Before = func(ctx *cli.Context) error { utils.SetupLogger(ctx) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index ec29598fb..0f5e443e4 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -276,6 +276,36 @@ var ( Usage: "solidity compiler to be used", Value: "solc", } + GpoMinGasPriceFlag = cli.StringFlag{ + Name: "gpomin", + Usage: "Minimum suggested gas price", + Value: new(big.Int).Mul(big.NewInt(10), common.Szabo).String(), + } + GpoMaxGasPriceFlag = cli.StringFlag{ + Name: "gpomax", + Usage: "Maximum suggested gas price", + Value: new(big.Int).Mul(big.NewInt(1000), common.Szabo).String(), + } + GpoFullBlockRatioFlag = cli.IntFlag{ + Name: "gpofull", + Usage: "Full block threshold for gas price calculation (%)", + Value: 80, + } + GpobaseStepDownFlag = cli.IntFlag{ + Name: "gpobasedown", + Usage: "Suggested gas price base step down ratio (1/1000)", + Value: 10, + } + GpobaseStepUpFlag = cli.IntFlag{ + Name: "gpobaseup", + Usage: "Suggested gas price base step up ratio (1/1000)", + Value: 100, + } + GpobaseCorrectionFactorFlag = cli.IntFlag{ + Name: "gpobasecf", + Usage: "Suggested gas price base correction factor (%)", + Value: 110, + } ) // MakeNAT creates a port mapper from set command line flags. @@ -313,33 +343,39 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config { clientID += "/" + customName } return ð.Config{ - Name: common.MakeName(clientID, version), - DataDir: ctx.GlobalString(DataDirFlag.Name), - ProtocolVersion: ctx.GlobalInt(ProtocolVersionFlag.Name), - GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name), - BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name), - SkipBcVersionCheck: false, - NetworkId: ctx.GlobalInt(NetworkIdFlag.Name), - LogFile: ctx.GlobalString(LogFileFlag.Name), - Verbosity: ctx.GlobalInt(VerbosityFlag.Name), - LogJSON: ctx.GlobalString(LogJSONFlag.Name), - Etherbase: ctx.GlobalString(EtherbaseFlag.Name), - MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name), - AccountManager: MakeAccountManager(ctx), - VmDebug: ctx.GlobalBool(VMDebugFlag.Name), - MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name), - MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name), - Port: ctx.GlobalString(ListenPortFlag.Name), - NAT: MakeNAT(ctx), - NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name), - Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name), - NodeKey: MakeNodeKey(ctx), - Shh: ctx.GlobalBool(WhisperEnabledFlag.Name), - Dial: true, - BootNodes: ctx.GlobalString(BootnodesFlag.Name), - GasPrice: common.String2Big(ctx.GlobalString(GasPriceFlag.Name)), - SolcPath: ctx.GlobalString(SolcPathFlag.Name), - AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name), + Name: common.MakeName(clientID, version), + DataDir: ctx.GlobalString(DataDirFlag.Name), + ProtocolVersion: ctx.GlobalInt(ProtocolVersionFlag.Name), + GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name), + BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name), + SkipBcVersionCheck: false, + NetworkId: ctx.GlobalInt(NetworkIdFlag.Name), + LogFile: ctx.GlobalString(LogFileFlag.Name), + Verbosity: ctx.GlobalInt(VerbosityFlag.Name), + LogJSON: ctx.GlobalString(LogJSONFlag.Name), + Etherbase: ctx.GlobalString(EtherbaseFlag.Name), + MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name), + AccountManager: MakeAccountManager(ctx), + VmDebug: ctx.GlobalBool(VMDebugFlag.Name), + MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name), + MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name), + Port: ctx.GlobalString(ListenPortFlag.Name), + NAT: MakeNAT(ctx), + NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name), + Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name), + NodeKey: MakeNodeKey(ctx), + Shh: ctx.GlobalBool(WhisperEnabledFlag.Name), + Dial: true, + BootNodes: ctx.GlobalString(BootnodesFlag.Name), + GasPrice: common.String2Big(ctx.GlobalString(GasPriceFlag.Name)), + GpoMinGasPrice: common.String2Big(ctx.GlobalString(GpoMinGasPriceFlag.Name)), + GpoMaxGasPrice: common.String2Big(ctx.GlobalString(GpoMaxGasPriceFlag.Name)), + GpoFullBlockRatio: ctx.GlobalInt(GpoFullBlockRatioFlag.Name), + GpobaseStepDown: ctx.GlobalInt(GpobaseStepDownFlag.Name), + GpobaseStepUp: ctx.GlobalInt(GpobaseStepUpFlag.Name), + GpobaseCorrectionFactor: ctx.GlobalInt(GpobaseCorrectionFactorFlag.Name), + SolcPath: ctx.GlobalString(SolcPathFlag.Name), + AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name), } } diff --git a/core/block_processor.go b/core/block_processor.go index 54378b2b9..0ed30ca21 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -260,9 +260,31 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st putTx(sm.extraDb, tx, block, uint64(i)) } + receiptsRlp := receipts.RlpEncode() + /*if len(receipts) > 0 { + glog.V(logger.Info).Infof("Saving %v receipts, rlp len is %v\n", len(receipts), len(receiptsRlp)) + }*/ + sm.extraDb.Put(append(receiptsPre, block.Hash().Bytes()...), receiptsRlp) + return state.Logs(), nil } +func (self *BlockProcessor) GetBlockReceipts(bhash common.Hash) (receipts types.Receipts, err error) { + var rdata []byte + rdata, err = self.extraDb.Get(append(receiptsPre, bhash[:]...)) + + if err == nil { + err = rlp.DecodeBytes(rdata, &receipts) + } else { + glog.V(logger.Detail).Infof("GetBlockReceipts error %v\n", err) + } + /*if len(receipts) > 0 { + glog.V(logger.Info).Infof("GBR len %v\n", len(receipts)) + }*/ + return + +} + // See YP section 4.3.4. "Block Header Validity" // Validates a block. Returns an error if the block is invalid. func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header, checkPow bool) error { diff --git a/eth/backend.go b/eth/backend.go index d2ec0cc62..c24b4e877 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -93,6 +93,13 @@ type Config struct { AccountManager *accounts.Manager SolcPath string + GpoMinGasPrice *big.Int + GpoMaxGasPrice *big.Int + GpoFullBlockRatio int + GpobaseStepDown int + GpobaseStepUp int + GpobaseCorrectionFactor int + // NewDB is used to create databases. // If nil, the default is to create leveldb databases on disk. NewDB func(path string) (common.Database, error) @@ -197,6 +204,13 @@ type Ethereum struct { SolcPath string solc *compiler.Solidity + GpoMinGasPrice *big.Int + GpoMaxGasPrice *big.Int + GpoFullBlockRatio int + GpobaseStepDown int + GpobaseStepUp int + GpobaseCorrectionFactor int + net *p2p.Server eventMux *event.TypeMux miner *miner.Miner @@ -266,22 +280,28 @@ func New(config *Config) (*Ethereum, error) { glog.V(logger.Info).Infof("Blockchain DB Version: %d", config.BlockChainVersion) eth := &Ethereum{ - shutdownChan: make(chan bool), - databasesClosed: make(chan bool), - blockDb: blockDb, - stateDb: stateDb, - extraDb: extraDb, - eventMux: &event.TypeMux{}, - accountManager: config.AccountManager, - DataDir: config.DataDir, - etherbase: common.HexToAddress(config.Etherbase), - clientVersion: config.Name, // TODO should separate from Name - ethVersionId: config.ProtocolVersion, - netVersionId: config.NetworkId, - NatSpec: config.NatSpec, - MinerThreads: config.MinerThreads, - SolcPath: config.SolcPath, - AutoDAG: config.AutoDAG, + shutdownChan: make(chan bool), + databasesClosed: make(chan bool), + blockDb: blockDb, + stateDb: stateDb, + extraDb: extraDb, + eventMux: &event.TypeMux{}, + accountManager: config.AccountManager, + DataDir: config.DataDir, + etherbase: common.HexToAddress(config.Etherbase), + clientVersion: config.Name, // TODO should separate from Name + ethVersionId: config.ProtocolVersion, + netVersionId: config.NetworkId, + NatSpec: config.NatSpec, + MinerThreads: config.MinerThreads, + SolcPath: config.SolcPath, + AutoDAG: config.AutoDAG, + GpoMinGasPrice: config.GpoMinGasPrice, + GpoMaxGasPrice: config.GpoMaxGasPrice, + GpoFullBlockRatio: config.GpoFullBlockRatio, + GpobaseStepDown: config.GpobaseStepDown, + GpobaseStepUp: config.GpobaseStepUp, + GpobaseCorrectionFactor: config.GpobaseCorrectionFactor, } eth.pow = ethash.New() diff --git a/rpc/api.go b/rpc/api.go index e35395734..8b9a080f8 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -59,7 +59,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err case "eth_mining": *reply = api.xeth().IsMining() case "eth_gasPrice": - v := xeth.DefaultGasPrice() + v := api.xeth().DefaultGasPrice() *reply = newHexNum(v.Bytes()) case "eth_accounts": *reply = api.xeth().Accounts() diff --git a/xeth/xeth.go b/xeth/xeth.go index d2f992084..1044b02f6 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -39,8 +39,11 @@ const ( LogFilterTy ) -func DefaultGas() *big.Int { return new(big.Int).Set(defaultGas) } -func DefaultGasPrice() *big.Int { return new(big.Int).Set(defaultGasPrice) } +func DefaultGas() *big.Int { return new(big.Int).Set(defaultGas) } + +func (self *XEth) DefaultGasPrice() *big.Int { + return self.gpo.SuggestPrice() +} type XEth struct { backend *eth.Ethereum @@ -68,6 +71,8 @@ type XEth struct { // register map[string][]*interface{} // TODO improve return type agent *miner.RemoteAgent + + gpo *eth.GasPriceOracle } func NewTest(eth *eth.Ethereum, frontend Frontend) *XEth { @@ -80,22 +85,23 @@ func NewTest(eth *eth.Ethereum, frontend Frontend) *XEth { // New creates an XEth that uses the given frontend. // If a nil Frontend is provided, a default frontend which // confirms all transactions will be used. -func New(eth *eth.Ethereum, frontend Frontend) *XEth { +func New(ethereum *eth.Ethereum, frontend Frontend) *XEth { xeth := &XEth{ - backend: eth, + backend: ethereum, frontend: frontend, quit: make(chan struct{}), - filterManager: filter.NewFilterManager(eth.EventMux()), + filterManager: filter.NewFilterManager(ethereum.EventMux()), logQueue: make(map[int]*logQueue), blockQueue: make(map[int]*hashQueue), transactionQueue: make(map[int]*hashQueue), messages: make(map[int]*whisperFilter), agent: miner.NewRemoteAgent(), + gpo: eth.NewGasPriceOracle(ethereum), } - if eth.Whisper() != nil { - xeth.whisper = NewWhisper(eth.Whisper()) + if ethereum.Whisper() != nil { + xeth.whisper = NewWhisper(ethereum.Whisper()) } - eth.Miner().Register(xeth.agent) + ethereum.Miner().Register(xeth.agent) if frontend == nil { xeth.frontend = dummyFrontend{} } @@ -829,7 +835,7 @@ func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr st } if msg.gasPrice.Cmp(big.NewInt(0)) == 0 { - msg.gasPrice = DefaultGasPrice() + msg.gasPrice = self.DefaultGasPrice() } block := self.CurrentBlock() @@ -898,7 +904,7 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS } if len(gasPriceStr) == 0 { - price = DefaultGasPrice() + price = self.DefaultGasPrice() } else { price = common.Big(gasPriceStr) } From 0930e190a7eec8f956e22ada638e5b97f7ba9cda Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Tue, 26 May 2015 14:28:32 +0200 Subject: [PATCH 2/9] added missing source --- eth/gasprice.go | 174 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 eth/gasprice.go diff --git a/eth/gasprice.go b/eth/gasprice.go new file mode 100644 index 000000000..f5b241e2c --- /dev/null +++ b/eth/gasprice.go @@ -0,0 +1,174 @@ +package eth + +import ( + "math/big" + "math/rand" + "sync" + + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger/glog" +) + +const gpoProcessPastBlocks = 100 + +type blockPriceInfo struct { + baseGasPrice *big.Int +} + +type GasPriceOracle struct { + eth *Ethereum + chain *core.ChainManager + pool *core.TxPool + events event.Subscription + blocks map[uint64]*blockPriceInfo + firstProcessed, lastProcessed uint64 + lastBaseMutex sync.Mutex + lastBase *big.Int +} + +func NewGasPriceOracle(eth *Ethereum) (self *GasPriceOracle) { + self = &GasPriceOracle{} + self.blocks = make(map[uint64]*blockPriceInfo) + self.eth = eth + self.chain = eth.chainManager + self.pool = eth.txPool + self.events = eth.EventMux().Subscribe( + core.ChainEvent{}, + core.ChainSplitEvent{}, + core.TxPreEvent{}, + core.TxPostEvent{}, + ) + self.processPastBlocks() + go self.listenLoop() + return +} + +func (self *GasPriceOracle) processPastBlocks() { + last := self.chain.CurrentBlock().NumberU64() + first := uint64(0) + if last > gpoProcessPastBlocks { + first = last - gpoProcessPastBlocks + } + self.firstProcessed = first + for i := first; i <= last; i++ { + self.processBlock(self.chain.GetBlockByNumber(i)) + } + +} + +func (self *GasPriceOracle) listenLoop() { + for { + ev, isopen := <-self.events.Chan() + if !isopen { + break + } + switch ev := ev.(type) { + case core.ChainEvent: + self.processBlock(ev.Block) + case core.ChainSplitEvent: + self.processBlock(ev.Block) + case core.TxPreEvent: + case core.TxPostEvent: + } + } + self.events.Unsubscribe() +} + +func (self *GasPriceOracle) processBlock(block *types.Block) { + i := block.NumberU64() + if i > self.lastProcessed { + self.lastProcessed = i + } + + lastBase := self.eth.GpoMinGasPrice + bpl := self.blocks[i-1] + if bpl != nil { + lastBase = bpl.baseGasPrice + } + if lastBase == nil { + return + } + + var corr int + lp := self.lowestPrice(block) + if lp == nil { + return + } + + if lastBase.Cmp(lp) < 0 { + corr = self.eth.GpobaseStepUp + } else { + corr = -self.eth.GpobaseStepDown + } + + crand := int64(corr * (900 + rand.Intn(201))) + newBase := new(big.Int).Mul(lastBase, big.NewInt(1000000+crand)) + newBase.Div(newBase, big.NewInt(1000000)) + + bpi := self.blocks[i] + if bpi == nil { + bpi = &blockPriceInfo{} + self.blocks[i] = bpi + } + bpi.baseGasPrice = newBase + self.lastBaseMutex.Lock() + self.lastBase = newBase + self.lastBaseMutex.Unlock() + + glog.V(logger.Detail).Infof("Processed block #%v, base price is %v\n", block.NumberU64(), newBase.Int64()) +} + +// returns the lowers possible price with which a tx was or could have been included +func (self *GasPriceOracle) lowestPrice(block *types.Block) *big.Int { + gasUsed := new(big.Int) + recepits, err := self.eth.BlockProcessor().GetBlockReceipts(block.Hash()) + if err != nil { + return self.eth.GpoMinGasPrice + } + + if len(recepits) > 0 { + gasUsed = recepits[len(recepits)-1].CumulativeGasUsed + } + + if new(big.Int).Mul(gasUsed, big.NewInt(100)).Cmp(new(big.Int).Mul(block.Header().GasLimit, + big.NewInt(int64(self.eth.GpoFullBlockRatio)))) < 0 { + // block is not full, could have posted a tx with MinGasPrice + return self.eth.GpoMinGasPrice + } + + if len(block.Transactions()) < 1 { + return self.eth.GpoMinGasPrice + } + + // block is full, find smallest gasPrice + minPrice := block.Transactions()[0].GasPrice() + for i := 1; i < len(block.Transactions()); i++ { + price := block.Transactions()[i].GasPrice() + if price.Cmp(minPrice) < 0 { + minPrice = price + } + } + return minPrice +} + +func (self *GasPriceOracle) SuggestPrice() *big.Int { + self.lastBaseMutex.Lock() + base := self.lastBase + self.lastBaseMutex.Unlock() + + baseCorr := new(big.Int).Mul(base, big.NewInt(int64(100+self.eth.GpobaseCorrectionFactor))) + baseCorr.Div(baseCorr, big.NewInt(100)) + + if baseCorr.Cmp(self.eth.GpoMinGasPrice) < 0 { + return self.eth.GpoMinGasPrice + } + + if baseCorr.Cmp(self.eth.GpoMaxGasPrice) > 0 { + return self.eth.GpoMaxGasPrice + } + + return baseCorr +} From 2e8016c80d450a7d1126b481f1262b7cd9dec24d Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Tue, 26 May 2015 14:39:13 +0200 Subject: [PATCH 3/9] fixed initial base price bug --- eth/gasprice.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eth/gasprice.go b/eth/gasprice.go index f5b241e2c..6f46559a2 100644 --- a/eth/gasprice.go +++ b/eth/gasprice.go @@ -159,6 +159,10 @@ func (self *GasPriceOracle) SuggestPrice() *big.Int { base := self.lastBase self.lastBaseMutex.Unlock() + if base == nil { + base = self.eth.GpoMinGasPrice + } + baseCorr := new(big.Int).Mul(base, big.NewInt(int64(100+self.eth.GpobaseCorrectionFactor))) baseCorr.Div(baseCorr, big.NewInt(100)) From 6e212bdc6d1319c84c305c446bbf1ba9ddfdc66d Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Tue, 26 May 2015 15:15:54 +0200 Subject: [PATCH 4/9] fallback for uninitialized GPO config values --- eth/gasprice.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eth/gasprice.go b/eth/gasprice.go index 6f46559a2..12e76fc2c 100644 --- a/eth/gasprice.go +++ b/eth/gasprice.go @@ -162,6 +162,9 @@ func (self *GasPriceOracle) SuggestPrice() *big.Int { if base == nil { base = self.eth.GpoMinGasPrice } + if base == nil { + return big.NewInt(10000000000000) // apparently MinGasPrice is not initialized during some tests + } baseCorr := new(big.Int).Mul(base, big.NewInt(int64(100+self.eth.GpobaseCorrectionFactor))) baseCorr.Div(baseCorr, big.NewInt(100)) From a977cecbe49e9cf049785a437581a767b079570c Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Wed, 27 May 2015 12:39:59 +0200 Subject: [PATCH 5/9] fixed gas price corr. factor --- eth/gasprice.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/gasprice.go b/eth/gasprice.go index 12e76fc2c..cd5293691 100644 --- a/eth/gasprice.go +++ b/eth/gasprice.go @@ -166,7 +166,7 @@ func (self *GasPriceOracle) SuggestPrice() *big.Int { return big.NewInt(10000000000000) // apparently MinGasPrice is not initialized during some tests } - baseCorr := new(big.Int).Mul(base, big.NewInt(int64(100+self.eth.GpobaseCorrectionFactor))) + baseCorr := new(big.Int).Mul(base, big.NewInt(int64(self.eth.GpobaseCorrectionFactor))) baseCorr.Div(baseCorr, big.NewInt(100)) if baseCorr.Cmp(self.eth.GpoMinGasPrice) < 0 { From 3c7b64ce20aefeae6728d09d96b34ef31bc405ac Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Wed, 10 Jun 2015 15:57:38 +0200 Subject: [PATCH 6/9] removed duplicate function after rebase --- core/block_processor.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/core/block_processor.go b/core/block_processor.go index 0ed30ca21..c01b110be 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -269,22 +269,6 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st return state.Logs(), nil } -func (self *BlockProcessor) GetBlockReceipts(bhash common.Hash) (receipts types.Receipts, err error) { - var rdata []byte - rdata, err = self.extraDb.Get(append(receiptsPre, bhash[:]...)) - - if err == nil { - err = rlp.DecodeBytes(rdata, &receipts) - } else { - glog.V(logger.Detail).Infof("GetBlockReceipts error %v\n", err) - } - /*if len(receipts) > 0 { - glog.V(logger.Info).Infof("GBR len %v\n", len(receipts)) - }*/ - return - -} - // See YP section 4.3.4. "Block Header Validity" // Validates a block. Returns an error if the block is invalid. func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header, checkPow bool) error { @@ -426,6 +410,8 @@ func getBlockReceipts(db common.Database, bhash common.Hash) (receipts types.Rec if err == nil { err = rlp.DecodeBytes(rdata, &receipts) + } else { + glog.V(logger.Detail).Infof("getBlockReceipts error %v\n", err) } return } From 610adfd83f14652ba08d99fb098d1d62123abd38 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Fri, 12 Jun 2015 13:57:30 +0200 Subject: [PATCH 7/9] fixed xeth.gpo = nil bug --- xeth/xeth.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xeth/xeth.go b/xeth/xeth.go index 1044b02f6..71753d6bd 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -42,6 +42,9 @@ const ( func DefaultGas() *big.Int { return new(big.Int).Set(defaultGas) } func (self *XEth) DefaultGasPrice() *big.Int { + if self.gpo == nil { + self.gpo = eth.NewGasPriceOracle(self.backend) + } return self.gpo.SuggestPrice() } @@ -96,7 +99,6 @@ func New(ethereum *eth.Ethereum, frontend Frontend) *XEth { transactionQueue: make(map[int]*hashQueue), messages: make(map[int]*whisperFilter), agent: miner.NewRemoteAgent(), - gpo: eth.NewGasPriceOracle(ethereum), } if ethereum.Whisper() != nil { xeth.whisper = NewWhisper(ethereum.Whisper()) @@ -233,6 +235,7 @@ func (self *XEth) WithState(statedb *state.StateDB) *XEth { xeth := &XEth{ backend: self.backend, frontend: self.frontend, + gpo: self.gpo, } xeth.state = NewState(xeth, statedb) From b42b70eb5fd55741175dd5503686843a9d7d043a Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Fri, 12 Jun 2015 14:11:10 +0200 Subject: [PATCH 8/9] fixed rpc/api.GasPrice --- rpc/api/eth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/api/eth.go b/rpc/api/eth.go index a0b9dad86..943f19b90 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -139,7 +139,7 @@ func (self *ethApi) IsMining(req *shared.Request) (interface{}, error) { } func (self *ethApi) GasPrice(req *shared.Request) (interface{}, error) { - return newHexNum(xeth.DefaultGasPrice().Bytes()), nil + return newHexNum(self.xeth.DefaultGasPrice().Bytes()), nil } func (self *ethApi) GetStorage(req *shared.Request) (interface{}, error) { From 1e3f4877c0e9ebf58ffa06b0b119fdf3bab21658 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Mon, 15 Jun 2015 16:48:59 +0200 Subject: [PATCH 9/9] Changed miner and gpo min gas price to 1 szabo --- cmd/utils/flags.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 0f5e443e4..696dbd142 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -23,10 +23,10 @@ import ( "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/rpc" - "github.com/ethereum/go-ethereum/xeth" "github.com/ethereum/go-ethereum/rpc/api" - "github.com/ethereum/go-ethereum/rpc/comms" "github.com/ethereum/go-ethereum/rpc/codec" + "github.com/ethereum/go-ethereum/rpc/comms" + "github.com/ethereum/go-ethereum/xeth" ) func init() { @@ -132,7 +132,7 @@ var ( GasPriceFlag = cli.StringFlag{ Name: "gasprice", Usage: "Sets the minimal gasprice when mining transactions", - Value: new(big.Int).Mul(big.NewInt(10), common.Szabo).String(), + Value: new(big.Int).Mul(big.NewInt(1), common.Szabo).String(), } UnlockedAccountFlag = cli.StringFlag{ @@ -279,12 +279,12 @@ var ( GpoMinGasPriceFlag = cli.StringFlag{ Name: "gpomin", Usage: "Minimum suggested gas price", - Value: new(big.Int).Mul(big.NewInt(10), common.Szabo).String(), + Value: new(big.Int).Mul(big.NewInt(1), common.Szabo).String(), } GpoMaxGasPriceFlag = cli.StringFlag{ Name: "gpomax", Usage: "Maximum suggested gas price", - Value: new(big.Int).Mul(big.NewInt(1000), common.Szabo).String(), + Value: new(big.Int).Mul(big.NewInt(100), common.Szabo).String(), } GpoFullBlockRatioFlag = cli.IntFlag{ Name: "gpofull", @@ -432,7 +432,7 @@ func IpcSocketPath(ctx *cli.Context) (ipcpath string) { if ctx.GlobalString(IPCPathFlag.Name) != common.DefaultIpcPath() { ipcpath = ctx.GlobalString(IPCPathFlag.Name) } else if ctx.GlobalString(DataDirFlag.Name) != "" && - ctx.GlobalString(DataDirFlag.Name) != common.DefaultDataDir() { + ctx.GlobalString(DataDirFlag.Name) != common.DefaultDataDir() { ipcpath = filepath.Join(ctx.GlobalString(DataDirFlag.Name), "geth.ipc") } }