From 9d45b03e8d7eb1c10ea42a1413d1b5ff1c57c7c9 Mon Sep 17 00:00:00 2001 From: plebhash Date: Wed, 2 Oct 2024 12:20:54 -0300 Subject: [PATCH 01/14] use fixed temp_dir for TP --- roles/tests-integration/tests/common/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/tests-integration/tests/common/mod.rs b/roles/tests-integration/tests/common/mod.rs index 5d37b39d5e..4f5c980093 100644 --- a/roles/tests-integration/tests/common/mod.rs +++ b/roles/tests-integration/tests/common/mod.rs @@ -66,10 +66,11 @@ pub struct TemplateProvider { impl TemplateProvider { pub fn start(port: u16) -> Self { - let path_name = format!("/tmp/.template-provider-{}", port); - let temp_dir = PathBuf::from(&path_name); + let temp_dir = PathBuf::from("/tmp/.template-provider"); let mut conf = Conf::default(); + let staticdir = format!(".bitcoin-{}", port); + conf.staticdir = Some(temp_dir.join(staticdir)); let port = format!("-sv2port={}", port); conf.args.extend(vec![ "-txindex=1", @@ -80,7 +81,6 @@ impl TemplateProvider { "-sv2feedelta=1000", "-loglevel=sv2:trace", ]); - conf.staticdir = Some(temp_dir.join(".bitcoin")); let os = env::consts::OS; let arch = env::consts::ARCH; From 78ff2e6eaf6b9c013254a093837f97faa8377fea Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 3 Oct 2024 13:50:07 +0530 Subject: [PATCH 02/14] remove dev occurance in ci --- .github/workflows/clippy-lint.yaml | 2 -- .github/workflows/coverage.yaml | 6 ++++-- .github/workflows/fmt.yaml | 2 -- .github/workflows/lockfiles.yaml | 4 +--- .github/workflows/mg.yaml | 6 ++++-- .github/workflows/rust-msrv.yaml | 2 -- .github/workflows/semver-check.yaml | 2 -- .github/workflows/sv2-header-check.yaml | 6 ++++-- .github/workflows/test.yaml | 2 -- 9 files changed, 13 insertions(+), 19 deletions(-) diff --git a/.github/workflows/clippy-lint.yaml b/.github/workflows/clippy-lint.yaml index fa2c45fac4..b8d4cba361 100644 --- a/.github/workflows/clippy-lint.yaml +++ b/.github/workflows/clippy-lint.yaml @@ -2,11 +2,9 @@ on: push: branches: - main - - dev pull_request: branches: - main - - dev name: Clippy Lint diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 5c20325c1b..c8e18d346d 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -18,9 +18,11 @@ name: Test Coverage on: push: - branches: [ main, dev ] + branches: + - main pull_request: - branches: [ main, dev ] + branches: + - main jobs: tarpaulin-test: diff --git a/.github/workflows/fmt.yaml b/.github/workflows/fmt.yaml index b0b3ecc185..181fc6088f 100644 --- a/.github/workflows/fmt.yaml +++ b/.github/workflows/fmt.yaml @@ -2,11 +2,9 @@ on: push: branches: - main - - dev pull_request: branches: - main - - dev name: Rustfmt diff --git a/.github/workflows/lockfiles.yaml b/.github/workflows/lockfiles.yaml index e87f016a7e..91131bfb98 100644 --- a/.github/workflows/lockfiles.yaml +++ b/.github/workflows/lockfiles.yaml @@ -1,14 +1,12 @@ name: Lockfiles -# Trigger the workflow on push or pull request events for the dev and main branches +# Trigger the workflow on push or pull request events for the main branch on: push: branches: - - dev - main pull_request: branches: - - dev - main jobs: diff --git a/.github/workflows/mg.yaml b/.github/workflows/mg.yaml index d22303f4fd..0088ad021f 100644 --- a/.github/workflows/mg.yaml +++ b/.github/workflows/mg.yaml @@ -4,9 +4,11 @@ name: MG Test on: push: - branches: [ main, dev ] + branches: + - main pull_request: - branches: [ main, dev ] + branches: + - main jobs: bad-pool-config-test: diff --git a/.github/workflows/rust-msrv.yaml b/.github/workflows/rust-msrv.yaml index 3384e4a2ff..62ba418b15 100644 --- a/.github/workflows/rust-msrv.yaml +++ b/.github/workflows/rust-msrv.yaml @@ -2,11 +2,9 @@ on: push: branches: - main - - dev pull_request: branches: - main - - dev name: MSRV 1.75 Check diff --git a/.github/workflows/semver-check.yaml b/.github/workflows/semver-check.yaml index 9a2a45ad3b..6543b473d3 100644 --- a/.github/workflows/semver-check.yaml +++ b/.github/workflows/semver-check.yaml @@ -4,11 +4,9 @@ on: push: branches: - "main" - - "dev" pull_request: branches: - "main" - - "dev" jobs: semver-check: diff --git a/.github/workflows/sv2-header-check.yaml b/.github/workflows/sv2-header-check.yaml index 62f5231fdf..b1b069a05c 100644 --- a/.github/workflows/sv2-header-check.yaml +++ b/.github/workflows/sv2-header-check.yaml @@ -1,8 +1,10 @@ on: push: - branches: [ main, dev ] + branches: + - main pull_request: - branches: [ main, dev ] + branches: + - main # Check sv2.h file is up to date with commit name: sv2.h Header Check diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5b669ebc0b..6665a902f0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,11 +2,9 @@ on: push: branches: - main - - dev pull_request: branches: - main - - dev name: Test, Prop Tests, Example Tests From 8e1412bf976f6ccc695bb753e81f603e654e54bd Mon Sep 17 00:00:00 2001 From: GitGab19 Date: Fri, 6 Sep 2024 02:09:08 +0200 Subject: [PATCH 03/14] add docs + comments as future follow ups exit :q --- protocols/v2/const-sv2/src/lib.rs | 144 +++++++++++++++++++++--------- 1 file changed, 101 insertions(+), 43 deletions(-) diff --git a/protocols/v2/const-sv2/src/lib.rs b/protocols/v2/const-sv2/src/lib.rs index c9cda82770..4fa934c0b5 100644 --- a/protocols/v2/const-sv2/src/lib.rs +++ b/protocols/v2/const-sv2/src/lib.rs @@ -1,27 +1,75 @@ -//! Central repository for all the sv2 constants +//! This crate serves as the central repository for all constants used in the SV2 protocol. +//! These constants are essential for message framing, encryption, and protocol-specific +//! identifiers across various SV2 components, including Mining, Job Declaration, and Template Distribution. +//! +//! It also includes definitions for key encryption settings and message types, ensuring consistency and accuracy +//! when working with SV2's binary protocol. These constants are used throughout the system to ensure that SV2 +//! messages are formatted and interpreted correctly. + #![cfg_attr(feature = "no_std", no_std)] +/// Identifier for the extension_type field in the SV2 frame, indicating no extensions. +// SHOULD WE DEFINE IT? It's not used anywhere than ffi pub const EXTENSION_TYPE_NO_EXTENSION: u16 = 0; +/// Size of the SV2 frame header in bytes. pub const SV2_FRAME_HEADER_SIZE: usize = 6; + +// WHAT IS THIS? It's not used anywhere, just declared in ffi pub const SV2_FRAME_HEADER_LEN_OFFSET: usize = 3; + +// WHAT IS THIS? It's not used anywhere, just declared in ffi pub const SV2_FRAME_HEADER_LEN_END: usize = 3; + +/// Maximum size of an SV2 frame chunk in bytes. pub const SV2_FRAME_CHUNK_SIZE: usize = 65535; -// For now only CHACHA and AES are supported both have a MAC of 16 bytes +/// Size of the MAC for supported AEAD encryption algorithm (ChaChaPoly). pub const AEAD_MAC_LEN: usize = 16; +/// Size of the encrypted SV2 frame header, including the MAC. +// Declared in ffi, and imported in framing_sv2/src/header.rs +// TAKE NOTE: header.rs is then imported into codec_sv2 just for this constant pub const ENCRYPTED_SV2_FRAME_HEADER_SIZE: usize = SV2_FRAME_HEADER_SIZE + AEAD_MAC_LEN; + +/// Size of the Noise protocol frame header in bytes. +// Declared in ffi, and imported in framing_sv2/src/header.rs +// TAKE NOTE: header.rs is then imported into codec_sv2 just for this constant pub const NOISE_FRAME_HEADER_SIZE: usize = 2; + +// Declared in ffi, and imported in framing_sv2/src/header.rs +// TAKE NOTE: header.rs is then imported into codec_sv2 just for this constant, and the const there is not even used pub const NOISE_FRAME_HEADER_LEN_OFFSET: usize = 0; + +// WHAT IS THIS? It's not used anywhere pub const NOISE_FRAME_MAX_SIZE: usize = u16::MAX as usize; +/// Size in bytes of the encoded elliptic curve point using ElligatorSwift encoding. +/// This encoding produces a 64-byte representation of the X-coordinate of a secp256k1 curve point. pub const ELLSWIFT_ENCODING_SIZE: usize = 64; + +// Does it make sense to just create an alias for this here? I think it could be created where it's imported pub const RESPONDER_EXPECTED_HANDSHAKE_MESSAGE_SIZE: usize = ELLSWIFT_ENCODING_SIZE; + +// Is this a different MAC with respect to the f ? pub const MAC: usize = 16; + +/// Size in bytes of the encrypted ElligatorSwift encoded data, which includes the original +/// ElligatorSwift encoded data and a MAC for integrity verification. pub const ENCRYPTED_ELLSWIFT_ENCODING_SIZE: usize = ELLSWIFT_ENCODING_SIZE + MAC; + +/// Size in bytes of the SIGNATURE_NOISE_MESSAGE, which contains information and a signature +/// for the handshake initiator, formatted according to the Noise Protocol specifications. pub const SIGNATURE_NOISE_MESSAGE_SIZE: usize = 74; + +/// Size in bytes of the encrypted signature noise message, which includes the SIGNATURE_NOISE_MESSAGE +/// and a MAC for integrity verification. pub const ENCRYPTED_SIGNATURE_NOISE_MESSAGE_SIZE: usize = SIGNATURE_NOISE_MESSAGE_SIZE + MAC; + +/// Size in bytes of the handshake message expected by the initiator, encompassing: +/// - ElligatorSwift encoded public key +/// - Encrypted ElligatorSwift encoding +/// - Encrypted SIGNATURE_NOISE_MESSAGE pub const INITIATOR_EXPECTED_HANDSHAKE_MESSAGE_SIZE: usize = ELLSWIFT_ENCODING_SIZE + ENCRYPTED_ELLSWIFT_ENCODING_SIZE + ENCRYPTED_SIGNATURE_NOISE_MESSAGE_SIZE; @@ -29,6 +77,8 @@ pub const INITIATOR_EXPECTED_HANDSHAKE_MESSAGE_SIZE: usize = ELLSWIFT_ENCODING_S /// If protocolName is less than or equal to 32 bytes in length, use protocolName with zero bytes /// appended to make 32 bytes. Otherwise, apply HASH to it. For name = /// "Noise_NX_Secp256k1+EllSwift_ChaChaPoly_SHA256", we need the hash. +/// More info at https://github.com/stratum-mining/sv2-spec/blob/main/04-Protocol-Security.md#451 +/// -handshake-act-1-nx-handshake-part-1---e pub const NOISE_HASHED_PROTOCOL_NAME_CHACHA: [u8; 32] = [ 46, 180, 120, 129, 32, 142, 158, 238, 31, 102, 159, 103, 198, 110, 231, 14, 169, 234, 136, 9, 13, 80, 63, 232, 48, 220, 75, 200, 62, 41, 191, 16, @@ -36,64 +86,72 @@ pub const NOISE_HASHED_PROTOCOL_NAME_CHACHA: [u8; 32] = [ // len = 1 // 47,53,45,41 = AESG +// SHOULDN'T WE REMOVE THIS? pub const NOISE_SUPPORTED_CIPHERS_MESSAGE: [u8; 5] = [1, 0x47, 0x53, 0x45, 0x41]; +/// Discriminants for distinct Stratum V2 (sub)protocols. More info at https://github.com/stratum- +/// mining/sv2-spec/blob/main/03-Protocol-Overview.md#3-protocol-overview pub const SV2_MINING_PROTOCOL_DISCRIMINANT: u8 = 0; pub const SV2_JOB_DECLARATION_PROTOCOL_DISCRIMINANT: u8 = 1; +// RENAME in SV2_TEMPLATE_DISTRIBUTION_PROTOCOL_DISCRIMINANT pub const SV2_TEMPLATE_DISTR_PROTOCOL_DISCRIMINANT: u8 = 2; -// COMMON MESSAGES TYPES +/// Common message types used across all Stratum V2 (sub)protocols. pub const MESSAGE_TYPE_SETUP_CONNECTION: u8 = 0x0; pub const MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS: u8 = 0x1; pub const MESSAGE_TYPE_SETUP_CONNECTION_ERROR: u8 = 0x2; pub const MESSAGE_TYPE_CHANNEL_ENDPOINT_CHANGED: u8 = 0x3; -// TEMPLATE DISTRIBUTION PROTOCOL MESSAGES TYPES -pub const MESSAGE_TYPE_COINBASE_OUTPUT_DATA_SIZE: u8 = 0x70; -pub const MESSAGE_TYPE_NEW_TEMPLATE: u8 = 0x71; -pub const MESSAGE_TYPE_SET_NEW_PREV_HASH: u8 = 0x72; -pub const MESSAGE_TYPE_REQUEST_TRANSACTION_DATA: u8 = 0x73; -pub const MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_SUCCESS: u8 = 0x74; -pub const MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_ERROR: u8 = 0x75; -pub const MESSAGE_TYPE_SUBMIT_SOLUTION: u8 = 0x76; -// JOB DECLARATION PROTOCOL MESSAGES TYPES + +/// Mining Protocol message types. +pub const MESSAGE_TYPE_OPEN_STANDARD_MINING_CHANNEL: u8 = 0x10; +pub const MESSAGE_TYPE_OPEN_STANDARD_MINING_CHANNEL_SUCCESS: u8 = 0x11; +pub const MESSAGE_TYPE_OPEN_MINING_CHANNEL_ERROR: u8 = 0x12; +pub const MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL: u8 = 0x13; +// Typo: MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL_SUCCESS +pub const MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL_SUCCES: u8 = 0x14; +pub const MESSAGE_TYPE_NEW_MINING_JOB: u8 = 0x15; +pub const MESSAGE_TYPE_UPDATE_CHANNEL: u8 = 0x16; +pub const MESSAGE_TYPE_UPDATE_CHANNEL_ERROR: u8 = 0x17; +pub const MESSAGE_TYPE_CLOSE_CHANNEL: u8 = 0x18; +pub const MESSAGE_TYPE_SET_EXTRANONCE_PREFIX: u8 = 0x19; +pub const MESSAGE_TYPE_SUBMIT_SHARES_STANDARD: u8 = 0x1a; +pub const MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED: u8 = 0x1b; +pub const MESSAGE_TYPE_SUBMIT_SHARES_SUCCESS: u8 = 0x1c; +pub const MESSAGE_TYPE_SUBMIT_SHARES_ERROR: u8 = 0x1d; +pub const MESSAGE_TYPE_NEW_EXTENDED_MINING_JOB: u8 = 0x1f; +pub const MESSAGE_TYPE_MINING_SET_NEW_PREV_HASH: u8 = 0x20; +pub const MESSAGE_TYPE_SET_TARGET: u8 = 0x21; +pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB: u8 = 0x22; +pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_SUCCESS: u8 = 0x23; +pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_ERROR: u8 = 0x24; + +// WE NEED TO MOVE THIS to 0x04 AND SHIFT the SETGROUPCHANNEL to 0x25 (we are not specs compliant now) +pub const MESSAGE_TYPE_RECONNECT: u8 = 0x25; +pub const MESSAGE_TYPE_SET_GROUP_CHANNEL: u8 = 0x26; + +/// Job Declaration Protocol message types. pub const MESSAGE_TYPE_ALLOCATE_MINING_JOB_TOKEN: u8 = 0x50; pub const MESSAGE_TYPE_ALLOCATE_MINING_JOB_TOKEN_SUCCESS: u8 = 0x51; -pub const MESSAGE_TYPE_DECLARE_MINING_JOB: u8 = 0x57; -pub const MESSAGE_TYPE_DECLARE_MINING_JOB_SUCCESS: u8 = 0x58; -pub const MESSAGE_TYPE_DECLARE_MINING_JOB_ERROR: u8 = 0x59; pub const MESSAGE_TYPE_IDENTIFY_TRANSACTIONS: u8 = 0x53; pub const MESSAGE_TYPE_IDENTIFY_TRANSACTIONS_SUCCESS: u8 = 0x54; pub const MESSAGE_TYPE_PROVIDE_MISSING_TRANSACTIONS: u8 = 0x55; pub const MESSAGE_TYPE_PROVIDE_MISSING_TRANSACTIONS_SUCCESS: u8 = 0x56; +pub const MESSAGE_TYPE_DECLARE_MINING_JOB: u8 = 0x57; +pub const MESSAGE_TYPE_DECLARE_MINING_JOB_SUCCESS: u8 = 0x58; +pub const MESSAGE_TYPE_DECLARE_MINING_JOB_ERROR: u8 = 0x59; pub const MESSAGE_TYPE_SUBMIT_SOLUTION_JD: u8 = 0x60; -// MINING PROTOCOL MESSAGES TYPES -pub const MESSAGE_TYPE_CLOSE_CHANNEL: u8 = 0x18; -/// This has been cahnged before was 0x1e it can be that old Sv2 implementation still use the old -/// one but this means that old impl are not following Sv2 spec -pub const MESSAGE_TYPE_NEW_EXTENDED_MINING_JOB: u8 = 0x1f; -pub const MESSAGE_TYPE_NEW_MINING_JOB: u8 = 0x15; -pub const MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL: u8 = 0x13; -pub const MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL_SUCCES: u8 = 0x14; -// in the spec page 21 is defined OpenMiningChannelError valid for both extended and standard -// messages but in the spec page 40 are defined two different message types for -// OpenStandardMiningChannelError and OpenExtendedMiningChannelError -pub const MESSAGE_TYPE_OPEN_MINING_CHANNEL_ERROR: u8 = 0x12; -pub const MESSAGE_TYPE_OPEN_STANDARD_MINING_CHANNEL: u8 = 0x10; -pub const MESSAGE_TYPE_OPEN_STANDARD_MINING_CHANNEL_SUCCESS: u8 = 0x11; -pub const MESSAGE_TYPE_RECONNECT: u8 = 0x25; -pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB: u8 = 0x22; -pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_ERROR: u8 = 0x24; -pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_SUCCESS: u8 = 0x23; -pub const MESSAGE_TYPE_SET_EXTRANONCE_PREFIX: u8 = 0x19; -pub const MESSAGE_TYPE_SET_GROUP_CHANNEL: u8 = 0x26; -pub const MESSAGE_TYPE_MINING_SET_NEW_PREV_HASH: u8 = 0x20; -pub const MESSAGE_TYPE_SET_TARGET: u8 = 0x21; -pub const MESSAGE_TYPE_SUBMIT_SHARES_ERROR: u8 = 0x1d; -pub const MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED: u8 = 0x1b; -pub const MESSAGE_TYPE_SUBMIT_SHARES_STANDARD: u8 = 0x1a; -pub const MESSAGE_TYPE_SUBMIT_SHARES_SUCCESS: u8 = 0x1c; -pub const MESSAGE_TYPE_UPDATE_CHANNEL: u8 = 0x16; -pub const MESSAGE_TYPE_UPDATE_CHANNEL_ERROR: u8 = 0x17; + +/// Template Distribution Protocol message types. +pub const MESSAGE_TYPE_COINBASE_OUTPUT_DATA_SIZE: u8 = 0x70; +pub const MESSAGE_TYPE_NEW_TEMPLATE: u8 = 0x71; +pub const MESSAGE_TYPE_SET_NEW_PREV_HASH: u8 = 0x72; +pub const MESSAGE_TYPE_REQUEST_TRANSACTION_DATA: u8 = 0x73; +pub const MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_SUCCESS: u8 = 0x74; +pub const MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_ERROR: u8 = 0x75; +pub const MESSAGE_TYPE_SUBMIT_SOLUTION: u8 = 0x76; + + +// WHAT'S THE PURPOSE OF THESE CHANNEL BITS??? // COMMON MESSAGES CHANNEL BIT pub const CHANNEL_BIT_SETUP_CONNECTION: bool = false; From 2cfce2e938f4a1763cc5572b697df1a3ce27ad37 Mon Sep 17 00:00:00 2001 From: Gabriele Vernetti Date: Thu, 26 Sep 2024 18:15:19 +0200 Subject: [PATCH 04/14] add README to const_sv2 crate + docs enhancements --- protocols/v2/const-sv2/README.md | 21 +++++++ protocols/v2/const-sv2/src/lib.rs | 97 ++++++++++++++++++++----------- 2 files changed, 84 insertions(+), 34 deletions(-) create mode 100644 protocols/v2/const-sv2/README.md diff --git a/protocols/v2/const-sv2/README.md b/protocols/v2/const-sv2/README.md new file mode 100644 index 0000000000..b8084d4547 --- /dev/null +++ b/protocols/v2/const-sv2/README.md @@ -0,0 +1,21 @@ +# const_sv2 + +[![crates.io](https://img.shields.io/crates/v/const_sv2.svg)](https://crates.io/crates/const_sv2) +[![docs.rs](https://docs.rs/const_sv2/badge.svg)](https://docs.rs/const_sv2) + +`const_sv2` is a Rust crate that provides essential constants for the SV2 (Stratum V2) protocol. These constants are crucial for message framing, encryption, and protocol-specific identifiers across various SV2 components, including Mining, Job Declaration, and Template Distribution protocols. + +## Features + +- **Protocol Constants**: Define key protocol discriminants, message types, and sizes for the SV2 binary protocol. +- **Encryption Support**: Includes constants for encryption using ChaChaPoly and ElligatorSwift encoding. +- **Channel Bits**: Defines whether specific messages are associated with a channel, simplifying protocol handling. +- **Modular**: Supports a `no_std` environment, enabling use in embedded systems or environments without a standard library. + +## Usage + +To use this crate, add it to your `Cargo.toml`: + +```toml +[dependencies] +const_sv2 = "2.0.0" diff --git a/protocols/v2/const-sv2/src/lib.rs b/protocols/v2/const-sv2/src/lib.rs index 4fa934c0b5..3534fbccec 100644 --- a/protocols/v2/const-sv2/src/lib.rs +++ b/protocols/v2/const-sv2/src/lib.rs @@ -1,24 +1,48 @@ //! This crate serves as the central repository for all constants used in the SV2 protocol. //! These constants are essential for message framing, encryption, and protocol-specific -//! identifiers across various SV2 components, including Mining, Job Declaration, and Template Distribution. +//! identifiers across various SV2 components, including Mining, Job Declaration, and Template Distribution protocols. //! //! It also includes definitions for key encryption settings and message types, ensuring consistency and accuracy //! when working with SV2's binary protocol. These constants are used throughout the system to ensure that SV2 //! messages are formatted and interpreted correctly. +//! +//! ### Discriminants for Stratum V2 (sub)protocols +//! Discriminants are unique identifiers used to distinguish between different Stratum V2 (sub)protocols. +//! Each protocol within the SV2 ecosystem has a specific discriminant value that indicates its type, +//! enabling the correct interpretation and handling of messages. +//! These discriminants ensure that messages are processed by the appropriate protocol handlers, +//! thereby facilitating seamless communication across different components of the SV2 architecture. +//! More info at + +//! +//! ### Message Types +//! Message types in the SV2 protocol define the specific operations and data exchanges between participants. +//! Each type corresponds to a distinct action or information transfer, facilitating communication in various +//! contexts such as mining operations, job declarations, and template distribution. Properly identifying and +//! handling these message types is crucial for maintaining protocol compliance and ensuring seamless +//! interactions within the SV2 ecosystem. The message types are categorized into common types and those +//! specific to each subprotocol, providing clarity on their intended use and interaction patterns. +//! +//! ### Channel Bits +//! The `channel bits` indicate whether a message is associated with a specific channel. +//! If the most significant bit of the `extension_type` (referred to as `channel_msg`) is set, +//! the message is related to a channel and includes a `channel_id`. In this case, +//! the first 4 bytes of the payload represent the `channel_id` the message is destined for. #![cfg_attr(feature = "no_std", no_std)] /// Identifier for the extension_type field in the SV2 frame, indicating no extensions. -// SHOULD WE DEFINE IT? It's not used anywhere than ffi pub const EXTENSION_TYPE_NO_EXTENSION: u16 = 0; /// Size of the SV2 frame header in bytes. pub const SV2_FRAME_HEADER_SIZE: usize = 6; -// WHAT IS THIS? It's not used anywhere, just declared in ffi +// It's not used anywhere. +// Refactoring: deprecate it. pub const SV2_FRAME_HEADER_LEN_OFFSET: usize = 3; -// WHAT IS THIS? It's not used anywhere, just declared in ffi +// It's not used anywhere. +// Refactoring: deprecate it. pub const SV2_FRAME_HEADER_LEN_END: usize = 3; /// Maximum size of an SV2 frame chunk in bytes. @@ -28,30 +52,32 @@ pub const SV2_FRAME_CHUNK_SIZE: usize = 65535; pub const AEAD_MAC_LEN: usize = 16; /// Size of the encrypted SV2 frame header, including the MAC. -// Declared in ffi, and imported in framing_sv2/src/header.rs -// TAKE NOTE: header.rs is then imported into codec_sv2 just for this constant +// Refactoring: declared in sv2-ffi, and imported in framing_sv2/src/header.rs +// header.rs is then imported into codec_sv2 just for this constant pub const ENCRYPTED_SV2_FRAME_HEADER_SIZE: usize = SV2_FRAME_HEADER_SIZE + AEAD_MAC_LEN; /// Size of the Noise protocol frame header in bytes. -// Declared in ffi, and imported in framing_sv2/src/header.rs -// TAKE NOTE: header.rs is then imported into codec_sv2 just for this constant +// Refactoring: declared in sv2-ffi, and imported in framing_sv2/src/header.rs +// header.rs is then imported into codec_sv2 just for this constant pub const NOISE_FRAME_HEADER_SIZE: usize = 2; -// Declared in ffi, and imported in framing_sv2/src/header.rs -// TAKE NOTE: header.rs is then imported into codec_sv2 just for this constant, and the const there is not even used +// Refactoring: declared in sv2-ffi, and imported in framing_sv2/src/header.rs +// header.rs is then imported into codec_sv2 just for this constant, and the const there is not even used pub const NOISE_FRAME_HEADER_LEN_OFFSET: usize = 0; -// WHAT IS THIS? It's not used anywhere +// It's not used anywhere. +// Refactoring: deprecate it. pub const NOISE_FRAME_MAX_SIZE: usize = u16::MAX as usize; /// Size in bytes of the encoded elliptic curve point using ElligatorSwift encoding. /// This encoding produces a 64-byte representation of the X-coordinate of a secp256k1 curve point. pub const ELLSWIFT_ENCODING_SIZE: usize = 64; -// Does it make sense to just create an alias for this here? I think it could be created where it's imported +// Refactoring: the alias could be created where it's imported, or we could just use one name everywhere pub const RESPONDER_EXPECTED_HANDSHAKE_MESSAGE_SIZE: usize = ELLSWIFT_ENCODING_SIZE; -// Is this a different MAC with respect to the f ? +// This is the same as AEAD_MAC_LEN. +// Refactoring: deprecate it. pub const MAC: usize = 16; /// Size in bytes of the encrypted ElligatorSwift encoded data, which includes the original @@ -77,8 +103,7 @@ pub const INITIATOR_EXPECTED_HANDSHAKE_MESSAGE_SIZE: usize = ELLSWIFT_ENCODING_S /// If protocolName is less than or equal to 32 bytes in length, use protocolName with zero bytes /// appended to make 32 bytes. Otherwise, apply HASH to it. For name = /// "Noise_NX_Secp256k1+EllSwift_ChaChaPoly_SHA256", we need the hash. -/// More info at https://github.com/stratum-mining/sv2-spec/blob/main/04-Protocol-Security.md#451 -/// -handshake-act-1-nx-handshake-part-1---e +/// More info at pub const NOISE_HASHED_PROTOCOL_NAME_CHACHA: [u8; 32] = [ 46, 180, 120, 129, 32, 142, 158, 238, 31, 102, 159, 103, 198, 110, 231, 14, 169, 234, 136, 9, 13, 80, 63, 232, 48, 220, 75, 200, 62, 41, 191, 16, @@ -86,28 +111,29 @@ pub const NOISE_HASHED_PROTOCOL_NAME_CHACHA: [u8; 32] = [ // len = 1 // 47,53,45,41 = AESG -// SHOULDN'T WE REMOVE THIS? +// We're dropping support for AESG. +// Refactoring: deprecate it. pub const NOISE_SUPPORTED_CIPHERS_MESSAGE: [u8; 5] = [1, 0x47, 0x53, 0x45, 0x41]; -/// Discriminants for distinct Stratum V2 (sub)protocols. More info at https://github.com/stratum- -/// mining/sv2-spec/blob/main/03-Protocol-Overview.md#3-protocol-overview +// Discriminants for distinct Stratum V2 (sub)protocols. More info at https://github.com/stratum- +// mining/sv2-spec/blob/main/03-Protocol-Overview.md#3-protocol-overview pub const SV2_MINING_PROTOCOL_DISCRIMINANT: u8 = 0; pub const SV2_JOB_DECLARATION_PROTOCOL_DISCRIMINANT: u8 = 1; -// RENAME in SV2_TEMPLATE_DISTRIBUTION_PROTOCOL_DISCRIMINANT +// Refactoring: rename this into SV2_TEMPLATE_DISTRIBUTION_PROTOCOL_DISCRIMINANT pub const SV2_TEMPLATE_DISTR_PROTOCOL_DISCRIMINANT: u8 = 2; -/// Common message types used across all Stratum V2 (sub)protocols. +// Common message types used across all Stratum V2 (sub)protocols. pub const MESSAGE_TYPE_SETUP_CONNECTION: u8 = 0x0; pub const MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS: u8 = 0x1; pub const MESSAGE_TYPE_SETUP_CONNECTION_ERROR: u8 = 0x2; pub const MESSAGE_TYPE_CHANNEL_ENDPOINT_CHANGED: u8 = 0x3; -/// Mining Protocol message types. +// Mining Protocol message types. pub const MESSAGE_TYPE_OPEN_STANDARD_MINING_CHANNEL: u8 = 0x10; pub const MESSAGE_TYPE_OPEN_STANDARD_MINING_CHANNEL_SUCCESS: u8 = 0x11; pub const MESSAGE_TYPE_OPEN_MINING_CHANNEL_ERROR: u8 = 0x12; pub const MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL: u8 = 0x13; -// Typo: MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL_SUCCESS +// Refactoring: fix typo with MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL_SUCCESS pub const MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL_SUCCES: u8 = 0x14; pub const MESSAGE_TYPE_NEW_MINING_JOB: u8 = 0x15; pub const MESSAGE_TYPE_UPDATE_CHANNEL: u8 = 0x16; @@ -125,11 +151,11 @@ pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB: u8 = 0x22; pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_SUCCESS: u8 = 0x23; pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_ERROR: u8 = 0x24; -// WE NEED TO MOVE THIS to 0x04 AND SHIFT the SETGROUPCHANNEL to 0x25 (we are not specs compliant now) +// Refactoring: we need to move this to 0x04 and shift SETGROUPCHANNEL to 0x25 (we are not specs compliant now) pub const MESSAGE_TYPE_RECONNECT: u8 = 0x25; pub const MESSAGE_TYPE_SET_GROUP_CHANNEL: u8 = 0x26; -/// Job Declaration Protocol message types. +// Job Declaration Protocol message types. pub const MESSAGE_TYPE_ALLOCATE_MINING_JOB_TOKEN: u8 = 0x50; pub const MESSAGE_TYPE_ALLOCATE_MINING_JOB_TOKEN_SUCCESS: u8 = 0x51; pub const MESSAGE_TYPE_IDENTIFY_TRANSACTIONS: u8 = 0x53; @@ -141,7 +167,7 @@ pub const MESSAGE_TYPE_DECLARE_MINING_JOB_SUCCESS: u8 = 0x58; pub const MESSAGE_TYPE_DECLARE_MINING_JOB_ERROR: u8 = 0x59; pub const MESSAGE_TYPE_SUBMIT_SOLUTION_JD: u8 = 0x60; -/// Template Distribution Protocol message types. +// Template Distribution Protocol message types. pub const MESSAGE_TYPE_COINBASE_OUTPUT_DATA_SIZE: u8 = 0x70; pub const MESSAGE_TYPE_NEW_TEMPLATE: u8 = 0x71; pub const MESSAGE_TYPE_SET_NEW_PREV_HASH: u8 = 0x72; @@ -150,15 +176,18 @@ pub const MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_SUCCESS: u8 = 0x74; pub const MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_ERROR: u8 = 0x75; pub const MESSAGE_TYPE_SUBMIT_SOLUTION: u8 = 0x76; +// The `channel bits` indicate whether a message is associated with a specific channel. +// If the most significant bit of the `extension_type` (referred to as `channel_msg`) is set, +// the message is related to a channel and includes a `channel_id`. In this case, +// the first 4 bytes of the payload represent the `channel_id` the message is destined for. +// For the Job Declaration and Template Distribution protocols, the `channel_msg` bit is always unset. -// WHAT'S THE PURPOSE OF THESE CHANNEL BITS??? - -// COMMON MESSAGES CHANNEL BIT pub const CHANNEL_BIT_SETUP_CONNECTION: bool = false; pub const CHANNEL_BIT_SETUP_CONNECTION_SUCCESS: bool = false; pub const CHANNEL_BIT_SETUP_CONNECTION_ERROR: bool = false; pub const CHANNEL_BIT_CHANNEL_ENDPOINT_CHANGED: bool = true; -// TEMPLATE DISTRIBUTION PROTOCOL MESSAGES CHANNEL BIT + +// For the Template Distribution protocol, the channel bit is always unset. pub const CHANNEL_BIT_COINBASE_OUTPUT_DATA_SIZE: bool = false; pub const CHANNEL_BIT_NEW_TEMPLATE: bool = false; pub const CHANNEL_BIT_SET_NEW_PREV_HASH: bool = false; @@ -166,7 +195,9 @@ pub const CHANNEL_BIT_REQUEST_TRANSACTION_DATA: bool = false; pub const CHANNEL_BIT_REQUEST_TRANSACTION_DATA_SUCCESS: bool = false; pub const CHANNEL_BIT_REQUEST_TRANSACTION_DATA_ERROR: bool = false; pub const CHANNEL_BIT_SUBMIT_SOLUTION: bool = false; -// JOB DECLARATION PROTOCOL MESSAGES CHANNEL BIT + +// In the Job Declaration protocol, the `channel_msg` bit is always unset, +// except for `SUBMIT_SOLUTION_JD`, which requires a specific channel reference. pub const CHANNEL_BIT_ALLOCATE_MINING_JOB_TOKEN: bool = false; pub const CHANNEL_BIT_ALLOCATE_MINING_JOB_TOKEN_SUCCESS: bool = false; pub const CHANNEL_BIT_DECLARE_MINING_JOB: bool = false; @@ -177,15 +208,13 @@ pub const CHANNEL_BIT_IDENTIFY_TRANSACTIONS_SUCCESS: bool = false; pub const CHANNEL_BIT_PROVIDE_MISSING_TRANSACTIONS: bool = false; pub const CHANNEL_BIT_PROVIDE_MISSING_TRANSACTIONS_SUCCESS: bool = false; pub const CHANNEL_BIT_SUBMIT_SOLUTION_JD: bool = true; -// MINING PROTOCOL MESSAGES CHANNEL BIT + +// Channel bits in the Mining protocol vary depending on the message. pub const CHANNEL_BIT_CLOSE_CHANNEL: bool = true; pub const CHANNEL_BIT_NEW_EXTENDED_MINING_JOB: bool = true; pub const CHANNEL_BIT_NEW_MINING_JOB: bool = true; pub const CHANNEL_BIT_OPEN_EXTENDED_MINING_CHANNEL: bool = false; pub const CHANNEL_BIT_OPEN_EXTENDED_MINING_CHANNEL_SUCCES: bool = false; -// in the spec page 21 is defined OpenMiningChannelError valid for both extended and standard -// messages but in the spec page 40 are defined two different message types for -// OpenStandardMiningChannelError and OpenExtendedMiningChannelError pub const CHANNEL_BIT_OPEN_MINING_CHANNEL_ERROR: bool = false; pub const CHANNEL_BIT_OPEN_STANDARD_MINING_CHANNEL: bool = false; pub const CHANNEL_BIT_OPEN_STANDARD_MINING_CHANNEL_SUCCESS: bool = false; From a3f7b261d674330a53b04a147da301c133cc1a43 Mon Sep 17 00:00:00 2001 From: Gabriele Vernetti Date: Thu, 26 Sep 2024 19:04:30 +0200 Subject: [PATCH 05/14] update header after `const_sv2` crate documentation --- protocols/v2/const-sv2/README.md | 2 +- protocols/v2/const-sv2/src/lib.rs | 102 ++++++++++++++++------------- protocols/v2/sv2-ffi/sv2.h | 103 ++++++++++++++++++------------ 3 files changed, 122 insertions(+), 85 deletions(-) diff --git a/protocols/v2/const-sv2/README.md b/protocols/v2/const-sv2/README.md index b8084d4547..1c919b895c 100644 --- a/protocols/v2/const-sv2/README.md +++ b/protocols/v2/const-sv2/README.md @@ -5,7 +5,7 @@ `const_sv2` is a Rust crate that provides essential constants for the SV2 (Stratum V2) protocol. These constants are crucial for message framing, encryption, and protocol-specific identifiers across various SV2 components, including Mining, Job Declaration, and Template Distribution protocols. -## Features +## Main Components - **Protocol Constants**: Define key protocol discriminants, message types, and sizes for the SV2 binary protocol. - **Encryption Support**: Includes constants for encryption using ChaChaPoly and ElligatorSwift encoding. diff --git a/protocols/v2/const-sv2/src/lib.rs b/protocols/v2/const-sv2/src/lib.rs index 3534fbccec..2e248a6334 100644 --- a/protocols/v2/const-sv2/src/lib.rs +++ b/protocols/v2/const-sv2/src/lib.rs @@ -1,37 +1,45 @@ -//! This crate serves as the central repository for all constants used in the SV2 protocol. -//! These constants are essential for message framing, encryption, and protocol-specific -//! identifiers across various SV2 components, including Mining, Job Declaration, and Template Distribution protocols. +//! This crate provides all constants used in the SV2 protocol. +//! These constants are essential for message framing, encryption, and +//! protocol-specific identifiers across various SV2 components, including +//! Mining, Job Declaration, and Template Distribution protocols. //! -//! It also includes definitions for key encryption settings and message types, ensuring consistency and accuracy -//! when working with SV2's binary protocol. These constants are used throughout the system to ensure that SV2 +//! It also includes definitions for key encryption settings and message types, +//! ensuring consistency and accuracy when working with SV2's binary protocol. +//! These constants are used throughout the system to ensure that SV2 //! messages are formatted and interpreted correctly. //! //! ### Discriminants for Stratum V2 (sub)protocols -//! Discriminants are unique identifiers used to distinguish between different Stratum V2 (sub)protocols. -//! Each protocol within the SV2 ecosystem has a specific discriminant value that indicates its type, -//! enabling the correct interpretation and handling of messages. -//! These discriminants ensure that messages are processed by the appropriate protocol handlers, -//! thereby facilitating seamless communication across different components of the SV2 architecture. -//! More info at +//! Discriminants are unique identifiers used to distinguish between different +//! Stratum V2 (sub)protocols. Each protocol within the SV2 ecosystem has a +//! specific discriminant value that indicates its type, enabling the correct +//! interpretation and handling of messages. These discriminants ensure that +//! messages are processed by the appropriate protocol handlers, +//! thereby facilitating seamless communication across different components of +//! the SV2 architecture. More info can be found [on Chapter 03 of the Stratum V2 specs](https://github.com/stratum-mining/sv2-spec/blob/main/03-Protocol-Overview.md#3-protocol-overview). //! //! ### Message Types -//! Message types in the SV2 protocol define the specific operations and data exchanges between participants. -//! Each type corresponds to a distinct action or information transfer, facilitating communication in various -//! contexts such as mining operations, job declarations, and template distribution. Properly identifying and -//! handling these message types is crucial for maintaining protocol compliance and ensuring seamless -//! interactions within the SV2 ecosystem. The message types are categorized into common types and those -//! specific to each subprotocol, providing clarity on their intended use and interaction patterns. +//! Message types in the SV2 protocol define the specific operations and data +//! exchanges between participants. Each type corresponds to a distinct action +//! or information transfer, facilitating communication in various contexts such +//! as mining operations, job declarations, and template distribution. Properly +//! identifying and handling these message types is crucial for maintaining +//! protocol compliance and ensuring seamless interactions within the SV2 +//! ecosystem. The message types are categorized into common types and those +//! specific to each subprotocol, providing clarity on their intended use and +//! interaction patterns. //! //! ### Channel Bits -//! The `channel bits` indicate whether a message is associated with a specific channel. -//! If the most significant bit of the `extension_type` (referred to as `channel_msg`) is set, -//! the message is related to a channel and includes a `channel_id`. In this case, -//! the first 4 bytes of the payload represent the `channel_id` the message is destined for. +//! The `channel bits` indicate whether a message is associated with a specific +//! channel. If the most significant bit of the `extension_type` (referred to as +//! `channel_msg`) is set, the message is related to a channel and includes a +//! `channel_id`. In this case, the first 4 bytes of the payload represent the +//! `channel_id` the message is destined for. #![cfg_attr(feature = "no_std", no_std)] -/// Identifier for the extension_type field in the SV2 frame, indicating no extensions. +/// Identifier for the extension_type field in the SV2 frame, indicating no +/// extensions. pub const EXTENSION_TYPE_NO_EXTENSION: u16 = 0; /// Size of the SV2 frame header in bytes. @@ -62,37 +70,43 @@ pub const ENCRYPTED_SV2_FRAME_HEADER_SIZE: usize = SV2_FRAME_HEADER_SIZE + AEAD_ pub const NOISE_FRAME_HEADER_SIZE: usize = 2; // Refactoring: declared in sv2-ffi, and imported in framing_sv2/src/header.rs -// header.rs is then imported into codec_sv2 just for this constant, and the const there is not even used +// header.rs is then imported into codec_sv2 just for this constant, and the +// const there is not even used pub const NOISE_FRAME_HEADER_LEN_OFFSET: usize = 0; // It's not used anywhere. // Refactoring: deprecate it. pub const NOISE_FRAME_MAX_SIZE: usize = u16::MAX as usize; -/// Size in bytes of the encoded elliptic curve point using ElligatorSwift encoding. -/// This encoding produces a 64-byte representation of the X-coordinate of a secp256k1 curve point. +/// Size in bytes of the encoded elliptic curve point using ElligatorSwift +/// encoding. This encoding produces a 64-byte representation of the +/// X-coordinate of a secp256k1 curve point. pub const ELLSWIFT_ENCODING_SIZE: usize = 64; -// Refactoring: the alias could be created where it's imported, or we could just use one name everywhere +// Refactoring: the alias could be created where it's imported, or we could just +// use one name everywhere pub const RESPONDER_EXPECTED_HANDSHAKE_MESSAGE_SIZE: usize = ELLSWIFT_ENCODING_SIZE; // This is the same as AEAD_MAC_LEN. // Refactoring: deprecate it. pub const MAC: usize = 16; -/// Size in bytes of the encrypted ElligatorSwift encoded data, which includes the original -/// ElligatorSwift encoded data and a MAC for integrity verification. +/// Size in bytes of the encrypted ElligatorSwift encoded data, which includes +/// the original ElligatorSwift encoded data and a MAC for integrity +/// verification. pub const ENCRYPTED_ELLSWIFT_ENCODING_SIZE: usize = ELLSWIFT_ENCODING_SIZE + MAC; -/// Size in bytes of the SIGNATURE_NOISE_MESSAGE, which contains information and a signature -/// for the handshake initiator, formatted according to the Noise Protocol specifications. +/// Size in bytes of the SIGNATURE_NOISE_MESSAGE, which contains information and +/// a signature for the handshake initiator, formatted according to the Noise +/// Protocol specifications. pub const SIGNATURE_NOISE_MESSAGE_SIZE: usize = 74; -/// Size in bytes of the encrypted signature noise message, which includes the SIGNATURE_NOISE_MESSAGE -/// and a MAC for integrity verification. +/// Size in bytes of the encrypted signature noise message, which includes the +/// SIGNATURE_NOISE_MESSAGE and a MAC for integrity verification. pub const ENCRYPTED_SIGNATURE_NOISE_MESSAGE_SIZE: usize = SIGNATURE_NOISE_MESSAGE_SIZE + MAC; -/// Size in bytes of the handshake message expected by the initiator, encompassing: +/// Size in bytes of the handshake message expected by the initiator, +/// encompassing: /// - ElligatorSwift encoded public key /// - Encrypted ElligatorSwift encoding /// - Encrypted SIGNATURE_NOISE_MESSAGE @@ -100,10 +114,10 @@ pub const INITIATOR_EXPECTED_HANDSHAKE_MESSAGE_SIZE: usize = ELLSWIFT_ENCODING_S + ENCRYPTED_ELLSWIFT_ENCODING_SIZE + ENCRYPTED_SIGNATURE_NOISE_MESSAGE_SIZE; -/// If protocolName is less than or equal to 32 bytes in length, use protocolName with zero bytes -/// appended to make 32 bytes. Otherwise, apply HASH to it. For name = -/// "Noise_NX_Secp256k1+EllSwift_ChaChaPoly_SHA256", we need the hash. -/// More info at +/// If protocolName is less than or equal to 32 bytes in length, use +/// protocolName with zero bytes appended to make 32 bytes. Otherwise, apply +/// HASH to it. For name = "Noise_NX_Secp256k1+EllSwift_ChaChaPoly_SHA256", we +/// need the hash. More info can be found [at this link](https://github.com/stratum-mining/sv2-spec/blob/main/04-Protocol-Security.md#451-handshake-act-1-nx-handshake-part-1---e). pub const NOISE_HASHED_PROTOCOL_NAME_CHACHA: [u8; 32] = [ 46, 180, 120, 129, 32, 142, 158, 238, 31, 102, 159, 103, 198, 110, 231, 14, 169, 234, 136, 9, 13, 80, 63, 232, 48, 220, 75, 200, 62, 41, 191, 16, @@ -151,7 +165,8 @@ pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB: u8 = 0x22; pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_SUCCESS: u8 = 0x23; pub const MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_ERROR: u8 = 0x24; -// Refactoring: we need to move this to 0x04 and shift SETGROUPCHANNEL to 0x25 (we are not specs compliant now) +// Refactoring: we need to move this to 0x04 and shift SETGROUPCHANNEL to 0x25 +// (we are not specs compliant now) pub const MESSAGE_TYPE_RECONNECT: u8 = 0x25; pub const MESSAGE_TYPE_SET_GROUP_CHANNEL: u8 = 0x26; @@ -176,11 +191,12 @@ pub const MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_SUCCESS: u8 = 0x74; pub const MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_ERROR: u8 = 0x75; pub const MESSAGE_TYPE_SUBMIT_SOLUTION: u8 = 0x76; -// The `channel bits` indicate whether a message is associated with a specific channel. -// If the most significant bit of the `extension_type` (referred to as `channel_msg`) is set, -// the message is related to a channel and includes a `channel_id`. In this case, -// the first 4 bytes of the payload represent the `channel_id` the message is destined for. -// For the Job Declaration and Template Distribution protocols, the `channel_msg` bit is always unset. +// The `channel bits` indicate whether a message is associated with a specific +// channel. If the most significant bit of the `extension_type` (referred to as +// `channel_msg`) is set, the message is related to a channel and includes a +// `channel_id`. In this case, the first 4 bytes of the payload represent the +// `channel_id` the message is destined for. For the Job Declaration and +// Template Distribution protocols, the `channel_msg` bit is always unset. pub const CHANNEL_BIT_SETUP_CONNECTION: bool = false; pub const CHANNEL_BIT_SETUP_CONNECTION_SUCCESS: bool = false; diff --git a/protocols/v2/sv2-ffi/sv2.h b/protocols/v2/sv2-ffi/sv2.h index 8c941fff9b..23fbc98076 100644 --- a/protocols/v2/sv2-ffi/sv2.h +++ b/protocols/v2/sv2-ffi/sv2.h @@ -4,36 +4,59 @@ #include #include +/// Identifier for the extension_type field in the SV2 frame, indicating no +/// extensions. static const uint16_t EXTENSION_TYPE_NO_EXTENSION = 0; +/// Size of the SV2 frame header in bytes. static const uintptr_t SV2_FRAME_HEADER_SIZE = 6; static const uintptr_t SV2_FRAME_HEADER_LEN_OFFSET = 3; static const uintptr_t SV2_FRAME_HEADER_LEN_END = 3; +/// Maximum size of an SV2 frame chunk in bytes. static const uintptr_t SV2_FRAME_CHUNK_SIZE = 65535; +/// Size of the MAC for supported AEAD encryption algorithm (ChaChaPoly). static const uintptr_t AEAD_MAC_LEN = 16; +/// Size of the encrypted SV2 frame header, including the MAC. static const uintptr_t ENCRYPTED_SV2_FRAME_HEADER_SIZE = (SV2_FRAME_HEADER_SIZE + AEAD_MAC_LEN); +/// Size of the Noise protocol frame header in bytes. static const uintptr_t NOISE_FRAME_HEADER_SIZE = 2; static const uintptr_t NOISE_FRAME_HEADER_LEN_OFFSET = 0; +/// Size in bytes of the encoded elliptic curve point using ElligatorSwift +/// encoding. This encoding produces a 64-byte representation of the +/// X-coordinate of a secp256k1 curve point. static const uintptr_t ELLSWIFT_ENCODING_SIZE = 64; static const uintptr_t RESPONDER_EXPECTED_HANDSHAKE_MESSAGE_SIZE = ELLSWIFT_ENCODING_SIZE; static const uintptr_t MAC = 16; +/// Size in bytes of the encrypted ElligatorSwift encoded data, which includes +/// the original ElligatorSwift encoded data and a MAC for integrity +/// verification. static const uintptr_t ENCRYPTED_ELLSWIFT_ENCODING_SIZE = (ELLSWIFT_ENCODING_SIZE + MAC); +/// Size in bytes of the SIGNATURE_NOISE_MESSAGE, which contains information and +/// a signature for the handshake initiator, formatted according to the Noise +/// Protocol specifications. static const uintptr_t SIGNATURE_NOISE_MESSAGE_SIZE = 74; +/// Size in bytes of the encrypted signature noise message, which includes the +/// SIGNATURE_NOISE_MESSAGE and a MAC for integrity verification. static const uintptr_t ENCRYPTED_SIGNATURE_NOISE_MESSAGE_SIZE = (SIGNATURE_NOISE_MESSAGE_SIZE + MAC); +/// Size in bytes of the handshake message expected by the initiator, +/// encompassing: +/// - ElligatorSwift encoded public key +/// - Encrypted ElligatorSwift encoding +/// - Encrypted SIGNATURE_NOISE_MESSAGE static const uintptr_t INITIATOR_EXPECTED_HANDSHAKE_MESSAGE_SIZE = ((ELLSWIFT_ENCODING_SIZE + ENCRYPTED_ELLSWIFT_ENCODING_SIZE) + ENCRYPTED_SIGNATURE_NOISE_MESSAGE_SIZE); static const uint8_t SV2_MINING_PROTOCOL_DISCRIMINANT = 0; @@ -50,85 +73,83 @@ static const uint8_t MESSAGE_TYPE_SETUP_CONNECTION_ERROR = 2; static const uint8_t MESSAGE_TYPE_CHANNEL_ENDPOINT_CHANGED = 3; -static const uint8_t MESSAGE_TYPE_COINBASE_OUTPUT_DATA_SIZE = 112; +static const uint8_t MESSAGE_TYPE_OPEN_STANDARD_MINING_CHANNEL = 16; -static const uint8_t MESSAGE_TYPE_NEW_TEMPLATE = 113; +static const uint8_t MESSAGE_TYPE_OPEN_STANDARD_MINING_CHANNEL_SUCCESS = 17; -static const uint8_t MESSAGE_TYPE_SET_NEW_PREV_HASH = 114; +static const uint8_t MESSAGE_TYPE_OPEN_MINING_CHANNEL_ERROR = 18; -static const uint8_t MESSAGE_TYPE_REQUEST_TRANSACTION_DATA = 115; +static const uint8_t MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL = 19; -static const uint8_t MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_SUCCESS = 116; +static const uint8_t MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL_SUCCES = 20; -static const uint8_t MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_ERROR = 117; +static const uint8_t MESSAGE_TYPE_NEW_MINING_JOB = 21; -static const uint8_t MESSAGE_TYPE_SUBMIT_SOLUTION = 118; +static const uint8_t MESSAGE_TYPE_UPDATE_CHANNEL = 22; -static const uint8_t MESSAGE_TYPE_ALLOCATE_MINING_JOB_TOKEN = 80; +static const uint8_t MESSAGE_TYPE_UPDATE_CHANNEL_ERROR = 23; -static const uint8_t MESSAGE_TYPE_ALLOCATE_MINING_JOB_TOKEN_SUCCESS = 81; +static const uint8_t MESSAGE_TYPE_CLOSE_CHANNEL = 24; -static const uint8_t MESSAGE_TYPE_DECLARE_MINING_JOB = 87; +static const uint8_t MESSAGE_TYPE_SET_EXTRANONCE_PREFIX = 25; -static const uint8_t MESSAGE_TYPE_DECLARE_MINING_JOB_SUCCESS = 88; +static const uint8_t MESSAGE_TYPE_SUBMIT_SHARES_STANDARD = 26; -static const uint8_t MESSAGE_TYPE_DECLARE_MINING_JOB_ERROR = 89; +static const uint8_t MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED = 27; -static const uint8_t MESSAGE_TYPE_IDENTIFY_TRANSACTIONS = 83; +static const uint8_t MESSAGE_TYPE_SUBMIT_SHARES_SUCCESS = 28; -static const uint8_t MESSAGE_TYPE_IDENTIFY_TRANSACTIONS_SUCCESS = 84; +static const uint8_t MESSAGE_TYPE_SUBMIT_SHARES_ERROR = 29; -static const uint8_t MESSAGE_TYPE_PROVIDE_MISSING_TRANSACTIONS = 85; +static const uint8_t MESSAGE_TYPE_NEW_EXTENDED_MINING_JOB = 31; -static const uint8_t MESSAGE_TYPE_PROVIDE_MISSING_TRANSACTIONS_SUCCESS = 86; +static const uint8_t MESSAGE_TYPE_MINING_SET_NEW_PREV_HASH = 32; -static const uint8_t MESSAGE_TYPE_SUBMIT_SOLUTION_JD = 96; +static const uint8_t MESSAGE_TYPE_SET_TARGET = 33; -static const uint8_t MESSAGE_TYPE_CLOSE_CHANNEL = 24; +static const uint8_t MESSAGE_TYPE_SET_CUSTOM_MINING_JOB = 34; -/// This has been cahnged before was 0x1e it can be that old Sv2 implementation still use the old -/// one but this means that old impl are not following Sv2 spec -static const uint8_t MESSAGE_TYPE_NEW_EXTENDED_MINING_JOB = 31; +static const uint8_t MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_SUCCESS = 35; -static const uint8_t MESSAGE_TYPE_NEW_MINING_JOB = 21; +static const uint8_t MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_ERROR = 36; -static const uint8_t MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL = 19; +static const uint8_t MESSAGE_TYPE_RECONNECT = 37; -static const uint8_t MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL_SUCCES = 20; +static const uint8_t MESSAGE_TYPE_SET_GROUP_CHANNEL = 38; -static const uint8_t MESSAGE_TYPE_OPEN_MINING_CHANNEL_ERROR = 18; +static const uint8_t MESSAGE_TYPE_ALLOCATE_MINING_JOB_TOKEN = 80; -static const uint8_t MESSAGE_TYPE_OPEN_STANDARD_MINING_CHANNEL = 16; +static const uint8_t MESSAGE_TYPE_ALLOCATE_MINING_JOB_TOKEN_SUCCESS = 81; -static const uint8_t MESSAGE_TYPE_OPEN_STANDARD_MINING_CHANNEL_SUCCESS = 17; +static const uint8_t MESSAGE_TYPE_IDENTIFY_TRANSACTIONS = 83; -static const uint8_t MESSAGE_TYPE_RECONNECT = 37; +static const uint8_t MESSAGE_TYPE_IDENTIFY_TRANSACTIONS_SUCCESS = 84; -static const uint8_t MESSAGE_TYPE_SET_CUSTOM_MINING_JOB = 34; +static const uint8_t MESSAGE_TYPE_PROVIDE_MISSING_TRANSACTIONS = 85; -static const uint8_t MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_ERROR = 36; +static const uint8_t MESSAGE_TYPE_PROVIDE_MISSING_TRANSACTIONS_SUCCESS = 86; -static const uint8_t MESSAGE_TYPE_SET_CUSTOM_MINING_JOB_SUCCESS = 35; +static const uint8_t MESSAGE_TYPE_DECLARE_MINING_JOB = 87; -static const uint8_t MESSAGE_TYPE_SET_EXTRANONCE_PREFIX = 25; +static const uint8_t MESSAGE_TYPE_DECLARE_MINING_JOB_SUCCESS = 88; -static const uint8_t MESSAGE_TYPE_SET_GROUP_CHANNEL = 38; +static const uint8_t MESSAGE_TYPE_DECLARE_MINING_JOB_ERROR = 89; -static const uint8_t MESSAGE_TYPE_MINING_SET_NEW_PREV_HASH = 32; +static const uint8_t MESSAGE_TYPE_SUBMIT_SOLUTION_JD = 96; -static const uint8_t MESSAGE_TYPE_SET_TARGET = 33; +static const uint8_t MESSAGE_TYPE_COINBASE_OUTPUT_DATA_SIZE = 112; -static const uint8_t MESSAGE_TYPE_SUBMIT_SHARES_ERROR = 29; +static const uint8_t MESSAGE_TYPE_NEW_TEMPLATE = 113; -static const uint8_t MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED = 27; +static const uint8_t MESSAGE_TYPE_SET_NEW_PREV_HASH = 114; -static const uint8_t MESSAGE_TYPE_SUBMIT_SHARES_STANDARD = 26; +static const uint8_t MESSAGE_TYPE_REQUEST_TRANSACTION_DATA = 115; -static const uint8_t MESSAGE_TYPE_SUBMIT_SHARES_SUCCESS = 28; +static const uint8_t MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_SUCCESS = 116; -static const uint8_t MESSAGE_TYPE_UPDATE_CHANNEL = 22; +static const uint8_t MESSAGE_TYPE_REQUEST_TRANSACTION_DATA_ERROR = 117; -static const uint8_t MESSAGE_TYPE_UPDATE_CHANNEL_ERROR = 23; +static const uint8_t MESSAGE_TYPE_SUBMIT_SOLUTION = 118; static const bool CHANNEL_BIT_SETUP_CONNECTION = false; From febdda0223e9d32e4b36ab870d478b2b4a56a435 Mon Sep 17 00:00:00 2001 From: plebhash Date: Sat, 5 Oct 2024 12:51:09 -0300 Subject: [PATCH 06/14] fix network_helpers_sv2 import on mining_pool mod --- roles/pool/src/lib/mining_pool/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/pool/src/lib/mining_pool/mod.rs b/roles/pool/src/lib/mining_pool/mod.rs index ac756bf8ac..008975a5a7 100644 --- a/roles/pool/src/lib/mining_pool/mod.rs +++ b/roles/pool/src/lib/mining_pool/mod.rs @@ -402,7 +402,7 @@ impl Pool { debug!("New connection from {}", address); let (receiver, sender): (Receiver, Sender) = - network_helpers::plain_connection_tokio::PlainConnection::new(stream).await; + network_helpers_sv2::plain_connection_tokio::PlainConnection::new(stream).await; handle_result!( status_tx, From e7014dd683cf44bb35788bb58ef7437dbca004ac Mon Sep 17 00:00:00 2001 From: plebhash Date: Tue, 8 Oct 2024 19:10:49 -0300 Subject: [PATCH 07/14] add nominal_hashrate_multiplier CLI arg to mining-device --- roles/test-utils/mining-device/README.md | 28 ++++++++++---- roles/test-utils/mining-device/src/lib/mod.rs | 37 +++++++++++++++---- roles/test-utils/mining-device/src/main.rs | 9 +++++ 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/roles/test-utils/mining-device/README.md b/roles/test-utils/mining-device/README.md index 4065c2c30b..b85bcc6e41 100644 --- a/roles/test-utils/mining-device/README.md +++ b/roles/test-utils/mining-device/README.md @@ -3,16 +3,28 @@ Header only sv2 cpu miner. ``` -Usage: mining-device [OPTIONS] --address-pool +Usage: mining_device [OPTIONS] --address-pool Options: - -p, --pubkey-pool Pool pub key, when left empty the pool certificate is not checked - -i, --id-device Sometimes used by the pool to identify the device - -a, --address-pool Address of the pool in this format ip:port or domain:port - --handicap This value is used to slow down the cpu miner, it represents the number of micro-seconds that are awaited between hashes [default: 0] - --id-user User id, used when a new channel is opened, it can be used by the pool to identify the miner - -h, --help Print help - -V, --version Print version + -p, --pubkey-pool + Pool pub key, when left empty the pool certificate is not checked + -i, --id-device + Sometimes used by the pool to identify the device + -a, --address-pool + Address of the pool in this format ip:port or domain:port + --handicap + This value is used to slow down the cpu miner, it represents the number of micro-seconds that are awaited between hashes [default: 0] + --id-user + User id, used when a new channel is opened, it can be used by the pool to identify the miner + --nominal-hashrate-multiplier + This floating point number is used to modify the advertised nominal hashrate when opening a channel with the upstream. + If 0.0 < nominal_hashrate_multiplier < 1.0, the CPU miner will advertise a nominal hashrate that is smaller than its real capacity. + If nominal_hashrate_multiplier > 1.0, the CPU miner will advertise a nominal hashrate that is bigger than its real capacity. + If empty, the CPU miner will simply advertise its real capacity. + -h, --help + Print help + -V, --version + Print version ``` Usage example: diff --git a/roles/test-utils/mining-device/src/lib/mod.rs b/roles/test-utils/mining-device/src/lib/mod.rs index abfa1d9691..b1ce7a0498 100644 --- a/roles/test-utils/mining-device/src/lib/mod.rs +++ b/roles/test-utils/mining-device/src/lib/mod.rs @@ -42,6 +42,7 @@ pub async fn connect( device_id: Option, user_id: Option, handicap: u32, + nominal_hashrate_multiplier: Option, ) { let address = address .clone() @@ -77,7 +78,16 @@ pub async fn connect( .await .unwrap(); info!("Pool noise connection established at {}", address); - Device::start(receiver, sender, address, device_id, user_id, handicap).await + Device::start( + receiver, + sender, + address, + device_id, + user_id, + handicap, + nominal_hashrate_multiplier, + ) + .await } pub type Message = MiningDeviceMessages<'static>; @@ -193,13 +203,22 @@ pub struct Device { notify_changes_to_mining_thread: NewWorkNotifier, } -fn open_channel(device_id: Option) -> OpenStandardMiningChannel<'static> { +fn open_channel( + device_id: Option, + nominal_hashrate_multiplier: Option, + handicap: u32, +) -> OpenStandardMiningChannel<'static> { let user_identity = device_id.unwrap_or_default().try_into().unwrap(); let id: u32 = 10; info!("Measuring CPU hashrate"); let p = std::thread::available_parallelism().unwrap().get() as u32 - 3; - let nominal_hash_rate = measure_hashrate(5) as f32 * p as f32; - info!("Pc hashrate is {}", nominal_hash_rate); + let measured_hashrate = measure_hashrate(5, handicap) as f32 * p as f32; + info!("Measured CPU hashrate is {}", measured_hashrate); + let nominal_hash_rate = match nominal_hashrate_multiplier { + Some(m) => measured_hashrate * m, + None => measured_hashrate, + }; + info!("MINING DEVICE: send open channel with request id {}", id); OpenStandardMiningChannel { request_id: id.into(), @@ -217,6 +236,7 @@ impl Device { device_id: Option, user_id: Option, handicap: u32, + nominal_hashrate_multiplier: Option, ) { let setup_connection_handler = Arc::new(Mutex::new(SetupConnectionHandler::new())); SetupConnectionHandler::setup( @@ -244,8 +264,9 @@ impl Device { sender: notify_changes_to_mining_thread, }, }; - let open_channel = - MiningDeviceMessages::Mining(Mining::OpenStandardMiningChannel(open_channel(user_id))); + let open_channel = MiningDeviceMessages::Mining(Mining::OpenStandardMiningChannel( + open_channel(user_id, nominal_hashrate_multiplier, handicap), + )); let frame: StdFrame = open_channel.try_into().unwrap(); self_.sender.send(frame.into()).await.unwrap(); let self_mutex = std::sync::Arc::new(Mutex::new(self_)); @@ -597,7 +618,7 @@ impl NextShareOutcome { } // returns hashrate based on how fast the device hashes over the given duration -fn measure_hashrate(duration_secs: u64) -> f64 { +fn measure_hashrate(duration_secs: u64, handicap: u32) -> f64 { let mut rng = thread_rng(); let prev_hash: [u8; 32] = generate_random_32_byte_array().to_vec().try_into().unwrap(); let prev_hash = Hash::from_inner(prev_hash); @@ -619,7 +640,7 @@ fn measure_hashrate(duration_secs: u64) -> f64 { let start_time = Instant::now(); let mut hashes: u64 = 0; let duration = Duration::from_secs(duration_secs); - let mut miner = Miner::new(0); + let mut miner = Miner::new(handicap); // We put the target to 0 we are only interested in how many hashes per unit of time we can do // and do not want to be botherd by messages about valid shares found. miner.new_target(vec![0_u8; 32]); diff --git a/roles/test-utils/mining-device/src/main.rs b/roles/test-utils/mining-device/src/main.rs index 02a19c12f0..74bff1b3f2 100644 --- a/roles/test-utils/mining-device/src/main.rs +++ b/roles/test-utils/mining-device/src/main.rs @@ -39,6 +39,14 @@ struct Args { help = "User id, used when a new channel is opened, it can be used by the pool to identify the miner" )] id_user: Option, + #[arg( + long, + help = "This floating point number is used to modify the advertised nominal hashrate when opening a channel with the upstream.\ + \nIf 0.0 < nominal_hashrate_multiplier < 1.0, the CPU miner will advertise a nominal hashrate that is smaller than its real capacity.\ + \nIf nominal_hashrate_multiplier > 1.0, the CPU miner will advertise a nominal hashrate that is bigger than its real capacity.\ + \nIf empty, the CPU miner will simply advertise its real capacity." + )] + nominal_hashrate_multiplier: Option, } #[tokio::main(flavor = "current_thread")] @@ -52,6 +60,7 @@ async fn main() { args.id_device, args.id_user, args.handicap, + args.nominal_hashrate_multiplier, ) .await; } From 3b8ade731e710d6659963bc028acf06f0f653910 Mon Sep 17 00:00:00 2001 From: plebhash Date: Tue, 8 Oct 2024 19:48:02 -0300 Subject: [PATCH 08/14] sanitize parallelism --- roles/test-utils/mining-device/src/lib/mod.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/roles/test-utils/mining-device/src/lib/mod.rs b/roles/test-utils/mining-device/src/lib/mod.rs index b1ce7a0498..af4404c58c 100644 --- a/roles/test-utils/mining-device/src/lib/mod.rs +++ b/roles/test-utils/mining-device/src/lib/mod.rs @@ -8,6 +8,7 @@ use std::{ atomic::{AtomicBool, Ordering}, Arc, }, + thread::available_parallelism, time::Duration, }; use tokio::net::TcpStream; @@ -211,8 +212,7 @@ fn open_channel( let user_identity = device_id.unwrap_or_default().try_into().unwrap(); let id: u32 = 10; info!("Measuring CPU hashrate"); - let p = std::thread::available_parallelism().unwrap().get() as u32 - 3; - let measured_hashrate = measure_hashrate(5, handicap) as f32 * p as f32; + let measured_hashrate = measure_hashrate(5, handicap) as f32; info!("Measured CPU hashrate is {}", measured_hashrate); let nominal_hash_rate = match nominal_hashrate_multiplier { Some(m) => measured_hashrate * m, @@ -652,7 +652,12 @@ fn measure_hashrate(duration_secs: u64, handicap: u32) -> f64 { } let elapsed_secs = start_time.elapsed().as_secs_f64(); - hashes as f64 / elapsed_secs + let hashrate_single_thread = hashes as f64 / elapsed_secs; + + // we just measured for a single thread, need to multiply by the available parallelism + let p = available_parallelism().unwrap().get(); + + hashrate_single_thread * p as f64 } fn generate_random_32_byte_array() -> [u8; 32] { let mut rng = thread_rng(); @@ -669,11 +674,7 @@ fn start_mining_threads( tokio::task::spawn(async move { let mut killers: Vec> = vec![]; loop { - let available_parallelism = u32::max( - 2, - std::thread::available_parallelism().unwrap().get() as u32, - ); - let p = available_parallelism - 1; + let p = available_parallelism().unwrap().get() as u32; let unit = u32::MAX / p; while have_new_job.recv().await.is_ok() { while let Some(killer) = killers.pop() { From 1ae28dbdc44879477d8c955eb516f493e8d07565 Mon Sep 17 00:00:00 2001 From: plebhash Date: Wed, 9 Oct 2024 11:55:35 -0300 Subject: [PATCH 09/14] add explanations of handicap and nominal hashrate multiplier --- roles/test-utils/mining-device/README.md | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/roles/test-utils/mining-device/README.md b/roles/test-utils/mining-device/README.md index b85bcc6e41..03ad7241a5 100644 --- a/roles/test-utils/mining-device/README.md +++ b/roles/test-utils/mining-device/README.md @@ -31,3 +31,30 @@ Usage example: ``` cargo run --release -- --address-pool 127.0.0.1:20000 --id-device device_id::SOLO::bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh ``` + +## handicap + +CPU mining could damage the system due to excessive heat. + +The `--handicap` parameter should be used as a safety mechanism to slow down the hashrate in order to preserve hardware. + +## nominal hashrate multiplier + +Let's imagine that: +- the upstream wants to receive shares every ~100s (on average) +- the CPU miner nominal hashrate is 1k H/s + +Maybe we want to do a test where we don't want to wait ~100s before a share is submitted by the CPU miner. + +In that case, we need the CPU miner to advertise a smaller hashrate, which will force the upstream to set a lower +difficulty target. + +The `--nominal-hashrate-multiplier` can be used to advertise a custom nominal hashrate. + +In the scenario described above, we could launch the CPU miner with `--nominal-hashrate-multiplier 0.01`. + +The CPU miner would advertise 0.01k H/s, which would cause the upstream to set the difficulty target such that the CPU miner would find a share within ~1s. + +This feature can also be used to advertise a bigger nominal hashrate by using values above `1.0`. + +That can also be useful for testing difficulty adjustment algorithms on Sv2 upstreams. \ No newline at end of file From 09b2833261a0096fd742a740f4f44b2c9ad1abf2 Mon Sep 17 00:00:00 2001 From: Gabriele Vernetti Date: Wed, 9 Oct 2024 12:22:44 +0200 Subject: [PATCH 10/14] README update to comply with docs standards const_sv2 crate description update --- protocols/v2/const-sv2/Cargo.toml | 2 +- protocols/v2/const-sv2/README.md | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/protocols/v2/const-sv2/Cargo.toml b/protocols/v2/const-sv2/Cargo.toml index 1a74cfa0b3..5d37e77abd 100644 --- a/protocols/v2/const-sv2/Cargo.toml +++ b/protocols/v2/const-sv2/Cargo.toml @@ -3,7 +3,7 @@ name = "const_sv2" version = "2.0.0" authors = ["fi3 "] edition = "2018" -description = "Sv2 constatnts" +description = "This crate holds all of the shared constants used across the different Stratum V2 protocols and roles crates" license = "MIT" repository = "https://github.com/stratum-mining/stratum" diff --git a/protocols/v2/const-sv2/README.md b/protocols/v2/const-sv2/README.md index 1c919b895c..b491997450 100644 --- a/protocols/v2/const-sv2/README.md +++ b/protocols/v2/const-sv2/README.md @@ -2,20 +2,21 @@ [![crates.io](https://img.shields.io/crates/v/const_sv2.svg)](https://crates.io/crates/const_sv2) [![docs.rs](https://docs.rs/const_sv2/badge.svg)](https://docs.rs/const_sv2) +[![rustc+](https://img.shields.io/badge/rustc-1.75.0%2B-lightgrey.svg)](https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html) +[![license](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](https://github.com/stratum-mining/stratum/blob/main/LICENSE.md) -`const_sv2` is a Rust crate that provides essential constants for the SV2 (Stratum V2) protocol. These constants are crucial for message framing, encryption, and protocol-specific identifiers across various SV2 components, including Mining, Job Declaration, and Template Distribution protocols. +`const_sv2` is a Rust crate that provides essential constants for the Sv2 (Stratum V2) protocol. These constants are crucial for message framing, encryption, and protocol-specific identifiers across various Sv2 components, including Mining, Job Declaration, and Template Distribution protocols. -## Main Components +## Key Capabilities -- **Protocol Constants**: Define key protocol discriminants, message types, and sizes for the SV2 binary protocol. -- **Encryption Support**: Includes constants for encryption using ChaChaPoly and ElligatorSwift encoding. +- **Protocol Constants**: Define key protocol discriminants, message types, and sizes for the Sv2 binary protocol. +- **Encryption Support**: Includes constants for encryption using `ChaChaPoly` and `ElligatorSwift` encoding. - **Channel Bits**: Defines whether specific messages are associated with a channel, simplifying protocol handling. - **Modular**: Supports a `no_std` environment, enabling use in embedded systems or environments without a standard library. ## Usage -To use this crate, add it to your `Cargo.toml`: +To include this crate in your project, run: -```toml -[dependencies] -const_sv2 = "2.0.0" +```sh +cargo add const_sv2 From ce2f0850e98fe44915c3aaef3981d19775201beb Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 10 Oct 2024 16:03:13 +0530 Subject: [PATCH 11/14] remove metadata from root cargo.toml --- examples/interop-cpp/Cargo.toml | 2 +- examples/ping-pong-with-noise/Cargo.toml | 2 +- examples/ping-pong-without-noise/Cargo.toml | 2 +- protocols/Cargo.toml | 13 ------------- protocols/fuzz-tests/Cargo.toml | 5 +++++ protocols/v1/Cargo.toml | 8 ++++++-- protocols/v2/binary-sv2/binary-sv2/Cargo.toml | 8 ++++++-- .../v2/binary-sv2/no-serde-sv2/codec/Cargo.toml | 8 ++++++-- .../binary-sv2/no-serde-sv2/derive_codec/Cargo.toml | 8 ++++++-- protocols/v2/binary-sv2/serde-sv2/Cargo.toml | 8 ++++++-- protocols/v2/codec-sv2/Cargo.toml | 8 ++++++-- protocols/v2/const-sv2/Cargo.toml | 8 ++++++-- protocols/v2/framing-sv2/Cargo.toml | 8 ++++++-- protocols/v2/noise-sv2/Cargo.toml | 8 ++++++-- protocols/v2/roles-logic-sv2/Cargo.toml | 7 ++++++- .../v2/subprotocols/common-messages/Cargo.toml | 8 ++++++-- .../v2/subprotocols/job-declaration/Cargo.toml | 8 ++++++-- protocols/v2/subprotocols/mining/Cargo.toml | 8 ++++++-- .../subprotocols/template-distribution/Cargo.toml | 8 ++++++-- protocols/v2/sv2-ffi/Cargo.toml | 8 ++++++-- roles/Cargo.toml | 13 ------------- roles/jd-client/Cargo.toml | 9 +++++++-- roles/jd-server/Cargo.toml | 9 ++++++++- roles/mining-proxy/Cargo.toml | 9 +++++++-- roles/pool/Cargo.toml | 8 +++++++- roles/roles-utils/network-helpers/Cargo.toml | 9 +++++++-- roles/roles-utils/rpc/Cargo.toml | 9 ++++++++- roles/test-utils/mining-device/Cargo.toml | 8 ++++++++ roles/test-utils/sv1-mining-device/Cargo.toml | 7 +++++++ roles/tests-integration/Cargo.toml | 7 +++++++ roles/translator/Cargo.toml | 7 ++++++- utils/Cargo.toml | 13 ------------- utils/bip32-key-derivation/Cargo.toml | 7 ++++++- utils/buffer/Cargo.toml | 8 ++++++-- utils/error-handling/Cargo.toml | 7 ++++++- utils/key-utils/Cargo.toml | 7 ++++++- utils/message-generator/Cargo.toml | 8 ++++++++ 37 files changed, 202 insertions(+), 86 deletions(-) diff --git a/examples/interop-cpp/Cargo.toml b/examples/interop-cpp/Cargo.toml index 6bd1d959cb..f6f192d79e 100644 --- a/examples/interop-cpp/Cargo.toml +++ b/examples/interop-cpp/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "interop-cpp" version = "0.1.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" publish = false diff --git a/examples/ping-pong-with-noise/Cargo.toml b/examples/ping-pong-with-noise/Cargo.toml index b1220bce7d..760f89eced 100644 --- a/examples/ping-pong-with-noise/Cargo.toml +++ b/examples/ping-pong-with-noise/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ping_pong_with_noise" version = "0.1.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" publish = false diff --git a/examples/ping-pong-without-noise/Cargo.toml b/examples/ping-pong-without-noise/Cargo.toml index 5619bfa4bb..9f5c90c584 100644 --- a/examples/ping-pong-without-noise/Cargo.toml +++ b/examples/ping-pong-without-noise/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ping_pong_without_noise" version = "0.1.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" publish = false diff --git a/protocols/Cargo.toml b/protocols/Cargo.toml index d1f21ca36d..2af4c9c982 100644 --- a/protocols/Cargo.toml +++ b/protocols/Cargo.toml @@ -1,16 +1,3 @@ -name = "stratum_v2_protocols" -version = "1.0.0" -authors = ["The Stratum v2 Developers"] -edition = "2021" -description = "The Stratum protocol defines how miners, proxies, and pools communicate to contribute hashrate to the Bitcoin network. Stratum v2 is a robust set of primitives which anyone can use to expand the protocol or implement a role." -documentation = "https://github.com/stratum-mining/stratum" -readme = "README.md" -homepage = "https://stratumprotocol.org" -repository = "https://github.com/stratum-mining/stratum" -license = "MIT + Apache-2.0" -license-file = "LICENSE.md" -keywords = ["stratum", "mining", "bitcoin", "protocol"] - [workspace] resolver="2" diff --git a/protocols/fuzz-tests/Cargo.toml b/protocols/fuzz-tests/Cargo.toml index d29d588ce9..52e34dfef1 100644 --- a/protocols/fuzz-tests/Cargo.toml +++ b/protocols/fuzz-tests/Cargo.toml @@ -4,6 +4,11 @@ version = "1.0.0" edition = "2021" authors = ["Automatically generated"] publish = false +documentation = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] [package.metadata] cargo-fuzz = true diff --git a/protocols/v1/Cargo.toml b/protocols/v1/Cargo.toml index 0e7bd18267..bdea8d4937 100644 --- a/protocols/v1/Cargo.toml +++ b/protocols/v1/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "sv1_api" version = "1.0.1" -authors = ["user"] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "API for bridging SV1 miners to SV2 pools" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/sv1_api" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/binary-sv2/binary-sv2/Cargo.toml b/protocols/v2/binary-sv2/binary-sv2/Cargo.toml index 922d491a21..d3882c01b2 100644 --- a/protocols/v2/binary-sv2/binary-sv2/Cargo.toml +++ b/protocols/v2/binary-sv2/binary-sv2/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "binary_sv2" version = "1.2.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "Sv2 data format" -license = "MIT" +documentation = "https://docs.rs/binary_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/Cargo.toml b/protocols/v2/binary-sv2/no-serde-sv2/codec/Cargo.toml index 5394f336cc..77894f4e69 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/Cargo.toml +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "binary_codec_sv2" version = "1.2.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "Sv2 data format" -license = "MIT" +documentation = "https://docs.rs/binary_codec_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/Cargo.toml b/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/Cargo.toml index 93f202d8bd..0653daf3d8 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/Cargo.toml +++ b/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "derive_codec_sv2" version = "1.1.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "Derive macro for Sv2 binary format serializer and deserializer" -license = "MIT" +documentation = "https://docs.rs/derive_codec_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/binary-sv2/serde-sv2/Cargo.toml b/protocols/v2/binary-sv2/serde-sv2/Cargo.toml index 2dcc744c8e..3f551f8244 100644 --- a/protocols/v2/binary-sv2/serde-sv2/Cargo.toml +++ b/protocols/v2/binary-sv2/serde-sv2/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "serde_sv2" version = "1.0.1" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "Serlializer and Deserializer for Stratum V2 data format" -license = "MIT" +documentation = "https://docs.rs/serde_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/codec-sv2/Cargo.toml b/protocols/v2/codec-sv2/Cargo.toml index 20b0288afa..092bcb9866 100644 --- a/protocols/v2/codec-sv2/Cargo.toml +++ b/protocols/v2/codec-sv2/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "codec_sv2" version = "1.2.1" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "Sv2 data format" -license = "MIT" +documentation = "https://docs.rs/codec_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] [dependencies] serde = { version = "1.0.89", default-features = false, optional = true } diff --git a/protocols/v2/const-sv2/Cargo.toml b/protocols/v2/const-sv2/Cargo.toml index 5d37e77abd..8030a1fcd7 100644 --- a/protocols/v2/const-sv2/Cargo.toml +++ b/protocols/v2/const-sv2/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "const_sv2" version = "2.0.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "This crate holds all of the shared constants used across the different Stratum V2 protocols and roles crates" -license = "MIT" +documentation = "https://docs.rs/const_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/framing-sv2/Cargo.toml b/protocols/v2/framing-sv2/Cargo.toml index 4450a46531..7e39d8ceeb 100644 --- a/protocols/v2/framing-sv2/Cargo.toml +++ b/protocols/v2/framing-sv2/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "framing_sv2" version = "2.0.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "Sv2 frames" -license = "MIT" +documentation = "https://docs.rs/framing_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/noise-sv2/Cargo.toml b/protocols/v2/noise-sv2/Cargo.toml index c627bc1af2..432b894dd7 100644 --- a/protocols/v2/noise-sv2/Cargo.toml +++ b/protocols/v2/noise-sv2/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "noise_sv2" version = "1.1.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "Sv2 noise" -license = "MIT" +documentation = "https://docs.rs/noise_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] [dependencies] secp256k1 = { version = "0.28.2", default-features = false, features =["hashes", "alloc","rand","rand-std"] } diff --git a/protocols/v2/roles-logic-sv2/Cargo.toml b/protocols/v2/roles-logic-sv2/Cargo.toml index 2b7c34610b..077c246fd6 100644 --- a/protocols/v2/roles-logic-sv2/Cargo.toml +++ b/protocols/v2/roles-logic-sv2/Cargo.toml @@ -1,10 +1,15 @@ [package] name = "roles_logic_sv2" version = "1.2.1" +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "Common handlers for use within SV2 roles" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/roles_logic_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/subprotocols/common-messages/Cargo.toml b/protocols/v2/subprotocols/common-messages/Cargo.toml index 783c208dfe..5891becfc3 100644 --- a/protocols/v2/subprotocols/common-messages/Cargo.toml +++ b/protocols/v2/subprotocols/common-messages/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "common_messages_sv2" version = "2.0.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "Sv2 subprotocol common messages" -license = "MIT" +documentation = "https://docs.rs/common_messages_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/subprotocols/job-declaration/Cargo.toml b/protocols/v2/subprotocols/job-declaration/Cargo.toml index 2ee4313f4c..79093ce179 100644 --- a/protocols/v2/subprotocols/job-declaration/Cargo.toml +++ b/protocols/v2/subprotocols/job-declaration/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "job_declaration_sv2" version = "1.0.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "SV2 job declaration protocol types" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/job_declaration_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] [dependencies] diff --git a/protocols/v2/subprotocols/mining/Cargo.toml b/protocols/v2/subprotocols/mining/Cargo.toml index c98bb7ec99..a5bda914dd 100644 --- a/protocols/v2/subprotocols/mining/Cargo.toml +++ b/protocols/v2/subprotocols/mining/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "mining_sv2" version = "1.0.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "SV2 mining protocol types" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/mining_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/subprotocols/template-distribution/Cargo.toml b/protocols/v2/subprotocols/template-distribution/Cargo.toml index b0120836dc..21c30c297f 100644 --- a/protocols/v2/subprotocols/template-distribution/Cargo.toml +++ b/protocols/v2/subprotocols/template-distribution/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "template_distribution_sv2" version = "1.0.2" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "Sv2 template distribution subprotocol" -license = "MIT" +documentation = "https://docs.rs/template_distribution_sv2" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/protocols/v2/sv2-ffi/Cargo.toml b/protocols/v2/sv2-ffi/Cargo.toml index 6498b1b5b8..35ca76a65b 100644 --- a/protocols/v2/sv2-ffi/Cargo.toml +++ b/protocols/v2/sv2-ffi/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "sv2_ffi" version = "1.0.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" +readme = "README.md" description = "SV2 FFI" -license = "MIT OR Apache-2.0" +documentation = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" repository = "https://github.com/stratum-mining/stratum" +homepage = "https://stratumprotocol.org" +keywords = ["stratum", "mining", "bitcoin", "protocol"] [lib] crate-type = ["staticlib"] diff --git a/roles/Cargo.toml b/roles/Cargo.toml index d44909a939..3e9c59fc7a 100644 --- a/roles/Cargo.toml +++ b/roles/Cargo.toml @@ -1,16 +1,3 @@ -name = "stratum_v2_roles" -version = "0.1.0" -authors = ["The Stratum v2 Developers"] -edition = "2021" -description = "The Stratum protocol defines how miners, proxies, and pools communicate to contribute hashrate to the Bitcoin network. Stratum v2 is a robust set of primitives which anyone can use to expand the protocol or implement a role." -documentation = "https://github.com/stratum-mining/stratum" -readme = "README.md" -homepage = "https://stratumprotocol.org" -repository = "https://github.com/stratum-mining/stratum" -license = "MIT + Apache-2.0" -license-file = "LICENSE.md" -keywords = ["stratum", "mining", "bitcoin", "protocol"] - [workspace] resolver="2" diff --git a/roles/jd-client/Cargo.toml b/roles/jd-client/Cargo.toml index dc2d46079d..c160720a37 100644 --- a/roles/jd-client/Cargo.toml +++ b/roles/jd-client/Cargo.toml @@ -1,10 +1,15 @@ [package] name = "jd_client" version = "0.1.1" +authors = ["The Stratum V2 Developers"] edition = "2021" -description = "TODO" -license = "MIT OR Apache-2.0" +description = "Job Declarator Client (JDC) role" +documentation = "https://docs.rs/jd_client" +readme = "README.md" +homepage = "https://stratumprotocol.org" repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] [lib] name = "jd_client" diff --git a/roles/jd-server/Cargo.toml b/roles/jd-server/Cargo.toml index e8d82438a1..b6086df18e 100644 --- a/roles/jd-server/Cargo.toml +++ b/roles/jd-server/Cargo.toml @@ -1,9 +1,16 @@ [package] name = "jd_server" version = "0.1.1" +authors = ["The Stratum V2 Developers"] edition = "2018" -license = "MIT OR Apache-2.0" +description = "Job Declarator Server (JDS) role" +documentation = "https://github.com/stratum-mining/stratum" +readme = "README.md" +homepage = "https://stratumprotocol.org" repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] + [lib] name = "jd_server" diff --git a/roles/mining-proxy/Cargo.toml b/roles/mining-proxy/Cargo.toml index 8ffb5d0953..ba635e49eb 100644 --- a/roles/mining-proxy/Cargo.toml +++ b/roles/mining-proxy/Cargo.toml @@ -1,11 +1,16 @@ [package] name = "mining_proxy_sv2" version = "0.1.1" -authors = ["user"] +authors = ["The Stratum V2 Developers"] edition = "2018" description = "SV2 mining proxy role" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/mining_proxy_sv2" +readme = "README.md" +homepage = "https://stratumprotocol.org" repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] + [lib] name = "mining_proxy_sv2" diff --git a/roles/pool/Cargo.toml b/roles/pool/Cargo.toml index c253e6b3e9..4668e8ee59 100644 --- a/roles/pool/Cargo.toml +++ b/roles/pool/Cargo.toml @@ -1,10 +1,16 @@ [package] name = "pool_sv2" version = "0.1.1" +authors = ["The Stratum V2 Developers"] edition = "2018" description = "SV2 pool role" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/pool_sv2" +readme = "README.md" +homepage = "https://stratumprotocol.org" repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] + [lib] name = "pool_sv2" diff --git a/roles/roles-utils/network-helpers/Cargo.toml b/roles/roles-utils/network-helpers/Cargo.toml index b4af8f293e..46d3fc532e 100644 --- a/roles/roles-utils/network-helpers/Cargo.toml +++ b/roles/roles-utils/network-helpers/Cargo.toml @@ -1,11 +1,16 @@ [package] name = "network_helpers_sv2" version = "2.0.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" description = "Networking utils for SV2 roles" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/network_helpers_sv2" +readme = "README.md" +homepage = "https://stratumprotocol.org" repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/roles/roles-utils/rpc/Cargo.toml b/roles/roles-utils/rpc/Cargo.toml index 6ae6e05527..db5c0f02db 100644 --- a/roles/roles-utils/rpc/Cargo.toml +++ b/roles/roles-utils/rpc/Cargo.toml @@ -1,9 +1,16 @@ [package] name = "rpc_sv2" version = "1.0.0" +authors = ["The Stratum V2 Developers"] edition = "2021" description = "SV2 JD Server RPC" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/rpc_sv2" +readme = "README.md" +homepage = "https://stratumprotocol.org" +repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/roles/test-utils/mining-device/Cargo.toml b/roles/test-utils/mining-device/Cargo.toml index 775d38f3b2..dc5c3bba5d 100644 --- a/roles/test-utils/mining-device/Cargo.toml +++ b/roles/test-utils/mining-device/Cargo.toml @@ -1,8 +1,16 @@ [package] name = "mining_device" version = "0.1.1" +authors = ["The Stratum V2 Developers"] edition = "2018" publish = false +documentation = "https://github.com/stratum-mining/stratum" +readme = "README.md" +homepage = "https://stratumprotocol.org" +repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/roles/test-utils/sv1-mining-device/Cargo.toml b/roles/test-utils/sv1-mining-device/Cargo.toml index 55b990c633..5d1dd2d0fa 100644 --- a/roles/test-utils/sv1-mining-device/Cargo.toml +++ b/roles/test-utils/sv1-mining-device/Cargo.toml @@ -1,8 +1,15 @@ [package] name = "sv1-mining-device" version = "0.1.0" +authors = ["The Stratum V2 Developers"] edition = "2021" publish = false +documentation = "https://github.com/stratum-mining/stratum" +readme = "README.md" +homepage = "https://stratumprotocol.org" +repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/roles/tests-integration/Cargo.toml b/roles/tests-integration/Cargo.toml index 00eab65fa5..3a1f6615da 100644 --- a/roles/tests-integration/Cargo.toml +++ b/roles/tests-integration/Cargo.toml @@ -1,7 +1,14 @@ [package] name = "integration-test" version = "0.1.0" +authors = ["The Stratum V2 Developers"] edition = "2021" +documentation = "https://github.com/stratum-mining/stratum" +readme = "README.md" +homepage = "https://stratumprotocol.org" +repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] [dependencies] bitcoind = "0.36.0" diff --git a/roles/translator/Cargo.toml b/roles/translator/Cargo.toml index a7c762a058..8699993447 100644 --- a/roles/translator/Cargo.toml +++ b/roles/translator/Cargo.toml @@ -1,10 +1,15 @@ [package] name = "translator_sv2" version = "0.1.1" +authors = ["The Stratum V2 Developers"] edition = "2021" description = "Server used to bridge SV1 miners to SV2 pools" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/translator_sv2" +readme = "README.md" +homepage = "https://stratumprotocol.org" repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] [lib] name = "translator_sv2" diff --git a/utils/Cargo.toml b/utils/Cargo.toml index aa22ee1aef..43e3c95fe8 100644 --- a/utils/Cargo.toml +++ b/utils/Cargo.toml @@ -1,16 +1,3 @@ -name = "stratum_v2_utils" -version = "1.0.0" -authors = ["The Stratum v2 Developers"] -edition = "2021" -description = "The Stratum protocol defines how miners, proxies, and pools communicate to contribute hashrate to the Bitcoin network. Stratum v2 is a robust set of primitives which anyone can use to expand the protocol or implement a role." -documentation = "https://github.com/stratum-mining/stratum" -readme = "README.md" -homepage = "https://stratumprotocol.org" -repository = "https://github.com/stratum-mining/stratum" -license = "MIT + Apache-2.0" -license-file = "LICENSE.md" -keywords = ["stratum", "mining", "bitcoin", "protocol"] - [workspace] resolver="2" diff --git a/utils/bip32-key-derivation/Cargo.toml b/utils/bip32-key-derivation/Cargo.toml index a2d0681e4c..5b5749e608 100644 --- a/utils/bip32-key-derivation/Cargo.toml +++ b/utils/bip32-key-derivation/Cargo.toml @@ -1,10 +1,15 @@ [package] name = "bip32_derivation" version = "1.0.0" +authors = ["The Stratum V2 Developers"] edition = "2021" description = "bip32_derivation" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/bip32_derivation" +readme = "README.md" +homepage = "https://stratumprotocol.org" repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] [lib] name = "bip32_derivation" diff --git a/utils/buffer/Cargo.toml b/utils/buffer/Cargo.toml index b3a8f543d9..1effc249eb 100644 --- a/utils/buffer/Cargo.toml +++ b/utils/buffer/Cargo.toml @@ -1,11 +1,15 @@ [package] name = "buffer_sv2" version = "1.1.0" -authors = ["fi3 "] +authors = ["The Stratum V2 Developers"] edition = "2018" description = "buffer" -license = "MIT" +documentation = "https://docs.rs/buffer_sv2" +readme = "README.md" +homepage = "https://stratumprotocol.org" repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] [dependencies] criterion = {version = "0.3", optional = true} diff --git a/utils/error-handling/Cargo.toml b/utils/error-handling/Cargo.toml index 6d3cb4a157..05a606b984 100644 --- a/utils/error-handling/Cargo.toml +++ b/utils/error-handling/Cargo.toml @@ -1,7 +1,12 @@ [package] name = "error_handling" version = "1.0.0" +authors = ["The Stratum V2 Developers"] edition = "2021" description = "Macro used to clean and centralize error handling within async processes" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/error_handling" +readme = "README.md" +homepage = "https://stratumprotocol.org" repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] diff --git a/utils/key-utils/Cargo.toml b/utils/key-utils/Cargo.toml index 55c5bba15f..b6c13b86a7 100644 --- a/utils/key-utils/Cargo.toml +++ b/utils/key-utils/Cargo.toml @@ -1,10 +1,15 @@ [package] name = "key-utils" version = "1.1.0" +authors = ["The Stratum V2 Developers"] edition = "2021" description = "Key utils" -license = "MIT OR Apache-2.0" +documentation = "https://docs.rs/key-utils" +readme = "README.md" +homepage = "https://stratumprotocol.org" repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/utils/message-generator/Cargo.toml b/utils/message-generator/Cargo.toml index f97d74f0d9..3be66a7724 100644 --- a/utils/message-generator/Cargo.toml +++ b/utils/message-generator/Cargo.toml @@ -1,7 +1,15 @@ [package] name = "message_generator_sv2" version = "1.0.1" +authors = ["The Stratum V2 Developers"] edition = "2021" +description = "message generator" +documentation = "https://github.com/stratum-mining/stratum" +readme = "README.md" +homepage = "https://stratumprotocol.org" +repository = "https://github.com/stratum-mining/stratum" +license = "MIT + Apache-2.0" +keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From b1ed20edc63be9de9b87d7032ecfd88271e40db1 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Tue, 8 Oct 2024 11:33:57 +0300 Subject: [PATCH 12/14] Remove unused code --- roles/jd-client/src/lib/upstream_sv2/mod.rs | 8 -------- roles/translator/src/lib/mod.rs | 4 ---- 2 files changed, 12 deletions(-) diff --git a/roles/jd-client/src/lib/upstream_sv2/mod.rs b/roles/jd-client/src/lib/upstream_sv2/mod.rs index 4209e686ae..70adb2dc9d 100644 --- a/roles/jd-client/src/lib/upstream_sv2/mod.rs +++ b/roles/jd-client/src/lib/upstream_sv2/mod.rs @@ -7,11 +7,3 @@ pub use upstream::Upstream; pub type Message = PoolMessages<'static>; pub type StdFrame = StandardSv2Frame; pub type EitherFrame = StandardEitherFrame; - -#[derive(Clone, Copy, Debug)] -pub struct Sv2MiningConnection { - _version: u16, - _setup_connection_flags: u32, - #[allow(dead_code)] - setup_connection_success_flags: u32, -} diff --git a/roles/translator/src/lib/mod.rs b/roles/translator/src/lib/mod.rs index 5a95bcde71..2c5a21c4d0 100644 --- a/roles/translator/src/lib/mod.rs +++ b/roles/translator/src/lib/mod.rs @@ -276,10 +276,6 @@ impl TranslatorSv2 { let _ = task_collector.safe_lock(|t| t.push((task.abort_handle(), "init task".to_string()))); } - - pub fn upstream_address(&self) -> SocketAddr { - self.config.upstream_address.clone().parse().unwrap() - } } fn kill_tasks(task_collector: Arc>>) { From 3d441049e9d05ff5452ad768e55bc1ba324ddd81 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Tue, 8 Oct 2024 11:34:09 +0300 Subject: [PATCH 13/14] Allow **potentianl** dead code .. should be examined later to check if need to be removed --- roles/jd-client/src/lib/downstream.rs | 1 + roles/jd-client/src/lib/error.rs | 2 ++ roles/jd-client/src/lib/proxy_config.rs | 1 + roles/jd-client/src/lib/upstream_sv2/upstream.rs | 2 ++ roles/mining-proxy/src/lib/error.rs | 1 + roles/translator/src/lib/proxy/bridge.rs | 1 + 6 files changed, 8 insertions(+) diff --git a/roles/jd-client/src/lib/downstream.rs b/roles/jd-client/src/lib/downstream.rs index 92e5a874a7..82a8076022 100644 --- a/roles/jd-client/src/lib/downstream.rs +++ b/roles/jd-client/src/lib/downstream.rs @@ -39,6 +39,7 @@ pub struct DownstreamMiningNode { receiver: Receiver, sender: Sender, pub status: DownstreamMiningNodeStatus, + #[allow(dead_code)] pub prev_job_id: Option, solution_sender: Sender>, withhold: bool, diff --git a/roles/jd-client/src/lib/error.rs b/roles/jd-client/src/lib/error.rs index c3e24bd4d3..f29decb3d6 100644 --- a/roles/jd-client/src/lib/error.rs +++ b/roles/jd-client/src/lib/error.rs @@ -6,6 +6,7 @@ use stratum_common::bitcoin::util::uint::ParseLengthError; pub type ProxyResult<'a, T> = core::result::Result>; +#[allow(dead_code)] #[derive(Debug)] pub enum ChannelSendError<'a> { SubmitSharesExtended( @@ -28,6 +29,7 @@ pub enum ChannelSendError<'a> { #[derive(Debug)] pub enum Error<'a> { + #[allow(dead_code)] VecToSlice32(Vec), /// Errors on bad CLI argument input. BadCliArgs, diff --git a/roles/jd-client/src/lib/proxy_config.rs b/roles/jd-client/src/lib/proxy_config.rs index 89c97a7beb..af03047d8a 100644 --- a/roles/jd-client/src/lib/proxy_config.rs +++ b/roles/jd-client/src/lib/proxy_config.rs @@ -37,6 +37,7 @@ pub struct ProxyConfig { pub cert_validity_sec: u64, pub tp_address: String, pub tp_authority_public_key: Option, + #[allow(dead_code)] pub retry: u32, pub upstreams: Vec, #[serde(deserialize_with = "duration_from_toml")] diff --git a/roles/jd-client/src/lib/upstream_sv2/upstream.rs b/roles/jd-client/src/lib/upstream_sv2/upstream.rs index b04efa3359..ed26674ff2 100644 --- a/roles/jd-client/src/lib/upstream_sv2/upstream.rs +++ b/roles/jd-client/src/lib/upstream_sv2/upstream.rs @@ -110,7 +110,9 @@ pub struct Upstream { tx_status: status::Sender, /// Minimum `extranonce2` size. Initially requested in the `jdc-config.toml`, and ultimately /// set by the SV2 Upstream via the SV2 `OpenExtendedMiningChannelSuccess` message. + #[allow(dead_code)] pub min_extranonce_size: u16, + #[allow(dead_code)] pub upstream_extranonce1_size: usize, /// String be included in coinbase tx input scriptsig pub pool_signature: String, diff --git a/roles/mining-proxy/src/lib/error.rs b/roles/mining-proxy/src/lib/error.rs index b5c900bfd9..75ded3a67a 100644 --- a/roles/mining-proxy/src/lib/error.rs +++ b/roles/mining-proxy/src/lib/error.rs @@ -9,6 +9,7 @@ pub type EitherFrame = StandardEitherFrame; #[derive(Debug)] #[allow(clippy::large_enum_variant)] #[allow(clippy::enum_variant_names)] +#[allow(dead_code)] pub enum Error { SendError(SendError), UpstreamNotAvailabe(SocketAddr), diff --git a/roles/translator/src/lib/proxy/bridge.rs b/roles/translator/src/lib/proxy/bridge.rs index 74db21111e..93f4efdeb2 100644 --- a/roles/translator/src/lib/proxy/bridge.rs +++ b/roles/translator/src/lib/proxy/bridge.rs @@ -540,6 +540,7 @@ mod test { pub mod test_utils { use super::*; + #[allow(dead_code)] pub struct BridgeInterface { pub tx_sv1_submit: Sender, pub rx_sv2_submit_shares_ext: Receiver>, From bdfab4c17324c531597a53c7f126145558d3b079 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Tue, 8 Oct 2024 11:34:43 +0300 Subject: [PATCH 14/14] Remove redundant cargo-clippy feature --- roles/jd-client/src/lib/upstream_sv2/upstream.rs | 2 +- roles/translator/src/lib/upstream_sv2/upstream.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/jd-client/src/lib/upstream_sv2/upstream.rs b/roles/jd-client/src/lib/upstream_sv2/upstream.rs index ed26674ff2..7a4b186787 100644 --- a/roles/jd-client/src/lib/upstream_sv2/upstream.rs +++ b/roles/jd-client/src/lib/upstream_sv2/upstream.rs @@ -146,7 +146,7 @@ impl Upstream { /// `UpstreamConnection` with a channel to send and receive messages from the SV2 Upstream /// role and uses channels provided in the function arguments to send and receive messages /// from the `Downstream`. - #[cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments))] + #[allow(clippy::too_many_arguments)] pub async fn new( address: SocketAddr, authority_public_key: Secp256k1PublicKey, diff --git a/roles/translator/src/lib/upstream_sv2/upstream.rs b/roles/translator/src/lib/upstream_sv2/upstream.rs index 6135174328..6e2ddf646c 100644 --- a/roles/translator/src/lib/upstream_sv2/upstream.rs +++ b/roles/translator/src/lib/upstream_sv2/upstream.rs @@ -115,7 +115,7 @@ impl Upstream { /// `UpstreamConnection` with a channel to send and receive messages from the SV2 Upstream /// role and uses channels provided in the function arguments to send and receive messages /// from the `Downstream`. - #[cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments))] + #[allow(clippy::too_many_arguments)] pub async fn new( address: SocketAddr, authority_public_key: Secp256k1PublicKey,