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

add builder specific information #14

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ clap = { version = "4.4", features = ["derive", "env"] }
commit = { git = "https://github.com/EspressoSystems/commit.git" }
derive_more = "0.99"
futures = "0.3"
hotshot-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.7.1" }
#hotshot-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.7.1" }
hotshot-types = { git = "https://github.com/EspressoSystems/HotShot.git", branch = "main" }
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 , but we'll want to pin again once there's an appropriate tage on HotShot.

Copy link
Contributor

@QuentinI QuentinI Feb 7, 2024

Choose a reason for hiding this comment

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

Wasn't the plan to wait for new tag in HotShot before switching to BuilderCommitment?
cc: @nyospe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! I think you are right. I missed the conversation.

serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10"
snafu = { version = "0.7", features = ["backtraces"] }
Expand Down
26 changes: 20 additions & 6 deletions src/block_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::{hash::Hash, marker::PhantomData};

use commit::{Commitment, Committable};
use hotshot_types::traits::{node_implementation::NodeType, BlockPayload};
use hotshot_types::{
traits::{node_implementation::NodeType, BlockPayload, signature_key::SignatureKey},
utils::BuilderCommitment
};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};

Expand Down Expand Up @@ -33,11 +36,22 @@ impl<I: NodeType> Committable for HashableBlock<I> {
}
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[serde(bound = "")]
pub struct BlockMetadata<I: NodeType> {
nyospe marked this conversation as resolved.
Show resolved Hide resolved
block_hash: BlockHash<I>,
block_size: u64,
offered_fee: u64,
_phantom: PhantomData<I>,
pub block_hash: BuilderCommitment,
pub block_size: u64,
pub offered_fee: u64,
pub signature: <<I as NodeType>::SignatureKey as SignatureKey>::PureAssembledSignatureType,
pub _phantom: PhantomData<I>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Always put PhantomData last...

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it actually needed here and in Blockdata anyways? I is already used in other fields

Copy link
Contributor

Choose a reason for hiding this comment

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

signature only binds SignatureKey::PureAssembledSignatureType, it cannot guarantee that there is a specific unique I: NodeType for that binding. Same for block_payload. We know it is whatever NodeType constrains BlockPayload to be, but we don't get the I bound to the struct.

We didn't need it when we had block_hash: BlockHash<I>, though...

pub sender: <I as NodeType>::SignatureKey,
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[serde(bound = "")]
pub struct Blockdata<I: NodeType> {
nyospe marked this conversation as resolved.
Show resolved Hide resolved
pub block_payload: <I as NodeType>::BlockPayload,
pub signature: <<I as NodeType>::SignatureKey as SignatureKey>::PureAssembledSignatureType,
pub _phantom: PhantomData<I>,
nyospe marked this conversation as resolved.
Show resolved Hide resolved
pub sender: <I as NodeType>::SignatureKey,
}
4 changes: 2 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{fmt::Display, path::PathBuf};
use clap::Args;
use derive_more::From;
use futures::FutureExt;
use hotshot_types::traits::{node_implementation::NodeType, signature_key::SignatureKey};
use hotshot_types::{traits::{node_implementation::NodeType, signature_key::SignatureKey}, utils::BuilderCommitment};
use serde::{Deserialize, Serialize};
use snafu::{ResultExt, Snafu};
use tagged_base64::TaggedBase64;
Expand Down Expand Up @@ -95,7 +95,7 @@ where
})?
.get("claim_block", |req, state| {
async move {
let hash = req.blob_param("block_hash")?;
let hash:BuilderCommitment = req.blob_param("block_hash")?;
let signature = req.blob_param("signature")?;
state
.claim_block(&hash, &signature)
Expand Down
7 changes: 4 additions & 3 deletions src/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use async_trait::async_trait;
use hotshot_types::{
data::VidCommitment,
traits::{node_implementation::NodeType, signature_key::SignatureKey},
utils::BuilderCommitment
};
use tagged_base64::TaggedBase64;

use crate::{
block_metadata::{BlockHash, BlockMetadata},
block_metadata::{BlockMetadata, Blockdata},
builder::BuildError,
};

Expand All @@ -23,8 +24,8 @@ where
) -> Result<Vec<BlockMetadata<I>>, BuildError>;
async fn claim_block(
&self,
block_hash: &BlockHash<I>,
block_hash: &BuilderCommitment,
signature: &<<I as NodeType>::SignatureKey as SignatureKey>::PureAssembledSignatureType,
) -> Result<I::BlockPayload, BuildError>;
) -> Result<Blockdata<I>, BuildError>;
async fn submit_txn(&self, txn: <I as NodeType>::Transaction) -> Result<(), BuildError>;
}
2 changes: 1 addition & 1 deletion src/query_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};

use crate::block_metadata::BlockMetadata;

#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[serde(bound = "")]
pub struct AvailableBlocksQueryData<I: NodeType> {
pub blocks: Vec<BlockMetadata<I>>,
Expand Down
Loading