From 713ac5223f485558b3cde6cf6c616937f716561c Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Wed, 29 May 2024 10:09:38 +0200 Subject: [PATCH] add logs for retry service (#1126) * add logs for retry service * fix comments * reducing log text --- src/eth_provider/provider.rs | 45 ++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/eth_provider/provider.rs b/src/eth_provider/provider.rs index e3d407785..37ecc2327 100644 --- a/src/eth_provider/provider.rs +++ b/src/eth_provider/provider.rs @@ -574,18 +574,17 @@ where #[cfg(feature = "hive")] self.deploy_evm_transaction_signer(signer).await?; - // Convert the transaction to a Starknet transaction - let transaction = to_starknet_transaction(&transaction_signed, maybe_chain_id, signer, max_fee)?; - - // Add the transaction to the Starknet provider - let res = self.starknet_provider.add_invoke_transaction(transaction).await.map_err(KakarotError::from)?; - // Serialize transaction document let transaction = from_recovered(TransactionSignedEcRecovered::from_signed_transaction(transaction_signed.clone(), signer)); // Update or insert the pending transaction in the database if let Some(pending_transaction) = pending_transaction { + tracing::info!( + "Updating transaction {}, retries: {}.", + transaction.hash.to_string(), + pending_transaction.retries + 1 + ); self.database .update_one::( StoredPendingTransaction::new(transaction, pending_transaction.retries + 1), @@ -594,15 +593,23 @@ where ) .await?; } else { + tracing::info!("New transaction {} in pending pool.", transaction.hash.to_string()); self.database.update_one::(transaction.into(), filter, true).await?; } + // Convert the transaction to a Starknet transaction + let starnet_transaction = to_starknet_transaction(&transaction_signed, maybe_chain_id, signer, max_fee)?; + + // Add the transaction to the Starknet provider + let res = + self.starknet_provider.add_invoke_transaction(starnet_transaction).await.map_err(KakarotError::from)?; + // Return transaction hash if testing feature is enabled, otherwise log and return Ethereum hash if cfg!(feature = "testing") { return Ok(B256::from_slice(&res.transaction_hash.to_bytes_be()[..])); } let hash = transaction_signed.hash(); - tracing::info!("Fired a transaction: Starknet Hash: {:?} --- Ethereum Hash: {:?}", res.transaction_hash, hash); + tracing::info!("Fired a transaction: Starknet Hash: {} --- Ethereum Hash: {}", res.transaction_hash, hash); Ok(hash) } @@ -1004,6 +1011,8 @@ where .await? .is_some() { + tracing::info!("Pruning pending transaction: {hash}"); + // Delete the pending transaction from the database self.database .delete_one::(into_filter("tx.hash", &hash, HASH_HEX_STRING_LEN)) @@ -1014,16 +1023,22 @@ where } // Generate primitive transaction, handle error if any - let Ok(transaction) = TransactionSignedEcRecovered::try_from(tx.tx.clone()) else { - // Delete the pending transaction from the database due conversion error - // Malformed transaction - self.database - .delete_one::(into_filter("tx.hash", &hash, HASH_HEX_STRING_LEN)) - .await?; - // Continue to the next iteration of the loop - continue; + let transaction = match TransactionSignedEcRecovered::try_from(tx.tx.clone()) { + Ok(transaction) => transaction, + Err(error) => { + tracing::info!("Pruning pending transaction: {hash}, conversion error: {error}"); + // Delete the pending transaction from the database due conversion error + // Malformed transaction + self.database + .delete_one::(into_filter("tx.hash", &hash, HASH_HEX_STRING_LEN)) + .await?; + // Continue to the next iteration of the loop + continue; + } }; + tracing::info!("Retrying transaction: {hash}"); + // Create a signed transaction and send it transactions_retried.push(self.send_raw_transaction(transaction.into_signed().envelope_encoded()).await?); }