mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-03 09:19:24 +00:00
Submit found aux blocks
This commit is contained in:
parent
d697d0017e
commit
13087dd45e
8 changed files with 69 additions and 17 deletions
|
@ -1309,6 +1309,34 @@ std::vector<AuxChainData> BlockTemplate::get_aux_chains(const uint32_t template_
|
||||||
return m_poolBlockTemplate->m_auxChains;
|
return m_poolBlockTemplate->m_auxChains;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BlockTemplate::get_aux_proof(const uint32_t template_id, const hash& h, std::vector<hash>& proof) 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_aux_proof(template_id, h, proof);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::pair<bool, hash>> t;
|
||||||
|
if (!get_merkle_proof(m_poolBlockTemplate->m_merkleTree, m_poolBlockTemplate->m_sidechainId, t)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
proof.clear();
|
||||||
|
proof.reserve(proof.size());
|
||||||
|
|
||||||
|
for (const auto& k : t) {
|
||||||
|
proof.emplace_back(k.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
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
|
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);
|
ReadLock lock(m_lock);
|
||||||
|
@ -1434,11 +1462,10 @@ void BlockTemplate::init_merge_mining_merkle_proof()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::vector<hash>> tree;
|
merkle_hash_full_tree(hashes, m_poolBlockTemplate->m_merkleTree);
|
||||||
merkle_hash_full_tree(hashes, tree);
|
|
||||||
|
|
||||||
std::vector<std::pair<bool, hash>> proof;
|
std::vector<std::pair<bool, hash>> proof;
|
||||||
get_merkle_proof(tree, m_poolBlockTemplate->m_sidechainId, proof);
|
get_merkle_proof(m_poolBlockTemplate->m_merkleTree, m_poolBlockTemplate->m_sidechainId, proof);
|
||||||
|
|
||||||
m_poolBlockTemplate->m_merkleProof.reserve(proof.size());
|
m_poolBlockTemplate->m_merkleProof.reserve(proof.size());
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
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& aux_diff, 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& aux_diff, difficulty_type& sidechain_difficulty, hash& seed_hash, size_t& nonce_offset, uint32_t& template_id) const;
|
||||||
|
|
||||||
std::vector<AuxChainData> get_aux_chains(const uint32_t template_id) const;
|
std::vector<AuxChainData> get_aux_chains(const uint32_t template_id) const;
|
||||||
|
bool get_aux_proof(const uint32_t template_id, const hash& h, std::vector<hash>& proof) 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;
|
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;
|
||||||
|
|
||||||
|
|
|
@ -244,7 +244,7 @@ void Miner::run(WorkerData* data)
|
||||||
if (j.m_auxDiff.check_pow(h)) {
|
if (j.m_auxDiff.check_pow(h)) {
|
||||||
for (const AuxChainData& aux_data : j.m_auxChains) {
|
for (const AuxChainData& aux_data : j.m_auxChains) {
|
||||||
if (aux_data.difficulty.check_pow(h)) {
|
if (aux_data.difficulty.check_pow(h)) {
|
||||||
m_pool->submit_aux_block_async(aux_data, j.m_templateId, j.m_nonce, j.m_extraNonce);
|
m_pool->submit_aux_block(aux_data.unique_id, j.m_templateId, j.m_nonce, j.m_extraNonce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,6 @@ p2pool::p2pool(int argc, char* argv[])
|
||||||
uv_mutex_init_checked(&m_minerLock);
|
uv_mutex_init_checked(&m_minerLock);
|
||||||
#endif
|
#endif
|
||||||
uv_mutex_init_checked(&m_submitBlockDataLock);
|
uv_mutex_init_checked(&m_submitBlockDataLock);
|
||||||
uv_mutex_init_checked(&m_submitAuxBlockDataLock);
|
|
||||||
|
|
||||||
m_api = p->m_apiPath.empty() ? nullptr : new p2pool_api(p->m_apiPath, p->m_localStats);
|
m_api = p->m_apiPath.empty() ? nullptr : new p2pool_api(p->m_apiPath, p->m_localStats);
|
||||||
|
|
||||||
|
@ -201,7 +200,6 @@ p2pool::~p2pool()
|
||||||
uv_mutex_destroy(&m_minerLock);
|
uv_mutex_destroy(&m_minerLock);
|
||||||
#endif
|
#endif
|
||||||
uv_mutex_destroy(&m_submitBlockDataLock);
|
uv_mutex_destroy(&m_submitBlockDataLock);
|
||||||
uv_mutex_destroy(&m_submitAuxBlockDataLock);
|
|
||||||
|
|
||||||
delete m_api;
|
delete m_api;
|
||||||
delete m_sideChain;
|
delete m_sideChain;
|
||||||
|
@ -590,15 +588,37 @@ void p2pool::submit_block_async(std::vector<uint8_t>&& blob)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void p2pool::submit_aux_block_async(const AuxChainData& aux_data, uint32_t template_id, uint32_t nonce, uint32_t extra_nonce)
|
void p2pool::submit_aux_block(const hash& chain_id, uint32_t template_id, uint32_t nonce, uint32_t extra_nonce)
|
||||||
{
|
{
|
||||||
// TODO
|
size_t nonce_offset = 0;
|
||||||
MutexLock lock(m_submitAuxBlockDataLock);
|
size_t extra_nonce_offset = 0;
|
||||||
|
size_t sidechain_id_offset = 0;
|
||||||
|
hash sidechain_id;
|
||||||
|
|
||||||
(void)aux_data;
|
std::vector<uint8_t> blob = m_blockTemplate->get_block_template_blob(template_id, extra_nonce, nonce_offset, extra_nonce_offset, sidechain_id_offset, sidechain_id);
|
||||||
(void)template_id;
|
|
||||||
(void)nonce;
|
if (blob.empty()) {
|
||||||
(void)extra_nonce;
|
LOGWARN(3, "submit_aux_block: block template blob not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t* p = blob.data();
|
||||||
|
memcpy(p + nonce_offset, &nonce, NONCE_SIZE);
|
||||||
|
memcpy(p + extra_nonce_offset, &extra_nonce, EXTRA_NONCE_SIZE);
|
||||||
|
memcpy(p + sidechain_id_offset, sidechain_id.h, HASH_SIZE);
|
||||||
|
|
||||||
|
for (MergeMiningClient* c : m_mergeMiningClients) {
|
||||||
|
if (chain_id == c->aux_id()) {
|
||||||
|
std::vector<hash> proof;
|
||||||
|
if (m_blockTemplate->get_aux_proof(template_id, c->aux_data(), proof)) {
|
||||||
|
c->merge_mining_submit_solution(blob, proof);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOGWARN(3, "submit_aux_block: failed to get merkle proof");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init_signals(p2pool* pool, bool init);
|
bool init_signals(p2pool* pool, bool init);
|
||||||
|
|
|
@ -87,7 +87,7 @@ public:
|
||||||
void submit_block_async(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce);
|
void submit_block_async(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce);
|
||||||
void submit_block_async(std::vector<uint8_t>&& blob);
|
void submit_block_async(std::vector<uint8_t>&& blob);
|
||||||
|
|
||||||
void submit_aux_block_async(const AuxChainData& aux_data, uint32_t template_id, uint32_t nonce, uint32_t extra_nonce);
|
void submit_aux_block(const hash& chain_id, uint32_t template_id, uint32_t nonce, uint32_t extra_nonce);
|
||||||
|
|
||||||
bool submit_sidechain_block(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce);
|
bool submit_sidechain_block(uint32_t template_id, uint32_t nonce, uint32_t extra_nonce);
|
||||||
|
|
||||||
|
@ -217,8 +217,6 @@ private:
|
||||||
mutable uv_mutex_t m_submitBlockDataLock;
|
mutable uv_mutex_t m_submitBlockDataLock;
|
||||||
SubmitBlockData m_submitBlockData;
|
SubmitBlockData m_submitBlockData;
|
||||||
|
|
||||||
uv_mutex_t m_submitAuxBlockDataLock;
|
|
||||||
|
|
||||||
uv_async_t m_submitBlockAsync;
|
uv_async_t m_submitBlockAsync;
|
||||||
uv_async_t m_blockTemplateAsync;
|
uv_async_t m_blockTemplateAsync;
|
||||||
uv_async_t m_stopAsync;
|
uv_async_t m_stopAsync;
|
||||||
|
|
|
@ -101,6 +101,7 @@ PoolBlock& PoolBlock::operator=(const PoolBlock& b)
|
||||||
m_sidechainHeight = b.m_sidechainHeight;
|
m_sidechainHeight = b.m_sidechainHeight;
|
||||||
m_difficulty = b.m_difficulty;
|
m_difficulty = b.m_difficulty;
|
||||||
m_cumulativeDifficulty = b.m_cumulativeDifficulty;
|
m_cumulativeDifficulty = b.m_cumulativeDifficulty;
|
||||||
|
m_merkleTree = b.m_merkleTree;
|
||||||
m_merkleProof = b.m_merkleProof;
|
m_merkleProof = b.m_merkleProof;
|
||||||
memcpy(m_sidechainExtraBuf, b.m_sidechainExtraBuf, sizeof(m_sidechainExtraBuf));
|
memcpy(m_sidechainExtraBuf, b.m_sidechainExtraBuf, sizeof(m_sidechainExtraBuf));
|
||||||
m_sidechainId = b.m_sidechainId;
|
m_sidechainId = b.m_sidechainId;
|
||||||
|
@ -295,6 +296,9 @@ void PoolBlock::reset_offchain_data()
|
||||||
m_auxChains.shrink_to_fit();
|
m_auxChains.shrink_to_fit();
|
||||||
|
|
||||||
m_auxNonce = 0;
|
m_auxNonce = 0;
|
||||||
|
|
||||||
|
m_merkleTree.clear();
|
||||||
|
m_merkleTree.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PoolBlock::get_pow_hash(RandomX_Hasher_Base* hasher, uint64_t height, const hash& seed_hash, hash& pow_hash, bool force_light_mode)
|
bool PoolBlock::get_pow_hash(RandomX_Hasher_Base* hasher, uint64_t height, const hash& seed_hash, hash& pow_hash, bool force_light_mode)
|
||||||
|
|
|
@ -151,6 +151,8 @@ struct PoolBlock
|
||||||
std::vector<AuxChainData> m_auxChains;
|
std::vector<AuxChainData> m_auxChains;
|
||||||
uint32_t m_auxNonce;
|
uint32_t m_auxNonce;
|
||||||
|
|
||||||
|
std::vector<std::vector<hash>> m_merkleTree;
|
||||||
|
|
||||||
std::vector<uint8_t> serialize_mainchain_data(size_t* header_size = nullptr, size_t* miner_tx_size = nullptr, int* outputs_offset = nullptr, int* outputs_blob_size = nullptr, const uint32_t* nonce = nullptr, const uint32_t* extra_nonce = nullptr) const;
|
std::vector<uint8_t> serialize_mainchain_data(size_t* header_size = nullptr, size_t* miner_tx_size = nullptr, int* outputs_offset = nullptr, int* outputs_blob_size = nullptr, const uint32_t* nonce = nullptr, const uint32_t* extra_nonce = nullptr) const;
|
||||||
std::vector<uint8_t> serialize_sidechain_data() const;
|
std::vector<uint8_t> serialize_sidechain_data() const;
|
||||||
|
|
||||||
|
|
|
@ -403,7 +403,7 @@ bool StratumServer::on_submit(StratumClient* client, uint32_t id, const char* jo
|
||||||
if (aux_diff.check_pow(resultHash)) {
|
if (aux_diff.check_pow(resultHash)) {
|
||||||
for (const AuxChainData& aux_data : block.get_aux_chains(template_id)) {
|
for (const AuxChainData& aux_data : block.get_aux_chains(template_id)) {
|
||||||
if (aux_data.difficulty.check_pow(resultHash)) {
|
if (aux_data.difficulty.check_pow(resultHash)) {
|
||||||
m_pool->submit_aux_block_async(aux_data, template_id, nonce, extra_nonce);
|
m_pool->submit_aux_block(aux_data.unique_id, template_id, nonce, extra_nonce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue