From 08384156e4663bcda4b0e34e880bc94390ea8d4a Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Thu, 16 May 2024 18:10:04 +0200 Subject: [PATCH] Better API name, added API descriptions --- docs/MERGE_MINING.MD | 16 +++++++++++----- src/merge_mining_client_json_rpc.cpp | 12 ++++++------ src/merge_mining_client_json_rpc.h | 4 ++-- tests/src/mm_server.py | 2 +- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/MERGE_MINING.MD b/docs/MERGE_MINING.MD index 09c2fdd..da2113a 100644 --- a/docs/MERGE_MINING.MD +++ b/docs/MERGE_MINING.MD @@ -48,6 +48,8 @@ P2Pool must be able to get mining jobs from merge mined chains and submit PoW so ### merge_mining_get_chain_id +Gets a unique ID that identifies this merge mined chain and separates it from other chains. + Example request: `{"jsonrpc":"2.0","id":"0","method":"merge_mining_get_chain_id"}` Response: a JSON containing these fields: @@ -59,9 +61,11 @@ Example response 1: `{"jsonrpc":"2.0","id":"0","result":{"chain_id":"0f28c4960d9 Example response 2: `{"jsonrpc":"2.0","id":"0","error":"something went wrong"}` -### merge_mining_get_job +### merge_mining_get_aux_block -Example request: `{"jsonrpc":"2.0","id":"0","method":"merge_mining_get_job","params":{"address":"MERGE_MINED_CHAIN_ADDRESS","aux_hash":"f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f","height":3000000,"prev_id":"ad505b0be8a49b89273e307106fa42133cbd804456724c5e7635bd953215d92a"}}` +Gets a blob of data (usually a new block for the merge mined chain) and its hash to be used for merge mining. + +Example request: `{"jsonrpc":"2.0","id":"0","method":"merge_mining_get_aux_block","params":{"address":"MERGE_MINED_CHAIN_ADDRESS","aux_hash":"f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f","height":3000000,"prev_id":"ad505b0be8a49b89273e307106fa42133cbd804456724c5e7635bd953215d92a"}}` Request: a JSON containing these fields: Field|Description @@ -86,14 +90,16 @@ Example response 2: `{"jsonrpc":"2.0","id":"0","result":{}}` ### merge_mining_submit_solution +Submits a PoW solution for the merge mined chain's block. Note that when merge mining with Monero, the PoW solution is always a Monero block template with merge mining data included in it. + Example request: `{"jsonrpc":"2.0","id":"0","method":"merge_mining_submit_solution","params":{"aux_blob":"4c6f72656d20697073756d","aux_hash":"f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f","blob":"...","merkle_proof":["hash1","hash2","hash3"],"path":3}}` Request: a JSON containing these fields: Field|Description -|- -`aux_blob`|Blob of data returned by `merge_mining_get_job`. -`aux_hash`|A 32-byte hex-encoded hash of the `aux_blob` - the same value that was returned by `merge_mining_get_job`. -`blob`|Monero block template that has enough PoW to satisfy difficulty returned by `merge_mining_get_job`. It also must have a merge mining tag in tx_extra of the coinbase transaction. +`aux_blob`|Blob of data returned by `merge_mining_get_aux_block`. +`aux_hash`|A 32-byte hex-encoded hash of the `aux_blob` - the same value that was returned by `merge_mining_get_aux_block`. +`blob`|Monero block template that has enough PoW to satisfy difficulty returned by `merge_mining_get_aux_block`. It also must have a merge mining tag in tx_extra of the coinbase transaction. `merkle_proof`|A proof that `aux_hash` was included when calculating Merkle root hash from the merge mining tag `path`|A path bitmap (32-bit unsigned integer) that complements `merkle_proof` diff --git a/src/merge_mining_client_json_rpc.cpp b/src/merge_mining_client_json_rpc.cpp index dc43821..54c5393 100644 --- a/src/merge_mining_client_json_rpc.cpp +++ b/src/merge_mining_client_json_rpc.cpp @@ -101,7 +101,7 @@ MergeMiningClientJSON_RPC::~MergeMiningClientJSON_RPC() void MergeMiningClientJSON_RPC::on_timer() { MinerData data = m_pool->miner_data(); - merge_mining_get_job(data.height, data.prev_id, m_auxWallet); + merge_mining_get_aux_block(data.height, data.prev_id, m_auxWallet); } void MergeMiningClientJSON_RPC::merge_mining_get_chain_id() @@ -172,7 +172,7 @@ bool MergeMiningClientJSON_RPC::parse_merge_mining_get_chain_id(const char* data return true; } -void MergeMiningClientJSON_RPC::merge_mining_get_job(uint64_t height, const hash& prev_id, const std::string& wallet) +void MergeMiningClientJSON_RPC::merge_mining_get_aux_block(uint64_t height, const hash& prev_id, const std::string& wallet) { if (m_getJobRunning) { return; @@ -190,7 +190,7 @@ void MergeMiningClientJSON_RPC::merge_mining_get_job(uint64_t height, const hash aux_hash = m_chainParams.aux_hash; } - s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"merge_mining_get_job\",\"params\":{" + s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"merge_mining_get_aux_block\",\"params\":{" << "\"address\":\"" << wallet << '"' << ",\"aux_hash\":\"" << aux_hash << '"' << ",\"height\":" << height @@ -204,7 +204,7 @@ void MergeMiningClientJSON_RPC::merge_mining_get_job(uint64_t height, const hash { WriteLock lock(m_lock); - if (parse_merge_mining_get_job(data, size, changed)) { + if (parse_merge_mining_get_aux_block(data, size, changed)) { chain_id = m_chainParams.aux_id; } } @@ -221,10 +221,10 @@ void MergeMiningClientJSON_RPC::merge_mining_get_job(uint64_t height, const hash }, &m_loop); } -bool MergeMiningClientJSON_RPC::parse_merge_mining_get_job(const char* data, size_t size, bool& changed) +bool MergeMiningClientJSON_RPC::parse_merge_mining_get_aux_block(const char* data, size_t size, bool& changed) { auto err = [](const char* msg) { - LOGWARN(3, "merge_mining_get_job RPC call failed: " << msg); + LOGWARN(3, "merge_mining_get_aux_block RPC call failed: " << msg); return false; }; diff --git a/src/merge_mining_client_json_rpc.h b/src/merge_mining_client_json_rpc.h index 2f24b54..f59d329 100644 --- a/src/merge_mining_client_json_rpc.h +++ b/src/merge_mining_client_json_rpc.h @@ -41,8 +41,8 @@ private: void merge_mining_get_chain_id(); bool parse_merge_mining_get_chain_id(const char* data, size_t size); - void merge_mining_get_job(uint64_t height, const hash& prev_id, const std::string& wallet); - bool parse_merge_mining_get_job(const char* data, size_t size, bool& changed); + void merge_mining_get_aux_block(uint64_t height, const hash& prev_id, const std::string& wallet); + bool parse_merge_mining_get_aux_block(const char* data, size_t size, bool& changed); bool parse_merge_mining_submit_solution(const char* data, size_t size); diff --git a/tests/src/mm_server.py b/tests/src/mm_server.py index d2bd8a5..7c75d21 100644 --- a/tests/src/mm_server.py +++ b/tests/src/mm_server.py @@ -24,7 +24,7 @@ class Server(http.server.BaseHTTPRequestHandler): if request['method'] == 'merge_mining_get_chain_id': response['result'] = {'chain_id':chain_id} - elif request['method'] == 'merge_mining_get_job': + elif request['method'] == 'merge_mining_get_aux_block': global counter counter += 1 s = aux_blob + '_' + str(counter // 10)