Browse Source

Difficulty adjustment.

cl-refactor
Gav Wood 10 years ago
parent
commit
b559aff4cc
  1. 8
      libethcore/BlockInfo.cpp

8
libethcore/BlockInfo.cpp

@ -202,10 +202,14 @@ u256 BlockInfo::childGasLimit(u256 const& _gasFloorTarget) const
u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const
{
const unsigned c_expDiffPeriod = 100000;
if (!m_number)
throw GenesisBlockCannotBeCalculated();
else
return max<u256>(c_minimumDifficulty, m_timestamp >= _parent.m_timestamp + c_durationLimit ? _parent.m_difficulty - (_parent.m_difficulty / c_difficultyBoundDivisor) : (_parent.m_difficulty + (_parent.m_difficulty / c_difficultyBoundDivisor)));
u256 o = max<u256>(c_minimumDifficulty, m_timestamp >= _parent.m_timestamp + c_durationLimit ? _parent.m_difficulty - (_parent.m_difficulty / c_difficultyBoundDivisor) : (_parent.m_difficulty + (_parent.m_difficulty / c_difficultyBoundDivisor)));
if (unsigned periodCount = unsigned(_parent.number() + 1) / c_expDiffPeriod)
o = (u256)max<bigint>(c_minimumDifficulty, bigint(o) - (bigint(1) << (periodCount - 1))); // latter will eventually become negative, so ensure it's a bigint.
return o;
}
void BlockInfo::verifyParent(BlockInfo const& _parent) const

Loading…
Cancel
Save