Skip to content

Commit

Permalink
introduce async_mining_allowed as JDS config parameter
Browse files Browse the repository at this point in the history
before issue #853 was reported, JDS would simply support async jobs by default and completely ignore this flag.

but checking this flag implies that JDS could either support async jobs or not, and that is what this commit does.

a new `asyn_mining_allowed` parameter is introduced to the TOML config files, and that is used when:
- checking for the flags of `SetupConnection` messages
- responding to `AllocateMiningJobToken` messages
  • Loading branch information
plebhash committed Jul 18, 2024
1 parent c4a2d85 commit ebc8a72
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Async Job Support
async_mining_allowed = true

# SRI Pool config
authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n"
Expand Down
3 changes: 3 additions & 0 deletions roles/jd-server/config-examples/jds-config-local-example.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Async Job Support
async_mining_allowed = true

# SRI Pool config
authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n"
Expand Down
2 changes: 1 addition & 1 deletion roles/jd-server/src/lib/job_declarator/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
request_id: message.request_id,
mining_job_token: token.to_le_bytes().to_vec().try_into().unwrap(),
coinbase_output_max_additional_size: 100,
async_mining_allowed: true,
async_mining_allowed: self.async_mining_allowed,
coinbase_output: self.coinbase_output.clone().try_into().unwrap(),
};
let message_enum = JobDeclaration::AllocateMiningJobTokenSuccess(message_success);
Expand Down
8 changes: 6 additions & 2 deletions roles/jd-server/src/lib/job_declarator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct AddTrasactionsToMempool {

#[derive(Debug)]
pub struct JobDeclaratorDownstream {
async_mining_allowed: bool,
sender: Sender<EitherFrame>,
receiver: Receiver<EitherFrame>,
// TODO this should be computed for each new template so that fees are included
Expand All @@ -70,6 +71,7 @@ pub struct JobDeclaratorDownstream {

impl JobDeclaratorDownstream {
pub fn new(
async_mining_allowed: bool,
receiver: Receiver<EitherFrame>,
sender: Sender<EitherFrame>,
config: &Configuration,
Expand All @@ -89,6 +91,7 @@ impl JobDeclaratorDownstream {
.expect("Invalid coinbase output in config");

Self {
async_mining_allowed,
receiver,
sender,
coinbase_output,
Expand Down Expand Up @@ -477,14 +480,14 @@ impl JobDeclarator {
let flag = setup_connection.flags;
let is_valid = SetupConnection::check_flags(
Protocol::JobDeclarationProtocol,
1,
config.async_mining_allowed as u32,
flag,
);

if is_valid {
let success_message = SetupConnectionSuccess {
used_version: 2,
flags: 0b_0000_0000_0000_0000_0000_0000_0000_0001,
flags: (setup_connection.flags & 1u32),
};
info!("Sending success message for proxy");
let sv2_frame: StdFrame = JdsMessages::Common(success_message.into())
Expand All @@ -495,6 +498,7 @@ impl JobDeclarator {

let jddownstream =
Arc::new(Mutex::new(JobDeclaratorDownstream::new(
(setup_connection.flags & 1u32) != 0u32, // this takes a bool instead of u32
receiver.clone(),
sender.clone(),
&config,
Expand Down
6 changes: 6 additions & 0 deletions roles/jd-server/src/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub struct CoinbaseOutput {

#[derive(Debug, Deserialize, Clone)]
pub struct Configuration {
#[serde(default = "default_true")]
pub async_mining_allowed: bool,
pub listen_jd_address: String,
pub authority_public_key: Secp256k1PublicKey,
pub authority_secret_key: Secp256k1SecretKey,
Expand All @@ -70,6 +72,10 @@ pub struct Configuration {
pub mempool_update_interval: Duration,
}

fn default_true() -> bool {
true
}

fn duration_from_toml<'de, D>(deserializer: D) -> Result<Duration, D::Error>
where
D: serde::Deserializer<'de>,
Expand Down

0 comments on commit ebc8a72

Please sign in to comment.