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

[Marketplace] Builder API adjustments #3493

Merged
merged 1 commit into from
Jul 26, 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
33 changes: 4 additions & 29 deletions crates/builder-api/api/v0_3/builder.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,12 @@ NAME = "hs-builder-get"
DESCRIPTION = ""
FORMAT_VERSION = "0.1.0"

[route.available_blocks]
PATH = ["availableblocks/:parent_hash/:view_number/:sender/:signature"]
":parent_hash" = "TaggedBase64"
[route.bundle]
PATH = ["bundle/:view_number"]
":view_number" = "Integer"
":sender" = "TaggedBase64"
":signature" = "TaggedBase64"
METHOD = "POST"
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/:view_number/:sender/:signature"]
":block_hash" = "TaggedBase64"
":view_number" = "Integer"
":sender" = "TaggedBase64"
":signature" = "TaggedBase64"
DOC = """
Get the specified block candidate.

Returns application-specific encoded transactions type
Fetch the bundle from the builder for the specified view.
"""

[route.builder_address]
Expand Down
32 changes: 0 additions & 32 deletions crates/builder-api/src/v0_3/block_info.rs

This file was deleted.

33 changes: 6 additions & 27 deletions crates/builder-api/src/v0_3/builder.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use futures::FutureExt;
use hotshot_types::{traits::node_implementation::NodeType, utils::BuilderCommitment};
use hotshot_types::traits::node_implementation::NodeType;
use snafu::ResultExt;
use tide_disco::{api::ApiError, method::ReadState, Api};

use super::{data_source::BuilderDataSource, Version};
use crate::api::load_api;
/// No changes to these types
pub use crate::v0_1::builder::{
submit_api, BlockAvailableSnafu, BlockClaimSnafu, BuildError, BuilderAddressSnafu, Error,
Options,
};
use crate::{api::load_api, v0_1::builder::try_extract_param};

pub fn define_api<State, Types: NodeType>(
options: &Options,
Expand All @@ -24,33 +24,12 @@ where
options.extensions.clone(),
)?;
api.with_version("0.0.3".parse().unwrap())
.get("available_blocks", |req, state| {
.get("bundle", |req, state| {
async move {
let hash = req.blob_param("parent_hash")?;
let view_number = req.integer_param("view_number")?;
let signature = try_extract_param(&req, "signature")?;
let sender = try_extract_param(&req, "sender")?;
state
.available_blocks(&hash, view_number, sender, &signature)
.await
.context(BlockAvailableSnafu {
resource: hash.to_string(),
})
}
.boxed()
})?
.get("claim_block", |req, state| {
async move {
let block_hash: BuilderCommitment = req.blob_param("block_hash")?;
let view_number = req.integer_param("view_number")?;
let signature = try_extract_param(&req, "signature")?;
let sender = try_extract_param(&req, "sender")?;
state
.claim_block(&block_hash, view_number, sender, &signature)
.await
.context(BlockClaimSnafu {
resource: block_hash.to_string(),
})
state.bundle(view_number).await.context(BlockClaimSnafu {
resource: view_number.to_string(),
})
}
.boxed()
})?
Expand Down
28 changes: 3 additions & 25 deletions crates/builder-api/src/v0_3/data_source.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
use async_trait::async_trait;
use hotshot_types::{
traits::{node_implementation::NodeType, signature_key::SignatureKey},
utils::BuilderCommitment,
vid::VidCommitment,
};
use hotshot_types::{bundle::Bundle, traits::node_implementation::NodeType};

use super::{
block_info::{AvailableBlockData, AvailableBlockInfo},
builder::BuildError,
};
use super::builder::BuildError;
/// No changes to these types
pub use crate::v0_1::data_source::AcceptsTxnSubmits;

#[async_trait]
pub trait BuilderDataSource<TYPES: NodeType> {
/// To get the list of available blocks
async fn available_blocks(
&self,
for_parent: &VidCommitment,
view_number: u64,
sender: TYPES::SignatureKey,
signature: &<TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType,
) -> Result<Vec<AvailableBlockInfo<TYPES>>, BuildError>;

/// to claim a block from the list of provided available blocks
async fn claim_block(
&self,
block_hash: &BuilderCommitment,
view_number: u64,
sender: TYPES::SignatureKey,
signature: &<TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType,
) -> Result<AvailableBlockData<TYPES>, BuildError>;
async fn bundle(&self, view_number: u64) -> Result<Bundle<TYPES>, BuildError>;

/// To get the builder's address
async fn builder_address(&self) -> Result<TYPES::BuilderSignatureKey, BuildError>;
Expand Down
1 change: 0 additions & 1 deletion crates/builder-api/src/v0_3/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod block_info;
pub mod builder;
pub mod data_source;
/// No changes to this module
Expand Down
23 changes: 4 additions & 19 deletions crates/task-impls/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,10 @@ pub mod v0_2 {
pub type Version = StaticVersion<0, 2>;
}

/// Version 0.3. Removes `claim_block_header_input` endpoint, adds fee information
/// to `claim_block` endpoint.
/// Version 0.3: marketplace. Bundles.
pub mod v0_3 {
use hotshot_builder_api::v0_3::block_info::AvailableBlockData;
pub use hotshot_builder_api::v0_3::Version;
use hotshot_types::{
traits::{node_implementation::NodeType, signature_key::SignatureKey},
utils::BuilderCommitment,
};
use tagged_base64::TaggedBase64;
use hotshot_types::{bundle::Bundle, traits::node_implementation::NodeType};
use vbs::version::StaticVersion;

pub use super::BuilderClientError;
Expand All @@ -217,18 +211,9 @@ pub mod v0_3 {
/// # Errors
/// - [`BuilderClientError::NotFound`] if block isn't available
/// - [`BuilderClientError::Api`] if API isn't responding or responds incorrectly
pub async fn claim_block(
&self,
block_hash: BuilderCommitment,
view_number: u64,
sender: TYPES::SignatureKey,
signature: &<<TYPES as NodeType>::SignatureKey as SignatureKey>::PureAssembledSignatureType,
) -> Result<AvailableBlockData<TYPES>, BuilderClientError> {
let encoded_signature: TaggedBase64 = signature.clone().into();
pub async fn bundle(&self, view_number: u64) -> Result<Bundle<TYPES>, BuilderClientError> {
self.inner
.get(&format!(
"claimblock/{block_hash}/{view_number}/{sender}/{encoded_signature}"
))
.get(&format!("bundle/{view_number}"))
.send()
.await
.map_err(Into::into)
Expand Down
Loading