diff --git a/.github/workflows/clippy-lint.yaml b/.github/workflows/clippy-lint.yaml
index 5c11d83da8..e73915f245 100644
--- a/.github/workflows/clippy-lint.yaml
+++ b/.github/workflows/clippy-lint.yaml
@@ -24,7 +24,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
- toolchain: stable
+ toolchain: 1.89
override: true
components: clippy
- name: Run Clippy on different workspaces and crates
diff --git a/.github/workflows/coverage-protocols.yaml b/.github/workflows/coverage-protocols.yaml
index a52bed95a6..dc0a96b0de 100644
--- a/.github/workflows/coverage-protocols.yaml
+++ b/.github/workflows/coverage-protocols.yaml
@@ -1,7 +1,7 @@
name: Protocol test Coverage
on:
- pull_request:
+ push:
branches:
- main
@@ -53,6 +53,14 @@ jobs:
flags: codec_sv2-coverage
token: ${{ secrets.CODECOV_TOKEN }}
+ - name: Upload channels_sv2-coverage to codecov.io
+ uses: codecov/codecov-action@v4
+ with:
+ directory: ./protocols/target/tarpaulin-reports/channels-sv2-coverage
+ file: ./protocols/target/tarpaulin-reports/channels-sv2-coverage/cobertura.xml
+ flags: channels_sv2-coverage
+ token: ${{ secrets.CODECOV_TOKEN }}
+
- name: Upload common_messages_sv2-coverage to codecov.io
uses: codecov/codecov-action@v4
with:
@@ -85,6 +93,14 @@ jobs:
flags: noise_sv2-coverage
token: ${{ secrets.CODECOV_TOKEN }}
+ - name: Upload parsers_sv2-coverage to codecov.io
+ uses: codecov/codecov-action@v4
+ with:
+ directory: ./protocols/target/tarpaulin-reports/parsers-sv2-coverage
+ file: ./protocols/target/tarpaulin-reports/parsers-sv2-coverage/cobertura.xml
+ flags: parsers_sv2-coverage
+ token: ${{ secrets.CODECOV_TOKEN }}
+
- name: Upload roles_logic_sv2-coverage to codecov.io
uses: codecov/codecov-action@v4
with:
@@ -101,14 +117,6 @@ jobs:
flags: v1-coverage
token: ${{ secrets.CODECOV_TOKEN }}
- - name: Upload sv2_ffi-coverage to codecov.io
- uses: codecov/codecov-action@v4
- with:
- directory: ./protocols/target/tarpaulin-reports/sv2-ffi-coverage
- file: ./protocols/target/tarpaulin-reports/sv2-ffi-coverage/cobertura.xml
- flags: sv2_ffi-coverage
- token: ${{ secrets.CODECOV_TOKEN }}
-
- name: Upload template_distribution_sv2-coverage to codecov.io
uses: codecov/codecov-action@v4
with:
diff --git a/.github/workflows/coverage-roles.yaml b/.github/workflows/coverage-roles.yaml
index 33e7497bb6..f777de8de7 100644
--- a/.github/workflows/coverage-roles.yaml
+++ b/.github/workflows/coverage-roles.yaml
@@ -1,7 +1,7 @@
name: Roles test Coverage
on:
- pull_request:
+ push:
branches:
- main
@@ -53,14 +53,6 @@ jobs:
flags: mining_device-coverage
token: ${{ secrets.CODECOV_TOKEN }}
- - name: Upload mining_proxy_sv2-coverage to codecov.io
- uses: codecov/codecov-action@v4
- with:
- directory: ./roles/target/tarpaulin-reports/mining-proxy-coverage
- file: ./roles/target/tarpaulin-reports/mining-proxy-coverage/cobertura.xml
- flags: mining_proxy_sv2-coverage
- token: ${{ secrets.CODECOV_TOKEN }}
-
- name: Upload pool_sv2-coverage to codecov.io
uses: codecov/codecov-action@v4
with:
diff --git a/.github/workflows/coverage-utils.yaml b/.github/workflows/coverage-utils.yaml
index 1b6c0156d0..6ff5e4f3a5 100644
--- a/.github/workflows/coverage-utils.yaml
+++ b/.github/workflows/coverage-utils.yaml
@@ -1,7 +1,7 @@
name: Util Test Coverage
on:
- pull_request:
+ push:
branches:
- main
diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml
index 1d0fe6f812..15df72e603 100644
--- a/.github/workflows/docs.yaml
+++ b/.github/workflows/docs.yaml
@@ -49,6 +49,16 @@ jobs:
cd protocols/v2/binary-sv2
cargo doc --features with_buffer_pool
+ - name: Rust Docs crate channels_sv2
+ run: |
+ cd protocols/v2/channels-sv2
+ cargo doc
+
+ - name: Rust Docs crate parsers_sv2
+ run: |
+ cd protocols/v2/parsers-sv2
+ cargo doc
+
- name: Rust Docs crate framing_sv2
run: |
cd protocols/v2/framing-sv2
@@ -84,11 +94,6 @@ jobs:
cd protocols/v2/subprotocols/template-distribution
cargo doc
- - name: Rust Docs crate sv2_ffi
- run: |
- cd protocols/v2/sv2-ffi
- cargo doc
-
- name: Rust Docs crate roles_logic_sv2
run: |
diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml
index 0829786c7e..b2c95722ba 100644
--- a/.github/workflows/integration-tests.yaml
+++ b/.github/workflows/integration-tests.yaml
@@ -24,10 +24,9 @@ jobs:
toolchain: stable
override: true
- - name: Roles Integration Tests
- run: |
- RUST_BACKTRACE=1 RUST_LOG=debug cargo test --manifest-path=test/integration-tests/Cargo.toml --verbose --test '*' -- --nocapture
+ - name: Install cargo-nextest
+ run: cargo install cargo-nextest --locked
- - name: SV1 Integration Tests
+ - name: Integration Tests
run: |
- RUST_BACKTRACE=1 RUST_LOG=debug cargo test --manifest-path=test/integration-tests/Cargo.toml --verbose --test 'sv1' --features sv1 -- --nocapture
+ RUST_BACKTRACE=1 RUST_LOG=debug cargo nextest run --manifest-path=test/integration-tests/Cargo.toml --features sv1 --nocapture
diff --git a/.github/workflows/release-libs.yaml b/.github/workflows/release-libs.yaml
index 20f3e5df2e..6f257aa37b 100644
--- a/.github/workflows/release-libs.yaml
+++ b/.github/workflows/release-libs.yaml
@@ -29,38 +29,51 @@ jobs:
- name: Login
run: cargo login ${{ secrets.CRATES_IO_DEPLOY_KEY }}
- - name: Publish crate common
+ # Base dependencies with no local dependencies
+ - name: Publish crate config_helpers_sv2
run: |
- ./scripts/release-libs.sh common
-
+ ./scripts/release-libs.sh roles/roles-utils/config-helpers
+
- name: Publish crate buffer_sv2
run: |
./scripts/release-libs.sh utils/buffer
- - name: Publish crate binary_sv2 derive_codec
+ - name: Publish crate error-handling
run: |
- ./scripts/release-libs.sh protocols/v2/binary-sv2/derive_codec
+ ./scripts/release-libs.sh utils/error-handling
+
+ - name: Publish crate key-utils
+ run: |
+ ./scripts/release-libs.sh utils/key-utils
+ - name: Publish crate noise_sv2
+ run: |
+ ./scripts/release-libs.sh protocols/v2/noise-sv2
+
+ # binary_sv2 (depends on buffer_sv2)
- name: Publish crate binary_sv2 codec
run: |
./scripts/release-libs.sh protocols/v2/binary-sv2/codec
+ - name: Publish crate binary_sv2 derive_codec
+ run: |
+ ./scripts/release-libs.sh protocols/v2/binary-sv2/derive_codec
+
- name: Publish crate binary_sv2
run: |
./scripts/release-libs.sh protocols/v2/binary-sv2
+ # framing_sv2(depends on binary_sv2, buffer_sv2, noise_sv2)
- name: Publish crate framing_sv2
run: |
./scripts/release-libs.sh protocols/v2/framing-sv2
- - name: Publish crate noise_sv2
- run: |
- ./scripts/release-libs.sh protocols/v2/noise-sv2
-
+ # codec_sv2 (depends on framing_sv2, noise_sv2, binary_sv2, buffer_sv2, key-utils)
- name: Publish crate codec_sv2
run: |
./scripts/release-libs.sh protocols/v2/codec-sv2
+ # Subprotocols (depend on binary_sv2)
- name: Publish crate common_messages
run: |
./scripts/release-libs.sh protocols/v2/subprotocols/common-messages
@@ -77,34 +90,51 @@ jobs:
run: |
./scripts/release-libs.sh protocols/v2/subprotocols/template-distribution
- - name: Publish crate sv2_ffi
+ # channels_sv2 (depends on binary_sv2, common_messages_sv2, mining_sv2, template_distribution_sv2, job_declaration_sv2)
+ - name: Publish crate channels_sv2
run: |
- ./scripts/release-libs.sh protocols/v2/sv2-ffi
+ ./scripts/release-libs.sh protocols/v2/channels-sv2
- - name: Publish crate roles_logic_sv2
+ # parsers_sv2 (depends on binary_sv2, framing_sv2, common_messages, mining, template_distribution, job_declaration)
+ - name: Publish crate parsers_sv2
run: |
- ./scripts/release-libs.sh protocols/v2/roles-logic-sv2
+ ./scripts/release-libs.sh protocols/v2/parsers-sv2
+ # sv1_api (depends on binary_sv2)
- name: Publish crate v1
run: |
./scripts/release-libs.sh protocols/v1
- - name: Publish crate bip32-key-derivation
+ # stratum_translation (depends on binary_sv2, mining_sv2, channels_sv2, v1)
+ - name: Publish crate stratum_translation
run: |
- ./scripts/release-libs.sh utils/bip32-key-derivation
+ ./scripts/release-libs.sh roles/roles-utils/stratum-translation
- - name: Publish crate error-handling
- run: |
- ./scripts/release-libs.sh utils/error-handling
-
- - name: Publish crate key-utils
+ # Roles logic (depends on codec_sv2 and subprotocols)
+ - name: Publish crate roles_logic_sv2
run: |
- ./scripts/release-libs.sh utils/key-utils
+ ./scripts/release-libs.sh protocols/v2/roles-logic-sv2
+ # Network helpers (depends on codec_sv2, sv1_api)
- name: Publish crate network_helpers_sv2
run: |
./scripts/release-libs.sh roles/roles-utils/network-helpers
+ # Common (depends on roles_logic_sv2 and network_helpers_sv2)
+ - name: Publish crate common
+ run: |
+ ./scripts/release-libs.sh common
+
+ # handlers_sv2 (depends on parsers_sv2, binary_sv2, common_messages_sv2, mining_sv2, template_distribution_sv2, job_declaration_sv2)
+ - name: Publish crate handlers_sv2
+ run: |
+ ./scripts/release-libs.sh protocols/v2/handlers-sv2
+
+ # Utilities that depend on stratum-common
+ - name: Publish crate bip32-key-derivation
+ run: |
+ ./scripts/release-libs.sh utils/bip32-key-derivation
+
- name: Publish crate rpc_sv2
run: |
- ./scripts/release-libs.sh roles/roles-utils/rpc
+ ./scripts/release-libs.sh roles/roles-utils/rpc
\ No newline at end of file
diff --git a/.github/workflows/rust-msrv.yaml b/.github/workflows/rust-msrv.yaml
index 8c2f8d27d5..8e892c586b 100644
--- a/.github/workflows/rust-msrv.yaml
+++ b/.github/workflows/rust-msrv.yaml
@@ -27,20 +27,20 @@ jobs:
- name: Build Protocols
run: cargo build --manifest-path=protocols/Cargo.toml
- name: Build Roles
- run: cargo build --manifest-path=roles/Cargo.toml
+ run: cargo build --locked --manifest-path=roles/Cargo.toml
- name: Build Utils
- run: cargo build --manifest-path=utils/Cargo.toml
+ run: cargo build --locked --manifest-path=utils/Cargo.toml
- name: Build Integration Tests
- run: cargo build --manifest-path=test/integration-tests/Cargo.toml
-
+ run: cargo build --locked --manifest-path=test/integration-tests/Cargo.toml
+
# also check test compilation without running tests
- name: Check Test Compilation for Benches
run: cargo test --manifest-path=benches/Cargo.toml --no-run
- name: Check Test Compilation for Protocols
run: cargo test --manifest-path=protocols/Cargo.toml --no-run
- name: Check Test Compilation for Roles
- run: cargo test --manifest-path=roles/Cargo.toml --no-run
+ run: cargo test --locked --manifest-path=roles/Cargo.toml --no-run
- name: Check Test Compilation for Utils
- run: cargo test --manifest-path=utils/Cargo.toml --no-run
+ run: cargo test --locked --manifest-path=utils/Cargo.toml --no-run
- name: Check Test Compilation for Integration Tests
- run: cargo test --manifest-path=test/integration-tests/Cargo.toml --no-run
\ No newline at end of file
+ run: cargo test --locked --manifest-path=test/integration-tests/Cargo.toml --no-run
diff --git a/.github/workflows/semver-check.yaml b/.github/workflows/semver-check.yaml
index 30596e25b0..5154c7499c 100644
--- a/.github/workflows/semver-check.yaml
+++ b/.github/workflows/semver-check.yaml
@@ -85,14 +85,22 @@ jobs:
working-directory: protocols/v2/subprotocols/template-distribution
run: cargo semver-checks
- - name: Run semver checks for protocols/v2/sv2-ffi
- working-directory: protocols/v2/sv2-ffi
- run: cargo semver-checks
-
- name: Run semver checks for protocols/v2/roles-logic-sv2
working-directory: protocols/v2/roles-logic-sv2
run: cargo semver-checks --default-features
+ - name: Run semver checks for protocols/v2/channels-sv2
+ working-directory: protocols/v2/channels-sv2
+ run: cargo semver-checks
+
+ - name: Run semver checks for protocols/v2/parsers-sv2
+ working-directory: protocols/v2/parsers-sv2
+ run: cargo semver-checks
+
+ - name: Run semver checks for protocols/v2/handlers-sv2
+ working-directory: protocols/v2/handlers-sv2
+ run: cargo semver-checks
+
- name: Run semver checks for protocols/v1
working-directory: protocols/v1
run: cargo semver-checks
@@ -109,6 +117,11 @@ jobs:
working-directory: utils/key-utils
run: cargo semver-checks
+ # TODO: Uncomment this when the stratum-translation crate is published to crates.io
+ #- name: Run semver checks for roles/roles-utils/stratum-translation
+ # working-directory: roles/roles-utils/stratum-translation
+ # run: cargo semver-checks
+
- name: Run semver checks for roles/roles-utils/network-helpers
working-directory: roles/roles-utils/network-helpers
run: cargo semver-checks
@@ -116,3 +129,7 @@ jobs:
- name: Run semver checks for roles/roles-utils/rpc
working-directory: roles/roles-utils/rpc
run: cargo semver-checks
+
+ - name: Run semver checks for roles/roles-utils/config-helpers
+ working-directory: roles/roles-utils/config-helpers
+ run: cargo semver-checks
\ No newline at end of file
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index 734c4552d7..19a67a4f1a 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -11,11 +11,11 @@ jobs:
strategy:
matrix:
os:
- - macos-13
+ - macos-latest
- ubuntu-latest
include:
- - os: macos-13
- target: x86_64-apple-darwin
+ - os: macos-latest
+ target: aarch64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
@@ -44,6 +44,19 @@ jobs:
run: |
cargo run --manifest-path=protocols/v2/framing-sv2/Cargo.toml --example sv2_frame
+ - name: Run codec-sv2 examples
+ run: |
+ cargo run --manifest-path=protocols/v2/codec-sv2/Cargo.toml --example unencrypted
+ cargo run --manifest-path=protocols/v2/codec-sv2/Cargo.toml --example encrypted --features=noise_sv2
+
+ - name: Run binary-sv2 examples
+ run: |
+ cargo run --manifest-path=protocols/v2/binary-sv2/Cargo.toml --example encode_decode
+
+ - name: Run noise-sv2 examples
+ run: |
+ cargo run --manifest-path=protocols/v2/noise-sv2/Cargo.toml --example handshake
+
- name: fuzz tests
run: |
if [ ${{ matrix.os }} == "ubuntu-latest" ]; then
@@ -62,6 +75,7 @@ jobs:
cargo test --manifest-path=utils/Cargo.toml
cargo test --manifest-path=roles/roles-utils/config-helpers/Cargo.toml
cargo test --manifest-path=roles/roles-utils/network-helpers/Cargo.toml sv1_connection::tests::test_sv1_connection --features sv1
+ cargo test --manifest-path=roles/roles-utils/stratum-translation/Cargo.toml
- name: Property based testing
run: |
diff --git a/.gitignore b/.gitignore
index 6720e2bde7..b475baf9f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,8 @@
*/**/target
/protocols/guix-example/guix-example.h
/protocols/Cargo.lock
+/common/Cargo.lock
+/protocols/v2/binary-sv2/derive_codec/Cargo.lock
/benches/Cargo.lock
/ignore
/vendor/ed25519-dalek/target
@@ -18,5 +20,8 @@ cobertura.xml
/examples/*/Cargo.lock
/scripts/sv2.h
/test/integration-tests/template-provider
+/test/integration-tests/minerd
**/template-provider
stratum-message-generator
+*.log
+**/minerd
\ No newline at end of file
diff --git a/README.md b/README.md
index ce735b11ac..0dc2c554f6 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,7 @@ SRI is fully open-source, community-developed, independent of any single entity,
To get started with the Stratum V2 Reference Implementation (SRI), please follow the detailed setup instructions available on the official website:
-[Getting Started with Stratum V2](https://stratumprotocol.org/getting-started/)
+[Getting Started with Stratum V2](https://stratumprotocol.org/blog/getting-started/)
This guide provides all the necessary information on prerequisites, installation, and configuration to help you begin using, testing or contributing to SRI.
@@ -61,7 +61,6 @@ The library is modular to address different use-cases and desired functionality.
- Pools supporting SV2 can deploy the open source binary crate (`roles/pool`) to offer their clients (miners participating in said pool) an SV2-compatible pool.
- The Rust helper library provides a suite of tools for mining pools to build custom SV2 compatible pool implementations.
-- The C library provides a set of FFI bindings to the Rust helper library for miners to integrate SV2 into their existing firmware stack.
## 🛣 Roadmap
@@ -84,10 +83,9 @@ The goals of this project are to provide:
- Pools supporting SV2
- Mining-device/hashrate producers integrating SV2 into their firmware
- Bitcoin nodes implementing Template Provider to build the `blocktemplate`
-2. The above Rust primitives as a C library available for use in other languages via FFI.
-3. A set of helpers built on top of the above primitives and the external Bitcoin-related Rust crates for anyone to implement the SV2 roles.
-4. An open-source implementation of a SV2 proxy for miners.
-5. An open-source implementation of a SV2 pool for mining pool operators.
+2. A set of helpers built on top of the above primitives and the external Bitcoin-related Rust crates for anyone to implement the SV2 roles.
+3. An open-source implementation of a SV2 proxy for miners.
+4. An open-source implementation of a SV2 pool for mining pool operators.
## 💻 Contribute
@@ -120,10 +118,10 @@ Email us at: stratumv2@gmail.com
SRI contributors are independently, financially supported by following entities:
-
-
-
-
+
+
+
+
## 📖 License
diff --git a/benches/Cargo.toml b/benches/Cargo.toml
index 7bc179f3fb..4cfd8f0161 100644
--- a/benches/Cargo.toml
+++ b/benches/Cargo.toml
@@ -4,7 +4,7 @@ version = "1.0.1"
edition = "2021"
[dependencies]
-stratum-common = { path = "../common", features=["bitcoin"]}
+bitcoin = { version = "0.32.5", optional = true }
async-std={version = "1.10.0", features = ["attributes"]}
criterion = "0.5.1"
async-channel = "1.4.0"
diff --git a/benches/benches/src/sv1/lib/client.rs b/benches/benches/src/sv1/lib/client.rs
index 3ef5fc38ef..e59f4086f2 100644
--- a/benches/benches/src/sv1/lib/client.rs
+++ b/benches/benches/src/sv1/lib/client.rs
@@ -3,7 +3,6 @@
//! messages. It also provides a trait implementation for handling server messages and managing
//! client state.
-use std::fmt::Write;
use v1::{
client_to_server,
error::Error,
@@ -27,7 +26,7 @@ pub struct Client {
impl Client {
pub fn new(client_id: u32) -> Client {
- let client = Client {
+ Client {
client_id,
extranonce1: extranonce_from_hex("00000000"),
extranonce2_size: 4,
@@ -37,9 +36,7 @@ impl Client {
last_notify: None,
sented_authorize_request: vec![],
authorized: vec![],
- };
-
- client
+ }
}
// this is what we want to benchmark
@@ -262,6 +259,6 @@ mod utils {
}
pub fn encode_hex(bytes: &[u8]) -> String {
- bytes.iter().map(|b| format!("{:02x}", b)).collect()
+ bytes.iter().map(|b| format!("{b:02x}")).collect()
}
}
diff --git a/common/Cargo.lock b/common/Cargo.lock
deleted file mode 100644
index 83e061fb92..0000000000
--- a/common/Cargo.lock
+++ /dev/null
@@ -1,205 +0,0 @@
-# This file is automatically @generated by Cargo.
-# It is not intended for manual editing.
-version = 3
-
-[[package]]
-name = "arrayvec"
-version = "0.7.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
-
-[[package]]
-name = "base58ck"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f"
-dependencies = [
- "bitcoin-internals",
- "bitcoin_hashes",
-]
-
-[[package]]
-name = "bech32"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d"
-
-[[package]]
-name = "bitcoin"
-version = "0.32.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ce6bc65742dea50536e35ad42492b234c27904a27f0abdcbce605015cb4ea026"
-dependencies = [
- "base58ck",
- "bech32",
- "bitcoin-internals",
- "bitcoin-io",
- "bitcoin-units",
- "bitcoin_hashes",
- "hex-conservative",
- "hex_lit",
- "secp256k1 0.29.1",
-]
-
-[[package]]
-name = "bitcoin-internals"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2"
-
-[[package]]
-name = "bitcoin-io"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf"
-
-[[package]]
-name = "bitcoin-units"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2"
-dependencies = [
- "bitcoin-internals",
-]
-
-[[package]]
-name = "bitcoin_hashes"
-version = "0.14.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
-dependencies = [
- "bitcoin-io",
- "hex-conservative",
-]
-
-[[package]]
-name = "cc"
-version = "1.0.97"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4"
-
-[[package]]
-name = "cfg-if"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
-
-[[package]]
-name = "getrandom"
-version = "0.2.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
-dependencies = [
- "cfg-if",
- "libc",
- "wasi",
-]
-
-[[package]]
-name = "hex-conservative"
-version = "0.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd"
-dependencies = [
- "arrayvec",
-]
-
-[[package]]
-name = "hex_lit"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd"
-
-[[package]]
-name = "libc"
-version = "0.2.154"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
-
-[[package]]
-name = "ppv-lite86"
-version = "0.2.17"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
-
-[[package]]
-name = "rand"
-version = "0.8.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
-dependencies = [
- "libc",
- "rand_chacha",
- "rand_core",
-]
-
-[[package]]
-name = "rand_chacha"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
-dependencies = [
- "ppv-lite86",
- "rand_core",
-]
-
-[[package]]
-name = "rand_core"
-version = "0.6.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
-dependencies = [
- "getrandom",
-]
-
-[[package]]
-name = "secp256k1"
-version = "0.28.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10"
-dependencies = [
- "rand",
- "secp256k1-sys 0.9.2",
-]
-
-[[package]]
-name = "secp256k1"
-version = "0.29.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113"
-dependencies = [
- "bitcoin_hashes",
- "secp256k1-sys 0.10.1",
-]
-
-[[package]]
-name = "secp256k1-sys"
-version = "0.9.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb"
-dependencies = [
- "cc",
-]
-
-[[package]]
-name = "secp256k1-sys"
-version = "0.10.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9"
-dependencies = [
- "cc",
-]
-
-[[package]]
-name = "stratum-common"
-version = "2.0.0"
-dependencies = [
- "bitcoin",
- "secp256k1 0.28.2",
-]
-
-[[package]]
-name = "wasi"
-version = "0.11.0+wasi-snapshot-preview1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
diff --git a/common/Cargo.toml b/common/Cargo.toml
index abbac337c5..648c2a818d 100644
--- a/common/Cargo.toml
+++ b/common/Cargo.toml
@@ -1,11 +1,15 @@
[package]
name = "stratum-common"
-version = "2.0.0"
-edition = "2018"
+version = "4.0.1"
+edition = "2021"
description = "SV2 pool role"
license = "MIT OR Apache-2.0"
repository = "https://github.com/stratum-mining/stratum"
[dependencies]
-bitcoin = {version="0.32.5",optional=true}
-secp256k1 = { version = "0.28.2", default-features = false, features =["alloc","rand","rand-std"] }
+roles_logic_sv2 = { path = "../protocols/v2/roles-logic-sv2", version = "5.0.0" }
+network_helpers_sv2 = { path = "../roles/roles-utils/network-helpers", version = "4.0.1", features = ["with_buffer_pool"], optional = true }
+
+[features]
+with_network_helpers = ["dep:network_helpers_sv2"]
+sv1 = ["network_helpers_sv2/sv1"]
diff --git a/common/src/lib.rs b/common/src/lib.rs
index 242c7acb35..eca6226f3f 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -2,6 +2,7 @@
//!
//! `stratum_common` is a utility crate designed to centralize
//! and manage the shared dependencies and utils across stratum crates.
-#[cfg(feature = "bitcoin")]
-pub use bitcoin;
-pub use secp256k1;
+
+#[cfg(feature = "with_network_helpers")]
+pub use network_helpers_sv2;
+pub use roles_logic_sv2;
diff --git a/examples/interop-cpp-no-cargo/.gitignore b/examples/interop-cpp-no-cargo/.gitignore
deleted file mode 100644
index 858137540d..0000000000
--- a/examples/interop-cpp-no-cargo/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-/sv2.h
-/a.out
-/libsv2_ffi.a
-/deps
diff --git a/examples/interop-cpp-no-cargo/README.md b/examples/interop-cpp-no-cargo/README.md
deleted file mode 100644
index 6db6b3c1e6..0000000000
--- a/examples/interop-cpp-no-cargo/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# C++ interop no cargo
-
-An example of how to build the code in ../../interop-cpp/ without using cargo.
-
-`./run.sh` will build and run the example
diff --git a/examples/interop-cpp-no-cargo/run.sh b/examples/interop-cpp-no-cargo/run.sh
deleted file mode 100755
index 5648647112..0000000000
--- a/examples/interop-cpp-no-cargo/run.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#! /bin/sh
-
-touch libsv2_ffi.a
-touch a.out
-
-# CLEAN
-rm -f libsv2_ffi.a
-rm -f a.out
-rm -f sv2.h
-
-./rust-build-script.sh ../../protocols/v2/ ../../utils/
-
-g++ -I ../../protocols/v2/sv2-ffi ../interop-cpp/template-provider/template-provider.cpp libsv2_ffi.a -lpthread -ldl
-
-./a.out &
-provider_pid=$!
-sleep 1 # wait for provider to start listening
-
-cargo run --manifest-path ../interop-cpp/Cargo.toml &
-run_pid=$!
-
-# If there is a first argument sleep for that long
-if [ -n "$1" ]; then
- sleep "$1"
-
- if ps -p $provider_pid > /dev/null && ps -p $run_pid > /dev/null
- then
- echo "Success!"
- kill $provider_pid
- kill $run_pid
- else
- echo "Failure!!!"
- exit 1
- fi
-fi
diff --git a/examples/interop-cpp-no-cargo/rust-build-script.sh b/examples/interop-cpp-no-cargo/rust-build-script.sh
deleted file mode 100755
index 927fdbfee6..0000000000
--- a/examples/interop-cpp-no-cargo/rust-build-script.sh
+++ /dev/null
@@ -1,162 +0,0 @@
-#! /bin/sh
-
-set -ex
-
-ROOT=$1
-UTILS=$2
-
-DEPS="./deps"
-
-rm -rf $DEPS
-
-mkdir $DEPS
-
-rustc \
- --crate-name buffer_sv2 \
- --edition=2018 \
- "$UTILS"/buffer/src/lib.rs \
- --error-format=json \
- --json=diagnostic-rendered-ansi,artifacts \
- --crate-type lib \
- --emit=dep-info,metadata,link \
- -C opt-level=3 \
- -C embed-bitcode=no \
- --out-dir $DEPS \
- -L dependency=$DEPS \
-
-rustc \
- --crate-name binary_codec_sv2 \
- --edition=2018 \
- $ROOT/binary-sv2/codec/src/lib.rs \
- --error-format=json \
- --json=diagnostic-rendered-ansi \
- --crate-type lib \
- --emit=dep-info,metadata,link \
- -C embed-bitcode=no \
- -C debug-assertions=off \
- --out-dir $DEPS \
- -L dependency=$DEPS
-
-rustc \
- --crate-name binary_codec_sv2 \
- --edition=2018 \
- $ROOT/binary-sv2/codec/src/lib.rs \
- --error-format=json \
- --json=diagnostic-rendered-ansi,artifacts \
- --crate-type lib \
- --emit=dep-info,metadata,link \
- -C opt-level=3 \
- -C embed-bitcode=no \
- --out-dir $DEPS \
- -L dependency=$DEPS
-
-rustc \
- --crate-name derive_codec_sv2 \
- --edition=2018 \
- $ROOT/binary-sv2/derive_codec/src/lib.rs \
- --error-format=json \
- --json=diagnostic-rendered-ansi \
- --crate-type proc-macro \
- --emit=dep-info,link \
- -C prefer-dynamic \
- -C embed-bitcode=no \
- -C debug-assertions=off \
- --out-dir $DEPS \
- -L dependency=$DEPS \
- --extern binary_codec_sv2=$DEPS/libbinary_codec_sv2.rlib \
- --extern proc_macro
-
-rustc \
- --crate-name binary_sv2 \
- --edition=2018 \
- $ROOT/binary-sv2/src/lib.rs \
- --error-format=json \
- --json=diagnostic-rendered-ansi,artifacts \
- --crate-type lib \
- --emit=dep-info,metadata,link \
- -C opt-level=3 \
- -C embed-bitcode=no \
- --cfg 'feature="default"' \
- --out-dir $DEPS \
- -L dependency=$DEPS \
- --extern binary_codec_sv2=$DEPS/libbinary_codec_sv2.rmeta \
- --extern derive_codec_sv2=$DEPS/libderive_codec_sv2.so
-
-rustc \
- --crate-name framing_sv2 \
- --edition=2018 \
- $ROOT/framing-sv2/src/lib.rs \
- --error-format=json \
- --json=diagnostic-rendered-ansi,artifacts \
- --crate-type lib \
- --emit=dep-info,metadata,link \
- -C opt-level=3 \
- -C embed-bitcode=no \
- --out-dir $DEPS \
- -L dependency=$DEPS \
- --extern binary_sv2=$DEPS/libbinary_sv2.rmeta \
- --extern const_sv2=$DEPS/libconst_sv2.rmeta
-
-rustc \
- --crate-name common_messages_sv2 \
- --edition=2018 \
- $ROOT/subprotocols/common-messages/src/lib.rs \
- --error-format=json \
- --json=diagnostic-rendered-ansi \
- --crate-type lib \
- --emit=dep-info,metadata,link \
- -C opt-level=3 \
- -C embed-bitcode=no \
- --out-dir $DEPS \
- -L dependency=$DEPS \
- --extern binary_sv2=$DEPS/libbinary_sv2.rmeta \
- --extern const_sv2=$DEPS/libconst_sv2.rmeta
-
-rustc \
- --crate-name template_distribution_sv2 \
- --edition=2018 \
- $ROOT/subprotocols/template-distribution/src/lib.rs \
- --error-format=json \
- --json=diagnostic-rendered-ansi \
- --crate-type lib \
- --emit=dep-info,metadata,link \
- -C opt-level=3 \
- -C embed-bitcode=no \
- --out-dir $DEPS \
- -L dependency=$DEPS \
- --extern binary_sv2=$DEPS/libbinary_sv2.rmeta \
- --extern const_sv2=$DEPS/libconst_sv2.rmeta
-
-rustc \
- --crate-name codec_sv2 \
- --edition=2018 \
- $ROOT/codec-sv2/src/lib.rs \
- --error-format=json \
- --json=diagnostic-rendered-ansi \
- --crate-type lib \
- --emit=dep-info,metadata,link \
- -C opt-level=3 \
- -C embed-bitcode=no \
- --out-dir $DEPS \
- -L dependency=$DEPS \
- --extern binary_sv2=$DEPS/libbinary_sv2.rmeta \
- --extern const_sv2=$DEPS/libconst_sv2.rmeta \
- --extern framing_sv2=$DEPS/libframing_sv2.rmeta \
- --extern buffer_sv2=$DEPS/libbuffer_sv2.rmeta
-
-rustc \
- --crate-name sv2_ffi \
- --edition=2018 \
- $ROOT/sv2-ffi/src/lib.rs \
- --error-format=json \
- --json=diagnostic-rendered-ansi \
- --crate-type staticlib \
- -C opt-level=3 \
- -C embed-bitcode=no \
- --out-dir ./ \
- -L dependency=$DEPS \
- --extern binary_sv2=$DEPS/libbinary_sv2.rlib \
- --extern codec_sv2=$DEPS/libcodec_sv2.rlib \
- --extern common_messages_sv2=$DEPS/libcommon_messages_sv2.rlib \
- --extern const_sv2=$DEPS/libconst_sv2.rlib \
- --extern template_distribution_sv2=$DEPS/libtemplate_distribution_sv2.rlib
diff --git a/examples/interop-cpp/.gitignore b/examples/interop-cpp/.gitignore
deleted file mode 100644
index 83a6f8cea6..0000000000
--- a/examples/interop-cpp/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/sv2.h
-/a.out
-/libsv2_ffi.a
diff --git a/examples/interop-cpp/Cargo.toml b/examples/interop-cpp/Cargo.toml
deleted file mode 100644
index 2b4bd73af3..0000000000
--- a/examples/interop-cpp/Cargo.toml
+++ /dev/null
@@ -1,15 +0,0 @@
-[package]
-name = "interop-cpp"
-version = "0.1.0"
-authors = ["The Stratum V2 Developers"]
-edition = "2018"
-publish = false
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
-codec_sv2 = { path = "../../protocols/v2/codec-sv2" }
-stratum_common = { path = "../../common" }
-binary_sv2 = { path = "../../protocols/v2/binary-sv2" }
-common_messages_sv2 = { path = "../../protocols/v2/subprotocols/common-messages" }
-template_distribution_sv2 = { path = "../../protocols/v2/subprotocols/template-distribution" }
diff --git a/examples/interop-cpp/README.md b/examples/interop-cpp/README.md
deleted file mode 100644
index 37da8d5495..0000000000
--- a/examples/interop-cpp/README.md
+++ /dev/null
@@ -1,182 +0,0 @@
-# C++ interop
-
-This crate provides an example of how to use the Rust Sv2 `Decoder` and `Encoder` from C++.
-
-To run the example: `./run.sh`.
-
-The example is composed by a Rust "downstream node" that keep sending a
-[`common_messages_sv2::SetupConnection`] message to a C++ "upstream node" that receive the message
-and keep answering with a [`common_messages_sv2::SetupConnectionError`].
-
-The Rust codec is exported as a C static library by the crate [sv2-ffi](../../protocols/v2/sv2-ffi).
-
-## Intro
-
-### Header file
-
-The [header file](../../protocols/v2/sv2-ffi/sv2.h) is generated with `cbindgen`.
-
-Rust enums definition are transformed by `cbingen` in:
-```c
-struct [Rust_enum_name] {
- union class Tag {
- [union_element_1_name]
- [union_element_2_name]
- ...
- }
-
- struct [union_element_1_name]_Body {
- [inner_union_element_name_if_any_1] _0;
- [inner_union_element_name_if_any_2] _1;
- ...
- }
-
- struct [union_element_2_name]_Body {
- [inner_union_element_name_if_any_1] _0;
- [inner_union_element_name_if_any_2] _1;
- ...
- }
-
- ...
-
- union {
- [union_element_1_name]_Body [union_element_1_name]
- [union_element_2_name]_Body [union_element_2_name]
- ...
- }
-
-}
-```
-
-For example the below Rust enum:
-```Rust
-#[repr(C)]
-pub enum CResult {
- Ok(T),
- Err(E),
-}
-```
-
-Will be transformed in:
-```c
-template
-struct CResult {
- enum class Tag {
- Ok,
- Err,
- };
-
- struct Ok_Body {
- T _0;
- };
-
- struct Err_Body {
- E _0;
- };
-
- Tag tag;
- union {
- Ok_Body ok;
- Err_Body err;
- };
-};
-```
-
-### Conventions
-
-#### Memory
-All the memory used shared struct/enums (also when borrowed) is allocated by Rust.
-
-When C++ take ownership of a Sv2 message the message must be manually dropped.
-
-#### Enums
-In order to pattern match against a Rust defined enum from C++:
-```
-CResult < CSv2Message, Sv2Error > frame = next_frame(decoder);
-
-switch (frame.tag) {
-
-case CResult < CSv2Message, Sv2Error > ::Tag::Ok:
- on_success(frame.ok._0);
- cout << "\n";
- cout << "START PARSING NEW FRAME";
- cout << "\n";
- send_setup_connection_error(new_socket);
- break;
-case CResult < CSv2Message, Sv2Error > ::Tag::Err:
- on_error(frame.err._0);
- break;
-};
-```
-
-### `CVec`
-[`binary_sv2::binary_codec_sv2::CVec`] is used to share bytes buffers between Rust and C++.
-
-A `CVec` can be either "borrowed" or "owned" if is on or the other depend by the method that we
-use to construct it.
-
-* (borrowed) [`binary_sv2::binary_codec_sv2::CVec::as_shared_buffer`]: used when we need to fill a Rust
- allocated buffer from C++. This method does not guarantee anything about the pointed memory
- and the user must enforce that the Rust side does not free the pointed memory while the
- C++ part is using it
- A `CVec` constructed with this method must not be freed by C++ (this is enforced by the fact that
- the function used to free the `CVec` is not exported in the C library)
-* (owned) `&[u8].into::()`: used to copy the contents of the `&[u8]` to a `CVec`.
- It must be dropped from C++ via [`sv2_ffi::drop_sv2_message`]
-* (owned) [`binary_sv2::binary_codec_sv2::cvec_from_buffer`]: used when a `CVec` must be created in C++,
- is used to construct a [`sv2_ffi::CSv2Message`] that will be dropped as usual with
- [`sv2_ffi::drop_sv2_message`]
-* (owned) `CVec2.into::>()`, see `CVec2` section
-* (owned) `Inner.into::()`: same as `&[u8].into::()`
-
-### `CVec2`
-A `CVec2` is a vector of `CVec`'s. It is always allocated in Rust, is used only as field of Sv2 messages, and is
-dropped when the Sv2 message gets dropped.
-
-## Memory management
-
-### Decoder
-
-[`sv2_ffi::DecoderWrapper`] is instantiated in C++ via [`sv2_ffi::new_decoder`].
-There is no need to drop it as it will live for the entire life of the program.
-
-[`sv2_ffi::get_writable`] returns a `CVec` and is Rust allocated memory that C++ can fill with the
-socket content. The `CVec` is "borrowed" (`&[u8].into::()`) so it will be automatically
-dropped by Rust.
-
-[`sv2_ffi::next_frame`] is used if a complete Sv2 frame is available, it returns a [`sv2_ffi::CSv2Message`].
-The message can contain one or more "owned" `CVec`'s, so it must be manually dropped via
-[`sv2_ffi::drop_sv2_message`].
-
-
-### Encoder
-
-[`sv2_ffi::EncoderWrapper`] is instantiated in C++ via [`sv2_ffi::new_encoder`].
-There is no need to drop it as it will live for the entire life of the program.
-
-A [`sv2_ffi::CSv2Message`] can be constructed in C++ ([here is an example](template-provider/template-provider.cpp#67))
-if the message contains one or more `CVec`'s, then the content of the `CVec` must be copied in a Rust allocated
-`CVec` with [`binary_sv2::binary_codec_sv2::cvec_from_buffer`]. The message must be dropped with
-[`sv2_ffi::drop_sv2_message`].
-
-[`sv2_ffi::encode`] encodes a [`sv2_ffi::CSv2Message`] as an encoded Sv2 frame in a buffer internal
-to [`sv2_ffi::EncoderWrapper`]. The buffer contents are returned as a "borrowed" `CVec`. After
-that, C++ has copied it and it must free the encoder with [`sv2_ffi::flush_encoder`].
-This is necessary because the encoder will reuse the internal buffer to encode the next message with
-[`sv2_ffi::flush_encoder`]. We let the encoder know that the content of the internal buffer has been copied
-and can be overwritten.
-
-
-## Decode Sv2 messages in C++
-
-1. Instantiate a decoder with [`sv2_ffi::new_decoder`]
-2. Fill the decoder, copying the input bytes in the buffer returned by [`sv2_ffi::get_writable`]
-3. If the above buffer is full, call [`sv2_ffi::next_frame`]. If the decoder has enough bytes to
- decode an Sv2 frame it will return a `CSv2Message`, otherwise it returns 2.
-
-## Encode Sv2 messages in C++
-
-1. Instantiate an encoder with [`sv2_ffi::new_encoder`]
-2. Call [`sv2_ffi::encode`] with a valid `CSv2Message`
-3. Copy the returned encoded frame where needed
-4. Call [`sv2_ffi::flush_encoder`] to let the encoder know that the encoded frame has been copied
\ No newline at end of file
diff --git a/examples/interop-cpp/run.sh b/examples/interop-cpp/run.sh
deleted file mode 100755
index 31f914e5d9..0000000000
--- a/examples/interop-cpp/run.sh
+++ /dev/null
@@ -1,41 +0,0 @@
-#! /bin/sh
-
-touch libsv2_ffi.a
-touch a.out
-
-# CLEAN
-rm -f libsv2_ffi.a
-rm -f a.out
-rm -f sv2.h
-
-cargo build \
- --manifest-path=../../protocols/Cargo.toml \
- --release \
- -p sv2_ffi && \
- cp ../../protocols/target/release/libsv2_ffi.a ./
-
-../../scripts/build_header.sh ../../protocols && mv ../../scripts/sv2.h .
-
-g++ -I ./ ./template-provider/template-provider.cpp libsv2_ffi.a -lpthread -ldl
-
-./a.out &
-provider_pid=$!
-sleep 1 # wait for provider to start listening
-cargo run &
-run_pid=$!
-
-# If there is a first argument sleep for that long
-if [ -n "$1" ]; then
- sleep "$1"
-
- if ps -p $provider_pid > /dev/null && ps -p $run_pid > /dev/null
- then
- echo "Success!"
- kill $provider_pid
- kill $run_pid
- else
- echo "Failure!!!"
- exit 1
- fi
-fi
-
diff --git a/examples/interop-cpp/src/main.rs b/examples/interop-cpp/src/main.rs
deleted file mode 100644
index 06e13e08f6..0000000000
--- a/examples/interop-cpp/src/main.rs
+++ /dev/null
@@ -1,136 +0,0 @@
-fn main() -> Result<(), std::io::Error> {
- use main_::main;
- main()
-}
-
-mod main_ {
- use codec_sv2::{Encoder, StandardDecoder, StandardSv2Frame};
- use common_messages_sv2::{Protocol, SetupConnection, SetupConnectionError};
- use std::{
- convert::{TryFrom, TryInto},
- io::{Read, Write},
- net::TcpStream,
- };
- use stratum_common::{
- CHANNEL_BIT_SETUP_CONNECTION, MESSAGE_TYPE_SETUP_CONNECTION,
- MESSAGE_TYPE_SETUP_CONNECTION_ERROR,
- };
-
- use binary_sv2::{
- decodable::{DecodableField, FieldMarker},
- encodable::EncodableField,
- from_bytes, Deserialize, Error,
- };
-
- #[derive(Clone, Debug)]
- pub enum Sv2Message<'a> {
- SetupConnection(SetupConnection<'a>),
- SetupConnectionError(SetupConnectionError<'a>),
- }
-
- impl binary_sv2::GetSize for Sv2Message<'_> {
- fn get_size(&self) -> usize {
- match self {
- Sv2Message::SetupConnection(a) => a.get_size(),
- Sv2Message::SetupConnectionError(a) => a.get_size(),
- }
- }
- }
-
- impl<'decoder> Deserialize<'decoder> for Sv2Message<'decoder> {
- fn get_structure(_v: &[u8]) -> std::result::Result, binary_sv2::Error> {
- unimplemented!()
- }
- fn from_decoded_fields(
- _v: Vec>,
- ) -> std::result::Result {
- unimplemented!()
- }
- }
-
- impl<'a> TryFrom<(u8, &'a mut [u8])> for Sv2Message<'a> {
- type Error = Error;
-
- fn try_from(v: (u8, &'a mut [u8])) -> Result {
- let msg_type = v.0;
- match msg_type {
- MESSAGE_TYPE_SETUP_CONNECTION => {
- let message: SetupConnection<'a> = from_bytes(v.1)?;
- Ok(Sv2Message::SetupConnection(message))
- }
- MESSAGE_TYPE_SETUP_CONNECTION_ERROR => {
- let message: SetupConnectionError<'a> = from_bytes(v.1)?;
- Ok(Sv2Message::SetupConnectionError(message))
- }
- _ => panic!(),
- }
- }
- }
-
- impl<'decoder> From> for EncodableField<'decoder> {
- fn from(m: Sv2Message<'decoder>) -> Self {
- match m {
- Sv2Message::SetupConnection(a) => a.into(),
- Sv2Message::SetupConnectionError(a) => a.into(),
- }
- }
- }
-
- pub fn main() -> Result<(), std::io::Error> {
- let mut encoder = Encoder::::new();
-
- let setup_connection = SetupConnection {
- protocol: Protocol::TemplateDistributionProtocol,
- min_version: 2,
- max_version: 2,
- flags: 0,
- endpoint_host: "0.0.0.0".to_string().into_bytes().try_into().unwrap(),
- endpoint_port: 8081,
- vendor: "Bitmain".to_string().into_bytes().try_into().unwrap(),
- hardware_version: "901".to_string().into_bytes().try_into().unwrap(),
- firmware: "abcX".to_string().into_bytes().try_into().unwrap(),
- device_id: "89567".to_string().into_bytes().try_into().unwrap(),
- };
-
- let setup_connection = StandardSv2Frame::from_message(
- setup_connection,
- MESSAGE_TYPE_SETUP_CONNECTION,
- 0,
- CHANNEL_BIT_SETUP_CONNECTION,
- )
- .unwrap();
- let setup_connection = encoder.encode(setup_connection).unwrap();
-
- #[allow(deprecated)]
- std::thread::sleep_ms(2000);
-
- let mut stream = TcpStream::connect("0.0.0.0:8080")?;
-
- let mut decoder = StandardDecoder::>::new();
-
- loop {
- #[allow(deprecated)]
- std::thread::sleep_ms(500);
-
- stream.write_all(setup_connection)?;
-
- loop {
- let buffer = decoder.writable();
- stream.read_exact(buffer).unwrap();
- if let Ok(mut f) = decoder.next_frame() {
- let msg_type = f.get_header().unwrap().msg_type();
- let payload = f.payload();
- let message: Sv2Message = (msg_type, payload).try_into().unwrap();
- match message {
- Sv2Message::SetupConnection(_) => panic!(),
- Sv2Message::SetupConnectionError(m) => {
- println!("RUST MESSAGE RECEIVED");
- println!(" {}", std::str::from_utf8(m.error_code.as_ref()).unwrap());
- }
- }
- break;
- }
- }
- }
- }
-}
diff --git a/examples/interop-cpp/template-provider/template-provider.cpp b/examples/interop-cpp/template-provider/template-provider.cpp
deleted file mode 100644
index 5bd1f12aa8..0000000000
--- a/examples/interop-cpp/template-provider/template-provider.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-#include
-
-#include
-
-#include
-
-#include
-
-#include
-
-#include
-
-#include
-
-#include
-
-using namespace std;
-#define PORT 8080
-
-void on_success(CSv2Message message) {
- cout << "PARSED FRAME:\n";
- cout << " Message version: ";
- cout << message.setup_connection._0.min_version;
- cout << "\n";
- switch (message.tag) {
-
- case CSv2Message::Tag::SetupConnection:
-
- switch (message.setup_connection._0.protocol) {
- case Protocol::MiningProtocol:
- cout << "MiningProtocol \n";
- drop_sv2_message(message);
- break;
- case Protocol::TemplateDistributionProtocol:
-
- cout << " Protocol: TDP \n";
- cout << " Vendor: ";
- cout << message.setup_connection._0.vendor.data;
- cout << "\n";
- cout << " H Version: ";
- cout << message.setup_connection._0.hardware_version.data;
- cout << "\n";
- cout << " Firmware: ";
- cout << message.setup_connection._0.firmware.data;
- cout << "\n";
- cout << " Device ID: ";
- cout << message.setup_connection._0.device_id.data;
- cout << "\n";
-
- drop_sv2_message(message);
- break;
- }
- }
-}
-
-void on_error(Sv2Error error) {
- switch (error.tag) {
- case Sv2Error::Tag::MissingBytes:
- cout << "Waiting for the remaining part of the frame \n";
- break;
- default:
- cout << "An unkwon error occured \n";
- break;
- }
-}
-
-void send_setup_connection_error(int socket, EncoderWrapper *encoder) {
- const char* error = "connection can not be created";
- uint8_t* error_ = (uint8_t*) error;
-
- CVec error_code = cvec_from_buffer(error_, strlen(error));
- CSetupConnectionError message;
- message.flags = 0;
- message.error_code = error_code;
-
- CSv2Message response;
- response.tag = CSv2Message::Tag::SetupConnectionError;
- response.setup_connection_error._0 = message;
-
- CResult encoded = encode(&response, encoder);
- switch (encoded.tag) {
-
- case CResult < CVec, Sv2Error > ::Tag::Ok:
- cout << "sending connection setup error \n";
- write(socket, encoded.ok._0.data, encoded.ok._0.len);
- drop_sv2_message(response);
- flush_encoder(encoder);
- break;
- case CResult < CVec, Sv2Error > ::Tag::Err:
- cout << "Some error occurred \n";
- break;
- };
-
- //char *hello = "Hello";
- //write(socket, hello, strlen(hello));
-}
-
-int main() {
- int server_fd, new_socket, valread;
- struct sockaddr_in address;
- int opt = 1;
- int addrlen = sizeof(address);
-
- // Creating socket file descriptor
- if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
- perror("socket failed");
- exit(EXIT_FAILURE);
- }
-
- // Forcefully attaching socket to the port 8080
- if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &
- opt, sizeof(opt))) {
- perror("setsockopt");
- exit(EXIT_FAILURE);
- }
- address.sin_family = AF_INET;
- address.sin_addr.s_addr = INADDR_ANY;
- address.sin_port = htons(PORT);
-
- // Forcefully attaching socket to the port 8080
- if (bind(server_fd, (struct sockaddr * ) & address,
- sizeof(address)) < 0) {
- perror("bind failed");
- exit(EXIT_FAILURE);
- }
- if (listen(server_fd, 3) < 0) {
- perror("listen");
- exit(EXIT_FAILURE);
- }
- if ((new_socket = accept(server_fd, (struct sockaddr * ) & address,
- (socklen_t * ) & addrlen)) < 0) {
- perror("accept");
- exit(EXIT_FAILURE);
- }
-
- // Istanciate Sv2 decoder
- DecoderWrapper * decoder = new_decoder();
- EncoderWrapper * encoder = new_encoder();
-
- int byte_read = 0;
-
- while (true) {
- CVec buffer = get_writable(decoder);
-
- while (byte_read < buffer.len) {
- byte_read += read(new_socket, buffer.data, (buffer.len - byte_read));
-
- }
-
- byte_read = 0;
- CResult < CSv2Message, Sv2Error > frame = next_frame(decoder);
-
-
- switch (frame.tag) {
-
- case CResult < CSv2Message, Sv2Error > ::Tag::Ok:
- on_success(frame.ok._0);
- cout << "\n";
- cout << "START PARSING NEW FRAME";
- cout << "\n";
- send_setup_connection_error(new_socket, encoder);
- break;
- case CResult < CSv2Message, Sv2Error > ::Tag::Err:
- on_error(frame.err._0);
- break;
- };
- }
-
- return 0;
-}
-
diff --git a/examples/ping-pong-encrypted/Cargo.toml b/examples/ping-pong-encrypted/Cargo.toml
index 8b3099a018..cf9e99fe51 100644
--- a/examples/ping-pong-encrypted/Cargo.toml
+++ b/examples/ping-pong-encrypted/Cargo.toml
@@ -11,7 +11,7 @@ binary_sv2 = { path = "../../protocols/v2/binary-sv2" }
codec_sv2 = { path = "../../protocols/v2/codec-sv2", features = [ "noise_sv2" ] }
noise_sv2 = { path = "../../protocols/v2/noise-sv2" }
key-utils = { version = "^1.0.0", path = "../../utils/key-utils" }
-network_helpers_sv2 = { version = "3.0.0", path = "../../roles/roles-utils/network-helpers" }
+network_helpers_sv2 = { version = "4.0.0", path = "../../roles/roles-utils/network-helpers" }
rand = "0.8"
tokio = { version = "1.44.1", features = [ "full" ] }
async-channel = "1.5.1"
diff --git a/protocols/Cargo.toml b/protocols/Cargo.toml
index 92b84df262..cd287c3493 100644
--- a/protocols/Cargo.toml
+++ b/protocols/Cargo.toml
@@ -14,8 +14,10 @@ members = [
"v2/subprotocols/template-distribution",
"v2/subprotocols/mining",
"v2/subprotocols/job-declaration",
- "v2/sv2-ffi",
"v2/roles-logic-sv2",
+ "v2/channels-sv2",
+ "v2/parsers-sv2",
+ "v2/handlers-sv2",
]
[profile.dev]
diff --git a/protocols/v1/Cargo.toml b/protocols/v1/Cargo.toml
index 91bf3dc2d3..ff3e569436 100644
--- a/protocols/v1/Cargo.toml
+++ b/protocols/v1/Cargo.toml
@@ -1,8 +1,8 @@
[package]
name = "sv1_api"
-version = "1.0.1"
+version = "2.1.1"
authors = ["The Stratum V2 Developers"]
-edition = "2018"
+edition = "2021"
readme = "README.md"
description = "API for bridging SV1 miners to SV2 pools"
documentation = "https://docs.rs/sv1_api"
@@ -20,7 +20,7 @@ hex = "0.4.3"
serde = { version = "1.0.89", default-features = false, features = ["derive", "alloc"] }
serde_json = { version = "1.0.64", default-features = false, features = ["alloc"] }
tracing = {version = "0.1"}
-binary_sv2 = { path = "../v2/binary-sv2", version = "^3.0.0" }
+binary_sv2 = { path = "../v2/binary-sv2", version = "^4.0.0" }
[dev-dependencies]
quickcheck = "1"
diff --git a/protocols/v1/examples/client_and_server.rs b/protocols/v1/examples/client_and_server.rs
index e99f047693..4812ed0c3e 100644
--- a/protocols/v1/examples/client_and_server.rs
+++ b/protocols/v1/examples/client_and_server.rs
@@ -86,12 +86,12 @@ fn server_pool_listen(listener: TcpListener) {
loop {
match listener.accept() {
Ok((stream, addr)) => {
- println!("SERVER - Accepting from: {}", addr);
+ println!("SERVER - Accepting from: {addr}");
let server = Server::new(stream);
let _ = Arc::new(Mutex::new(server));
}
Err(e) => {
- eprintln!("SERVER - Accept error: {}", e);
+ eprintln!("SERVER - Accept error: {e}");
break;
}
}
@@ -139,7 +139,7 @@ impl Server<'_> {
thread::spawn(move || loop {
if let Ok(mut self_) = cloned.try_lock() {
if let Ok(line) = self_.receiver_incoming.try_recv() {
- println!("SERVER - message: {}", line);
+ println!("SERVER - message: {line}");
let message: Result = serde_json::from_str(&line);
if let Ok(message) = message {
if let Ok(Some(resp)) = self_.handle_message(message) {
@@ -171,7 +171,7 @@ impl Server<'_> {
run_time -= notify_time as i32;
if run_time <= 0 {
- println!("Test Success - ran for {} seconds", TEST_DURATION);
+ println!("Test Success - ran for {TEST_DURATION} seconds");
exit(0)
}
}
@@ -305,7 +305,7 @@ impl Client<'static> {
thread::sleep(Duration::from_secs(1));
match TcpStream::connect(socket) {
Ok(st) => {
- println!("CLIENT - connected to server at {}", socket);
+ println!("CLIENT - connected to server at {socket}");
let (sender_incoming, receiver_incoming) = mpsc::channel::();
let (sender_outgoing, receiver_outgoing) = mpsc::channel::();
@@ -560,7 +560,7 @@ impl<'a> IsClient<'a> for Client<'a> {
&mut self,
message: Message,
) -> Result