diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-08-17 21:37:58 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-08-17 21:37:58 +0800 |
commit | 2497f28aa9d74f84468055fbc4675f379b7e4a5a (patch) | |
tree | 69831e75cfab05b57d805b6c619d386e62c186e3 /eth | |
parent | ff1f6fa09dd24610cb1982a49953fa1cd06696d9 (diff) | |
parent | 49ece3155c998bd877cf96d1b6826c0c5f293a63 (diff) | |
download | dexon-2497f28aa9d74f84468055fbc4675f379b7e4a5a.tar.gz dexon-2497f28aa9d74f84468055fbc4675f379b7e4a5a.tar.zst dexon-2497f28aa9d74f84468055fbc4675f379b7e4a5a.zip |
Merge pull request #1627 from zsfelfoldi/gpo
GPO update
Diffstat (limited to 'eth')
-rw-r--r-- | eth/gasprice.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/eth/gasprice.go b/eth/gasprice.go index 031098e9a..3caad73c6 100644 --- a/eth/gasprice.go +++ b/eth/gasprice.go @@ -37,12 +37,11 @@ type blockPriceInfo struct { 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 + lastBase, minBase *big.Int } func NewGasPriceOracle(eth *Ethereum) (self *GasPriceOracle) { @@ -50,13 +49,15 @@ func NewGasPriceOracle(eth *Ethereum) (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{}, ) + + minbase := new(big.Int).Mul(self.eth.GpoMinGasPrice, big.NewInt(100)) + minbase = minbase.Div(minbase, big.NewInt(int64(self.eth.GpobaseCorrectionFactor))) + self.minBase = minbase + self.processPastBlocks() go self.listenLoop() return @@ -93,8 +94,6 @@ func (self *GasPriceOracle) listenLoop() { self.processBlock(ev.Block) case core.ChainSplitEvent: self.processBlock(ev.Block) - case core.TxPreEvent: - case core.TxPostEvent: } } self.events.Unsubscribe() @@ -131,6 +130,10 @@ func (self *GasPriceOracle) processBlock(block *types.Block) { newBase := new(big.Int).Mul(lastBase, big.NewInt(1000000+crand)) newBase.Div(newBase, big.NewInt(1000000)) + if newBase.Cmp(self.minBase) < 0 { + newBase = self.minBase + } + bpi := self.blocks[i] if bpi == nil { bpi = &blockPriceInfo{} @@ -146,7 +149,7 @@ func (self *GasPriceOracle) processBlock(block *types.Block) { // 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) + gasUsed := big.NewInt(0) receipts := self.eth.BlockProcessor().GetBlockReceipts(block.Hash()) if len(receipts) > 0 { @@ -158,12 +161,12 @@ func (self *GasPriceOracle) lowestPrice(block *types.Block) *big.Int { 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 + return big.NewInt(0) } txs := block.Transactions() if len(txs) == 0 { - return self.eth.GpoMinGasPrice + return big.NewInt(0) } // block is full, find smallest gasPrice minPrice := txs[0].GasPrice() |