Skip to content

Commit

Permalink
add logs for retry service (#1126)
Browse files Browse the repository at this point in the history
* add logs for retry service

* fix comments

* reducing log text
  • Loading branch information
tcoratger authored May 29, 2024
1 parent a7e9dde commit 713ac52
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/eth_provider/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
StoredPendingTransaction::new(transaction, pending_transaction.retries + 1),
Expand All @@ -594,15 +593,23 @@ where
)
.await?;
} else {
tracing::info!("New transaction {} in pending pool.", transaction.hash.to_string());
self.database.update_one::<StoredPendingTransaction>(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)
}
Expand Down Expand Up @@ -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::<StoredPendingTransaction>(into_filter("tx.hash", &hash, HASH_HEX_STRING_LEN))
Expand All @@ -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::<StoredPendingTransaction>(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::<StoredPendingTransaction>(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?);
}
Expand Down

0 comments on commit 713ac52

Please sign in to comment.