From 06e9bf982cc84fc79c5394490b2a73cfcfb7c935 Mon Sep 17 00:00:00 2001 From: Artemii Gerasimovich Date: Fri, 6 Dec 2024 23:03:32 +0100 Subject: [PATCH] Move legacy and refactored legacy to separate crates --- .github/workflows/build_nix.yml | 6 -- .github/workflows/lint.yml | 5 -- .github/workflows/test.yml | 5 -- Cargo.lock | 47 ++++++++++- Cargo.toml | 2 +- crates/legacy/src/{old => }/builder_state.rs | 0 crates/legacy/src/lib.rs | 78 ++++++++++++++++++- crates/legacy/src/old/lib.rs | 75 ------------------ crates/legacy/src/{old => }/service.rs | 0 .../src/{old => }/testing/basic_test.rs | 0 .../{old => }/testing/finalization_test.rs | 0 crates/legacy/src/{old => }/testing/mod.rs | 0 crates/legacy_refactored/Cargo.toml | 45 +++++++++++ .../src}/block_size_limits.rs | 0 .../src}/block_store.rs | 0 .../src}/lib.rs | 0 .../src}/service.rs | 0 .../src}/testing/basic.rs | 0 .../src}/testing/block_size.rs | 0 .../src}/testing/finalization.rs | 0 .../src}/testing/integration.rs | 0 .../src}/testing/mod.rs | 0 22 files changed, 163 insertions(+), 100 deletions(-) rename crates/legacy/src/{old => }/builder_state.rs (100%) delete mode 100644 crates/legacy/src/old/lib.rs rename crates/legacy/src/{old => }/service.rs (100%) rename crates/legacy/src/{old => }/testing/basic_test.rs (100%) rename crates/legacy/src/{old => }/testing/finalization_test.rs (100%) rename crates/legacy/src/{old => }/testing/mod.rs (100%) create mode 100644 crates/legacy_refactored/Cargo.toml rename crates/{legacy/src/refactored => legacy_refactored/src}/block_size_limits.rs (100%) rename crates/{legacy/src/refactored => legacy_refactored/src}/block_store.rs (100%) rename crates/{legacy/src/refactored => legacy_refactored/src}/lib.rs (100%) rename crates/{legacy/src/refactored => legacy_refactored/src}/service.rs (100%) rename crates/{legacy/src/refactored => legacy_refactored/src}/testing/basic.rs (100%) rename crates/{legacy/src/refactored => legacy_refactored/src}/testing/block_size.rs (100%) rename crates/{legacy/src/refactored => legacy_refactored/src}/testing/finalization.rs (100%) rename crates/{legacy/src/refactored => legacy_refactored/src}/testing/integration.rs (100%) rename crates/{legacy/src/refactored => legacy_refactored/src}/testing/mod.rs (100%) diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml index 5a5f6eba..7dff7d5c 100644 --- a/.github/workflows/build_nix.yml +++ b/.github/workflows/build_nix.yml @@ -11,12 +11,6 @@ on: jobs: nix: - strategy: - matrix: - flags: ["--cfg legacy_builder_refactored", ""] - env: - RUSTFLAGS: "${{ matrix.flags }}" - RUSTDOCFLAGS: "${{ matrix.flags }}" runs-on: ubuntu-latest timeout-minutes: 90 steps: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1610e0b7..92f471d6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,14 +14,9 @@ concurrency: jobs: lint: - strategy: - matrix: - flags: ["--cfg legacy_builder_refactored", ""] runs-on: ubuntu-latest env: - RUSTFLAGS: "${{ matrix.flags }}" - RUSTDOCFLAGS: "${{ matrix.flags }}" RUST_LOG: info steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3dd437d6..6441cebb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,12 +14,7 @@ concurrency: jobs: test: - strategy: - matrix: - flags: ["--cfg legacy_builder_refactored", ""] env: - RUSTFLAGS: "${{ matrix.flags }}" - RUSTDOCFLAGS: "${{ matrix.flags }}" RUST_LOG: info runs-on: ubuntu-latest steps: diff --git a/Cargo.lock b/Cargo.lock index 36129282..a6736007 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -2917,7 +2917,46 @@ dependencies = [ [[package]] name = "hotshot-builder-core" -version = "0.1.57" +version = "0.1.58" +dependencies = [ + "anyhow", + "async-broadcast", + "async-lock 3.4.0", + "async-trait", + "atomic", + "bincode", + "bytemuck", + "coarsetime", + "committable", + "derive_more 1.0.0", + "futures", + "hotshot", + "hotshot-builder-api", + "hotshot-example-types", + "hotshot-macros", + "hotshot-task-impls", + "hotshot-testing", + "hotshot-types", + "lru 0.12.5", + "marketplace-builder-shared", + "num_cpus", + "once_cell", + "portpicker", + "serde", + "sha2 0.10.8", + "tagged-base64", + "tide-disco", + "tokio", + "tracing", + "tracing-subscriber 0.3.18", + "tracing-test 0.1.0", + "url", + "vbs", +] + +[[package]] +name = "hotshot-builder-core-refactored" +version = "0.1.58" dependencies = [ "anyhow", "async-broadcast", @@ -4648,7 +4687,7 @@ dependencies = [ [[package]] name = "marketplace-builder-core" -version = "0.1.57" +version = "0.1.58" dependencies = [ "anyhow", "async-broadcast", @@ -4678,7 +4717,7 @@ dependencies = [ [[package]] name = "marketplace-builder-shared" -version = "0.1.57" +version = "0.1.58" dependencies = [ "anyhow", "async-broadcast", diff --git a/Cargo.toml b/Cargo.toml index 892e61bf..6fa0bd80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["crates/*"] [workspace.package] -version = "0.1.57" +version = "0.1.58" edition = "2021" [workspace.dependencies] diff --git a/crates/legacy/src/old/builder_state.rs b/crates/legacy/src/builder_state.rs similarity index 100% rename from crates/legacy/src/old/builder_state.rs rename to crates/legacy/src/builder_state.rs diff --git a/crates/legacy/src/lib.rs b/crates/legacy/src/lib.rs index 42842991..820e2153 100644 --- a/crates/legacy/src/lib.rs +++ b/crates/legacy/src/lib.rs @@ -1,5 +1,75 @@ -#[cfg_attr(legacy_builder_refactored, path = "refactored/lib.rs")] -#[cfg_attr(not(legacy_builder_refactored), path = "old/lib.rs")] -mod implementation; +// Copyright (c) 2024 Espresso Systems (espressosys.com) +// This file is part of the HotShot Builder Protocol. +// -pub use implementation::*; +// Builder Phase 1 +// It mainly provides three API services to hotshot proposers: +// 1. Serves a proposer(leader)'s request to provide blocks information +// 2. Serves a proposer(leader)'s request to provide the full blocks information +// 3. Serves a proposer(leader)'s request to provide the block header information + +// It also provides one API services external users: +// 1. Serves a user's request to submit a private transaction + +// providing the core services to support above API services +pub mod builder_state; + +// Core interaction with the HotShot network +pub mod service; + +// tracking the testing +#[cfg(test)] +pub mod testing; + +use hotshot_builder_api::v0_1::builder::BuildError; +use tokio::sync::mpsc::UnboundedReceiver; + +/// `WaitAndKeep` is a helper enum that allows for the lazy polling of a single +/// value from an unbound receiver. +#[derive(Debug)] +pub enum WaitAndKeep { + Keep(T), + Wait(UnboundedReceiver), +} + +#[derive(Debug)] +pub(crate) enum WaitAndKeepGetError { + FailedToResolvedVidCommitmentFromChannel, +} + +impl From for BuildError { + fn from(e: WaitAndKeepGetError) -> Self { + match e { + WaitAndKeepGetError::FailedToResolvedVidCommitmentFromChannel => { + BuildError::Error("failed to resolve VidCommitment from channel".to_string()) + } + } + } +} + +impl WaitAndKeep { + /// get will return a clone of the value that is already stored within the + /// value of `WaitAndKeep::Keep` if the value is already resolved. Otherwise + /// it will poll the next value from the channel and replace the locally + /// stored `WaitAndKeep::Wait` with the resolved value as a `WaitAndKeep::Keep`. + /// + /// Note: This pattern seems very similar to a Future, and ultimately + /// returns a future. It's not clear why this needs to be implemented + /// in such a way and not just implemented as a boxed future. + pub(crate) async fn get(&mut self) -> Result { + match self { + WaitAndKeep::Keep(t) => Ok(t.clone()), + WaitAndKeep::Wait(fut) => { + let got = fut + .recv() + .await + .ok_or(WaitAndKeepGetError::FailedToResolvedVidCommitmentFromChannel); + if let Ok(got) = &got { + let mut replace = WaitAndKeep::Keep(got.clone()); + core::mem::swap(self, &mut replace); + } + got + } + } + } +} diff --git a/crates/legacy/src/old/lib.rs b/crates/legacy/src/old/lib.rs deleted file mode 100644 index 820e2153..00000000 --- a/crates/legacy/src/old/lib.rs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2024 Espresso Systems (espressosys.com) -// This file is part of the HotShot Builder Protocol. -// - -// Builder Phase 1 -// It mainly provides three API services to hotshot proposers: -// 1. Serves a proposer(leader)'s request to provide blocks information -// 2. Serves a proposer(leader)'s request to provide the full blocks information -// 3. Serves a proposer(leader)'s request to provide the block header information - -// It also provides one API services external users: -// 1. Serves a user's request to submit a private transaction - -// providing the core services to support above API services -pub mod builder_state; - -// Core interaction with the HotShot network -pub mod service; - -// tracking the testing -#[cfg(test)] -pub mod testing; - -use hotshot_builder_api::v0_1::builder::BuildError; -use tokio::sync::mpsc::UnboundedReceiver; - -/// `WaitAndKeep` is a helper enum that allows for the lazy polling of a single -/// value from an unbound receiver. -#[derive(Debug)] -pub enum WaitAndKeep { - Keep(T), - Wait(UnboundedReceiver), -} - -#[derive(Debug)] -pub(crate) enum WaitAndKeepGetError { - FailedToResolvedVidCommitmentFromChannel, -} - -impl From for BuildError { - fn from(e: WaitAndKeepGetError) -> Self { - match e { - WaitAndKeepGetError::FailedToResolvedVidCommitmentFromChannel => { - BuildError::Error("failed to resolve VidCommitment from channel".to_string()) - } - } - } -} - -impl WaitAndKeep { - /// get will return a clone of the value that is already stored within the - /// value of `WaitAndKeep::Keep` if the value is already resolved. Otherwise - /// it will poll the next value from the channel and replace the locally - /// stored `WaitAndKeep::Wait` with the resolved value as a `WaitAndKeep::Keep`. - /// - /// Note: This pattern seems very similar to a Future, and ultimately - /// returns a future. It's not clear why this needs to be implemented - /// in such a way and not just implemented as a boxed future. - pub(crate) async fn get(&mut self) -> Result { - match self { - WaitAndKeep::Keep(t) => Ok(t.clone()), - WaitAndKeep::Wait(fut) => { - let got = fut - .recv() - .await - .ok_or(WaitAndKeepGetError::FailedToResolvedVidCommitmentFromChannel); - if let Ok(got) = &got { - let mut replace = WaitAndKeep::Keep(got.clone()); - core::mem::swap(self, &mut replace); - } - got - } - } - } -} diff --git a/crates/legacy/src/old/service.rs b/crates/legacy/src/service.rs similarity index 100% rename from crates/legacy/src/old/service.rs rename to crates/legacy/src/service.rs diff --git a/crates/legacy/src/old/testing/basic_test.rs b/crates/legacy/src/testing/basic_test.rs similarity index 100% rename from crates/legacy/src/old/testing/basic_test.rs rename to crates/legacy/src/testing/basic_test.rs diff --git a/crates/legacy/src/old/testing/finalization_test.rs b/crates/legacy/src/testing/finalization_test.rs similarity index 100% rename from crates/legacy/src/old/testing/finalization_test.rs rename to crates/legacy/src/testing/finalization_test.rs diff --git a/crates/legacy/src/old/testing/mod.rs b/crates/legacy/src/testing/mod.rs similarity index 100% rename from crates/legacy/src/old/testing/mod.rs rename to crates/legacy/src/testing/mod.rs diff --git a/crates/legacy_refactored/Cargo.toml b/crates/legacy_refactored/Cargo.toml new file mode 100644 index 00000000..a5e64591 --- /dev/null +++ b/crates/legacy_refactored/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "hotshot-builder-core-refactored" +version = { workspace = true } +edition = { workspace = true } + +[dependencies] +marketplace-builder-shared = { path = "../shared" } + +anyhow = { workspace = true } +async-broadcast = { workspace = true } +async-lock = { workspace = true } +async-trait = { workspace = true } +atomic = "0.6" +bincode = { workspace = true } +bytemuck = { version = "1.19", features = ["derive"] } +coarsetime = "0.1.34" +committable = { workspace = true } +derive_more = { workspace = true, features = ["deref", "deref_mut", "debug"] } +futures = { workspace = true } +hotshot = { workspace = true } +hotshot-builder-api = { workspace = true } +hotshot-types = { workspace = true } +lru = { workspace = true } +once_cell = { workspace = true } +serde = { workspace = true, features = ["derive"] } +sha2 = { workspace = true } +tagged-base64 = { workspace = true } +tide-disco = { workspace = true } +tokio = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } +vbs = { workspace = true } + +[dev-dependencies] +hotshot-example-types = { workspace = true } +hotshot-macros = { workspace = true } +hotshot-task-impls = { workspace = true } +hotshot-testing = { workspace = true } +num_cpus = { workspace = true } +portpicker = { workspace = true } +tracing-test = { workspace = true } +url = { workspace = true } + +[lints] +workspace = true diff --git a/crates/legacy/src/refactored/block_size_limits.rs b/crates/legacy_refactored/src/block_size_limits.rs similarity index 100% rename from crates/legacy/src/refactored/block_size_limits.rs rename to crates/legacy_refactored/src/block_size_limits.rs diff --git a/crates/legacy/src/refactored/block_store.rs b/crates/legacy_refactored/src/block_store.rs similarity index 100% rename from crates/legacy/src/refactored/block_store.rs rename to crates/legacy_refactored/src/block_store.rs diff --git a/crates/legacy/src/refactored/lib.rs b/crates/legacy_refactored/src/lib.rs similarity index 100% rename from crates/legacy/src/refactored/lib.rs rename to crates/legacy_refactored/src/lib.rs diff --git a/crates/legacy/src/refactored/service.rs b/crates/legacy_refactored/src/service.rs similarity index 100% rename from crates/legacy/src/refactored/service.rs rename to crates/legacy_refactored/src/service.rs diff --git a/crates/legacy/src/refactored/testing/basic.rs b/crates/legacy_refactored/src/testing/basic.rs similarity index 100% rename from crates/legacy/src/refactored/testing/basic.rs rename to crates/legacy_refactored/src/testing/basic.rs diff --git a/crates/legacy/src/refactored/testing/block_size.rs b/crates/legacy_refactored/src/testing/block_size.rs similarity index 100% rename from crates/legacy/src/refactored/testing/block_size.rs rename to crates/legacy_refactored/src/testing/block_size.rs diff --git a/crates/legacy/src/refactored/testing/finalization.rs b/crates/legacy_refactored/src/testing/finalization.rs similarity index 100% rename from crates/legacy/src/refactored/testing/finalization.rs rename to crates/legacy_refactored/src/testing/finalization.rs diff --git a/crates/legacy/src/refactored/testing/integration.rs b/crates/legacy_refactored/src/testing/integration.rs similarity index 100% rename from crates/legacy/src/refactored/testing/integration.rs rename to crates/legacy_refactored/src/testing/integration.rs diff --git a/crates/legacy/src/refactored/testing/mod.rs b/crates/legacy_refactored/src/testing/mod.rs similarity index 100% rename from crates/legacy/src/refactored/testing/mod.rs rename to crates/legacy_refactored/src/testing/mod.rs