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

First iteration on AuctionResultsProvider implementation #1760

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 }
58 changes: 49 additions & 9 deletions types/src/v0/impls/auction.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
use crate::{
eth_signature_key::{EthKeyPair, SigningError},
v0_1::ValidatedState,
v0_3::{BidTx, BidTxBody, FullNetworkTx},
v0_3::{
AuctionResults, AuctionResultsProvider, BidTx, BidTxBody, FullNetworkTx, HasUrls,
SolverClient,
},
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::HasUrl, node_implementation::ConsensusTime,
node_implementation::{ConsensusTime, NodeType},
signature_key::BuilderSignatureKey,
},
};
use std::str::FromStr;
use thiserror::Error;
use url::Url;
use vbs::version::StaticVersion;

impl FullNetworkTx {
/// Proxy for `execute` method of each transaction variant.
Expand Down Expand Up @@ -98,6 +103,11 @@ impl BidTxBody {
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 @@ -213,19 +223,49 @@ impl BidTx {
pub fn account(&self) -> FeeAccount {
self.body.account
}
}

impl HasUrl for BidTx {
/// Get the `url` field from the body.
fn url(&self) -> Url {
self.body.url()
}
}

impl HasUrl for BidTxBody {
/// Get the cloned `url` field.
fn url(&self) -> Url {
self.url.clone()
impl AuctionResults {
pub fn winning_bids(&self) -> &[BidTx] {
&self.winning_bids
}
pub fn reserve_bids(&self) -> &[(NamespaceId, Url)] {
&self.reserve_bids
}
}

impl HasUrls for AuctionResults {
fn urls(&self) -> Vec<Url> {
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>;

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

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

Expand Down
49 changes: 46 additions & 3 deletions types/src/v0/v0_3/auction.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use crate::{FeeAccount, FeeAmount, NamespaceId};
use anyhow::Result;
use async_trait::async_trait;
use ethers::types::Signature;
use hotshot_types::data::ViewNumber;
use serde::{Deserialize, Serialize};
use hotshot_types::{data::ViewNumber, traits::node_implementation::NodeType};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use surf_disco::Request;
use tide_disco::error::ServerError;
use url::Url;
use vbs::version::StaticVersionType;

#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, Hash)]
/// Wrapper enum for Full Network Transactions. Each transaction type
Expand Down Expand Up @@ -40,7 +45,24 @@ pub struct BidTxBody {
pub(crate) namespaces: Vec<NamespaceId>,
}

/// The results of an Auction
// TODO this will be in HotShot
pub trait HasUrls {
/// Returns the builer url associated with the datatype
fn urls(&self) -> Vec<Url>;
}

// TODO this will be in HotShot
#[async_trait]
pub trait AuctionResultsProvider<TYPES: NodeType>: Send + Sync + Clone {
/// The AuctionSolverResult is a type that holds the data associated with a particular solver
/// run, for a particular view.
type AuctionResult: HasUrls;

/// Fetches the auction result for a view. Does not cache the result,
/// subsequent calls will invoke additional wasted calls.
async fn fetch_auction_result(&self, view_number: TYPES::Time) -> Result<Self::AuctionResult>;
}

#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, Hash)]
pub struct AuctionResults {
/// view number the results are for
Expand All @@ -50,3 +72,24 @@ pub struct AuctionResults {
/// A list of reserve sequencers being used
pub(crate) reserve_bids: Vec<(NamespaceId, Url)>,
}

type SurfClient<Ver> = surf_disco::Client<ServerError, Ver>;

#[derive(Debug, Clone)]
pub struct SolverClient<Ver: StaticVersionType> {
agent: SurfClient<Ver>,
_url: Url,
}

impl<Ver: StaticVersionType> SolverClient<Ver> {
pub fn new(url: Url) -> Self {
Self {
agent: SurfClient::new(url.clone()),
_url: url,
}
}

pub fn get<T: DeserializeOwned>(&self, route: &str) -> Request<T, ServerError, Ver> {
self.agent.get(route)
}
}
4 changes: 3 additions & 1 deletion types/src/v0/v0_3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ pub const VERSION: Version = Version { major: 0, minor: 3 };
mod auction;
mod header;

pub use auction::{AuctionResults, BidTx, BidTxBody, FullNetworkTx};
pub use auction::{
AuctionResults, AuctionResultsProvider, BidTx, BidTxBody, FullNetworkTx, HasUrls, SolverClient,
};
pub use header::Header;
Loading