Skip to content

Commit

Permalink
jdc fallback to solo-mining
Browse files Browse the repository at this point in the history
in this PR is fixed the fallback to solo-mining in the case that the
upstream sends a `SubmitShareError` on a valid share AND there are no
other available upstreams in the JDC config. To check this PR you should
follow the same procedure as described in the commit messages of the
branch of this PR (which deals with a similar problem).
stratum-mining#1001
The only exception is that the JDC should use this config
test/config/change-upstream/jdc-config-local-example-change-upstream-solo-fallback.toml

panics:
2024-07-11T15:57:25.769622Z  INFO roles_logic_sv2::handlers::template_distribution: Received NewTemplate with id: 694, is future: true
thread 'tokio-runtime-worker' panicked at jd-client/src/lib/downstream.rs:379:74:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2024-07-11T15:57:35.319832Z  INFO roles_logic_sv2::handlers::mining: Received UpdateChannel->Extended message
thread 'tokio-runtime-worker' panicked at jd-client/src/lib/downstream.rs:525:13:
not yet implemented
2024-07-11T15:57:41.633138Z ERROR network_helpers_sv2::noise_connection_tokio: Disconnected from client while reading : early eof - 127.0.0.1:56278
^C2024-07-11T15:57:57.023091Z  INFO jd_client: Interrupt received
  • Loading branch information
lorbax committed Jul 16, 2024
1 parent d4800cd commit 54fb3e8
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 12 deletions.
6 changes: 3 additions & 3 deletions benches/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions roles/jd-client/src/lib/downstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct DownstreamMiningNode {
miner_coinbase_output: Vec<TxOut>,
// used to retreive the job id of the share that we send upstream
last_template_id: u64,
jd: Option<Arc<Mutex<JobDeclarator>>>,
pub jd: Option<Arc<Mutex<JobDeclarator>>>,
}

#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -376,12 +376,12 @@ impl DownstreamMiningNode {
let to_send = to_send.into_values();
for message in to_send {
let message = if let Mining::NewExtendedMiningJob(job) = message {
let jd = self_mutex.safe_lock(|s| s.jd.clone()).unwrap().unwrap();
jd.safe_lock(|jd| jd.coinbase_tx_prefix = job.coinbase_tx_prefix.clone())
.unwrap();
jd.safe_lock(|jd| jd.coinbase_tx_suffix = job.coinbase_tx_suffix.clone())
.unwrap();

if let Some(jd) = self_mutex.safe_lock(|s| s.jd.clone()).unwrap() {
jd.safe_lock(|jd| jd.coinbase_tx_prefix = job.coinbase_tx_prefix.clone())
.unwrap();
jd.safe_lock(|jd| jd.coinbase_tx_suffix = job.coinbase_tx_suffix.clone())
.unwrap();
}
Mining::NewExtendedMiningJob(job)
} else {
message
Expand Down Expand Up @@ -514,15 +514,24 @@ impl

fn handle_update_channel(
&mut self,
_: UpdateChannel,
m: UpdateChannel,
) -> Result<SendTo<UpstreamMiningNode>, Error> {
if !self.status.is_solo_miner() {
// Safe unwrap alreay checked if it cointains upstream with is_solo_miner
Ok(SendTo::RelaySameMessageToRemote(
self.status.get_upstream().unwrap(),
))
} else {
todo!()
let maximum_target =
roles_logic_sv2::utils::hash_rate_to_target(m.nominal_hash_rate.into(), 10.0)?;
self.status
.get_channel()
.update_target_for_channel(m.channel_id, maximum_target.clone().into());
let set_target = SetTarget {
channel_id: m.channel_id,
maximum_target,
};
Ok(SendTo::Respond(Mining::SetTarget(set_target)))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# SRI JDC config
downstream_address = "127.0.0.1"
downstream_port = 34265

# Version support
max_supported_version = 2
min_supported_version = 2

# Minimum extranonce2 size for downstream
# Max value: 16 (leaves 0 bytes for search space splitting of downstreams)
# Max value for CGminer: 8
# Min value: 2
min_extranonce2_size = 8

# Withhold
withhold = false

# Auth keys for open encrypted connection downstream
authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n"
cert_validity_sec = 3600

# How many time the JDC try to reinitialize itself after a failure
retry = 10

# Template Provider config
# Local TP (this is pointing to localhost so you must run a TP locally for this configuration to work)
tp_address = "127.0.0.1:8442"
# Hosted testnet TP
# tp_address = "75.119.150.111:8442"

# Solo Mining config
# List of coinbase outputs used to build the coinbase tx in case of Solo Mining (as last-resort solution of the pools fallback system)
# ! Put your Extended Public Key or Script as output_script_value !
# ! Right now only one output is supported, so comment all the ones you don't need !
# For P2PK, P2PKH, P2WPKH, P2TR a public key is needed. For P2SH and P2WSH, a redeem script is needed.
coinbase_outputs = [
#{ output_script_type = "P2PK", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" },
#{ output_script_type = "P2PKH", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" },
#{ output_script_type = "P2SH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" },
#{ output_script_type = "P2WSH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" },
{ output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
#{ output_script_type = "P2TR", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
]

[timeout]
unit = "secs"
value = 1

# List of upstreams (JDS) used as backup endpoints
# In case of shares refused by the JDS, the fallback system will propose the same job to the next upstream in this list
[[upstreams]]
authority_pubkey = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
pool_address = "127.0.0.1:44254"
jd_address = "127.0.0.1:34264"
# Pool signature (string to be included in coinbase tx)
pool_signature = "Stratum v2 SRI Pool"
#[[upstreams]]
#authority_pubkey = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
#pool_address = "127.0.0.1:34254"
#jd_address = "127.0.0.1:34264"
# Pool signature (string to be included in coinbase tx)
#pool_signature = "Stratum v2 SRI Pool"

# [[upstreams]]
# authority_pubkey = "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL"
# pool_address = "127.0.0.1:34254"
# jd_address = "127.0.0.1:34264"
# Pool signature (string to be included in coinbase tx)
# pool_signature = "Stratum v2 SRI Pool"

0 comments on commit 54fb3e8

Please sign in to comment.