26 SealEngineRegistrar* SealEngineRegistrar::s_this =
nullptr;
35 SealEngineFace::populateFromParent(_bi, _parent);
47 if (m_onSealGenerated)
48 m_onSealGenerated(ret.
out());
60 if (difficulty != expected)
67 _bi.
verify(_s, _parent, _block);
71 if (_bi.
difficulty() < chainParams().minimumDifficulty)
72 BOOST_THROW_EXCEPTION(
76 if (_bi.
gasLimit() < chainParams().minGasLimit)
80 if (_bi.
gasLimit() > chainParams().maxGasLimit)
84 if (_bi.
number() && _bi.
extraData().size() > chainParams().maximumExtraDataSize)
86 BOOST_THROW_EXCEPTION(
93 u256 const& daoHardfork = chainParams().daoHardforkBlock;
94 if (daoHardfork != 0 && daoHardfork + 9 >= daoHardfork && _bi.
number() >= daoHardfork &&
95 _bi.
number() <= daoHardfork + 9)
97 BOOST_THROW_EXCEPTION(
99 <<
errinfo_comment(
"Received block from the wrong fork (invalid extradata)."));
105 auto parentGasLimit = _parent.
gasLimit();
106 if (gasLimit < chainParams().minGasLimit || gasLimit > chainParams().maxGasLimit ||
107 gasLimit <= parentGasLimit - parentGasLimit / chainParams().gasLimitBoundDivisor ||
108 gasLimit >= parentGasLimit + parentGasLimit / chainParams().gasLimitBoundDivisor)
109 BOOST_THROW_EXCEPTION(
113 (
bigint)(parentGasLimit / chainParams().gasLimitBoundDivisor)))
116 parentGasLimit / chainParams().gasLimitBoundDivisor)));
128 if ((_ir & ImportRequirements::TransactionSignatures) && _header.
number() < chainParams().EIP158ForkBlock && _t.
isReplayProtected())
131 if ((_ir & ImportRequirements::TransactionSignatures) &&
135 if ((_ir & ImportRequirements::TransactionBasic) &&
140 if (_header.
number() >= chainParams().homesteadForkBlock && (_ir & ImportRequirements::TransactionSignatures) && _t.
hasSignature())
146 if ((_ir & ImportRequirements::TransactionBasic) && _t.
baseGasRequired(schedule) > _t.
gas())
154 string(
"_gasUsed + (bigint)_t.gas() > _header.gasLimit()")));
160 assert(ret &&
"Seal engine not found.");
168 return chainParams().scheduleForBlockNumber(_blockNumber);
171 u256 SealEngineBase::blockReward(
u256 const& _blockNumber)
const 173 EVMSchedule const& schedule{evmSchedule(_blockNumber)};
174 return chainParams().blockReward(schedule);
180 const unsigned c_expDiffPeriod = 100000;
183 throw GenesisBlockCannotBeCalculated();
199 max<bigint>(1 - timestampDiff / 10, -99) :
200 max<bigint>((_parent.
hasUncles() ? 2 : 1) - timestampDiff / 9,
207 unsigned exponentialIceAgeBlockNumber = unsigned(_parent.
number() + 1);
212 if (exponentialIceAgeBlockNumber >= 5000000)
213 exponentialIceAgeBlockNumber -= 5000000;
215 exponentialIceAgeBlockNumber = 0;
220 if (exponentialIceAgeBlockNumber >= 3000000)
221 exponentialIceAgeBlockNumber -= 3000000;
223 exponentialIceAgeBlockNumber = 0;
226 unsigned periodCount = exponentialIceAgeBlockNumber / c_expDiffPeriod;
228 o += (
bigint(1) << (periodCount - 2));
231 o = max<bigint>(minimumDifficulty, o);
232 return u256(min<bigint>(o, std::numeric_limits<u256>::max()));
238 u256 gasFloorTarget = _gasFloorTarget ==
Invalid256 ? 3141562 : _gasFloorTarget;
241 if (gasLimit < gasFloorTarget)
242 return min<u256>(gasFloorTarget, gasLimit + gasLimit / boundDivisor - 1);
244 return max<u256>(gasFloorTarget,
245 gasLimit - gasLimit / boundDivisor + 1 + (_bi.
gasUsed() * 6 / 5) / boundDivisor);
Too little gas to pay for the base transaction cost.
u256 calculateEthashDifficulty(ChainOperationParams const &_chainParams, BlockHeader const &_bi, BlockHeader const &_parent)
u256 constantinopleForkBlock
bool verify(Public const &_k, Signature const &_s, h256 const &_hash)
Verify signature.
bool hasZeroSignature() const
boost::error_info< struct tag_min, bigint > errinfo_min
boost::error_info< struct tag_max, bigint > errinfo_max
bool isReplayProtected() const
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<> > bigint
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
u256 constexpr Invalid256
boost::error_info< struct tag_got, bigint > errinfo_got
bool hasSignature() const
boost::error_info< struct tag_extraData, bytes > errinfo_extraData
u256 calculateGasLimit(ChainOperationParams const &_chainParams, BlockHeader const &_bi, u256 const &_gasFloorTarget)
bytes const & out() const
Read the byte stream.
boost::tuple< errinfo_required, errinfo_got, errinfo_comment > RequirementErrorComment
u256 gasLimitBoundDivisor
u256 difficultyBoundDivisor
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
std::string sealEngineName
The chain sealer name: e.g. Ethash, NoProof, BasicAuthority.
boost::error_info< struct tag_comment, std::string > errinfo_comment
void setChainParams(ChainOperationParams const &_params)
boost::tuple< errinfo_required, errinfo_got > RequirementError
Class for writing to an RLP bytestream.
int64_t baseGasRequired(EVMSchedule const &_es) const
Encodes a transaction, ready to be exported to or freshly imported from RLP.
#define ETH_REGISTER_SEAL_ENGINE(Name)