Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 122 additions & 149 deletions Cargo.lock

Large diffs are not rendered by default.

54 changes: 50 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct ConfigFile {
tp_address: Option<String>,
api_base_url: Option<String>,
pool_addresses: Option<Vec<String>>,
restore_channel: Option<String>,
interval: Option<u64>,
delay: Option<u64>,
downstream_hashrate: Option<String>,
Expand Down Expand Up @@ -130,6 +131,7 @@ impl ConfigFile {
tp_address: None,
api_base_url: None,
pool_addresses: None,
restore_channel: None,
interval: None,
delay: None,
downstream_hashrate: None,
Expand Down Expand Up @@ -166,6 +168,7 @@ pub struct Configuration {
tp_address: Option<String>,
api_base_url: Option<String>,
pool_addresses: Vec<String>,
restore_channel: Option<Vec<u8>>,
interval: u64,
delay: u64,
downstream_hashrate: f32,
Expand Down Expand Up @@ -228,6 +231,7 @@ and make that test pass."
tp_address: Option<String>,
api_base_url: Option<String>,
pool_addresses: Vec<String>,
restore_channel: Option<Vec<u8>>,
interval: u64,
delay: u64,
downstream_hashrate: f32,
Expand Down Expand Up @@ -275,6 +279,7 @@ and make that test pass."
tp_address,
api_base_url,
pool_addresses,
restore_channel,
interval,
delay,
downstream_hashrate,
Expand Down Expand Up @@ -361,10 +366,11 @@ and make that test pass."
None,
None,
Vec::new(),
None,
120_000,
0,
DEFAULT_SV1_HASHPOWER,
crate::translator::downstream::diff_management::NON_LOCAL_DOWNSTREAM_MIN_DIFFICULTY,
crate::translator::NON_LOCAL_DOWNSTREAM_MIN_DIFFICULTY,
"info".to_string(),
"off".to_string(),
false,
Expand Down Expand Up @@ -432,6 +438,10 @@ and make that test pass."
}
}

pub fn restore_channel() -> Option<Vec<u8>> {
Self::cfg().restore_channel.clone()
}

pub async fn pool_address() -> Option<Vec<SocketAddr>> {
match fetch_pool_urls().await {
Ok(addresses) => Some(addresses),
Expand Down Expand Up @@ -661,6 +671,10 @@ and make that test pass."
"DMND_CLIENT_POOL_ADDRESSES",
],
);
let restore_channel = config
.restore_channel
.or_else(|| std::env::var("RESTORE_CHANNEL").ok())
.map(Self::parse_restore_channel);

let miner_name = args
.miner_name
Expand Down Expand Up @@ -749,9 +763,7 @@ and make that test pass."
.ok()
.and_then(|s| parse_downstream_min_difficulty(&s).ok())
})
.unwrap_or(
crate::translator::downstream::diff_management::NON_LOCAL_DOWNSTREAM_MIN_DIFFICULTY,
);
.unwrap_or(crate::translator::NON_LOCAL_DOWNSTREAM_MIN_DIFFICULTY);
println!("Using downstream minimum difficulty: {downstream_min_difficulty}");

let listening_addr = args.listening_addr.or(config.listening_addr).or_else(|| {
Expand Down Expand Up @@ -873,6 +885,7 @@ and make that test pass."
tp_address,
api_base_url,
pool_addresses,
restore_channel,
interval,
delay,
downstream_hashrate,
Expand Down Expand Up @@ -903,6 +916,39 @@ and make that test pass."
api_tx_token,
)
}

fn parse_restore_channel(value: String) -> Vec<u8> {
let trimmed = value.trim();
if let Some(hex) = trimmed
.strip_prefix("0x")
.or_else(|| trimmed.strip_prefix("hex:"))
{
return Self::parse_restore_channel_hex(hex).unwrap_or_else(|error| panic!("{error}"));
}

value.into_bytes()
}

fn parse_restore_channel_hex(hex: &str) -> Result<Vec<u8>, String> {
if hex.len() % 2 != 0 {
return Err(
"Invalid restore_channel hex value: expected an even number of hex digits"
.to_string(),
);
}

hex.as_bytes()
.chunks(2)
.map(|pair| {
let pair = std::str::from_utf8(pair).map_err(|_| {
"Invalid restore_channel hex value: expected ASCII hex digits".to_string()
})?;
u8::from_str_radix(pair, 16).map_err(|_| {
format!("Invalid restore_channel hex byte `{pair}`: expected 00 through ff")
})
})
.collect()
}
}

/// Parses a hashrate string (e.g., "10T", "2.5P", "500E") into an f32 value in h/s.
Expand Down
21 changes: 9 additions & 12 deletions src/jd_client/job_declarator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub struct JobDeclarator {
sender: TSender<StandardEitherFrame<PoolMessages<'static>>>,
allocated_tokens: Vec<AllocateMiningJobTokenSuccess<'static>>,
req_ids: Id,
min_extranonce_size: u16,
// (Sent DeclareMiningJob, is future, template id, merkle path)
last_declare_mining_jobs_sent: HashMap<u32, Option<LastDeclareJob>>,
pub last_set_new_prev_hash: Option<SetNewPrevHash<'static>>,
Expand Down Expand Up @@ -100,8 +99,6 @@ impl JobDeclarator {
info!("JD CONNECTED");
}

let min_extranonce_size = crate::MIN_EXTRANONCE_SIZE;

let task_manager = TaskManager::initialize();
let abortable = task_manager
.safe_lock(|t| t.get_aborter())
Expand All @@ -111,7 +108,6 @@ impl JobDeclarator {
sender,
allocated_tokens: vec![],
req_ids: Id::new(),
min_extranonce_size,
last_declare_mining_jobs_sent: HashMap::with_capacity(2),
last_set_new_prev_hash: None,
future_jobs: HashMap::with_hasher(BuildNoHashHasher::default()),
Expand Down Expand Up @@ -241,8 +237,8 @@ impl JobDeclarator {
}
super::IS_CUSTOM_JOB_SET.store(false, std::sync::atomic::Ordering::Release);
// now as u64 unix time
let (id, _, sender) = self_mutex
.safe_lock(|s| (s.req_ids.next(), s.min_extranonce_size, s.sender.clone()))
let (id, sender) = self_mutex
.safe_lock(|s| (s.req_ids.next(), s.sender.clone()))
.map_err(|_| Error::JobDeclaratorMutexCorrupted)?;

let template_transactions = tx_list_.to_vec();
Expand Down Expand Up @@ -433,7 +429,7 @@ impl JobDeclarator {
}
};
if sender.send(sv2_frame.into()).await.is_err() {
error!("Job declarator failed to send message");
error!("Job declarator failed to send message AAAAA");
ProxyState::update_jd_state(JdState::Down);
break;
};
Expand All @@ -447,7 +443,7 @@ impl JobDeclarator {
}
}
});
TaskManager::add_allocate_tokens(task_manager, main_task.into())
TaskManager::add_main_task(task_manager, main_task.into())
.await
.map_err(|_| Error::JobDeclaratorTaskManagerFailed)
}
Expand Down Expand Up @@ -477,14 +473,15 @@ impl JobDeclarator {
&& s.last_set_new_prev_hash != Some(set_new_prev_hash.clone())
//it means that a new prev_hash is arrived while the previous hasn't exited the loop yet
{
s.set_new_prev_hash_counter -= 1;
s.set_new_prev_hash_counter = s.set_new_prev_hash_counter.saturating_sub(1);
Some(None)
} else {
s.future_jobs
.remove(&id)
.map(|(job, merkle_path, template, pool_outs)| {
s.future_jobs = HashMap::with_hasher(BuildNoHashHasher::default());
s.set_new_prev_hash_counter -= 1;
s.future_jobs.clear();
s.set_new_prev_hash_counter =
s.set_new_prev_hash_counter.saturating_sub(1);
Some((job, s.up.clone(), merkle_path, template, pool_outs))
})
}
Expand Down Expand Up @@ -555,7 +552,7 @@ impl JobDeclarator {
.expect("Infallible operation");

if sender.send(frame.into()).await.is_err() {
error!("Job declarator failed to send message");
error!("Job declarator failed to send message BBBB");
ProxyState::update_jd_state(JdState::Down);
}
}
Expand Down
Loading
Loading