Skip to content

Commit

Permalink
Better API name, added API descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed May 16, 2024
1 parent d219b78 commit 0838415
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
16 changes: 11 additions & 5 deletions docs/MERGE_MINING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

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_job","params":{"address":"MERGE_MINED_CHAIN_ADDRESS","aux_hash":"f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f","height":3000000,"prev_id":"ad505b0be8a49b89273e307106fa42133cbd804456724c5e7635bd953215d92a"}}`
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
Expand All @@ -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`

Expand Down
12 changes: 6 additions & 6 deletions src/merge_mining_client_json_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
}
}
Expand All @@ -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;
};

Expand Down
4 changes: 2 additions & 2 deletions src/merge_mining_client_json_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class MergeMiningClientJSON_RPC : public IMergeMiningClient
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);

Expand Down
2 changes: 1 addition & 1 deletion tests/src/mm_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def do_POST(self):

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)
Expand Down

0 comments on commit 0838415

Please sign in to comment.