From 756ca99f6d1fca9eff7667fb5aa61072dd762ca2 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 28 Jul 2015 21:54:53 +0200 Subject: [PATCH] Minor updates to gas limit floor machanism. --- eth/main.cpp | 5 +++++ libethcore/BlockInfo.cpp | 14 +++++++------- libethcore/BlockInfo.h | 3 ++- libethcore/Params.cpp | 3 ++- libethcore/Params.h | 1 + 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index 8528b0526..e17a6ebaf 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -1105,6 +1105,7 @@ int main(int argc, char** argv) string jsonAdmin; string genesisJSON; dev::eth::Network releaseNetwork = c_network; + u256 gasFloor = UndefinedU256; string privateChain; bool upnp = true; @@ -1347,6 +1348,8 @@ int main(int argc, char** argv) } else if (arg == "--frontier") releaseNetwork = eth::Network::Frontier; + else if (arg == "--gas-floor" && i + 1 < argc) + gasFloor = u256(argv[++i]); else if (arg == "--olympic") releaseNetwork = eth::Network::Olympic; /* else if ((arg == "-B" || arg == "--block-fees") && i + 1 < argc) @@ -1514,6 +1517,8 @@ int main(int argc, char** argv) CanonBlockChain::forceGenesisExtraData(sha3(privateChain).asBytes()); if (!genesisJSON.empty()) CanonBlockChain::setGenesis(genesisJSON); + if (gasFloor != UndefinedU256) + c_gasFloorTarget = gasFloor; if (g_logVerbosity > 0) { diff --git a/libethcore/BlockInfo.cpp b/libethcore/BlockInfo.cpp index 4729ff25e..0b1cdd622 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -184,23 +184,23 @@ void BlockInfo::populateFromParent(BlockInfo const& _parent) m_stateRoot = _parent.stateRoot(); m_number = _parent.m_number + 1; m_parentHash = _parent.m_hash; - m_gasLimit = selectGasLimit(_parent); + m_gasLimit = _parent.childGasLimit(); m_gasUsed = 0; m_difficulty = calculateDifficulty(_parent); } -u256 BlockInfo::selectGasLimit(BlockInfo const& _parent) const +u256 BlockInfo::childGasLimit(u256 const& _gasFloorTarget) const { - u256 const c_gasFloorTarget = c_network == Network::Frontier ? 5000 : 3141592; + u256 gasFloorTarget = + _gasFloorTarget == UndefinedU256 ? c_gasFloorTarget : _gasFloorTarget; if (!m_number) throw GenesisBlockCannotBeCalculated(); else - // target minimum of 3141592 - if (_parent.m_gasLimit < c_gasFloorTarget) - return min(c_gasFloorTarget, _parent.m_gasLimit + _parent.m_gasLimit / c_gasLimitBoundDivisor - 1); + if (m_gasLimit < gasFloorTarget) + return min(gasFloorTarget, m_gasLimit + m_gasLimit / c_gasLimitBoundDivisor - 1); else - return max(c_gasFloorTarget, _parent.m_gasLimit - _parent.m_gasLimit / c_gasLimitBoundDivisor + 1 + (_parent.m_gasUsed * 6 / 5) / c_gasLimitBoundDivisor); + return max(gasFloorTarget, m_gasLimit - m_gasLimit / c_gasLimitBoundDivisor + 1 + (m_gasUsed * 6 / 5) / c_gasLimitBoundDivisor); } u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const diff --git a/libethcore/BlockInfo.h b/libethcore/BlockInfo.h index 8474284a3..c6812a112 100644 --- a/libethcore/BlockInfo.h +++ b/libethcore/BlockInfo.h @@ -115,7 +115,7 @@ public: void populateFromParent(BlockInfo const& parent); u256 calculateDifficulty(BlockInfo const& _parent) const; - u256 selectGasLimit(BlockInfo const& _parent) const; + u256 childGasLimit(u256 const& _gasFloorTarget = UndefinedU256) const; h256 const& boundary() const; h256 const& parentHash() const { return m_parentHash; } @@ -127,6 +127,7 @@ public: void setCoinbaseAddress(Address const& _v) { m_coinbaseAddress = _v; noteDirty(); } void setRoots(h256 const& _t, h256 const& _r, h256 const& _u, h256 const& _s) { m_transactionsRoot = _t; m_receiptsRoot = _r; m_stateRoot = _s; m_sha3Uncles = _u; noteDirty(); } void setGasUsed(u256 const& _v) { m_gasUsed = _v; noteDirty(); } + void setGasLimit(u256 const& _v) { m_gasLimit = _v; noteDirty(); } void setExtraData(bytes const& _v) { m_extraData = _v; noteDirty(); } void setLogBloom(LogBloom const& _v) { m_logBloom = _v; noteDirty(); } void setDifficulty(u256 const& _v) { m_difficulty = _v; noteDirty(); } diff --git a/libethcore/Params.cpp b/libethcore/Params.cpp index 0612db84e..fbf0f6d9e 100644 --- a/libethcore/Params.cpp +++ b/libethcore/Params.cpp @@ -36,6 +36,7 @@ u256 c_minimumDifficulty; u256 c_difficultyBoundDivisor; u256 c_durationLimit; u256 c_blockReward; +u256 c_gasFloorTarget; //--- END: AUTOGENERATED FROM /feeStructure.json #if ETH_FRONTIER @@ -60,7 +61,7 @@ Network resetNetwork(Network _n) c_minGasLimit = 5000; break; } - + c_gasFloorTarget = c_network == Network::Frontier ? 5000 : 3141592; c_gasLimitBoundDivisor = 1024; c_minimumDifficulty = 131072; c_difficultyBoundDivisor = 2048; diff --git a/libethcore/Params.h b/libethcore/Params.h index 6736d4f86..69469612b 100644 --- a/libethcore/Params.h +++ b/libethcore/Params.h @@ -36,6 +36,7 @@ extern u256 c_difficultyBoundDivisor; extern u256 c_durationLimit; extern u256 c_maximumExtraDataSize; extern u256 c_blockReward; +extern u256 c_gasFloorTarget; //--- END: AUTOGENERATED FROM /feeStructure.json }