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

Insert bid transactions into solver state #1907

Merged
merged 4 commits into from
Aug 27, 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
11 changes: 7 additions & 4 deletions marketplace-solver/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use espresso_types::{
v0_3::{RollupRegistration, RollupUpdate},
v0_3::{BidTx, RollupRegistration, RollupUpdate},
NamespaceId,
};
use futures::FutureExt;
Expand Down Expand Up @@ -98,9 +98,12 @@ where
options.extensions.clone(),
)?;

// TODO ED: We need to fill these in with the appropriate logic later
api.post("submit_bid", |_req, _state| {
async move { Ok("Bid Submitted") }.boxed()
api.post("submit_bid", |req, state| {
async move {
let bid = req.body_json::<BidTx>()?;
state.submit_bid_tx(bid).await
}
.boxed()
})?
.get("auction_results", |req, state| {
async move {
Expand Down
25 changes: 14 additions & 11 deletions marketplace-solver/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ use async_trait::async_trait;
use committable::Committable;
use espresso_types::{
v0_3::{
RollupRegistration, RollupRegistrationBody, RollupUpdate, RollupUpdatebody,
BidTx, RollupRegistration, RollupRegistrationBody, RollupUpdate, RollupUpdatebody,
SolverAuctionResults,
},
PubKey, SeqTypes,
};
use hotshot::types::SignatureKey;
use hotshot_types::{
data::ViewNumber, signature_key::BuilderKey, traits::node_implementation::NodeType, PeerConfig,
};
use hotshot_types::{data::ViewNumber, traits::node_implementation::NodeType, PeerConfig};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sqlx::{FromRow, PgPool};
Expand Down Expand Up @@ -46,8 +44,7 @@ impl GlobalState {

pub struct SolverState {
pub stake_table: StakeTable,
// todo (abdul) : () will be replaced w BidTx
pub bid_txs: HashMap<ViewNumber, HashMap<BuilderKey, ()>>,
pub bid_txs: HashMap<ViewNumber, HashMap<<SeqTypes as NodeType>::BuilderSignatureKey, BidTx>>,
}

pub struct StakeTable {
Expand All @@ -56,9 +53,8 @@ pub struct StakeTable {

#[async_trait]
pub trait UpdateSolverState {
// TODO (abdul) : add BidTx from types crate.
async fn submit_bix_tx(&mut self) -> anyhow::Result<()>;
// TODO (abdul)
async fn submit_bid_tx(&mut self, bid_tx: BidTx) -> SolverResult<()>;

async fn register_rollup(
&self,
registration: RollupRegistration,
Expand All @@ -67,12 +63,14 @@ pub trait UpdateSolverState {
&self,
update: RollupUpdate,
) -> SolverResult<RollupRegistration>;

async fn get_all_rollup_registrations(&self) -> SolverResult<Vec<RollupRegistration>>;
// TODO (abdul) : return AuctionResults

async fn calculate_auction_results_permissionless(
&self,
view_number: ViewNumber,
) -> SolverResult<SolverAuctionResults>;

async fn calculate_auction_results_permissioned(
&self,
view_number: ViewNumber,
Expand All @@ -82,7 +80,12 @@ pub trait UpdateSolverState {

#[async_trait]
impl UpdateSolverState for GlobalState {
async fn submit_bix_tx(&mut self) -> anyhow::Result<()> {
async fn submit_bid_tx(&mut self, bid_tx: BidTx) -> SolverResult<()> {
let view = bid_tx.view();
let builder_key = bid_tx.account();

let bid_txs = &mut self.solver.bid_txs;
bid_txs.entry(view).or_default().insert(builder_key, bid_tx);
Ok(())
}

Expand Down
Loading