Skip to content

Commit

Permalink
remove fn extended_job_to_non_segwit
Browse files Browse the repository at this point in the history
since the previous commit this function is no longer necessary
  • Loading branch information
plebhash committed Feb 21, 2025
1 parent 5c6db60 commit a4950dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 51 deletions.
48 changes: 4 additions & 44 deletions protocols/v2/roles-logic-sv2/src/job_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ use std::{collections::HashMap, convert::TryInto};
use template_distribution_sv2::{NewTemplate, SetNewPrevHash};
use tracing::debug;

use stratum_common::bitcoin::{
blockdata::transaction::{Transaction, TxOut},
consensus::Decodable,
util::psbt::serialize::Deserialize,
};
use stratum_common::bitcoin::{blockdata::transaction::TxOut, consensus::Decodable};

#[derive(Debug)]
pub struct JobsCreators {
Expand Down Expand Up @@ -235,45 +231,6 @@ fn new_extended_job(
Ok(new_extended_mining_job)
}

/// Helper type to strip a segwit data from the coinbase_tx_prefix and coinbase_tx_suffix
/// to ensure miners are hashing with the correct coinbase
pub fn extended_job_to_non_segwit(
job: NewExtendedMiningJob<'static>,
full_extranonce_len: usize,
) -> Result<NewExtendedMiningJob<'static>, Error> {
let mut encoded = job.coinbase_tx_prefix.to_vec();
// just add empty extranonce space so it can be deserialized. The real extranonce
// should be inserted based on the miner's shares
let extranonce = vec![0_u8; full_extranonce_len];
encoded.extend_from_slice(&extranonce[..]);
encoded.extend_from_slice(job.coinbase_tx_suffix.inner_as_ref());
let tx = Transaction::deserialize(&encoded).map_err(|_| Error::InvalidCoinbase)?;

let coinbase = Coinbase {
tx,
script_sig_prefix_len: job.coinbase_tx_prefix.len()
- (
4 + // version
1 + // input count
32 + // outpoint
4 + // input index
1
// script length byte
),
};

Ok(NewExtendedMiningJob {
channel_id: job.channel_id,
job_id: job.job_id,
min_ntime: job.min_ntime,
version: job.version,
version_rolling_allowed: job.version_rolling_allowed,
merkle_path: job.merkle_path,
coinbase_tx_prefix: coinbase.clone().coinbase_tx_prefix()?,
coinbase_tx_suffix: coinbase.coinbase_tx_suffix()?,
})
}

// Test
#[cfg(test)]

Expand All @@ -284,6 +241,9 @@ pub mod tests {
use binary_sv2::u256_from_int;
use quickcheck::{Arbitrary, Gen};
use std::{cmp, vec};
use stratum_common::bitcoin::{
blockdata::transaction::Transaction, util::psbt::serialize::Deserialize,
};

#[cfg(feature = "prop_test")]
use std::borrow::BorrowMut;
Expand Down
8 changes: 1 addition & 7 deletions roles/translator/src/lib/proxy/next_mining_notify.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use roles_logic_sv2::{
job_creator::extended_job_to_non_segwit,
mining_sv2::{NewExtendedMiningJob, SetNewPrevHash},
};
use roles_logic_sv2::mining_sv2::{NewExtendedMiningJob, SetNewPrevHash};
use tracing::debug;
use v1::{
server_to_client,
Expand All @@ -17,9 +14,6 @@ pub fn create_notify(
new_job: NewExtendedMiningJob<'static>,
clean_jobs: bool,
) -> server_to_client::Notify<'static> {
// TODO 32 must be changed!
let new_job = extended_job_to_non_segwit(new_job, 32)
.expect("failed to convert extended job to non segwit");
// Make sure that SetNewPrevHash + NewExtendedMiningJob is matching (not future)
let job_id = new_job.job_id.to_string();

Expand Down

0 comments on commit a4950dd

Please sign in to comment.