|
@@ -39,8 +39,9 @@ use tracing::{error, info};
|
|
|
|
|
|
|
|
use crate::{
|
|
use crate::{
|
|
|
proto::ProposalMessage,
|
|
proto::ProposalMessage,
|
|
|
|
|
+ server_error,
|
|
|
task::miner::{generate_next_block, MinerRewardsRecipientConfig},
|
|
task::miner::{generate_next_block, MinerRewardsRecipientConfig},
|
|
|
- DarkfiNode, Error, Result,
|
|
|
|
|
|
|
+ DarkfiNode, Error, Result, RpcError,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// https://github.com/SChernykh/p2pool/blob/master/docs/MERGE_MINING.MD
|
|
// https://github.com/SChernykh/p2pool/blob/master/docs/MERGE_MINING.MD
|
|
@@ -89,7 +90,13 @@ impl DarkfiNode {
|
|
|
//
|
|
//
|
|
|
// --> {"jsonrpc":"2.0", "method": "merge_mining_get_chain_id", "id": 1}
|
|
// --> {"jsonrpc":"2.0", "method": "merge_mining_get_chain_id", "id": 1}
|
|
|
// <-- {"jsonrpc":"2.0", "result": {"chain_id": "0f28c...7863"}, "id": 1}
|
|
// <-- {"jsonrpc":"2.0", "result": {"chain_id": "0f28c...7863"}, "id": 1}
|
|
|
- pub async fn xmr_merge_mining_get_chain_id(&self, id: u16, _params: JsonValue) -> JsonResult {
|
|
|
|
|
|
|
+ pub async fn xmr_merge_mining_get_chain_id(&self, id: u16, params: JsonValue) -> JsonResult {
|
|
|
|
|
+ // Check request doesn't contain params
|
|
|
|
|
+ if !params.get::<Vec<JsonValue>>().unwrap().is_empty() {
|
|
|
|
|
+ return JsonError::new(InvalidParams, None, id).into()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Grab genesis block to use as chain identifier
|
|
|
let (_, genesis_hash) = match self.validator.blockchain.genesis() {
|
|
let (_, genesis_hash) = match self.validator.blockchain.genesis() {
|
|
|
Ok(v) => v,
|
|
Ok(v) => v,
|
|
|
Err(e) => {
|
|
Err(e) => {
|
|
@@ -129,6 +136,12 @@ impl DarkfiNode {
|
|
|
// --> {"jsonrpc":"2.0", "method": "merge_mining_get_aux_block", "params": {"address": "MERGE_MINED_CHAIN_ADDRESS", "aux_hash": "f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f", "height": 3000000, "prev_id":"ad505b0be8a49b89273e307106fa42133cbd804456724c5e7635bd953215d92a"}, "id": 1}
|
|
// --> {"jsonrpc":"2.0", "method": "merge_mining_get_aux_block", "params": {"address": "MERGE_MINED_CHAIN_ADDRESS", "aux_hash": "f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f", "height": 3000000, "prev_id":"ad505b0be8a49b89273e307106fa42133cbd804456724c5e7635bd953215d92a"}, "id": 1}
|
|
|
// <-- {"jsonrpc":"2.0", "result": {"aux_blob": "4c6f72656d20697073756d", "aux_diff": 123456, "aux_hash":"f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f"}, "id": 1}
|
|
// <-- {"jsonrpc":"2.0", "result": {"aux_blob": "4c6f72656d20697073756d", "aux_diff": 123456, "aux_hash":"f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f"}, "id": 1}
|
|
|
pub async fn xmr_merge_mining_get_aux_block(&self, id: u16, params: JsonValue) -> JsonResult {
|
|
pub async fn xmr_merge_mining_get_aux_block(&self, id: u16, params: JsonValue) -> JsonResult {
|
|
|
|
|
+ // Check if node is synced before responding to p2pool
|
|
|
|
|
+ if !*self.validator.synced.read().await {
|
|
|
|
|
+ return server_error(RpcError::NotSynced, id, None)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Parse request params
|
|
|
let Some(params) = params.get::<HashMap<String, JsonValue>>() else {
|
|
let Some(params) = params.get::<HashMap<String, JsonValue>>() else {
|
|
|
return JsonError::new(InvalidParams, None, id).into()
|
|
return JsonError::new(InvalidParams, None, id).into()
|
|
|
};
|
|
};
|
|
@@ -309,6 +322,12 @@ impl DarkfiNode {
|
|
|
// --> {"jsonrpc":"2.0", "method": "merge_mining_submit_solution", "params": {"aux_blob": "4c6f72656d20697073756d", "aux_hash": "f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f", "blob": "...", "merkle_proof": ["hash1", "hash2", "hash3"], "path": 3, "seed_hash": "22c3d47c595ae888b5d7fc304235f92f8854644d4fad38c5680a5d4a81009fcd"}, "id": 1}
|
|
// --> {"jsonrpc":"2.0", "method": "merge_mining_submit_solution", "params": {"aux_blob": "4c6f72656d20697073756d", "aux_hash": "f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f", "blob": "...", "merkle_proof": ["hash1", "hash2", "hash3"], "path": 3, "seed_hash": "22c3d47c595ae888b5d7fc304235f92f8854644d4fad38c5680a5d4a81009fcd"}, "id": 1}
|
|
|
// <-- {"jsonrpc":"2.0", "result": {"status": "accepted"}, "id": 1}
|
|
// <-- {"jsonrpc":"2.0", "result": {"status": "accepted"}, "id": 1}
|
|
|
pub async fn xmr_merge_mining_submit_solution(&self, id: u16, params: JsonValue) -> JsonResult {
|
|
pub async fn xmr_merge_mining_submit_solution(&self, id: u16, params: JsonValue) -> JsonResult {
|
|
|
|
|
+ // Check if node is synced before responding to p2pool
|
|
|
|
|
+ if !*self.validator.synced.read().await {
|
|
|
|
|
+ return server_error(RpcError::NotSynced, id, None)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Parse request params
|
|
|
let Some(params) = params.get::<HashMap<String, JsonValue>>() else {
|
|
let Some(params) = params.get::<HashMap<String, JsonValue>>() else {
|
|
|
return JsonError::new(InvalidParams, None, id).into()
|
|
return JsonError::new(InvalidParams, None, id).into()
|
|
|
};
|
|
};
|