Skip to content

Commit

Permalink
Merge pull request stratum-mining#623 from vincenzopalazzo/macros/com…
Browse files Browse the repository at this point in the history
…mon-strate

common: introduce a new common crate
  • Loading branch information
Fi3 authored Sep 29, 2023
2 parents 09024a6 + dfe38c1 commit a9202dc
Show file tree
Hide file tree
Showing 32 changed files with 145 additions and 140 deletions.
67 changes: 18 additions & 49 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "stratum-common"
version = "0.1.0"
edition = "2018"
description = "SV2 pool role"
license = "MIT OR Apache-2.0"
repository = "https://github.com/stratum-mining/stratum"

[dependencies]
bitcoin = "0.29.1"
5 changes: 5 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! # Stratum Common Crate
//!
//! `stratum_common` is a utility crate designed to centralize
//! and manage the shared dependencies and utils across stratum crates.
pub use bitcoin;
2 changes: 1 addition & 1 deletion protocols/v2/roles-logic-sv2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/stratum-mining/stratum"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
stratum-common = { path = "../../../common" }
serde = { version = "1.0.89", features = ["derive", "alloc"], default-features = false, optional = true}
binary_sv2 = {version = "^0.1.6", path = "../../../protocols/v2/binary-sv2/binary-sv2", default-features = true }
common_messages_sv2 = { path = "../../../protocols/v2/subprotocols/common-messages", version = "^0.1.5" }
Expand All @@ -17,7 +18,6 @@ template_distribution_sv2 = { path = "../../../protocols/v2/subprotocols/templat
job_declaration_sv2 = { path = "../../../protocols/v2/subprotocols/job-declaration", version = "^0.1.0" }
const_sv2 = { version = "^0.1.2", path = "../../../protocols/v2/const-sv2"}
framing_sv2 = { version = "^0.1.5", path = "../../../protocols/v2/framing-sv2" }
bitcoin = "0.29.2"
tracing = { version = "0.1"}
chacha20poly1305 = { version = "0.10.1"}
nohash-hasher = "0.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ use nohash_hasher::BuildNoHashHasher;
use std::{collections::HashMap, convert::TryInto, sync::Arc};
use template_distribution_sv2::{NewTemplate, SetNewPrevHash as SetNewPrevHashFromTp};

use bitcoin::{
hashes::{hex::ToHex, sha256d::Hash, Hash as Hash_},
TxOut,
};

use tracing::{debug, error, info};

use stratum_common::{
bitcoin,
bitcoin::{
hashes::{hex::ToHex, sha256d::Hash, Hash as Hash_},
TxOut,
},
};

/// A stripped type of `SetCustomMiningJob` without the (`channel_id, `request_id` and `token`) fields
#[derive(Debug)]
pub struct PartialSetCustomMiningJob {
Expand Down
35 changes: 17 additions & 18 deletions protocols/v2/roles-logic-sv2/src/job_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
//! a template provider as well as logic to clean up old templates when new blocks are mined
use crate::{errors, utils::Id, Error};
use binary_sv2::B064K;
use bitcoin::{
blockdata::{
transaction::{OutPoint, Transaction, TxIn, TxOut},
witness::Witness,
},
util::psbt::serialize::{Deserialize, Serialize},
};
pub use bitcoin::{
consensus::{deserialize, serialize, Decodable, Encodable},
hash_types::{PubkeyHash, ScriptHash, WPubkeyHash, WScriptHash},
hashes::Hash,
secp256k1::SecretKey,
util::key::PrivateKey,
};
use mining_sv2::NewExtendedMiningJob;
use nohash_hasher::BuildNoHashHasher;
use std::{collections::HashMap, convert::TryInto};
use template_distribution_sv2::{NewTemplate, SetNewPrevHash};
use tracing::debug;

use stratum_common::{
bitcoin,
bitcoin::{
blockdata::{
transaction::{OutPoint, Transaction, TxIn, TxOut},
witness::Witness,
},
consensus::Decodable,
util::psbt::serialize::{Deserialize, Serialize},
},
};

#[derive(Debug)]
pub struct JobsCreators {
lasts_new_template: Vec<NewTemplate<'static>>,
Expand Down Expand Up @@ -463,13 +461,16 @@ pub mod tests {
use crate::utils::merkle_root_from_path;
#[cfg(feature = "prop_test")]
use binary_sv2::u256_from_int;
use bitcoin::{secp256k1::Secp256k1, util::key::PublicKey, Network};
use quickcheck::{Arbitrary, Gen};
use std::{cmp, vec};

#[cfg(feature = "prop_test")]
use std::borrow::BorrowMut;

use stratum_common::bitcoin::{
consensus::Encodable, secp256k1::Secp256k1, Network, PrivateKey, PublicKey,
};

pub fn template_from_gen(g: &mut Gen) -> NewTemplate<'static> {
let mut coinbase_prefix_gen = Gen::new(255);
let mut coinbase_prefix: vec::Vec<u8> = vec::Vec::new();
Expand Down Expand Up @@ -525,7 +526,7 @@ pub mod tests {
}

#[cfg(feature = "prop_test")]
use bitcoin::Script;
use stratum_common::bitcoin::Script;

// Test job_id_from_template
#[cfg(feature = "prop_test")]
Expand Down Expand Up @@ -637,8 +638,6 @@ pub mod tests {
assert_eq!(jobs_creators.lasts_new_template.len(), 0);
}

use bitcoin::consensus::Encodable;

#[quickcheck_macros::quickcheck]
fn it_parse_valid_tx_outs(
mut hash1: Vec<u8>,
Expand Down
7 changes: 4 additions & 3 deletions protocols/v2/roles-logic-sv2/src/job_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use crate::{
utils::{merkle_root_from_path, Id, Mutex},
Error,
};
use bitcoin::hashes::{sha256d, Hash, HashEngine};
use mining_sv2::{
NewExtendedMiningJob, NewMiningJob, SetNewPrevHash, SubmitSharesError, SubmitSharesStandard,
Target,
};
use nohash_hasher::BuildNoHashHasher;
use std::{collections::HashMap, convert::TryInto, sync::Arc};

use stratum_common::bitcoin::hashes::{sha256d, Hash, HashEngine};

/// Used to convert an extended mining job to a standard mining job. The `extranonce` field must
/// be exactly 32 bytes.
pub fn extended_to_standard_job_for_group_channel<'a>(
Expand Down Expand Up @@ -259,6 +260,8 @@ mod tests {
use quickcheck::{Arbitrary, Gen};
use std::convert::TryFrom;

use stratum_common::bitcoin::{Script, TxOut};

const BLOCK_REWARD: u64 = 625_000_000_000;

#[test]
Expand Down Expand Up @@ -305,8 +308,6 @@ mod tests {
);
}

use bitcoin::{Script, TxOut};

#[test]
fn test_group_channel_job_dispatcher() {
let out = TxOut {
Expand Down
1 change: 0 additions & 1 deletion protocols/v2/roles-logic-sv2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub mod parsers;
pub mod routing_logic;
pub mod selectors;
pub mod utils;
pub use bitcoin;
pub use common_messages_sv2;
pub use errors::Error;
pub use job_declaration_sv2;
Expand Down
Loading

0 comments on commit a9202dc

Please sign in to comment.