Skip to content

Commit

Permalink
Bring hotshot-types and hs-builder-api into Hotshot (#2812)
Browse files Browse the repository at this point in the history
* WIP

* Still chasing a bug

* One down, one to go

* ... and done.

* Cleanup and finishing touches

* Fixing the post-merge code, and one missed issue in the pre-merge code.

* Some clarifying name changes.

* Removing bincode dependency where applicable

* cleanup of some (not quite all) remaining bincode invocations

* dependency versioning tags and cleanup

* bump version

* Bumping anticipated version

* Now with new VBS

* branch => tag on dependencies

* Update lock?

* Cargo.lock update

* Apparently `just * lint` runs with --features="hotshot-testing" enabled

* integrate new storage type

* fix build, tie up stragglers, modifying tasks next

* merge latest stable tabs

* merge latest tags and fix method signatures

* Update *-disco

* Dependencies updated to tags

* Add builder-api and types to repo

* fix doc

* hs-builder-api -> hotshot-builder-api

* fmt

---------

Co-authored-by: Nathan F Yospe <[email protected]>
Co-authored-by: Jarred Parr <[email protected]>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent b0adec3 commit 8bf55cf
Show file tree
Hide file tree
Showing 53 changed files with 6,251 additions and 290 deletions.
303 changes: 76 additions & 227 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ repository = "https://github.com/EspressoSystems/HotShot"
# when implementing traits externally
[workspace]
members = [
"crates/hotshot",
"crates/hotshot-stake-table",
"crates/libp2p-networking",
"crates/macros",
"crates/testing-macros",
"crates/task",
"crates/task-impls",
"crates/testing",
"crates/examples",
"crates/example-types",
"crates/hotshot",
"crates/hotshot-stake-table",
"crates/libp2p-networking",
"crates/macros",
"crates/testing-macros",
"crates/task",
"crates/task-impls",
"crates/testing",
"crates/examples",
"crates/example-types",
"crates/types",
"crates/builder-api",
]
resolver = "2"

Expand Down Expand Up @@ -59,9 +61,9 @@ futures = "0.3.30"
# TODO generic-array should not be a direct dependency
# https://github.com/EspressoSystems/HotShot/issues/1850
generic-array = { version = "0.14.7", features = ["serde"] }
hotshot-types = { git = "https://github.com/EspressoSystems/hotshot-types", tag = "0.1.11" }
hs-builder-api = { git = "https://github.com/EspressoSystems/hs-builder-api", tag = "0.1.6" }
jf-primitives = { git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.2" }
jf-primitives = { git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.2", features = [
"test-srs",
] }
jf-plonk = { git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.2" }
jf-relation = { git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.2" }
jf-utils = { git = "https://github.com/espressosystems/jellyfish", tag = "0.4.2" }
Expand Down
19 changes: 19 additions & 0 deletions crates/builder-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "hotshot-builder-api"
version = "0.1.6"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = { workspace = true }
clap = { version = "4.4", features = ["derive", "env"] }
derive_more = "0.99"
futures = "0.3"
hotshot-types = { path = "../types" }
serde = { workspace = true }
snafu = { workspace = true }
tagged-base64 = { workspace = true }
tide-disco = { workspace = true }
toml = { workspace = true }
versioned-binary-serialization = { workspace = true }
4 changes: 4 additions & 0 deletions crates/builder-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# hotshot-builder-api
Minimal dependencies shared API definitions for HotShot Builder protocol

# HotShot Consensus Module
65 changes: 65 additions & 0 deletions crates/builder-api/api/builder.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright (c) 2024 Espresso Systems (espressosys.com)
# This file is part of the HotShot Builder Protocol.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

[meta]
NAME = "hs-builder-get"
DESCRIPTION = ""
FORMAT_VERSION = "0.1.0"

[route.available_blocks]
PATH = ["availableblocks/:parent_hash"]
":parent_hash" = "TaggedBase64"
DOC = """
Get descriptions for all block candidates based on a specific parent block.
Returns
```
[
"block_metadata": {
"block_hash": TaggedBase64,
"block_size": integer,
"offered_fee": integer,
},
]
```
"""

[route.claim_block]
PATH = ["claimblock/:block_hash/:signature"]
":block_hash" = "TaggedBase64"
":signature" = "TaggedBase64"
DOC = """
Get the specified block candidate.
Returns application-specific encoded transactions type
"""

[route.claim_header_input]
PATH = ["claimheaderinput/:block_hash/:signature"]
":block_hash" = "TaggedBase64"
":signature" = "TaggedBase64"
DOC = """
Get the specified block candidate.
Returns application-specific block header type
"""
33 changes: 33 additions & 0 deletions crates/builder-api/api/submit.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2024 Espresso Systems (espressosys.com)
# This file is part of the HotShot Builder Protocol.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


[meta]
NAME = "hs-builder-submit"
DESCRIPTION = ""
FORMAT_VERSION = "0.1.0"

[route.submit_txn]
PATH = ["/submit"]
METHOD = "POST"
DOC = "Submit a transaction to builder's private mempool."
59 changes: 59 additions & 0 deletions crates/builder-api/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2022 Espresso Systems (espressosys.com)
// This file is part of the HotShot Query Service library.
//
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// You should have received a copy of the GNU General Public License along with this program. If not,
// see <https://www.gnu.org/licenses/>.

use std::fs;
use std::path::Path;
use tide_disco::api::{Api, ApiError};
use toml::{map::Entry, Value};
use versioned_binary_serialization::version::StaticVersionType;

pub(crate) fn load_api<State, Error, Ver: StaticVersionType>(
path: Option<impl AsRef<Path>>,
default: &str,
extensions: impl IntoIterator<Item = Value>,
) -> Result<Api<State, Error, Ver>, ApiError> {
let mut toml = match path {
Some(path) => load_toml(path.as_ref())?,
None => toml::from_str(default).map_err(|err| ApiError::CannotReadToml {
reason: err.to_string(),
})?,
};
for extension in extensions {
merge_toml(&mut toml, extension);
}
Api::new(toml)
}

fn merge_toml(into: &mut Value, from: Value) {
if let (Value::Table(into), Value::Table(from)) = (into, from) {
for (key, value) in from {
match into.entry(key) {
Entry::Occupied(mut entry) => merge_toml(entry.get_mut(), value),
Entry::Vacant(entry) => {
entry.insert(value);
}
}
}
}
}

fn load_toml(path: &Path) -> Result<Value, ApiError> {
let bytes = fs::read(path).map_err(|err| ApiError::CannotReadToml {
reason: err.to_string(),
})?;
let string = std::str::from_utf8(&bytes).map_err(|err| ApiError::CannotReadToml {
reason: err.to_string(),
})?;
toml::from_str(string).map_err(|err| ApiError::CannotReadToml {
reason: err.to_string(),
})
}
38 changes: 38 additions & 0 deletions crates/builder-api/src/block_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::{hash::Hash, marker::PhantomData};

use hotshot_types::{
traits::{node_implementation::NodeType, signature_key::SignatureKey, BlockPayload},
utils::BuilderCommitment,
vid::VidCommitment,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[serde(bound = "")]
pub struct AvailableBlockInfo<I: NodeType> {
pub block_hash: BuilderCommitment,
pub block_size: u64,
pub offered_fee: u64,
pub signature: <<I as NodeType>::SignatureKey as SignatureKey>::PureAssembledSignatureType,
pub sender: <I as NodeType>::SignatureKey,
pub _phantom: PhantomData<I>,
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[serde(bound = "")]
pub struct AvailableBlockData<I: NodeType> {
pub block_payload: <I as NodeType>::BlockPayload,
pub metadata: <<I as NodeType>::BlockPayload as BlockPayload>::Metadata,
pub signature: <<I as NodeType>::SignatureKey as SignatureKey>::PureAssembledSignatureType,
pub sender: <I as NodeType>::SignatureKey,
pub _phantom: PhantomData<I>,
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[serde(bound = "")]
pub struct AvailableBlockHeaderInput<I: NodeType> {
pub vid_commitment: VidCommitment,
pub signature: <<I as NodeType>::SignatureKey as SignatureKey>::PureAssembledSignatureType,
pub sender: <I as NodeType>::SignatureKey,
pub _phantom: PhantomData<I>,
}
Loading

0 comments on commit 8bf55cf

Please sign in to comment.