Skip to content

Commit

Permalink
Update to hotshot rc-0.5.66
Browse files Browse the repository at this point in the history
Most changes are being brought in from #1696. Also includes changes
from #1781. Most compile errors are fixed. Depends on
`hotshot-query-service` pointing to the same hotshot tab (see
Cargo.tmol patch).
  • Loading branch information
tbro committed Jul 25, 2024
1 parent e47d57c commit 3214997
Show file tree
Hide file tree
Showing 22 changed files with 742 additions and 473 deletions.
236 changes: 65 additions & 171 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ dotenvy = "0.15"
ethers = { version = "2.0", features = ["solc"] }
futures = "0.3"

hotshot = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.65" }
hotshot = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.66" }
# Hotshot imports
hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "rc-0.5.65" }
hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "rc-0.5.66" }
hotshot-builder-core = { git = "https://github.com/EspressoSystems/hotshot-builder-core", tag = "rc-0.1.35" }
hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", tag = "rc-0.1.34" }
hotshot-orchestrator = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.65" }
hotshot-orchestrator = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.66" }
hotshot-query-service = { git = "https://github.com/EspressoSystems/hotshot-query-service", tag = "rc-0.1.46" }
hotshot-stake-table = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.65" }
hotshot-stake-table = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.66" }
hotshot-state-prover = { version = "0.1.0", path = "hotshot-state-prover" }
hotshot-task = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.65" }
hotshot-testing = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.65" }
hotshot-types = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.65" }
hotshot-task = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.66" }
hotshot-testing = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.66" }
hotshot-types = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.66" }
hotshot-contract-adapter = { version = "0.1.0", path = "contracts/rust/adapter" }
# Temporary, used to pull in the mock auction results provider
hotshot-example-types = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.65" }
hotshot-example-types = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.66" }

# Push CDN imports
cdn-broker = { git = "https://github.com/EspressoSystems/Push-CDN", features = [
Expand Down Expand Up @@ -131,3 +131,7 @@ paste = "1.0"
rand = "0.8.5"
time = "0.3"
trait-set = "0.3.0"


[patch."https://github.com/EspressoSystems/hotshot-query-service.git"]
hotshot-query-service = { path = "../hotshot-query-service" }
2 changes: 2 additions & 0 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ tracing = { workspace = true }
trait-set = { workspace = true }
url = { workspace = true }
vbs = { workspace = true }
surf-disco = { workspace = true }
tide-disco = { workspace = true }
5 changes: 4 additions & 1 deletion types/src/v0/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use committable::Commitment;
use serde::{Deserialize, Serialize};
use vbs::version::Version;

use crate::{v0_1, v0_2, v0_3, ChainConfig};
use crate::{
v0_1::{self, ChainConfig},
v0_2, v0_3,
};

/// Each variant represents a specific minor version header.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
Expand Down
85 changes: 73 additions & 12 deletions types/src/v0/impls/auction.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
use super::state::ValidatedState;
use crate::{
eth_signature_key::{EthKeyPair, SigningError},
v0_1::ValidatedState,
v0_3::{BidTx, BidTxBody, FullNetworkTx},
v0_3::{BidTx, BidTxBody, FullNetworkTx, SolverAuctionResults},
FeeAccount, FeeAmount, FeeError, FeeInfo, NamespaceId,
};
use async_trait::async_trait;
use committable::{Commitment, Committable};
use ethers::types::Signature;
use hotshot_types::{
data::ViewNumber,
traits::{
auction_results_provider::HasUrls, node_implementation::ConsensusTime,
auction_results_provider::{AuctionResultsProvider, HasUrls},
node_implementation::{ConsensusTime, NodeType},
signature_key::BuilderSignatureKey,
},
};
use std::str::FromStr;
use thiserror::Error;
use tide_disco::error::ServerError;
use url::Url;
use vbs::version::StaticVersion;

pub fn mock_full_network_txs(key: Option<EthKeyPair>) -> Vec<FullNetworkTx> {
// if no key is supplied, use `test_key_pair`. Since default `BidTxBody` is
// signed with `test_key_pair`, it will verify successfully
let key = key.unwrap_or_else(FeeAccount::test_key_pair);
vec![FullNetworkTx::Bid(BidTx::mock(key))]
}

impl FullNetworkTx {
/// Proxy for `execute` method of each transaction variant.
Expand Down Expand Up @@ -93,11 +104,20 @@ impl BidTxBody {
pub fn amount(&self) -> FeeAmount {
self.bid_amount
}
/// get the view number
pub fn view(&self) -> ViewNumber {
self.view
}
/// Instantiate a `BidTxBody` containing the values of `self`
/// with a new `url` field.
pub fn with_url(self, url: Url) -> Self {
Self { url, ..self }
}

/// Get the cloned `url` field.
fn url(&self) -> Url {
self.url.clone()
}
}

impl Default for BidTxBody {
Expand Down Expand Up @@ -169,8 +189,7 @@ impl BidTx {
return Err(ExecutionError::UnresolvableChainConfig);
};

// TODO change to `bid_recipient` when this logic is finally enabled
let recipient = chain_config.fee_recipient;
let recipient = chain_config.bid_recipient.unwrap();
// Charge the bid amount
state
.charge_fee(FeeInfo::new(self.account(), self.amount()), recipient)
Expand Down Expand Up @@ -213,19 +232,61 @@ impl BidTx {
pub fn account(&self) -> FeeAccount {
self.body.account
}
/// get the view number
pub fn view(&self) -> ViewNumber {
self.body.view
}
/// Get the `url` field from the body.
fn url(&self) -> Url {
self.body.url()
}
}

impl HasUrls for BidTx {
/// Get the `url` field from the body.
fn urls(&self) -> Vec<Url> {
self.body.urls()
impl SolverAuctionResults {
pub fn winning_bids(&self) -> &[BidTx] {
&self.winning_bids
}
pub fn reserve_bids(&self) -> &[(NamespaceId, Url)] {
&self.reserve_bids
}
pub fn genesis() -> Self {
Self {
view_number: ViewNumber::genesis(),
winning_bids: vec![],
reserve_bids: vec![],
}
}
}

impl HasUrls for BidTxBody {
/// Get the cloned `url` field.
impl HasUrls for SolverAuctionResults {
fn urls(&self) -> Vec<Url> {
vec![self.url.clone()]
self.winning_bids()
.iter()
.map(|bid| bid.url())
.chain(self.reserve_bids().iter().map(|bid| bid.1.clone()))
.collect()
}
}

const SOLVER_URL: &str = "https://solver:1234";
type Ver = StaticVersion<0, 3>;
type SurfClient<Ver> = surf_disco::Client<ServerError, Ver>;

#[async_trait]
impl<TYPES: NodeType> AuctionResultsProvider<TYPES> for SolverAuctionResults {
type AuctionResult = SolverAuctionResults;

/// Fetch the auction results.
async fn fetch_auction_result(
&self,
view_number: TYPES::Time,
) -> anyhow::Result<Self::AuctionResult> {
let resp = SurfClient::<Ver>::new(Url::from_str(SOLVER_URL).unwrap())
.get::<SolverAuctionResults>(&format!("/v0/api/auction_results/{}", *view_number))
.send()
.await
.unwrap();
Ok(resp)
}
}

Expand Down
13 changes: 9 additions & 4 deletions types/src/v0/impls/block/full_payload/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use jf_vid::VidScheme;
use sha2::Digest;

use crate::{
ChainConfig, Index, Iter, NamespaceId, NodeState, NsIndex, NsPayload, NsPayloadBuilder,
NsPayloadRange, NsTable, NsTableBuilder, Payload, PayloadByteLen, SeqTypes, Transaction,
TxProof, ValidatedState,
v0::impls::{NodeState, ValidatedState},
v0_1::ChainConfig,
Index, Iter, NamespaceId, NsIndex, NsPayload, NsPayloadBuilder, NsPayloadRange, NsTable,
NsTableBuilder, Payload, PayloadByteLen, SeqTypes, Transaction, TxProof,
};

impl Payload {
Expand Down Expand Up @@ -136,7 +137,11 @@ impl BlockPayload<SeqTypes> for Payload {
}
};

Self::from_transactions_sync(transactions, chain_config, instance_state)
Self::from_transactions_sync(
transactions,
ChainConfig::from(chain_config),
instance_state,
)
}

// TODO avoid cloning the entire payload here?
Expand Down
70 changes: 4 additions & 66 deletions types/src/v0/impls/chain_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::str::FromStr;

use bytesize::ByteSize;
use committable::{Commitment, Committable};
use committable::Commitment;
use derive_more::From;
use ethers::types::U256;
use itertools::Either;
Expand All @@ -10,7 +9,7 @@ use sequencer_utils::{
};
use snafu::Snafu;

use crate::{BlockSize, ChainConfig, ChainId, ResolvableChainConfig};
use crate::{BlockSize, ChainId};

impl_serde_from_string_or_integer!(ChainId);
impl_to_fixed_bytes!(ChainId, U256);
Expand Down Expand Up @@ -77,69 +76,6 @@ impl FromStringOrInteger for BlockSize {
}
}

impl Default for ChainConfig {
fn default() -> Self {
Self {
chain_id: U256::from(35353).into(), // arbitrarily chosen chain ID
max_block_size: 10240.into(),
base_fee: 0.into(),
fee_contract: None,
fee_recipient: Default::default(),
}
}
}

impl Committable for ChainConfig {
fn tag() -> String {
"CHAIN_CONFIG".to_string()
}

fn commit(&self) -> Commitment<Self> {
let comm = committable::RawCommitmentBuilder::new(&Self::tag())
.fixed_size_field("chain_id", &self.chain_id.to_fixed_bytes())
.u64_field("max_block_size", *self.max_block_size)
.fixed_size_field("base_fee", &self.base_fee.to_fixed_bytes())
.fixed_size_field("fee_recipient", &self.fee_recipient.to_fixed_bytes());
let comm = if let Some(addr) = self.fee_contract {
comm.u64_field("fee_contract", 1).fixed_size_bytes(&addr.0)
} else {
comm.u64_field("fee_contract", 0)
};
comm.finalize()
}
}

impl ResolvableChainConfig {
pub fn commit(&self) -> Commitment<ChainConfig> {
match self.chain_config {
Either::Left(config) => config.commit(),
Either::Right(commitment) => commitment,
}
}
pub fn resolve(self) -> Option<ChainConfig> {
match self.chain_config {
Either::Left(config) => Some(config),
Either::Right(_) => None,
}
}
}

impl From<Commitment<ChainConfig>> for ResolvableChainConfig {
fn from(value: Commitment<ChainConfig>) -> Self {
Self {
chain_config: Either::Right(value),
}
}
}

impl From<ChainConfig> for ResolvableChainConfig {
fn from(value: ChainConfig) -> Self {
Self {
chain_config: Either::Left(value),
}
}
}

#[derive(Clone, Debug, From, Snafu)]
pub struct ParseSizeError {
msg: String,
Expand All @@ -151,6 +87,8 @@ pub fn parse_size(s: &str) -> Result<u64, ParseSizeError> {

#[cfg(test)]
mod tests {
use crate::v0_3::{ChainConfig, ResolvableChainConfig};

use super::*;

#[test]
Expand Down
28 changes: 28 additions & 0 deletions types/src/v0/impls/fee_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ethers::{
};
use hotshot_query_service::explorer::MonetaryValue;
use hotshot_types::traits::block_contents::BuilderFee;
use itertools::Itertools;
use jf_merkle_tree::{
ForgetableMerkleTreeScheme, ForgetableUniversalMerkleTreeScheme, LookupResult,
MerkleCommitment, MerkleTreeError, MerkleTreeScheme, ToTraversalPath,
Expand Down Expand Up @@ -74,6 +75,10 @@ impl FeeInfo {
pub fn amount(&self) -> FeeAmount {
self.amount
}
/// 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()
}
}

impl IterableFeeInfo for Vec<FeeInfo> {
Expand Down Expand Up @@ -414,3 +419,26 @@ impl From<(FeeAccountProof, U256)> for AccountQueryData {
Self { balance, proof }
}
}

#[cfg(test)]
mod test {
use ethers::abi::Address;

use crate::{FeeAccount, FeeAmount, FeeInfo};

use super::IterableFeeInfo;

#[test]
fn test_iterable_fee_info() {
let addr = Address::zero();
let fee = FeeInfo::new(addr, FeeAmount::from(1));
let fees = vec![fee, fee, fee];
// check the sum of amounts
let sum = fees.amount().unwrap();
assert_eq!(FeeAmount::from(3), sum);

// check accounts collector
let accounts = fees.accounts();
assert_eq!(vec![FeeAccount::from(Address::zero())], accounts);
}
}
Loading

0 comments on commit 3214997

Please sign in to comment.