Skip to content

Commit

Permalink
Create builder state coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinI committed Nov 12, 2024
1 parent 941a8b2 commit eaa3970
Show file tree
Hide file tree
Showing 17 changed files with 1,500 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
disallowed-names = [ "TYPES" ]
doc-valid-idents = [ "HotShot", ".." ]
disallowed-names = ["TYPES"]
doc-valid-idents = ["HotShot", ".."]
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
runs-on: ubuntu-latest
env:
RUSTFLAGS: '--cfg async_executor_impl="async-std" --cfg async_channel_impl="async-std"'
RUSTDOCFLAGS: '--cfg async_executor_impl="async-std" --cfg async_channel_impl="async-std"'
RUST_LOG: info
steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Cargo.lock
/target*
/.vscode

mutants.out/
mutants.out.old/

# OSX
**/.DS_Store

15 changes: 14 additions & 1 deletion Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ clap = "4.5"
chrono = { version = "0.4", features = ["serde"] }
committable = "0.2"
derivative = "2.2"
derive_more = "1.0"
either = "1.13"
futures = "0.3"
jf-vid = { version = "0.1.0", git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.5" }
hex = "0.4.3"
lru = "0.12.5"
multimap = "0.10.0"
nonempty-collections = "0.2"
num_cpus = "1.16"
rand = "0.8"
serde = "1.0"
Expand All @@ -40,6 +43,7 @@ tide-disco = "0.9"
tokio = "1"
toml = "0.8"
tracing = "0.1"
typenum = "1.17"
url = "2.3"
vbs = "0.1"
vec1 = "1.12"
Expand All @@ -52,6 +56,7 @@ edition = "2021"
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(async_executor_impl, values("async-std", "tokio"))',
'cfg(async_channel_impl, values("async-std", "tokio"))',
'cfg(coverage_nightly)',
] }

[workspace.lints.clippy]
Expand Down
9 changes: 6 additions & 3 deletions crates/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ name = "marketplace-builder-shared"
version = { workspace = true }
edition = { workspace = true }

[features]
testing = []

[dependencies]
anyhow = { workspace = true }
async-broadcast = { workspace = true }
async-compatibility-layer = { workspace = true }
async-lock = { workspace = true }
async-std = { workspace = true }
async-trait = { workspace = true }
bincode = { workspace = true }
chrono = { workspace = true }
committable = { workspace = true }
derive_more = { workspace = true, features = ["debug"] }
either = { workspace = true }
futures = { workspace = true }
hex = { workspace = true }
hotshot = { workspace = true }
hotshot-builder-api = { workspace = true }
hotshot-events-service = { workspace = true }
hotshot-example-types = { workspace = true }
hotshot-task-impls = { workspace = true }
hotshot-testing = { workspace = true }
hotshot-types = { workspace = true }
jf-vid = { workspace = true }
nonempty-collections = { workspace = true }
rand = { workspace = true }
serde = { workspace = true }
surf-disco = { workspace = true }
Expand Down
69 changes: 65 additions & 4 deletions crates/shared/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
//! Shared types dealing with block information
use committable::Commitment;
use std::time::Instant;

use committable::{Commitment, Committable};
use hotshot_types::data::fake_commitment;
use hotshot_types::traits::node_implementation::ConsensusTime;
use hotshot_types::{
data::Leaf, traits::node_implementation::NodeType, utils::BuilderCommitment, vid::VidCommitment,
data::Leaf,
traits::{block_contents::Transaction, node_implementation::NodeType},
utils::BuilderCommitment,
vid::VidCommitment,
};

/// Enum to hold the different sources of the transaction
#[derive(Clone, Debug, PartialEq)]
pub enum TransactionSource {
/// Transaction from private mempool
Private,
/// Transaction from public mempool
Public,
}

/// [`ReceivedTransaction`] represents receipt information concerning a received
/// [`NodeType::Transaction`].
#[derive(Debug, Clone)]
pub struct ReceivedTransaction<Types: NodeType> {
/// the transaction
pub transaction: Types::Transaction,
/// transaction's hash
pub commit: Commitment<Types::Transaction>,
/// transaction's esitmated length
pub min_block_size: u64,
/// transaction's source
pub source: TransactionSource,
/// received time
pub time_in: Instant,
}

impl<Types: NodeType> ReceivedTransaction<Types> {
pub fn new(transaction: Types::Transaction, source: TransactionSource) -> Self {
Self {
commit: transaction.commit(),
min_block_size: transaction.minimum_block_size(),
source,
time_in: Instant::now(),
transaction,
}
}
}

/// Unique identifier for a block
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BlockId<Types: NodeType> {
Expand All @@ -31,7 +75,7 @@ impl<Types: NodeType> std::fmt::Display for BlockId<Types> {
/// and view of the block it targets to extend, i.e.
/// builder with given state ID assumes blocks/bundles it's building
/// are going to be included immediately after the parent block.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct BuilderStateId<Types: NodeType> {
/// View number of the parent block
pub parent_view: Types::View,
Expand All @@ -50,12 +94,29 @@ impl<Types: NodeType> std::fmt::Display for BuilderStateId<Types> {
}

/// References to the parent block that is extended to spawn the new builder state.
#[derive(Debug, Clone)]
#[derive(derive_more::Debug, Clone, PartialEq, Eq)]
pub struct ParentBlockReferences<Types: NodeType> {
pub view_number: Types::View,
pub vid_commitment: VidCommitment,
pub leaf_commit: Commitment<Leaf<Types>>,
pub builder_commitment: BuilderCommitment,
pub tx_number: usize,
}

impl<Types> ParentBlockReferences<Types>
where
Types: NodeType,
{
/// Create mock references for bootstrap (don't correspond to a real block)
pub fn bootstrap() -> Self {
Self {
view_number: Types::View::genesis(),
vid_commitment: VidCommitment::default(),
leaf_commit: fake_commitment(),
builder_commitment: BuilderCommitment::from_bytes([0; 32]),
tx_number: 0,
}
}
}

// implement display for the derived info
Expand Down
Loading

0 comments on commit eaa3970

Please sign in to comment.