Browse Source

Minor updates to gas limit floor machanism.

cl-refactor
Gav Wood 10 years ago
parent
commit
756ca99f6d
  1. 5
      eth/main.cpp
  2. 14
      libethcore/BlockInfo.cpp
  3. 3
      libethcore/BlockInfo.h
  4. 3
      libethcore/Params.cpp
  5. 1
      libethcore/Params.h

5
eth/main.cpp

@ -1105,6 +1105,7 @@ int main(int argc, char** argv)
string jsonAdmin; string jsonAdmin;
string genesisJSON; string genesisJSON;
dev::eth::Network releaseNetwork = c_network; dev::eth::Network releaseNetwork = c_network;
u256 gasFloor = UndefinedU256;
string privateChain; string privateChain;
bool upnp = true; bool upnp = true;
@ -1347,6 +1348,8 @@ int main(int argc, char** argv)
} }
else if (arg == "--frontier") else if (arg == "--frontier")
releaseNetwork = eth::Network::Frontier; releaseNetwork = eth::Network::Frontier;
else if (arg == "--gas-floor" && i + 1 < argc)
gasFloor = u256(argv[++i]);
else if (arg == "--olympic") else if (arg == "--olympic")
releaseNetwork = eth::Network::Olympic; releaseNetwork = eth::Network::Olympic;
/* else if ((arg == "-B" || arg == "--block-fees") && i + 1 < argc) /* else if ((arg == "-B" || arg == "--block-fees") && i + 1 < argc)
@ -1514,6 +1517,8 @@ int main(int argc, char** argv)
CanonBlockChain<Ethash>::forceGenesisExtraData(sha3(privateChain).asBytes()); CanonBlockChain<Ethash>::forceGenesisExtraData(sha3(privateChain).asBytes());
if (!genesisJSON.empty()) if (!genesisJSON.empty())
CanonBlockChain<Ethash>::setGenesis(genesisJSON); CanonBlockChain<Ethash>::setGenesis(genesisJSON);
if (gasFloor != UndefinedU256)
c_gasFloorTarget = gasFloor;
if (g_logVerbosity > 0) if (g_logVerbosity > 0)
{ {

14
libethcore/BlockInfo.cpp

@ -184,23 +184,23 @@ void BlockInfo::populateFromParent(BlockInfo const& _parent)
m_stateRoot = _parent.stateRoot(); m_stateRoot = _parent.stateRoot();
m_number = _parent.m_number + 1; m_number = _parent.m_number + 1;
m_parentHash = _parent.m_hash; m_parentHash = _parent.m_hash;
m_gasLimit = selectGasLimit(_parent); m_gasLimit = _parent.childGasLimit();
m_gasUsed = 0; m_gasUsed = 0;
m_difficulty = calculateDifficulty(_parent); 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) if (!m_number)
throw GenesisBlockCannotBeCalculated(); throw GenesisBlockCannotBeCalculated();
else else
// target minimum of 3141592 if (m_gasLimit < gasFloorTarget)
if (_parent.m_gasLimit < c_gasFloorTarget) return min<u256>(gasFloorTarget, m_gasLimit + m_gasLimit / c_gasLimitBoundDivisor - 1);
return min<u256>(c_gasFloorTarget, _parent.m_gasLimit + _parent.m_gasLimit / c_gasLimitBoundDivisor - 1);
else else
return max<u256>(c_gasFloorTarget, _parent.m_gasLimit - _parent.m_gasLimit / c_gasLimitBoundDivisor + 1 + (_parent.m_gasUsed * 6 / 5) / c_gasLimitBoundDivisor); return max<u256>(gasFloorTarget, m_gasLimit - m_gasLimit / c_gasLimitBoundDivisor + 1 + (m_gasUsed * 6 / 5) / c_gasLimitBoundDivisor);
} }
u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const

3
libethcore/BlockInfo.h

@ -115,7 +115,7 @@ public:
void populateFromParent(BlockInfo const& parent); void populateFromParent(BlockInfo const& parent);
u256 calculateDifficulty(BlockInfo const& _parent) const; 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& boundary() const;
h256 const& parentHash() const { return m_parentHash; } h256 const& parentHash() const { return m_parentHash; }
@ -127,6 +127,7 @@ public:
void setCoinbaseAddress(Address const& _v) { m_coinbaseAddress = _v; noteDirty(); } 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 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 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 setExtraData(bytes const& _v) { m_extraData = _v; noteDirty(); }
void setLogBloom(LogBloom const& _v) { m_logBloom = _v; noteDirty(); } void setLogBloom(LogBloom const& _v) { m_logBloom = _v; noteDirty(); }
void setDifficulty(u256 const& _v) { m_difficulty = _v; noteDirty(); } void setDifficulty(u256 const& _v) { m_difficulty = _v; noteDirty(); }

3
libethcore/Params.cpp

@ -36,6 +36,7 @@ u256 c_minimumDifficulty;
u256 c_difficultyBoundDivisor; u256 c_difficultyBoundDivisor;
u256 c_durationLimit; u256 c_durationLimit;
u256 c_blockReward; u256 c_blockReward;
u256 c_gasFloorTarget;
//--- END: AUTOGENERATED FROM /feeStructure.json //--- END: AUTOGENERATED FROM /feeStructure.json
#if ETH_FRONTIER #if ETH_FRONTIER
@ -60,7 +61,7 @@ Network resetNetwork(Network _n)
c_minGasLimit = 5000; c_minGasLimit = 5000;
break; break;
} }
c_gasFloorTarget = c_network == Network::Frontier ? 5000 : 3141592;
c_gasLimitBoundDivisor = 1024; c_gasLimitBoundDivisor = 1024;
c_minimumDifficulty = 131072; c_minimumDifficulty = 131072;
c_difficultyBoundDivisor = 2048; c_difficultyBoundDivisor = 2048;

1
libethcore/Params.h

@ -36,6 +36,7 @@ extern u256 c_difficultyBoundDivisor;
extern u256 c_durationLimit; extern u256 c_durationLimit;
extern u256 c_maximumExtraDataSize; extern u256 c_maximumExtraDataSize;
extern u256 c_blockReward; extern u256 c_blockReward;
extern u256 c_gasFloorTarget;
//--- END: AUTOGENERATED FROM /feeStructure.json //--- END: AUTOGENERATED FROM /feeStructure.json
} }

Loading…
Cancel
Save