Tari: Added `coinbase_merkle_proof` to `pow_data`

merge-mining
SChernykh 2024-05-10 13:56:28 +02:00
parent d6364709ca
commit e986e5dc2e
7 changed files with 21 additions and 7 deletions

View File

@ -61,6 +61,8 @@ public:
FORCEINLINE const std::vector<MinerShare>& shares() const { return m_shares; }
FORCEINLINE uint64_t get_reward() const { return m_finalReward; }
FORCEINLINE std::vector<uint8_t> get_coinbase_merkle_proof() const { ReadLock lock(m_lock); return m_merkleTreeMainBranch; }
#ifdef P2POOL_UNIT_TESTS
FORCEINLINE const PoolBlock* pool_block_template() const { return m_poolBlockTemplate; }
FORCEINLINE std::mt19937_64& rng() { return m_rng; }

View File

@ -38,7 +38,7 @@ public:
virtual ~IMergeMiningClient() {}
[[nodiscard]] virtual bool get_params(ChainParameters& out_params) const = 0;
virtual void submit_solution(const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof) = 0;
virtual void submit_solution(const BlockTemplate* block_tpl, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof) = 0;
};
} // namespace p2pool

View File

@ -283,7 +283,7 @@ bool MergeMiningClientJSON_RPC::parse_merge_mining_get_job(const char* data, siz
return true;
}
void MergeMiningClientJSON_RPC::submit_solution(const uint8_t (&/*hashing_blob*/)[128], size_t /*nonce_offset*/, const hash& /*seed_hash*/, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof)
void MergeMiningClientJSON_RPC::submit_solution(const BlockTemplate* /*block_tpl*/, const uint8_t (&/*hashing_blob*/)[128], size_t /*nonce_offset*/, const hash& /*seed_hash*/, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof)
{
ReadLock lock(m_lock);

View File

@ -30,7 +30,7 @@ public:
~MergeMiningClientJSON_RPC() override;
bool get_params(ChainParameters& out_params) const override;
void submit_solution(const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof) override;
void submit_solution(const BlockTemplate* block_tpl, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof) override;
private:
static void loop(void* data);

View File

@ -125,7 +125,7 @@ bool MergeMiningClientTari::get_params(ChainParameters& out_params) const
return true;
}
void MergeMiningClientTari::submit_solution(const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& /*merkle_proof*/)
void MergeMiningClientTari::submit_solution(const BlockTemplate* block_tpl, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& /*merkle_proof*/)
{
Block block;
{
@ -157,7 +157,19 @@ void MergeMiningClientTari::submit_solution(const uint8_t (&hashing_blob)[128],
// Tx Merkle tree root
data.append(reinterpret_cast<const char*>(hashing_blob + nonce_offset + sizeof(uint32_t)), HASH_SIZE);
// TODO: serialize coinbase_merkle_proof, coinbase_tx_extra, coinbase_tx_hasher, aux_chain_merkle_proof
// Coinbase transaction's Merkle proof
const std::vector<uint8_t> coinbase_merkle_proof = block_tpl->get_coinbase_merkle_proof();
// Number of hashes in the proof (varint, but an O(logN) proof will never get bigger than 127)
data.append(1, static_cast<char>(coinbase_merkle_proof.size() / HASH_SIZE));
// Hashes in the proof
data.append(reinterpret_cast<const char*>(coinbase_merkle_proof.data()), coinbase_merkle_proof.size());
// Path bitmap (always 0 for the coinbase tx)
data.append(1, 0);
// TODO: serialize coinbase_tx_hasher, coinbase_tx_extra, aux_chain_merkle_proof
pow->set_pow_data(data);
}

View File

@ -31,7 +31,7 @@ public:
~MergeMiningClientTari() override;
bool get_params(ChainParameters& out_params) const override;
void submit_solution(const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof) override;
void submit_solution(const BlockTemplate* block_tpl, const uint8_t (&hashing_blob)[128], size_t nonce_offset, const hash& seed_hash, const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof) override;
static constexpr char TARI_PREFIX[] = "tari://";

View File

@ -679,7 +679,7 @@ void p2pool::submit_aux_block(const hash& chain_id, uint32_t template_id, uint32
}
}
c->submit_solution(hashing_blob, nonce_offset, seed_hash, blob, proof);
c->submit_solution(block_tpl, hashing_blob, nonce_offset, seed_hash, blob, proof);
}
else {
LOGWARN(3, "submit_aux_block: failed to get merkle proof for chain_id " << chain_id);