Skip to content

Commit 5e5cdb7

Browse files
committed
Add tracing and spans
1 parent 5224c64 commit 5e5cdb7

File tree

6 files changed

+110
-33
lines changed

6 files changed

+110
-33
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ log = { version = "0.4.27" }
3838
num = "0.4.3"
3939
rand = "0.8.0"
4040
tokio = { version = "1.43.0", features = ["full"] }
41+
tracing = "0.1.41"
4142

4243
mantis-sdk = { path = "mantis-sdk" }

mantis-sdk/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ alloy = { workspace = true }
2727
anyhow = { workspace = true }
2828
base64 = { workspace = true }
2929
chrono = { workspace = true }
30-
env_logger = { workspace = true }
31-
log = { workspace = true }
3230
num = { workspace = true }
3331
rand = { workspace = true }
3432
tokio = { workspace = true }
35-
36-
[lints.clippy]
37-
obfuscated_if_else = "allow"
33+
tracing = { workspace = true }

mantis-sdk/src/ethereum.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloy::sol;
66
use alloy::transports::Transport;
77
use anyhow::{anyhow, Result};
88
use chrono::Utc;
9-
use log::info;
9+
use tracing::{info, instrument};
1010
use Escrow::NewIntent;
1111

1212
use crate::{random_intent_id, retry};
@@ -34,6 +34,7 @@ pub struct GasFees {
3434
pub max_priority_fee_per_gas: u128,
3535
}
3636

37+
#[instrument(skip_all)]
3738
pub async fn escrow_funds<P, T>(
3839
provider: P,
3940
escrow_address: Address,
@@ -114,6 +115,7 @@ where
114115
Ok(receipt)
115116
}
116117

118+
#[instrument(skip_all)]
117119
pub async fn solve_intent_remote<P, T>(
118120
provider: P,
119121
escrow_address: Address,
@@ -163,6 +165,7 @@ where
163165
Ok(receipt)
164166
}
165167

168+
#[instrument(skip_all)]
166169
pub async fn solve_intent_local<P, T>(
167170
provider: P,
168171
escrow_address: Address,
@@ -208,6 +211,7 @@ where
208211
Ok(receipt)
209212
}
210213

214+
#[instrument(skip_all)]
211215
pub async fn cancel_intent<P, T>(
212216
provider: P,
213217
escrow_address: Address,
@@ -243,6 +247,7 @@ where
243247
Ok(receipt)
244248
}
245249

250+
#[instrument(skip_all)]
246251
pub async fn approve_erc20<P, T>(
247252
provider: P,
248253
token: Address,
@@ -279,6 +284,7 @@ where
279284
Ok(receipt)
280285
}
281286

287+
#[instrument(skip_all)]
282288
pub async fn send_raw_tx<P, T>(
283289
provider: P,
284290
to: Address,

mantis-sdk/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::fmt::Display;
22
use std::future::Future;
33
use std::time::Duration;
44

5-
use log::{error, warn};
65
use rand::Rng;
76
use tokio::time::sleep;
7+
use tracing::{error, warn};
88

99
pub mod auction;
1010
pub mod ethereum;

mantis-sdk/src/solana.rs

Lines changed: 99 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use anchor_lang::prelude::declare_program;
55
use anchor_spl::associated_token;
66
use anyhow::{anyhow, Context, Result};
77
use chrono::Utc;
8-
use log::info;
98
use num::BigUint;
109
use solana_client::nonblocking::rpc_client::RpcClient;
1110
use solana_client::rpc_config::RpcTransactionConfig;
@@ -25,6 +24,7 @@ use solana_transaction_status::EncodedConfirmedTransactionWithStatusMeta;
2524
use spl_associated_token_account::get_associated_token_address_with_program_id;
2625
use spl_associated_token_account::instruction::create_associated_token_account_idempotent;
2726
use spl_token::instruction::transfer;
27+
use tracing::{info, instrument};
2828

2929
use crate::{random_intent_id, retry};
3030

@@ -54,6 +54,7 @@ impl TxInstructions {
5454
}
5555
}
5656

57+
#[instrument(skip_all)]
5758
pub async fn escrow_funds(
5859
client: &RpcClient,
5960
payer: Arc<Keypair>,
@@ -76,9 +77,11 @@ pub async fn escrow_funds(
7677
let timeout = timestamp + timeout_sec;
7778
let intent_id = random_intent_id();
7879

79-
let token_in_mint = (token_in == Pubkey::default())
80-
.then_some(spl_token::native_mint::ID)
81-
.unwrap_or(token_in);
80+
let token_in_mint = if token_in == Pubkey::default() {
81+
spl_token::native_mint::ID
82+
} else {
83+
token_in
84+
};
8285

8386
let (escrow_pda, _) = Pubkey::find_program_address(&[ESCROW_SEED], &program_id);
8487
let (escrow_sol_pda, _) = Pubkey::find_program_address(&[ESCROW_SEED, SOL_SEED], &program_id);
@@ -139,7 +142,11 @@ pub async fn escrow_funds(
139142
.args(escrow_args)
140143
.instructions()?;
141144

142-
let recent_blockhash = retry(|| client.get_latest_blockhash(), 3).await?;
145+
let recent_blockhash = retry(
146+
|| client.get_latest_blockhash(),
147+
3,
148+
)
149+
.await?;
143150

144151
let escrow_transaction = Transaction::new_signed_with_payer(
145152
&escrow_instructions,
@@ -148,10 +155,15 @@ pub async fn escrow_funds(
148155
recent_blockhash,
149156
);
150157

151-
let signature = retry(|| client.send_and_confirm_transaction(&escrow_transaction), 3).await?;
158+
let signature = retry(
159+
|| client.send_and_confirm_transaction(&escrow_transaction),
160+
3,
161+
)
162+
.await?;
152163
Ok(signature)
153164
}
154165

166+
#[instrument(skip_all)]
155167
pub async fn cancel_intent(
156168
client: &RpcClient,
157169
payer: Arc<Keypair>,
@@ -202,7 +214,11 @@ pub async fn cancel_intent(
202214
.args(cancel_args)
203215
.instructions()?;
204216

205-
let recent_blockhash = retry(|| client.get_latest_blockhash(), 3).await?;
217+
let recent_blockhash = retry(
218+
|| client.get_latest_blockhash(),
219+
3,
220+
)
221+
.await?;
206222

207223
let cancel_transaction = Transaction::new_signed_with_payer(
208224
&cancel_instructions,
@@ -211,10 +227,15 @@ pub async fn cancel_intent(
211227
recent_blockhash,
212228
);
213229

214-
let signature = retry(|| client.send_and_confirm_transaction(&cancel_transaction), 3).await?;
230+
let signature = retry(
231+
|| client.send_and_confirm_transaction(&cancel_transaction),
232+
3,
233+
)
234+
.await?;
215235
Ok(signature)
216236
}
217237

238+
#[instrument(skip_all)]
218239
pub async fn initialize(client: &RpcClient, payer: Arc<Keypair>, program_id: Pubkey) -> Result<Signature> {
219240
let cluster = Cluster::Custom(client.url(), String::default());
220241
let client_anchor = Client::new_with_options(cluster, payer.clone(), CommitmentConfig::processed());
@@ -243,7 +264,11 @@ pub async fn initialize(client: &RpcClient, payer: Arc<Keypair>, program_id: Pub
243264
.args(initialize_args)
244265
.instructions()?;
245266

246-
let recent_blockhash = retry(|| client.get_latest_blockhash(), 3).await?;
267+
let recent_blockhash = retry(
268+
|| client.get_latest_blockhash(),
269+
3,
270+
)
271+
.await?;
247272

248273
let initialize_tx = Transaction::new_signed_with_payer(
249274
&initialize_ix,
@@ -252,10 +277,15 @@ pub async fn initialize(client: &RpcClient, payer: Arc<Keypair>, program_id: Pub
252277
recent_blockhash,
253278
);
254279

255-
let signature = retry(|| client.send_and_confirm_transaction(&initialize_tx), 3).await?;
280+
let signature = retry(
281+
|| client.send_and_confirm_transaction(&initialize_tx),
282+
3,
283+
)
284+
.await?;
256285
Ok(signature)
257286
}
258287

288+
#[instrument(skip_all)]
259289
pub async fn create_associated_token_account(
260290
client: &RpcClient,
261291
payer: Arc<Keypair>,
@@ -265,7 +295,11 @@ pub async fn create_associated_token_account(
265295
let (create_associated_account_ix, ata) =
266296
create_associated_token_account_ix(client, payer.clone(), user, token_mint).await?;
267297

268-
let recent_blockhash = retry(|| client.get_latest_blockhash(), 3).await?;
298+
let recent_blockhash = retry(
299+
|| client.get_latest_blockhash(),
300+
3,
301+
)
302+
.await?;
269303

270304
let create_associated_account_tx = Transaction::new_signed_with_payer(
271305
&[create_associated_account_ix],
@@ -299,6 +333,7 @@ pub async fn create_associated_token_account_ix(
299333
Ok((instructions, ata))
300334
}
301335

336+
#[instrument(skip_all)]
302337
pub async fn get_transaction_info(
303338
client: &RpcClient,
304339
signature: Signature,
@@ -308,16 +343,25 @@ pub async fn get_transaction_info(
308343
commitment: Some(CommitmentConfig::confirmed()),
309344
max_supported_transaction_version: Some(0),
310345
};
311-
let transaction_info = retry(|| client.get_transaction_with_config(&signature, config), 3).await?;
346+
let transaction_info = retry(
347+
|| client.get_transaction_with_config(&signature, config),
348+
3,
349+
)
350+
.await?;
312351

313352
Ok(transaction_info)
314353
}
315354

355+
#[instrument(skip_all)]
316356
pub async fn get_lookup_table_accounts(
317357
client: &RpcClient,
318358
lookup_table_addresses: &[Pubkey],
319359
) -> Result<Vec<AddressLookupTableAccount>> {
320-
let lookup_table_accounts = retry(|| client.get_multiple_accounts(lookup_table_addresses), 3).await?;
360+
let lookup_table_accounts = retry(
361+
|| client.get_multiple_accounts(lookup_table_addresses),
362+
3,
363+
)
364+
.await?;
321365

322366
lookup_table_addresses
323367
.iter()
@@ -334,6 +378,7 @@ pub async fn get_lookup_table_accounts(
334378
.collect()
335379
}
336380

381+
#[instrument(skip_all)]
337382
pub async fn transfer_spl_token(
338383
client: &RpcClient,
339384
sender: Arc<Keypair>,
@@ -344,7 +389,11 @@ pub async fn transfer_spl_token(
344389
let transfer_spl_token_ix =
345390
transfer_spl_token_ix(client, sender.clone(), recipient, token_mint, amount).await?;
346391

347-
let recent_blockhash = retry(|| client.get_latest_blockhash(), 3).await?;
392+
let recent_blockhash = retry(
393+
|| client.get_latest_blockhash(),
394+
3,
395+
)
396+
.await?;
348397

349398
let transfer_spl_token_tx = Transaction::new_signed_with_payer(
350399
&transfer_spl_token_ix,
@@ -353,7 +402,11 @@ pub async fn transfer_spl_token(
353402
recent_blockhash,
354403
);
355404

356-
let signature = retry(|| client.send_and_confirm_transaction(&transfer_spl_token_tx), 3).await?;
405+
let signature = retry(
406+
|| client.send_and_confirm_transaction(&transfer_spl_token_tx),
407+
3,
408+
)
409+
.await?;
357410
Ok(signature)
358411
}
359412

@@ -393,6 +446,7 @@ pub async fn transfer_spl_token_ix(
393446
Ok(transfer_instructions)
394447
}
395448

449+
#[instrument(skip_all)]
396450
pub async fn submit_through_rpc(
397451
client: &RpcClient,
398452
payer: Arc<Keypair>,
@@ -404,25 +458,40 @@ pub async fn submit_through_rpc(
404458
&transaction.instructions,
405459
Some(&payer.pubkey()),
406460
&[&*payer],
407-
retry(|| client.get_latest_blockhash(), 3).await?,
461+
retry(
462+
|| client.get_latest_blockhash(),
463+
3,
464+
)
465+
.await?,
408466
);
409-
retry(|| client.send_and_confirm_transaction(&transaction), 3)
410-
.await
411-
.context("Failed to send legacy transaction")
467+
retry(
468+
|| client.send_and_confirm_transaction(&transaction),
469+
3,
470+
)
471+
.await
472+
.context("Failed to send legacy transaction")
412473
} else {
413474
let message = v0::Message::try_compile(
414475
&payer.pubkey(),
415476
&transaction.instructions,
416477
&transaction.address_lookup_table,
417-
retry(|| client.get_latest_blockhash(), 3).await?,
478+
retry(
479+
|| client.get_latest_blockhash(),
480+
3,
481+
)
482+
.await?,
418483
)?;
419484
let transaction = VersionedTransaction::try_new(VersionedMessage::V0(message), &[&payer])?;
420-
retry(|| client.send_and_confirm_transaction(&transaction), 3)
421-
.await
422-
.context("Failed to send versioned transaction")
485+
retry(
486+
|| client.send_and_confirm_transaction(&transaction),
487+
3,
488+
)
489+
.await
490+
.context("Failed to send versioned transaction")
423491
}
424492
}
425493

494+
#[instrument(skip_all)]
426495
pub async fn submit_through_rpc_multiple(
427496
client: &RpcClient,
428497
payer: Arc<Keypair>,
@@ -446,8 +515,14 @@ pub async fn submit_through_rpc_multiple(
446515
Ok(signatures)
447516
}
448517

518+
#[instrument(skip_all)]
449519
pub async fn get_token_program_id(client: &RpcClient, token_mint: &Pubkey) -> Result<Pubkey> {
450-
match retry(|| client.get_account(token_mint), 3).await? {
520+
match retry(
521+
|| client.get_account(token_mint),
522+
3,
523+
)
524+
.await?
525+
{
451526
account if account.owner == spl_token_2022::ID => Ok(spl_token_2022::ID),
452527
account if account.owner == spl_token::ID => Ok(spl_token::ID),
453528
_ => Err(anyhow!("Failed to get token program ID for token {}", token_mint)),

0 commit comments

Comments
 (0)