Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(evmlib): add timeout to pending tx builder #2565

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions evmlib/src/contract/network_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use crate::common::{Address, Calldata, TxHash, U256};
use crate::contract::network_token::NetworkTokenContract::NetworkTokenContractInstance;
use crate::TX_TIMEOUT;
use alloy::network::TransactionBuilder;
use alloy::providers::{Network, Provider};
use alloy::sol;
Expand Down Expand Up @@ -108,9 +109,10 @@ where
.await
.inspect_err(|err| {
error!(
"Error approving spender {spender:?} to spend raw amt of tokens {value}: {err:?}"
"Error to send_transaction while approving spender {spender:?} to spend raw amt of tokens {value}: {err:?}"
)
})?;
})?
.with_timeout(Some(TX_TIMEOUT));

let pending_tx_hash = *pending_tx_builder.tx_hash();

Expand Down Expand Up @@ -150,8 +152,9 @@ where
.send_transaction(transaction_request)
.await
.inspect_err(|err| {
error!("Error transferring raw amt of tokens to {receiver:?}: {err:?}")
})?;
error!("Error to send_transaction during transfer raw amt of tokens to {receiver:?}: {err:?}")
})?
.with_timeout(Some(TX_TIMEOUT));

let pending_tx_hash = *pending_tx_builder.tx_hash();
debug!(
Expand Down
16 changes: 12 additions & 4 deletions evmlib/src/contract/payment_vault/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::common::{Address, Amount, Calldata, TxHash};
use crate::contract::payment_vault::error::Error;
use crate::contract::payment_vault::interface::IPaymentVault;
use crate::contract::payment_vault::interface::IPaymentVault::IPaymentVaultInstance;
use crate::TX_TIMEOUT;
use alloy::network::{Network, TransactionBuilder};
use alloy::providers::Provider;
use alloy::transports::Transport;
Expand Down Expand Up @@ -59,13 +60,20 @@ where
.with_to(to)
.with_input(calldata);

let tx_hash = self
let pending_tx_builder = self
.contract
.provider()
.send_transaction(transaction_request)
.await?
.watch()
.await?;
.await
.inspect_err(|err| error!("Error to send_transaction during pay_for_quotes: {err:?}"))?
.with_timeout(Some(TX_TIMEOUT));

let pending_tx_hash = pending_tx_builder.tx_hash();
debug!("pay_for_quotes is pending with tx hash: {pending_tx_hash}");

let tx_hash = pending_tx_builder.watch().await.inspect_err(|err| {
error!("Error to watch transaction during pay_for_quotes: {err:?}")
})?;

Ok(tx_hash)
}
Expand Down
3 changes: 3 additions & 0 deletions evmlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const ARBITRUM_ONE_DATA_PAYMENTS_ADDRESS: Address =
const ARBITRUM_SEPOLIA_DATA_PAYMENTS_ADDRESS: Address =
address!("993C7739f50899A997fEF20860554b8a28113634");

/// Timeout for transactions
const TX_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(60);

#[serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CustomNetwork {
Expand Down
17 changes: 15 additions & 2 deletions evmlib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::contract::payment_vault::handler::PaymentVaultHandler;
use crate::contract::payment_vault::MAX_TRANSFERS_PER_TRANSACTION;
use crate::contract::{network_token, payment_vault};
use crate::utils::http_provider;
use crate::Network;
use crate::{Network, TX_TIMEOUT};
use alloy::hex::ToHexExt;
use alloy::network::{Ethereum, EthereumWallet, NetworkWallet, TransactionBuilder};
use alloy::providers::fillers::{
Expand Down Expand Up @@ -262,7 +262,20 @@ pub async fn transfer_gas_tokens(
.with_to(receiver)
.with_value(amount);

let tx_hash = provider.send_transaction(tx).await?.watch().await?;
let pending_tx_builder = provider
.send_transaction(tx)
.await
.inspect_err(|err| {
error!("Error to send_transaction during transfer_gas_tokens: {err}");
})?
.with_timeout(Some(TX_TIMEOUT));
let pending_tx_hash = *pending_tx_builder.tx_hash();
debug!("The transfer of gas tokens is pending with tx_hash: {pending_tx_hash}");

let tx_hash = pending_tx_builder.watch().await.inspect_err(|err| {
error!("Error watching transfer_gas_tokens tx with hash {pending_tx_hash}: {err}")
})?;
debug!("Transfer of gas tokens with tx_hash: {tx_hash} is successful");

Ok(tx_hash)
}
Expand Down
Loading