[MM_Proxy] Fix logic flaw in proxy_request_to_monerod
Reverts logic.
Only the submit_block request needs special handling depending for the proxy_submit_to_origin configuration option.
cargo-fmt
use crate::{
block_template_data::{BlockTemplateDataBuilder, BlockTemplateRepository},
- common::{json_rpc, merge_mining, monero_rpc::CoreRpcErrorCode, proxy},
+ common::{json_rpc, merge_mining, monero_rpc::CoreRpcErrorCode, proxy, proxy::convert_json_to_hyper_json_response},
error::MmProxyError,
};
use bytes::Bytes;
@@ -775,22 +775,27 @@ impl InnerService {
monerod_uri,
);
- let json_response = if self.config.proxy_submit_to_origin {
- let resp = builder
- // This is a cheap clone of the request body
- .body(request.body().clone())
- .send()
- .await
- .map_err(MmProxyError::MonerodRequestFailed)?;
- convert_reqwest_response_to_hyper_json_response(resp).await?
- } else {
- let json = json::from_slice::<json::Value>(&request.body()[..])?;
- match json["method"].as_str() {
- Some("submitblock") | Some("submit_block") => {
+ let mut submit_block = false;
+ let body: Bytes = request.body().clone();
+ let json = json::from_slice::<json::Value>(&body[..]).unwrap_or_default();
+ if let Some(method) = json["method"].as_str() {
+ match method {
+ "submitblock" | "submit_block" => {
+ submit_block = true;
+ },
+ _ => {},
+ }
+ }
+
+ let json_response;
+
+ // If the request is a block submission and we are not submitting blocks
+ // to the origin (self-select mode, see next comment for a full explanation)
+ if submit_block && !self.config.proxy_submit_to_origin {
debug!(
target: LOG_TARGET,
- "[monerod] skip: Proxy configured for self-select mode. Pool will submit to MoneroD, \
- submitting to Tari.",
+ "[monerod] skip: Proxy configured for self-select mode. Pool will submit to MoneroD, submitting to \
+ Tari.",
);
// This is required for self-select configuration.
@@ -809,19 +814,16 @@ impl InnerService {
// NB!: This is by design, do not change this without understanding
// it's implications.
let accept_response = json_rpc::default_block_accept_response(json["id"].as_i64());
- proxy::convert_json_to_hyper_json_response(accept_response, StatusCode::OK, monerod_uri.clone())
- .await?
- },
- _ => {
+ json_response =
+ convert_json_to_hyper_json_response(accept_response, StatusCode::OK, monerod_uri.clone()).await?;
+ } else {
let resp = builder
// This is a cheap clone of the request body
- .body(request.body().clone())
+ .body(body)
.send()
.await
.map_err(MmProxyError::MonerodRequestFailed)?;
- convert_reqwest_response_to_hyper_json_response(resp).await?
- },
- }
+ json_response = convert_reqwest_response_to_hyper_json_response(resp).await?
};
let rpc_status = if json_response.body()["error"].is_null() {
