diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-06-30 06:44:23 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-06-30 06:44:23 +0800 |
commit | 7c4ed8055cc036214279e3ebded74c58d6808d05 (patch) | |
tree | b35a10b7a41c5e1f03300c7afb51f8a76202dbf8 /eth/gasprice.go | |
parent | 9d8b512b27f691fc1980b850e04eb436a3938626 (diff) | |
parent | 992e4f83cb05946fa53132a9184d4ac3f38b62bc (diff) | |
download | go-tangerine-7c4ed8055cc036214279e3ebded74c58d6808d05.tar go-tangerine-7c4ed8055cc036214279e3ebded74c58d6808d05.tar.gz go-tangerine-7c4ed8055cc036214279e3ebded74c58d6808d05.tar.bz2 go-tangerine-7c4ed8055cc036214279e3ebded74c58d6808d05.tar.lz go-tangerine-7c4ed8055cc036214279e3ebded74c58d6808d05.tar.xz go-tangerine-7c4ed8055cc036214279e3ebded74c58d6808d05.tar.zst go-tangerine-7c4ed8055cc036214279e3ebded74c58d6808d05.zip |
Merge pull request #1357 from obscuren/core-optimisations-2
core: optimisations
Diffstat (limited to 'eth/gasprice.go')
-rw-r--r-- | eth/gasprice.go | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/eth/gasprice.go b/eth/gasprice.go index cd5293691..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) + } } } @@ -133,20 +140,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 } |