Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move legacy and refactored legacy to separate crates #271

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
47 changes: 43 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["crates/*"]

[workspace.package]
version = "0.1.57"
version = "0.1.58"
edition = "2021"

[workspace.dependencies]
Expand Down
78 changes: 74 additions & 4 deletions crates/legacy/src/lib.rs
Copy link
Contributor Author

@QuentinI QuentinI Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just moving crates/legacy/src/old/lib.rs -> crates/legacy/src/lib.rs, git isn't smart enough to realize what happened and thinks I changed it.

Original file line number Diff line number Diff line change
@@ -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<T> {
Keep(T),
Wait(UnboundedReceiver<T>),
}

#[derive(Debug)]
pub(crate) enum WaitAndKeepGetError {
FailedToResolvedVidCommitmentFromChannel,
}

impl From<WaitAndKeepGetError> for BuildError {
fn from(e: WaitAndKeepGetError) -> Self {
match e {
WaitAndKeepGetError::FailedToResolvedVidCommitmentFromChannel => {
BuildError::Error("failed to resolve VidCommitment from channel".to_string())
}
}
}
}

impl<T: Clone> WaitAndKeep<T> {
/// 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<T, WaitAndKeepGetError> {
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
}
}
}
}
75 changes: 0 additions & 75 deletions crates/legacy/src/old/lib.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions crates/legacy_refactored/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Loading