From 76821d167acd7da15e13b23beeceb6779138ffe5 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Sat, 27 Jun 2015 03:08:50 +0200 Subject: core, eth, rpc: avoid unnecessary block header copying --- eth/gasprice.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'eth/gasprice.go') diff --git a/eth/gasprice.go b/eth/gasprice.go index cd5293691..44202d709 100644 --- a/eth/gasprice.go +++ b/eth/gasprice.go @@ -133,20 +133,20 @@ func (self *GasPriceOracle) lowestPrice(block *types.Block) *big.Int { gasUsed = recepits[len(recepits)-1].CumulativeGasUsed } - if new(big.Int).Mul(gasUsed, big.NewInt(100)).Cmp(new(big.Int).Mul(block.Header().GasLimit, + if new(big.Int).Mul(gasUsed, big.NewInt(100)).Cmp(new(big.Int).Mul(block.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 { + txs := block.Transactions() + if len(txs) == 0 { 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() + minPrice := txs[0].GasPrice() + for i := 1; i < len(txs); i++ { + price := txs[i].GasPrice() if price.Cmp(minPrice) < 0 { minPrice = price } -- cgit v1.2.3 From 5d9df7348d80fbd5de9a92d7f6abe6c02646c24d Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Mon, 29 Jun 2015 13:48:10 +0200 Subject: gpo non-existent block checks --- eth/gasprice.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'eth/gasprice.go') diff --git a/eth/gasprice.go b/eth/gasprice.go index 44202d709..ddf1c8c09 100644 --- a/eth/gasprice.go +++ b/eth/gasprice.go @@ -47,14 +47,21 @@ func NewGasPriceOracle(eth *Ethereum) (self *GasPriceOracle) { } func (self *GasPriceOracle) processPastBlocks() { - last := self.chain.CurrentBlock().NumberU64() - first := uint64(0) + last := int64(-1) + cblock := self.chain.CurrentBlock() + if cblock != nil { + last = int64(cblock.NumberU64()) + } + first := int64(0) if last > gpoProcessPastBlocks { first = last - gpoProcessPastBlocks } - self.firstProcessed = first + self.firstProcessed = uint64(first) for i := first; i <= last; i++ { - self.processBlock(self.chain.GetBlockByNumber(i)) + block := self.chain.GetBlockByNumber(uint64(i)) + if block != nil { + self.processBlock(block) + } } } -- cgit v1.2.3