Skip to content

Commit 8979f83

Browse files
authored
Chore/more quote instrument (#471)
1 parent c32c341 commit 8979f83

10 files changed

Lines changed: 55 additions & 17 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auction-server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "auction-server"
3-
version = "0.21.1"
3+
version = "0.22.0"
44
edition = "2021"
55
license-file = "license.txt"
66

auction-server/src/auction/entities/bid.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub trait BidStatus:
6666
fn is_pending(&self) -> bool;
6767
fn is_awaiting_signature(&self) -> bool;
6868
fn is_submitted(&self) -> bool;
69+
fn is_cancelled(&self) -> bool;
6970
fn is_finalized(&self) -> bool;
7071

7172
fn new_lost() -> Self;
@@ -137,6 +138,10 @@ impl BidStatus for BidStatusSvm {
137138
matches!(self, BidStatusSvm::Submitted { .. })
138139
}
139140

141+
fn is_cancelled(&self) -> bool {
142+
matches!(self, BidStatusSvm::Cancelled { .. })
143+
}
144+
140145
fn is_finalized(&self) -> bool {
141146
matches!(
142147
self,
@@ -181,6 +186,10 @@ impl BidStatus for BidStatusEvm {
181186
matches!(self, BidStatusEvm::Submitted { .. })
182187
}
183188

189+
fn is_cancelled(&self) -> bool {
190+
false
191+
}
192+
184193
fn is_finalized(&self) -> bool {
185194
matches!(self, BidStatusEvm::Lost { .. } | BidStatusEvm::Won { .. })
186195
}

auction-server/src/auction/repository/get_or_create_in_memory_bid_lock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use {
77
};
88

99
impl<T: ChainTrait> Repository<T> {
10+
#[tracing::instrument(skip_all)]
1011
pub async fn get_or_create_in_memory_bid_lock(
1112
&self,
1213
key: entities::BidId,

auction-server/src/auction/service/cancel_bid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl Service<Svm> {
5858
}
5959
}
6060

61-
#[tracing::instrument(skip_all, err)]
61+
#[tracing::instrument(skip_all, err, fields(bid_id = %input.bid_id))]
6262
pub async fn cancel_bid(&self, input: CancelBidInput) -> Result<(), RestError> {
6363
// Lock the bid to prevent submission
6464
let bid_lock = self

auction-server/src/auction/service/handle_bid.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ where
2323
{
2424
#[tracing::instrument(
2525
skip_all,
26-
fields(bid_id, profile_name, simulation_error, permission_key),
26+
fields(bid_id, profile_name, permission_key, opportunity_id),
2727
err
2828
)]
2929
pub async fn handle_bid(
@@ -33,17 +33,11 @@ where
3333
if let Some(profile) = &input.bid_create.profile {
3434
tracing::Span::current().record("profile_name", &profile.name);
3535
}
36-
let verification = self
36+
let (chain_data, amount) = self
3737
.verify_bid(VerifyBidInput {
3838
bid_create: input.bid_create.clone(),
3939
})
40-
.await;
41-
if let Err(RestError::SimulationError { result: _, reason }) = &verification {
42-
// Long values are truncated and the errors are at the end of the simulation logs
43-
let error = reason.split('\n').rev().collect::<Vec<_>>().join("\n");
44-
tracing::Span::current().record("simulation_error", error);
45-
}
46-
let (chain_data, amount) = verification?;
40+
.await?;
4741
let bid = self
4842
.repo
4943
.add_bid(input.bid_create, &chain_data, &amount)

auction-server/src/auction/service/submit_quote.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ impl Service<Svm> {
4141
let winner_bid = auction
4242
.bids
4343
.iter()
44-
.find(|bid| bid.status.is_awaiting_signature() || bid.status.is_submitted())
44+
.find(|bid| bid.status.is_awaiting_signature() || bid.status.is_submitted() || bid.status.is_cancelled())
4545
.cloned()
4646
.ok_or(RestError::BadParameters("This quote has already been submitted and finalized on-chain. No further changes are allowed.".to_string()))?;
4747

48-
if winner_bid.status.is_submitted() {
48+
if winner_bid.status.is_cancelled() {
49+
Err(RestError::BadParameters(
50+
"This quote has already been cancelled.".to_string(),
51+
))
52+
} else if winner_bid.status.is_submitted() {
4953
Err(RestError::BadParameters(
5054
"Quote is already submitted on-chain.".to_string(),
5155
))
@@ -54,6 +58,7 @@ impl Service<Svm> {
5458
}
5559
}
5660

61+
#[tracing::instrument(skip_all, err)]
5762
async fn submit_auction_bid_for_lock(
5863
&self,
5964
bid: entities::Bid<Svm>,
@@ -92,14 +97,15 @@ impl Service<Svm> {
9297
Ok(())
9398
}
9499

95-
#[tracing::instrument(skip_all, err)]
100+
#[tracing::instrument(skip_all, err, fields(bid_id, auction_id = %input.auction_id))]
96101
pub async fn submit_quote(
97102
&self,
98103
input: SubmitQuoteInput,
99104
) -> Result<VersionedTransaction, RestError> {
100105
let (auction, winner_bid) = self.get_bid_to_submit(input.auction_id).await?;
101106

102107
let mut bid = winner_bid.clone();
108+
tracing::Span::current().record("bid_id", bid.id.to_string());
103109
let (_, swap_instruction) = self
104110
.extract_express_relay_instruction(
105111
bid.chain_data.transaction.clone(),

auction-server/src/auction/service/verification.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,7 @@ impl Service<Svm> {
15041504
Ok(())
15051505
}
15061506

1507+
#[tracing::instrument(skip_all, err)]
15071508
async fn verify_signatures(
15081509
&self,
15091510
bid: &entities::BidCreate<Svm>,
@@ -1557,6 +1558,7 @@ impl Service<Svm> {
15571558
}
15581559
}
15591560

1561+
#[tracing::instrument(skip_all, err)]
15601562
pub async fn simulate_swap_bid(
15611563
&self,
15621564
bid: &entities::BidCreate<Svm>,
@@ -1601,6 +1603,7 @@ impl Service<Svm> {
16011603
}
16021604
}
16031605

1606+
#[tracing::instrument(skip_all, err)]
16041607
pub async fn simulate_bid(&self, bid: &entities::BidCreate<Svm>) -> Result<(), RestError> {
16051608
const RETRY_LIMIT: usize = 5;
16061609
const RETRY_DELAY: Duration = Duration::from_millis(100);
@@ -1712,6 +1715,10 @@ impl Verification<Svm> for Service<Svm> {
17121715
input: VerifyBidInput<Svm>,
17131716
) -> Result<VerificationResult<Svm>, RestError> {
17141717
let bid = input.bid_create;
1718+
if let BidChainDataCreateSvm::Swap(chain_data) = &bid.chain_data {
1719+
tracing::Span::current()
1720+
.record("opportunity_id", chain_data.opportunity_id.to_string());
1721+
}
17151722
let transaction = bid.chain_data.get_transaction().clone();
17161723
Svm::check_tx_size(&transaction)?;
17171724
self.check_compute_budget(&transaction).await?;

auction-server/src/opportunity/service/get_quote.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ fn get_fee_token(
175175
}
176176

177177
impl Service<ChainTypeSvm> {
178+
#[tracing::instrument(skip_all, err)]
178179
async fn get_opportunity_create_for_quote(
179180
&self,
180181
quote_create: entities::QuoteCreate,
@@ -377,7 +378,18 @@ impl Service<ChainTypeSvm> {
377378
}
378379
}
379380

380-
#[tracing::instrument(skip_all)]
381+
#[tracing::instrument(
382+
skip_all,
383+
err,
384+
fields(
385+
opportunity_id,
386+
auction_id,
387+
searcher_token,
388+
user_token,
389+
bid_ids,
390+
winner_bid
391+
)
392+
)]
381393
pub async fn get_quote(&self, input: GetQuoteInput) -> Result<entities::Quote, RestError> {
382394
let referral_fee_info = self
383395
.unwrap_referral_fee_info(
@@ -407,8 +419,11 @@ impl Service<ChainTypeSvm> {
407419
opportunity: opportunity_create,
408420
})
409421
.await?;
422+
tracing::Span::current().record("opportunity_id", opportunity.id.to_string());
410423
let searcher_token = opportunity.sell_tokens[0].clone();
411424
let user_token = opportunity.buy_tokens[0].clone();
425+
tracing::Span::current().record("searcher_token", format!("{:?}", searcher_token));
426+
tracing::Span::current().record("user_token", format!("{:?}", user_token));
412427
if searcher_token.amount == 0 && user_token.amount == 0 {
413428
return Err(RestError::BadParameters(
414429
"Token amount cannot be zero".to_string(),
@@ -432,7 +447,10 @@ impl Service<ChainTypeSvm> {
432447
permission_key: permission_key_svm.clone(),
433448
})
434449
.await;
435-
450+
tracing::Span::current().record(
451+
"bid_ids",
452+
tracing::field::display(crate::auction::entities::BidContainerTracing(&bids)),
453+
);
436454
let total_bids = if bids.len() < 10 {
437455
bids.len().to_string()
438456
} else {
@@ -467,6 +485,7 @@ impl Service<ChainTypeSvm> {
467485
}
468486
}
469487
let winner_bid = bids.first().expect("failed to get first bid");
488+
tracing::Span::current().record("winner_bid_id", winner_bid.id.to_string());
470489

471490
let (_, swap_instruction) = auction_service
472491
.extract_express_relay_instruction(
@@ -495,6 +514,7 @@ impl Service<ChainTypeSvm> {
495514
let auction = auction_service
496515
.add_auction(AddAuctionInput { auction })
497516
.await?;
517+
tracing::Span::current().record("auction_id", auction.id.to_string());
498518

499519
// Remove opportunity to prevent further bids
500520
// The handle auction loop will take care of the bids that were submitted late

auction-server/src/opportunity/service/get_quote_request_account_balances.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl QuoteRequestAccountBalances {
132132

133133

134134
impl Service<ChainTypeSvm> {
135+
#[tracing::instrument(skip_all, err)]
135136
pub async fn get_quote_request_account_balances(
136137
&self,
137138
input: QuoteRequestAccountBalancesInput,

0 commit comments

Comments
 (0)