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

feature gate hotshot trait impls #2343

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion 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 sequencer/src/block/namespace_payload/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a> Iter<'a> {
}
}

impl<'a> Iterator for Iter<'a> {
impl Iterator for Iter<'_> {
type Item = Index;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
1 change: 1 addition & 0 deletions sequencer/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::needless_lifetimes)]
use core::fmt::Display;
use jf_signature::{bls_over_bn254, schnorr};
use sequencer_utils::logging;
Expand Down
8 changes: 5 additions & 3 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ edition = "2021"

[features]
testing = []
default = ["hotshot-impls"]
hotshot-impls = ["hotshot", "hotshot-orchestrator", "dyn-clone"]

[dependencies]

Expand All @@ -22,12 +24,12 @@ cld = { workspace = true }
committable = { workspace = true }
contract-bindings = { path = "../contract-bindings" }
derive_more = { workspace = true }
dyn-clone = { workspace = true }
dyn-clone = { workspace = true, optional = true }
ethers = { workspace = true }
fluent-asserter = "0.1.9"
futures = { workspace = true }
hotshot = { workspace = true }
hotshot-orchestrator = { workspace = true }
hotshot = { workspace = true, optional = true }
hotshot-orchestrator = { workspace = true, optional = true }
hotshot-query-service = { workspace = true }
hotshot-types = { workspace = true }
itertools = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions types/src/eth_signature_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use ethers::{
types::{Address, Signature},
utils::public_key_to_address,
};
use hotshot_types::traits::signature_key::BuilderSignatureKey;
use hotshot_types::traits::signature_key::PrivateSignatureKey;

use hotshot_types::traits::signature_key::{BuilderSignatureKey, PrivateSignatureKey};
use serde::{Deserialize, Serialize};
use thiserror::Error;

Expand Down
2 changes: 1 addition & 1 deletion types/src/reference_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(test)]
#![cfg(all(test, feature = "hotshot-impls"))]
//! Reference data types.
//!
//! This module provides some reference instantiations of various data types which have an external,
Expand Down
5 changes: 5 additions & 0 deletions types/src/v0/impls/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl Default for BidTxBody {
}
}
}

impl Default for BidTx {
fn default() -> Self {
BidTxBody::default()
Expand Down Expand Up @@ -217,6 +218,7 @@ impl BidTx {

Ok(())
}

/// Cryptographic signature verification
fn verify(&self) -> Result<(), ExecutionError> {
self.body
Expand Down Expand Up @@ -328,6 +330,7 @@ impl Default for SolverAuctionResults {
}
}

#[cfg(feature = "hotshot-impls")]
impl HasUrls for SolverAuctionResults {
/// Get the urls to fetch bids from builders.
fn urls(&self) -> Vec<Url> {
Expand Down Expand Up @@ -359,6 +362,7 @@ impl Default for SolverAuctionResultsProvider {
}
}

#[cfg(feature = "hotshot-impls")]
#[async_trait]
impl<TYPES: NodeType> AuctionResultsProvider<TYPES> for SolverAuctionResultsProvider {
/// Fetch the auction results from the solver.
Expand All @@ -378,6 +382,7 @@ impl<TYPES: NodeType> AuctionResultsProvider<TYPES> for SolverAuctionResultsProv
}
}

#[cfg(feature = "hotshot-impls")]
mod test {
use super::*;

Expand Down
1 change: 1 addition & 0 deletions types/src/v0/impls/block/full_payload/ns_proof/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "hotshot-impls")]
use futures::future;
use hotshot::helpers::initialize_logging;
use hotshot::traits::BlockPayload;
Expand Down
2 changes: 2 additions & 0 deletions types/src/v0/impls/block/full_payload/ns_table/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "hotshot-impls")]
use hotshot::traits::BlockPayload;
use rand::{Rng, RngCore};
use sequencer_utils::test_utils::setup_test;
Expand Down Expand Up @@ -67,6 +68,7 @@ fn ns_table_byte_len() {
}
}

#[cfg(feature = "hotshot-impls")]
#[tokio::test(flavor = "multi_thread")]
async fn payload_byte_len() {
setup_test();
Expand Down
9 changes: 8 additions & 1 deletion types/src/v0/impls/block/full_payload/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ use crate::{
v0::impls::{NodeState, ValidatedState},
v0_1::ChainConfig,
Index, Iter, NamespaceId, NsIndex, NsPayload, NsPayloadBuilder, NsPayloadRange, NsTable,
NsTableBuilder, Payload, PayloadByteLen, SeqTypes, TxProof,
NsTableBuilder, Payload, PayloadByteLen, TxProof,
};

#[cfg(feature = "hotshot-impls")]
use crate::SeqTypes;

#[derive(serde::Deserialize, serde::Serialize, Error, Debug, Eq, PartialEq)]
pub enum BlockBuildingError {
#[error("Parent state commitment {0} of block doesn't match current state commitment")]
Expand Down Expand Up @@ -70,6 +73,7 @@ impl Payload {

// PRIVATE HELPERS START HERE

#[cfg(feature = "hotshot-impls")]
/// Need a sync version of [`BlockPayload::from_transactions`] in order to impl [`BlockPayload::empty`].
fn from_transactions_sync(
transactions: impl IntoIterator<Item = <Self as BlockPayload<SeqTypes>>::Transaction> + Send,
Expand Down Expand Up @@ -125,6 +129,7 @@ impl Payload {
}
}

#[cfg(feature = "hotshot-impls")]
#[async_trait]
impl BlockPayload<SeqTypes> for Payload {
// TODO BlockPayload trait eliminate unneeded args, return vals of type
Expand Down Expand Up @@ -204,6 +209,7 @@ impl BlockPayload<SeqTypes> for Payload {
}
}

#[cfg(feature = "hotshot-impls")]
impl QueryablePayload<SeqTypes> for Payload {
// TODO changes to QueryablePayload trait:
// https://github.com/EspressoSystems/hotshot-query-service/issues/639
Expand Down Expand Up @@ -292,6 +298,7 @@ impl PayloadByteLen {
}
}

#[cfg(feature = "hotshot-impls")]
#[cfg(any(test, feature = "testing"))]
impl hotshot_types::traits::block_contents::TestableBlock<SeqTypes> for Payload {
fn genesis() -> Self {
Expand Down
2 changes: 1 addition & 1 deletion types/src/v0/impls/block/namespace_payload/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'a> Iter<'a> {
}
}

impl<'a> Iterator for Iter<'a> {
impl Iterator for Iter<'_> {
type Item = Index;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use hotshot::helpers::initialize_logging;

use crate::{
v0::impls::block::{usize_max_from_byte_len, usize_to_bytes},
NamespaceId, NsPayloadBuilder, NsPayloadOwned,
};

#[test]
fn ns_payload_len() {
initialize_logging();
let ns_id = NamespaceId::from(69_u32); // dummy

// ordinary valid ns_payload
Expand Down Expand Up @@ -96,8 +93,6 @@ fn ns_payload_len() {

#[test]
fn negative_len_txs() {
initialize_logging();

let ns_id = NamespaceId::from(69_u32); // dummy

// 1 negative-length tx at the end, no overlapping tx bytes
Expand Down Expand Up @@ -164,8 +159,6 @@ fn negative_len_txs() {

#[test]
fn negative_len_txs_and_abnormal_payload_len() {
initialize_logging();

let ns_id = NamespaceId::from(69_u32); // dummy

// 1 negative-length tx in the middle, overlapping tx bytes
Expand Down Expand Up @@ -239,8 +232,6 @@ fn negative_len_txs_and_abnormal_payload_len() {

#[test]
fn tx_table_header() {
initialize_logging();

let ns_id = NamespaceId::from(69_u32); // dummy

// header declares 1 fewer txs, tx table bytes appear in tx payloads, wasted
Expand Down
2 changes: 1 addition & 1 deletion types/src/v0/impls/block/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(test)]
#![cfg(all(test, feature = "hotshot-impls"))]
use std::collections::BTreeMap;

use hotshot::traits::BlockPayload;
Expand Down
8 changes: 7 additions & 1 deletion types/src/v0/impls/fee_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ use thiserror::Error;
use crate::{
eth_signature_key::EthKeyPair, v0_3::IterableFeeInfo, AccountQueryData, FeeAccount,
FeeAccountProof, FeeAmount, FeeInfo, FeeMerkleCommitment, FeeMerkleProof, FeeMerkleTree,
SeqTypes,
};

#[cfg(feature = "hotshot-impls")]
use crate::SeqTypes;

/// Possible charge fee failures
#[derive(Error, Debug, Eq, PartialEq)]
pub enum FeeError {
Expand Down Expand Up @@ -75,6 +77,8 @@ impl FeeInfo {
pub fn amount(&self) -> FeeAmount {
self.amount
}

#[cfg(feature = "hotshot-impls")]
/// Get a `Vec<FeeInfo>` from `Vec<BuilderFee>`
pub fn from_builder_fees(fees: Vec<BuilderFee<SeqTypes>>) -> Vec<FeeInfo> {
fees.into_iter().map(FeeInfo::from).collect()
Expand All @@ -101,6 +105,7 @@ impl IterableFeeInfo for Vec<FeeInfo> {
}
}

#[cfg(feature = "hotshot-impls")]
impl IterableFeeInfo for Vec<BuilderFee<SeqTypes>> {
/// Get sum of amounts
fn amount(&self) -> Option<FeeAmount> {
Expand All @@ -119,6 +124,7 @@ impl IterableFeeInfo for Vec<BuilderFee<SeqTypes>> {
}
}

#[cfg(feature = "hotshot-impls")]
impl From<BuilderFee<SeqTypes>> for FeeInfo {
fn from(fee: BuilderFee<SeqTypes>) -> Self {
Self {
Expand Down
12 changes: 10 additions & 2 deletions types/src/v0/impls/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ use crate::{
v0_1, v0_2,
v0_3::{self, ChainConfig, IterableFeeInfo, SolverAuctionResults},
BlockMerkleCommitment, BuilderSignature, FeeAccount, FeeAmount, FeeInfo, FeeMerkleCommitment,
Header, L1BlockInfo, L1Snapshot, Leaf, NamespaceId, NsTable, SeqTypes, UpgradeType,
Header, L1BlockInfo, L1Snapshot, NamespaceId, NsTable, UpgradeType,
};

#[cfg(feature = "hotshot-impls")]
use crate::{Leaf, SeqTypes};

use super::{instance_state::NodeState, state::ValidatedState};

impl v0_1::Header {
Expand Down Expand Up @@ -342,6 +345,7 @@ macro_rules! field_mut {
};
}

#[cfg(feature = "hotshot-impls")]
impl Header {
#[allow(clippy::too_many_arguments)]
fn from_info(
Expand Down Expand Up @@ -714,6 +718,7 @@ impl From<anyhow::Error> for InvalidBlockHeader {
}
}

#[cfg(feature = "hotshot-impls")]
impl BlockHeader<SeqTypes> for Header {
type Error = InvalidBlockHeader;

Expand Down Expand Up @@ -1064,12 +1069,14 @@ impl BlockHeader<SeqTypes> for Header {
}
}

#[cfg(feature = "hotshot-impls")]
impl QueryableHeader<SeqTypes> for Header {
fn timestamp(&self) -> u64 {
self.timestamp()
}
}

#[cfg(feature = "hotshot-impls")]
impl ExplorerHeader<SeqTypes> for Header {
type BalanceAmount = FeeAmount;
type WalletAddress = Vec<FeeAccount>;
Expand Down Expand Up @@ -1107,7 +1114,7 @@ impl ExplorerHeader<SeqTypes> for Header {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "hotshot-impls"))]
mod test_headers {

use std::sync::Arc;
Expand Down Expand Up @@ -1409,6 +1416,7 @@ mod test_headers {
}
}

#[cfg(feature = "hotshot-impls")]
#[tokio::test(flavor = "multi_thread")]
async fn test_proposal_validation_success() {
setup_test();
Expand Down
5 changes: 3 additions & 2 deletions types/src/v0/impls/instance_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::v0::{
retain_accounts, traits::StateCatchup, v0_3::ChainConfig, FeeMerkleTree, GenesisHeader,
L1BlockInfo, L1Client, PubKey, Timestamp, Upgrade, UpgradeMode,
L1BlockInfo, L1Client, Timestamp, Upgrade, UpgradeMode,
};
use hotshot_types::traits::states::InstanceState;
use hotshot_types::HotShotConfig;
Expand Down Expand Up @@ -147,8 +147,9 @@ impl Default for NodeState {

impl InstanceState for NodeState {}

#[cfg(feature = "hotshot-impls")]
impl Upgrade {
pub fn set_hotshot_config_parameters(&self, config: &mut HotShotConfig<PubKey>) {
pub fn set_hotshot_config_parameters(&self, config: &mut HotShotConfig<crate::PubKey>) {
match &self.mode {
UpgradeMode::View(v) => {
config.start_proposing_view = v.start_proposing_view;
Expand Down
5 changes: 4 additions & 1 deletion types/src/v0/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ pub use auction::SolverAuctionResultsProvider;
pub use fee_info::{retain_accounts, FeeError};
pub use instance_state::NodeState;
pub use state::ProposalValidationError;
pub use state::{get_l1_deposits, BuilderValidationError, StateValidationError, ValidatedState};
pub use state::{BuilderValidationError, StateValidationError, ValidatedState};

#[cfg(feature = "hotshot-impls")]
pub use state::get_l1_deposits;

#[cfg(any(test, feature = "testing"))]
pub use instance_state::mock;
3 changes: 2 additions & 1 deletion types/src/v0/impls/solver.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(feature = "hotshot-impls")]
use committable::{Commitment, Committable};
use hotshot::types::SignatureKey;
use hotshot_types::traits::signature_key::SignatureKey;

use super::{
v0_3::{RollupRegistrationBody, RollupUpdatebody},
Expand Down
Loading
Loading