40 map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers;
42 m_farm.setSealers(sealers);
46 setMixHash(m_sealing, sol.
mixHash);
47 setNonce(m_sealing, sol.
nonce);
48 if (!quickVerifySeal(m_sealing))
51 if (m_onSealGenerated)
54 m_sealing.streamRLP(ret);
55 m_onSealGenerated(ret.
out());
68 return EthashAux::seedHash((
unsigned)_bi.
number());
73 return { {
"nonce",
toJS(nonce(_bi)) }, {
"seedHash",
toJS(seedHash(_bi)) }, {
"mixHash",
toJS(mixHash(_bi)) }, {
"boundary",
toJS(boundary(_bi)) }, {
"difficulty",
toJS(_bi.
difficulty()) } };
82 if (_bi.
difficulty() < chainParams().u256Param(
"minimumDifficulty"))
85 if (_bi.
gasLimit() < chainParams().u256Param(
"minGasLimit"))
88 if (_bi.
gasLimit() > chainParams().u256Param(
"maxGasLimit"))
91 if (_bi.
number() && _bi.
extraData().size() > chainParams().maximumExtraDataSize)
94 u256 daoHardfork = chainParams().u256Param(
"daoHardforkBlock");
95 if (daoHardfork != 0 && daoHardfork + 9 >= daoHardfork && _bi.
number() >= daoHardfork && _bi.
number() <= daoHardfork + 9)
97 BOOST_THROW_EXCEPTION(ExtraDataIncorrect() <<
errinfo_comment(
"Received block from the wrong fork (invalid extradata)."));
103 auto expected = calculateDifficulty(_bi, _parent);
105 if (difficulty != expected)
109 auto parentGasLimit = _parent.
gasLimit();
111 gasLimit < chainParams().u256Param(
"minGasLimit") ||
112 gasLimit > chainParams().u256Param(
"maxGasLimit") ||
113 gasLimit <= parentGasLimit - parentGasLimit / chainParams().u256Param(
"gasLimitBoundDivisor") ||
114 gasLimit >= parentGasLimit + parentGasLimit / chainParams().u256Param(
"gasLimitBoundDivisor"))
115 BOOST_THROW_EXCEPTION(
119 <<
errinfo_max((
bigint)((
bigint)parentGasLimit + parentGasLimit / chainParams().u256Param(
"gasLimitBoundDivisor")))
126 InvalidBlockNonce ex;
135 BOOST_THROW_EXCEPTION(ex);
139 InvalidBlockNonce ex;
143 BOOST_THROW_EXCEPTION(ex);
149 if (_ir & ImportRequirements::TransactionSignatures)
151 if (_bi.
number() >= chainParams().u256Param(
"homsteadForkBlock"))
153 if (_bi.
number() >= chainParams().u256Param(
"EIP158ForkBlock"))
155 int chainID(chainParams().u256Param(
"chainID"));
168 u256 gasFloorTarget = _gasFloorTarget ==
Invalid256 ? 3141562 : _gasFloorTarget;
170 u256 boundDivisor = chainParams().u256Param(
"gasLimitBoundDivisor");
171 if (gasLimit < gasFloorTarget)
172 return min<u256>(gasFloorTarget, gasLimit + gasLimit / boundDivisor - 1);
174 return max<u256>(gasFloorTarget, gasLimit - gasLimit / boundDivisor + 1 + (_bi.
gasUsed() * 6 / 5) / boundDivisor);
177 void Ethash::manuallySubmitWork(
const h256& _mixHash,
Nonce _nonce)
184 const unsigned c_expDiffPeriod = 100000;
187 throw GenesisBlockCannotBeCalculated();
188 auto minimumDifficulty = chainParams().u256Param(
"minimumDifficulty");
189 auto difficultyBoundDivisor = chainParams().u256Param(
"difficultyBoundDivisor");
190 auto durationLimit = chainParams().u256Param(
"durationLimit");
193 if (_bi.
number() < chainParams().u256Param(
"homsteadForkBlock"))
201 unsigned periodCount = unsigned(_parent.
number() + 1) / c_expDiffPeriod;
203 o += (
bigint(1) << (periodCount - 2));
205 o = max<bigint>(minimumDifficulty, o);
211 SealEngineFace::populateFromParent(_bi, _parent);
222 auto m = mixHash(_bi);
224 auto b = boundary(_bi);
235 bool pre = quickVerifySeal(_bi);
239 cwarn <<
"Fail on preVerify";
244 auto result = EthashAux::eval(seedHash(_bi), _bi.
hash(
WithoutSeal), nonce(_bi));
245 bool slow = result.value <= boundary(_bi) && result.mixHash == mixHash(_bi);
250 cwarn <<
"WARNING: evaluated result gives true whereas ethash_quick_check_difficulty gives false.";
252 cwarn <<
"nonce:" << nonce(_bi);
253 cwarn <<
"mixHash:" << mixHash(_bi);
255 cwarn <<
"boundary:" << boundary(_bi);
256 cwarn <<
"result.value:" << result.value;
257 cwarn <<
"result.mixHash:" << result.mixHash;
267 m_farm.setWork(m_sealing);
268 m_farm.start(m_sealer);
269 m_farm.setWork(m_sealing);
270 bytes shouldPrecompute = option(
"precomputeDAG");
271 if (!shouldPrecompute.empty() && shouldPrecompute[0] == 1)
272 ensurePrecomputed((
unsigned)_bi.
number());
280 void Ethash::ensurePrecomputed(
unsigned _number)
Too little gas to pay for the base transaction cost.
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
bool ethash_quick_check_difficulty(ethash_h256_t const *header_hash, uint64_t const nonce, ethash_h256_t const *mix_hash, ethash_h256_t const *boundary)
Difficulty quick check for POW preverification.
bytes const & out() const
Read the byte stream.
bool verify(Public const &_k, Signature const &_s, h256 const &_hash)
Verify signature.
std::vector< std::string > strings
std::hash for asio::adress
boost::error_info< struct tag_min, bigint > errinfo_min
boost::error_info< struct tag_max, bigint > errinfo_max
int64_t baseGasRequired(EVMSchedule const &_es) const
#define ETHASH_EPOCH_LENGTH
boost::error_info< struct tag_mixHash, h256 > errinfo_mixHash
boost::error_info< struct tag_hash, h256 > errinfo_hash256
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
boost::error_info< struct tag_ethashResult, std::tuple< h256, h256 >> errinfo_ethashResult
std::string toJS(FixedHash< S > const &_h)
boost::error_info< struct tag_got, bigint > errinfo_got
std::vector< byte > bytes
boost::error_info< struct tag_target, h256 > errinfo_target
boost::error_info< struct tag_extraData, bytes > errinfo_extraData
void checkChainId(int chainId=-4) const
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
std::unordered_map< std::string, std::string > StringHashMap
Main API hub for interfacing with Ethereum.
boost::error_info< struct tag_difficulty, u256 > errinfo_difficulty
Type of a seedhash/blockhash e.t.c.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u64
boost::error_info< struct tag_seedHash, h256 > errinfo_seedHash
boost::error_info< struct tag_comment, std::string > errinfo_comment
A miner - a member and adoptee of the Farm.
boost::tuple< errinfo_required, errinfo_got > RequirementError
Class for writing to an RLP bytestream.
Encodes a transaction, ready to be exported to or freshly imported from RLP.
#define ETH_REGISTER_SEAL_ENGINE(Name)
boost::error_info< struct tag_nonce, h64 > errinfo_nonce