|
|
@ -63,24 +63,47 @@ ethash_params EthashAux::params(unsigned _n) |
|
|
|
return p; |
|
|
|
} |
|
|
|
|
|
|
|
h256 EthashAux::seedHash(unsigned _number) |
|
|
|
{ |
|
|
|
unsigned epoch = _number / ETHASH_EPOCH_LENGTH; |
|
|
|
RecursiveGuard l(get()->x_this); |
|
|
|
if (_number < get()->m_seedHashes.size()) |
|
|
|
return get()->m_seedHashes[_number]; |
|
|
|
h256 ret; |
|
|
|
unsigned n = 0; |
|
|
|
if (!get()->m_seedHashes.empty()) |
|
|
|
{ |
|
|
|
ret = get()->m_seedHashes.back(); |
|
|
|
n = get()->m_seedHashes.size() - 1; |
|
|
|
} |
|
|
|
cdebug << "Searching for seedHash of epoch " << epoch; |
|
|
|
for (; n < epoch; ++n, ret = sha3(ret)) |
|
|
|
cdebug << "Epoch" << n << "is" << ret.abridged(); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
ethash_params EthashAux::params(h256 const& _seedHash) |
|
|
|
{ |
|
|
|
RecursiveGuard l(get()->x_this); |
|
|
|
unsigned epoch = 0; |
|
|
|
try |
|
|
|
{ |
|
|
|
epoch = get()->m_seedHashes.at(_seedHash); |
|
|
|
epoch = get()->m_epochs.at(_seedHash); |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
{ |
|
|
|
for (h256 h; h != _seedHash && epoch < 2048; ++epoch, h = h256(h)) {} |
|
|
|
cdebug << "Searching for seedHash " << _seedHash.abridged(); |
|
|
|
for (h256 h; h != _seedHash && epoch < 2048; ++epoch, h = sha3(h)) |
|
|
|
{ |
|
|
|
cdebug << "Epoch" << epoch << "is" << h.abridged(); |
|
|
|
} |
|
|
|
if (epoch == 2048) |
|
|
|
{ |
|
|
|
std::ostringstream error; |
|
|
|
error << "apparent block number for " << _seedHash.abridged() << " is too high; max is " << (ETHASH_EPOCH_LENGTH * 2048); |
|
|
|
throw std::invalid_argument(error.str()); |
|
|
|
} |
|
|
|
get()->m_seedHashes[_seedHash] = epoch; |
|
|
|
get()->m_epochs[_seedHash] = epoch; |
|
|
|
} |
|
|
|
return params(epoch * ETHASH_EPOCH_LENGTH); |
|
|
|
} |
|
|
|