Skip to content

Commit

Permalink
Autopilot: Remove /reveal roundtrip (#2964)
Browse files Browse the repository at this point in the history
# Description
Currently, we have no use for reveal and we are calling settle
unconditionally after it.

We are storing the internalised and uninternalised calldata that is
returned in the database. However, since slippage accounting moved
towards counting internal buffer trades as slippage we have no more use
for the "uninternalised" calldata. The final calldata can also be
recovered from the settled transaction, and doesn't matter in the case
settlement failed.

# Changes
- Remove `/reveal` roundtrip
- Remove internalised and uninternalised calldata from the
competition/solution objects

## How to test
1. Acceptance tests

## Related Issues
Fixes #2942
  • Loading branch information
m-lord-renkse authored Sep 11, 2024
1 parent 1979beb commit f2cb4c7
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 171 deletions.
18 changes: 0 additions & 18 deletions crates/autopilot/src/database/competition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use {
auction_participants::Participant,
auction_prices::AuctionPrice,
byte_array::ByteArray,
settlement_call_data::SettlementCallData,
settlement_scores::Score,
surplus_capturing_jit_order_owners,
Address,
Expand Down Expand Up @@ -34,12 +33,6 @@ pub struct Competition {
/// chain before this block height.
pub block_deadline: u64,
pub competition_simulation_block: u64,
/// Winner settlement call data
#[derivative(Debug(format_with = "shared::debug_bytes"))]
pub call_data: Vec<u8>,
/// Uninternalized winner settlement call data
#[derivative(Debug(format_with = "shared::debug_bytes"))]
pub uninternalized_call_data: Vec<u8>,
pub competition_table: SolverCompetitionDB,
}

Expand Down Expand Up @@ -109,17 +102,6 @@ impl super::Postgres {
.await
.context("auction_prices::insert")?;

database::settlement_call_data::insert(
&mut ex,
SettlementCallData {
auction_id: competition.auction_id,
call_data: competition.call_data.clone(),
uninternalized_call_data: competition.uninternalized_call_data.clone(),
},
)
.await
.context("settlement_call_data::insert")?;

database::auction_orders::insert(
&mut ex,
competition.auction_id,
Expand Down
123 changes: 22 additions & 101 deletions crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
},
infra::{
self,
solvers::dto::{reveal, settle, solve},
solvers::dto::{settle, solve},
},
maintenance::Maintenance,
run::Liveness,
Expand Down Expand Up @@ -192,19 +192,6 @@ impl RunLoop {
if let Some(Participant { driver, solution }) = solutions.last() {
tracing::info!(driver = %driver.name, solution = %solution.id(), "winner");

let reveal_start = Instant::now();
let revealed = match self.reveal(driver, auction_id, solution.id()).await {
Ok(result) => {
Metrics::reveal_ok(driver, reveal_start.elapsed());
result
}
Err(err) => {
Metrics::reveal_err(driver, reveal_start.elapsed(), &err);
tracing::warn!(driver = %driver.name, ?err, "failed to reveal winning solution");
return;
}
};

let block_deadline = competition_simulation_block + self.submission_deadline;

// Post-processing should not be executed asynchronously since it includes steps
Expand All @@ -216,7 +203,6 @@ impl RunLoop {
competition_simulation_block,
solution,
&solutions,
revealed,
block_deadline,
)
.await
Expand Down Expand Up @@ -250,7 +236,6 @@ impl RunLoop {
competition_simulation_block: u64,
winning_solution: &competition::SolutionWithId,
solutions: &[Participant<'_>],
revealed: reveal::Response,
block_deadline: u64,
) -> Result<()> {
let start = Instant::now();
Expand All @@ -267,9 +252,6 @@ impl RunLoop {
.collect::<HashSet<_>>();

let mut fee_policies = Vec::new();
let call_data = revealed.calldata.internalized.clone();
let uninternalized_call_data = revealed.calldata.uninternalized.clone();

for order_id in winning_solution.order_ids() {
match auction
.orders
Expand Down Expand Up @@ -303,38 +285,27 @@ impl RunLoop {
solutions: solutions
.iter()
.enumerate()
.map(|(index, participant)| {
let is_winner = solutions.len() - index == 1;
let mut settlement = SolverSettlement {
solver: participant.driver.name.clone(),
solver_address: participant.solution.solver().0,
score: Some(Score::Solver(participant.solution.score().get().0)),
ranking: solutions.len() - index,
orders: participant
.solution
.orders()
.iter()
.map(|(id, order)| Order::Colocated {
id: (*id).into(),
sell_amount: order.sell.into(),
buy_amount: order.buy.into(),
})
.collect(),
clearing_prices: participant
.solution
.prices()
.iter()
.map(|(token, price)| (token.0, price.get().into()))
.collect(),
call_data: None,
uninternalized_call_data: None,
};
if is_winner {
settlement.call_data = Some(revealed.calldata.internalized.clone());
settlement.uninternalized_call_data =
Some(revealed.calldata.uninternalized.clone());
}
settlement
.map(|(index, participant)| SolverSettlement {
solver: participant.driver.name.clone(),
solver_address: participant.solution.solver().0,
score: Some(Score::Solver(participant.solution.score().get().0)),
ranking: solutions.len() - index,
orders: participant
.solution
.orders()
.iter()
.map(|(id, order)| Order::Colocated {
id: (*id).into(),
sell_amount: order.sell.into(),
buy_amount: order.buy.into(),
})
.collect(),
clearing_prices: participant
.solution
.prices()
.iter()
.map(|(token, price)| (token.0, price.get().into()))
.collect(),
})
.collect(),
};
Expand All @@ -351,8 +322,6 @@ impl RunLoop {
.collect(),
block_deadline,
competition_simulation_block,
call_data,
uninternalized_call_data,
competition_table,
};

Expand Down Expand Up @@ -647,28 +616,6 @@ impl RunLoop {
Ok(futures::future::join_all(futures).await)
}

/// Ask the winning solver to reveal their solution.
async fn reveal(
&self,
driver: &infra::Driver,
auction: domain::auction::Id,
solution_id: u64,
) -> Result<reveal::Response, RevealError> {
let response = driver
.reveal(&reveal::Request { solution_id })
.await
.map_err(RevealError::Failure)?;
if !response
.calldata
.internalized
.ends_with(&auction.to_be_bytes())
{
return Err(RevealError::AuctionMismatch);
}

Ok(response)
}

/// Execute the solver's solution. Returns Ok when the corresponding
/// transaction has been mined.
async fn settle(
Expand Down Expand Up @@ -769,14 +716,6 @@ enum SolveError {
Failure(anyhow::Error),
}

#[derive(Debug, thiserror::Error)]
enum RevealError {
#[error("revealed calldata does not match auction")]
AuctionMismatch,
#[error(transparent)]
Failure(anyhow::Error),
}

#[derive(Debug, thiserror::Error)]
enum SettleError {
#[error(transparent)]
Expand Down Expand Up @@ -888,24 +827,6 @@ impl Metrics {
.inc();
}

fn reveal_ok(driver: &infra::Driver, elapsed: Duration) {
Self::get()
.reveal
.with_label_values(&[&driver.name, "success"])
.observe(elapsed.as_secs_f64());
}

fn reveal_err(driver: &infra::Driver, elapsed: Duration, err: &RevealError) {
let label = match err {
RevealError::AuctionMismatch => "mismatch",
RevealError::Failure(_) => "error",
};
Self::get()
.reveal
.with_label_values(&[&driver.name, label])
.observe(elapsed.as_secs_f64());
}

fn settle_ok(driver: &infra::Driver, elapsed: Duration) {
Self::get()
.settle
Expand Down
10 changes: 5 additions & 5 deletions crates/driver/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ paths:
description: |
Reveal the calldata of the previously solved auction.
This may be used by the autopilot to verify the solution before requesting its execution it on chain.
This may be used by the autopilot for the shadow competition to verify the solution before requesting its execution it on chain.
requestBody:
required: true
content:
Expand Down Expand Up @@ -243,7 +243,7 @@ components:
type: string
signingScheme:
type: string
enum: ["eip712", "ethsign", "presign", "eip1271"]
enum: [ "eip712", "ethsign", "presign", "eip1271" ]
signature:
description: Hex encoded bytes with `0x` prefix.
type: string
Expand Down Expand Up @@ -380,7 +380,7 @@ components:
solutionId:
description: |
The unique identifier of the solution.
This id is used to identify the solution when executing it.
type: string
example: "1"
Expand Down Expand Up @@ -408,7 +408,7 @@ components:
clearingPrices:
description: |
Mapping of hex token address to price.
The prices of tokens for settled user orders as passed to the settlement contract.
type: object
additionalProperties:
Expand Down Expand Up @@ -467,7 +467,7 @@ components:
properties:
kind:
type: string
enum: [ "priceImprovement" ]
enum: ["priceImprovement"]
maxVolumeFactor:
description: Never charge more than that percentage of the order volume.
type: number
Expand Down
5 changes: 0 additions & 5 deletions crates/e2e/tests/e2e/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub struct Cip20Data {
pub participants: Vec<database::auction_participants::Participant>,
pub prices: Vec<database::auction_prices::AuctionPrice>,
pub score: database::settlement_scores::Score,
pub call_data: database::settlement_call_data::SettlementCallData,
pub competition: serde_json::Value,
}

Expand Down Expand Up @@ -74,9 +73,6 @@ SELECT * FROM settlements WHERE auction_id = $1";
let score = database::settlement_scores::fetch(&mut db, auction_id)
.await
.unwrap()?;
let call_data = database::settlement_call_data::fetch(&mut db, auction_id)
.await
.unwrap()?;
let competition = database::solver_competition::load_by_id(&mut db, auction_id)
.await
.unwrap()?
Expand All @@ -88,7 +84,6 @@ SELECT * FROM settlements WHERE auction_id = $1";
participants,
prices,
score,
call_data,
competition,
})
}
3 changes: 0 additions & 3 deletions crates/e2e/tests/e2e/solver_competition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,8 @@ async fn solver_competition(web3: Web3) {

// Non winning candidate
assert!(competition.common.solutions[0].ranking == 2);
assert!(competition.common.solutions[0].call_data.is_none());

// Winning candidate
assert!(competition.common.solutions[1].ranking == 1);
assert!(competition.common.solutions[1].call_data.is_some());
}

async fn fairness_check(web3: Web3) {
Expand Down
2 changes: 0 additions & 2 deletions crates/e2e/tests/e2e/univ2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ async fn test(web3: Web3) {
&& data.participants.iter().any(|p| p.participant.0 == solver.address().0)
// and won the auction
&& data.score.winner.0 == solver.address().0
// and calldata is present
&& !data.call_data.call_data.is_empty()
};
wait_for_condition(TIMEOUT, cip_20_data_updated)
.await
Expand Down
9 changes: 0 additions & 9 deletions crates/model/src/format.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pub mod auction;
pub mod fee_policy;
mod format;
pub mod interaction;
pub mod order;
pub mod quote;
Expand Down
13 changes: 0 additions & 13 deletions crates/model/src/solver_competition.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use {
crate::{auction::AuctionId, order::OrderUid},
bytes_hex::BytesHex,
derivative::Derivative,
number::serialization::HexOrDecimalU256,
primitive_types::{H160, H256, U256},
Expand Down Expand Up @@ -55,14 +54,6 @@ pub struct SolverSettlement {
#[serde_as(as = "BTreeMap<_, HexOrDecimalU256>")]
pub clearing_prices: BTreeMap<H160, U256>,
pub orders: Vec<Order>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde_as(as = "Option<BytesHex>")]
#[derivative(Debug(format_with = "crate::format::debug_optional_bytes"))]
pub call_data: Option<Vec<u8>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde_as(as = "Option<BytesHex>")]
#[derivative(Debug(format_with = "crate::format::debug_optional_bytes"))]
pub uninternalized_call_data: Option<Vec<u8>>,
}

#[serde_as]
Expand Down Expand Up @@ -176,8 +167,6 @@ mod tests {
"executedAmount": "14",
}
],
"callData": "0x13",
"uninternalizedCallData": "0x1314",
},
],
});
Expand Down Expand Up @@ -219,8 +208,6 @@ mod tests {
executed_amount: 14.into(),
},
],
call_data: Some(vec![0x13]),
uninternalized_call_data: Some(vec![0x13, 0x14]),
}],
},
};
Expand Down
Loading

0 comments on commit f2cb4c7

Please sign in to comment.