Skip to content

Commit 2f7a263

Browse files
authored
Add more logs (#110)
1 parent 30c3fc6 commit 2f7a263

File tree

8 files changed

+275
-152
lines changed

8 files changed

+275
-152
lines changed

auction-server/src/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub(crate) mod opportunity;
109109
pub mod profile;
110110
pub(crate) mod ws;
111111

112+
#[derive(Debug)]
112113
pub enum RestError {
113114
/// The request contained invalid parameters
114115
BadParameters(String),

auction-server/src/api/opportunity.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,17 @@ pub async fn post_opportunity(
109109

110110
verify_opportunity(params.clone(), chain_store, store.relayer.address())
111111
.await
112-
.map_err(|e| RestError::InvalidOpportunity(e.to_string()))?;
112+
.map_err(|e| {
113+
tracing::warn!(
114+
"Failed to verify opportunity: {:?} - params: {:?}",
115+
e,
116+
versioned_params
117+
);
118+
RestError::InvalidOpportunity(e.to_string())
119+
})?;
113120

114121
if store.opportunity_exists(&opportunity).await {
122+
tracing::warn!("Duplicate opportunity submission: {:?}", opportunity);
115123
return Err(RestError::BadParameters(
116124
"Duplicate opportunity submission".to_string(),
117125
));
@@ -125,7 +133,11 @@ pub async fn post_opportunity(
125133
opportunity.clone(),
126134
)))
127135
.map_err(|e| {
128-
tracing::error!("Failed to send update: {}", e);
136+
tracing::error!(
137+
"Failed to send update: {} - opportunity: {:?}",
138+
e,
139+
opportunity
140+
);
129141
RestError::TemporarilyUnavailable
130142
})?;
131143

auction-server/src/api/profile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use {
2424
},
2525
};
2626

27-
#[derive(Serialize, Deserialize, ToSchema, Clone, ToResponse)]
27+
#[derive(Serialize, Deserialize, ToSchema, Clone, ToResponse, Debug)]
2828
pub struct CreateProfile {
2929
/// The name of the profile to create
3030
#[schema(example = "John Doe")]

auction-server/src/auction.rs

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,17 @@ async fn conclude_submitted_auction(store: Arc<Store>, auction: models::Auction)
290290
{
291291
if let Err(err) = store
292292
.broadcast_bid_status_and_update(
293-
bid,
293+
bid.clone(),
294294
get_bid_status(decoded_log, &receipt),
295295
Some(&auction),
296296
)
297297
.await
298298
{
299-
tracing::error!("Failed to broadcast bid status: {:?}", err);
299+
tracing::error!(
300+
"Failed to broadcast bid status: {:?} - bid: {:?}",
301+
err,
302+
bid
303+
);
300304
}
301305
}
302306
}))
@@ -317,9 +321,18 @@ async fn conclude_submitted_auctions(store: Arc<Store>, chain_id: String) {
317321
);
318322

319323
for auction in auctions.iter() {
320-
store
321-
.task_tracker
322-
.spawn(conclude_submitted_auction(store.clone(), auction.clone()));
324+
store.task_tracker.spawn({
325+
let (store, auction) = (store.clone(), auction.clone());
326+
async move {
327+
if let Err(err) = conclude_submitted_auction(store.clone(), auction.clone()).await {
328+
tracing::error!(
329+
"Failed to submit auction: {:?} - auction: {:?}",
330+
err,
331+
auction
332+
);
333+
}
334+
}
335+
});
323336
}
324337
}
325338

@@ -330,14 +343,22 @@ async fn broadcast_submitted_bids(
330343
auction: models::Auction,
331344
) {
332345
join_all(bids.iter().enumerate().map(|(i, bid)| {
333-
store.broadcast_bid_status_and_update(
334-
bid.to_owned(),
335-
BidStatus::Submitted {
336-
result: tx_hash,
337-
index: i as u32,
338-
},
339-
Some(&auction),
340-
)
346+
let (store, auction, index) = (store.clone(), auction.clone(), i as u32);
347+
async move {
348+
if let Err(err) = store
349+
.broadcast_bid_status_and_update(
350+
bid.to_owned(),
351+
BidStatus::Submitted {
352+
result: tx_hash,
353+
index,
354+
},
355+
Some(&auction),
356+
)
357+
.await
358+
{
359+
tracing::error!("Failed to broadcast bid status: {:?} - bid: {:?}", err, bid);
360+
}
361+
}
341362
}))
342363
.await;
343364
}
@@ -357,14 +378,22 @@ async fn broadcast_lost_bids(
357378
return None;
358379
}
359380

360-
Some(store.broadcast_bid_status_and_update(
361-
bid.clone(),
362-
BidStatus::Lost {
363-
result: tx_hash,
364-
index: None,
365-
},
366-
auction,
367-
))
381+
let store = store.clone();
382+
Some(async move {
383+
if let Err(err) = store
384+
.broadcast_bid_status_and_update(
385+
bid.clone(),
386+
BidStatus::Lost {
387+
result: tx_hash,
388+
index: None,
389+
},
390+
auction,
391+
)
392+
.await
393+
{
394+
tracing::error!("Failed to broadcast bid status: {:?} - bid: {:?}", err, bid);
395+
}
396+
})
368397
}))
369398
.await;
370399
}
@@ -506,7 +535,7 @@ pub fn get_express_relay_contract(
506535
SignableExpressRelayContract::new(address, client)
507536
}
508537

509-
async fn submit_auctions(store: Arc<Store>, chain_id: String) -> Result<()> {
538+
async fn submit_auctions(store: Arc<Store>, chain_id: String) {
510539
let permission_keys = store.get_permission_keys_for_auction(&chain_id).await;
511540

512541
tracing::info!(
@@ -516,13 +545,23 @@ async fn submit_auctions(store: Arc<Store>, chain_id: String) -> Result<()> {
516545
);
517546

518547
for permission_key in permission_keys.iter() {
519-
store.task_tracker.spawn(submit_auction(
520-
store.clone(),
521-
permission_key.clone(),
522-
chain_id.clone(),
523-
));
548+
store.task_tracker.spawn({
549+
let (store, permission_key, chain_id) =
550+
(store.clone(), permission_key.clone(), chain_id.clone());
551+
async move {
552+
if let Err(err) =
553+
submit_auction(store, permission_key.clone(), chain_id.clone()).await
554+
{
555+
tracing::error!(
556+
"Failed to submit auction: {:?} - permission_key: {:?} - chain_id: {:?}",
557+
err,
558+
permission_key,
559+
chain_id
560+
);
561+
}
562+
}
563+
});
524564
}
525-
Ok(())
526565
}
527566

528567
async fn get_ws_provider(store: Arc<Store>, chain_id: String) -> Result<Provider<Ws>> {
@@ -566,7 +605,7 @@ pub async fn run_submission_loop(store: Arc<Store>, chain_id: String) -> Result<
566605
Ok(())
567606
}
568607

569-
#[derive(Serialize, Deserialize, ToSchema, Clone)]
608+
#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)]
570609
pub struct Bid {
571610
/// The permission key to bid on.
572611
#[schema(example = "0xdeadbeef", value_type = String)]
@@ -669,13 +708,16 @@ pub async fn handle_bid(
669708
match call.clone().await {
670709
Ok(results) => {
671710
if !results[0].external_success {
711+
// The call should be reverted because the "revert_on_failure" is set to true.
712+
tracing::error!("Simulation failed and call is not reverted: {:?}", results,);
672713
return Err(RestError::SimulationError {
673714
result: results[0].external_result.clone(),
674715
reason: results[0].multicall_revert_reason.clone(),
675716
});
676717
}
677718
}
678719
Err(e) => {
720+
tracing::warn!("Error while simulating bid: {:?}", e);
679721
return match e {
680722
ContractError::Revert(reason) => {
681723
if let Some(ExpressRelayErrors::ExternalCallFailed(failure_result)) =
@@ -698,10 +740,10 @@ pub async fn handle_bid(
698740
}
699741
}
700742

701-
let estimated_gas = call
702-
.estimate_gas()
703-
.await
704-
.map_err(|_| RestError::TemporarilyUnavailable)?;
743+
let estimated_gas = call.estimate_gas().await.map_err(|e| {
744+
tracing::error!("Error while estimating gas: {:?}", e);
745+
RestError::TemporarilyUnavailable
746+
})?;
705747

706748
verify_bid_exceeds_gas_cost(
707749
estimated_gas,

auction-server/src/models.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use {
1515
uuid::Uuid,
1616
};
1717

18-
#[derive(Clone)]
18+
#[derive(Clone, Debug)]
1919
pub struct TxHash(pub Option<H256>);
2020

2121
impl From<Option<Vec<u8>>> for TxHash {
@@ -36,7 +36,7 @@ impl Deref for TxHash {
3636
}
3737

3838
pub type AuctionId = Uuid;
39-
#[derive(Clone, FromRow)]
39+
#[derive(Clone, FromRow, Debug)]
4040
pub struct Auction {
4141
pub id: AuctionId,
4242
pub creation_time: PrimitiveDateTime,
@@ -59,7 +59,7 @@ pub struct Opportunity {
5959
pub target_contract: Vec<u8>,
6060
pub target_call_value: BigDecimal,
6161
pub target_calldata: Vec<u8>,
62-
pub removal_time: PrimitiveDateTime,
62+
pub removal_time: Option<PrimitiveDateTime>,
6363
pub sell_tokens: JsonValue,
6464
pub buy_tokens: JsonValue,
6565
}

auction-server/src/opportunity_adapter.rs

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ pub async fn verify_opportunity(
184184
)
185185
.calldata()
186186
.ok_or(anyhow!(
187-
"Failed to generate calldata for opportunity adapter"
188-
))?;
187+
"Failed to generate calldata for opportunity adapter - params: {:?} - signature: {:?}",
188+
params_with_signature.params,
189+
signature
190+
))?;
189191

190192
let call = get_simulation_call(
191193
relayer,
@@ -262,15 +264,20 @@ pub async fn verify_opportunity(
262264
if !result.multicall_statuses[0].external_success {
263265
tracing::info!(
264266
"Opportunity simulation failed: {:?}",
265-
result.multicall_statuses[0]
267+
result.multicall_statuses
266268
);
267269
return Err(anyhow!(
268270
"Express Relay Simulation failed: {:?}",
269-
result.multicall_statuses[0].external_result
271+
result.multicall_statuses
270272
));
271273
}
272274
}
273-
Err(e) => return Err(anyhow!(format!("Error decoding multicall result: {:?}", e))),
275+
Err(e) => {
276+
return Err(anyhow!(format!(
277+
"Error decoding multicall result: {:?} - result: {:?}",
278+
e, result
279+
)))
280+
}
274281
}
275282
Ok(VerificationResult::Success)
276283
}
@@ -619,34 +626,43 @@ pub async fn handle_opportunity_bid(
619626
let adapter_calldata =
620627
make_adapter_calldata(params.clone(), opportunity_bid.clone(), chain_store)
621628
.await
622-
.map_err(|e| RestError::BadParameters(e.to_string()))?;
623-
match handle_bid(
624-
store.clone(),
625-
Bid {
626-
permission_key: params.permission_key.clone(),
627-
chain_id: params.chain_id.clone(),
628-
target_contract: chain_store.config.adapter_factory_contract,
629-
target_calldata: adapter_calldata,
630-
amount: opportunity_bid.amount,
631-
},
632-
initiation_time,
633-
auth,
634-
)
635-
.await
636-
{
629+
.map_err(|e| {
630+
tracing::error!(
631+
"Error making adapter calldata: {:?} - opportunity: {:?}",
632+
e,
633+
opportunity
634+
);
635+
RestError::BadParameters(e.to_string())
636+
})?;
637+
let bid = Bid {
638+
permission_key: params.permission_key.clone(),
639+
chain_id: params.chain_id.clone(),
640+
target_contract: chain_store.config.adapter_factory_contract,
641+
target_calldata: adapter_calldata,
642+
amount: opportunity_bid.amount,
643+
};
644+
match handle_bid(store.clone(), bid.clone(), initiation_time, auth).await {
637645
Ok(id) => Ok(id),
638-
Err(e) => match e {
639-
RestError::SimulationError { result, reason } => {
640-
let parsed = parse_revert_error(&result);
641-
match parsed {
642-
Some(decoded) => Err(RestError::BadParameters(decoded)),
643-
None => {
644-
tracing::info!("Could not parse revert reason: {}", reason);
645-
Err(RestError::SimulationError { result, reason })
646+
Err(e) => {
647+
tracing::warn!(
648+
"Error handling bid: {:?} - opportunity: {:?} - bid: {:?}",
649+
e,
650+
opportunity,
651+
bid
652+
);
653+
match e {
654+
RestError::SimulationError { result, reason } => {
655+
let parsed = parse_revert_error(&result);
656+
match parsed {
657+
Some(decoded) => Err(RestError::BadParameters(decoded)),
658+
None => {
659+
tracing::info!("Could not parse revert reason: {}", reason);
660+
Err(RestError::SimulationError { result, reason })
661+
}
646662
}
647663
}
664+
_ => Err(e),
648665
}
649-
_ => Err(e),
650-
},
666+
}
651667
}
652668
}

0 commit comments

Comments
 (0)