mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-09 04:09:29 +00:00
Fixed submit_block
This commit is contained in:
parent
47f551c046
commit
850eb8e6e0
3 changed files with 29 additions and 16 deletions
|
@ -1210,23 +1210,27 @@ uint32_t BlockTemplate::get_hashing_blobs(uint32_t extra_nonce_start, uint32_t c
|
|||
return blob_size;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> BlockTemplate::get_block_template_blob(uint32_t template_id, size_t& nonce_offset, size_t& extra_nonce_offset) const
|
||||
std::vector<uint8_t> BlockTemplate::get_block_template_blob(uint32_t template_id, uint32_t sidechain_extra_nonce, size_t& nonce_offset, size_t& extra_nonce_offset, size_t& sidechain_id_offset, hash& sidechain_id) const
|
||||
{
|
||||
ReadLock lock(m_lock);
|
||||
|
||||
if (template_id != m_templateId) {
|
||||
const BlockTemplate* old = m_oldTemplates[template_id % array_size(&BlockTemplate::m_oldTemplates)];
|
||||
if (old && (template_id == old->m_templateId)) {
|
||||
return old->get_block_template_blob(template_id, nonce_offset, extra_nonce_offset);
|
||||
return old->get_block_template_blob(template_id, sidechain_extra_nonce, nonce_offset, extra_nonce_offset, sidechain_id_offset, sidechain_id);
|
||||
}
|
||||
|
||||
nonce_offset = 0;
|
||||
extra_nonce_offset = 0;
|
||||
sidechain_id_offset = 0;
|
||||
sidechain_id = {};
|
||||
return std::vector<uint8_t>();
|
||||
}
|
||||
|
||||
nonce_offset = m_nonceOffset;
|
||||
extra_nonce_offset = m_extraNonceOffsetInTemplate;
|
||||
sidechain_id_offset = m_extraNonceOffsetInTemplate + m_poolBlockTemplate->m_extraNonceSize + 2;
|
||||
sidechain_id = calc_sidechain_hash(sidechain_extra_nonce);
|
||||
return m_blockTemplateBlob;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
uint32_t get_hashing_blob(uint32_t extra_nonce, uint8_t (&blob)[128], uint64_t& height, uint64_t& sidechain_height, difficulty_type& difficulty, difficulty_type& sidechain_difficulty, hash& seed_hash, size_t& nonce_offset, uint32_t& template_id) const;
|
||||
uint32_t get_hashing_blobs(uint32_t extra_nonce_start, uint32_t count, std::vector<uint8_t>& blobs, uint64_t& height, difficulty_type& difficulty, difficulty_type& sidechain_difficulty, hash& seed_hash, size_t& nonce_offset, uint32_t& template_id) const;
|
||||
|
||||
std::vector<uint8_t> get_block_template_blob(uint32_t template_id, size_t& nonce_offset, size_t& extra_nonce_offset) const;
|
||||
std::vector<uint8_t> get_block_template_blob(uint32_t template_id, uint32_t sidechain_extra_nonce, size_t& nonce_offset, size_t& extra_nonce_offset, size_t& sidechain_id_offset, hash& sidechain_id) const;
|
||||
|
||||
FORCEINLINE uint64_t height() const { return m_height; }
|
||||
FORCEINLINE difficulty_type difficulty() const { return m_difficulty; }
|
||||
|
|
|
@ -517,19 +517,26 @@ void p2pool::submit_block() const
|
|||
|
||||
size_t nonce_offset = 0;
|
||||
size_t extra_nonce_offset = 0;
|
||||
size_t sidechain_id_offset = 0;
|
||||
hash sidechain_id;
|
||||
bool is_external = false;
|
||||
|
||||
if (submit_data.blob.empty()) {
|
||||
LOGINFO(0, "submit_block: height = " << height << ", template id = " << submit_data.template_id << ", nonce = " << submit_data.nonce << ", extra_nonce = " << submit_data.extra_nonce);
|
||||
submit_data.blob = m_blockTemplate->get_block_template_blob(submit_data.template_id, submit_data.extra_nonce, nonce_offset, extra_nonce_offset, sidechain_id_offset, sidechain_id);
|
||||
|
||||
LOGINFO(0, log::LightGreen() << "submit_block: height = " << height
|
||||
<< ", template id = " << submit_data.template_id
|
||||
<< ", nonce = " << submit_data.nonce
|
||||
<< ", extra_nonce = " << submit_data.extra_nonce
|
||||
<< ", id = " << sidechain_id);
|
||||
|
||||
submit_data.blob = m_blockTemplate->get_block_template_blob(submit_data.template_id, nonce_offset, extra_nonce_offset);
|
||||
if (submit_data.blob.empty()) {
|
||||
LOGERR(0, "submit_block: couldn't find block template with id " << submit_data.template_id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOGINFO(0, "submit_block: height = " << height << ", external blob (" << submit_data.blob.size() << " bytes)");
|
||||
LOGINFO(0, log::LightGreen() << "submit_block: height = " << height << ", external blob (" << submit_data.blob.size() << " bytes)");
|
||||
is_external = true;
|
||||
}
|
||||
|
||||
|
@ -543,26 +550,28 @@ void p2pool::submit_block() const
|
|||
const uint32_t extra_nonce = submit_data.extra_nonce;
|
||||
|
||||
for (size_t i = 0; i < submit_data.blob.size(); ++i) {
|
||||
char buf[16];
|
||||
|
||||
uint8_t b;
|
||||
if (nonce_offset && nonce_offset <= i && i < nonce_offset + sizeof(submit_data.nonce)) {
|
||||
snprintf(buf, sizeof(buf), "%02x", submit_data.nonce & 255);
|
||||
b = submit_data.nonce & 255;
|
||||
submit_data.nonce >>= 8;
|
||||
}
|
||||
else if (extra_nonce_offset && extra_nonce_offset <= i && i < extra_nonce_offset + sizeof(submit_data.extra_nonce)) {
|
||||
snprintf(buf, sizeof(buf), "%02x", submit_data.extra_nonce & 255);
|
||||
b = submit_data.extra_nonce & 255;
|
||||
submit_data.extra_nonce >>= 8;
|
||||
}
|
||||
else {
|
||||
snprintf(buf, sizeof(buf), "%02x", submit_data.blob[i]);
|
||||
else if (sidechain_id_offset && sidechain_id_offset <= i && i < sidechain_id_offset + HASH_SIZE) {
|
||||
b = sidechain_id.h[i - sidechain_id_offset];
|
||||
}
|
||||
|
||||
request.append(buf);
|
||||
else {
|
||||
b = submit_data.blob[i];
|
||||
}
|
||||
request.append(1, "0123456789abcdef"[b >> 4]);
|
||||
request.append(1, "0123456789abcdef"[b & 15]);
|
||||
}
|
||||
request.append("\"]}");
|
||||
|
||||
JSONRPCRequest::call(m_params->m_host, m_params->m_rpcPort, request, m_params->m_rpcLogin, m_params->m_socks5Proxy,
|
||||
[height, diff, template_id, nonce, extra_nonce, is_external](const char* data, size_t size)
|
||||
[height, diff, template_id, nonce, extra_nonce, &sidechain_id, is_external](const char* data, size_t size)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
if (doc.Parse<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(data, size).HasParseError() || !doc.IsObject()) {
|
||||
|
@ -589,7 +598,7 @@ void p2pool::submit_block() const
|
|||
LOGWARN(3, "submit_block (external blob): daemon returned error: " << (error_msg ? error_msg : "unknown error"));
|
||||
}
|
||||
else {
|
||||
LOGERR(0, "submit_block: daemon returned error: '" << (error_msg ? error_msg : "unknown error") << "', template id = " << template_id << ", nonce = " << nonce << ", extra_nonce = " << extra_nonce);
|
||||
LOGERR(0, "submit_block: daemon returned error: '" << (error_msg ? error_msg : "unknown error") << "', template id = " << template_id << ", nonce = " << nonce << ", extra_nonce = " << extra_nonce << ", id = " << sidechain_id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue