Skip to content

Commit d7e638d

Browse files
committed
update: integrate l-monninger feedback
1 parent cbda177 commit d7e638d

File tree

5 files changed

+40
-28
lines changed

5 files changed

+40
-28
lines changed

protocol-units/bridge/chains/ethereum/src/client.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::send_transaction;
1+
use crate::utils::{calculate_storage_slot, send_transaction, send_transaction_rules};
22
use alloy::primitives::{private::serde::Deserialize, Address, FixedBytes, U256};
33
use alloy::providers::{Provider, ProviderBuilder, RootProvider};
44
use alloy::signers::k256::elliptic_curve::SecretKey;
@@ -26,7 +26,6 @@ use crate::types::{
2626
AlloyProvider, AtomicBridgeCounterparty, AtomicBridgeInitiator, CounterpartyContract,
2727
EthAddress, EthHash, InitiatorContract,
2828
};
29-
use crate::utils::{calculate_storage_slot, send_tx_rules};
3029

3130
const GAS_LIMIT: u128 = 10_000_000_000_000_000;
3231
const RETRIES: u32 = 6;
@@ -127,7 +126,7 @@ impl EthClient {
127126
) -> Result<(), anyhow::Error> {
128127
let contract = self.initiator_contract().expect("Initiator contract not set");
129128
let call = contract.initialize(weth.0, owner.0);
130-
send_transaction(call.to_owned(), &send_tx_rules(), RETRIES, GAS_LIMIT)
129+
send_transaction(call.to_owned(), &send_transaction_rules(), RETRIES, GAS_LIMIT)
131130
.await
132131
.expect("Failed to send transaction");
133132
Ok(())
@@ -236,15 +235,14 @@ impl BridgeContractInitiator for EthClient {
236235
U256::from(time_lock.0),
237236
)
238237
.value(U256::from(amount.0));
239-
let _ =
240-
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
241-
.await
242-
.map_err(|e| {
243-
BridgeContractInitiatorError::GenericError(format!(
244-
"Failed to send transaction: {}",
245-
e
246-
))
247-
})?;
238+
let _ = send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
239+
.await
240+
.map_err(|e| {
241+
BridgeContractInitiatorError::GenericError(format!(
242+
"Failed to send transaction: {}",
243+
e
244+
))
245+
})?;
248246
Ok(())
249247
}
250248

@@ -267,7 +265,7 @@ impl BridgeContractInitiator for EthClient {
267265
AtomicBridgeInitiator::new(self.initiator_contract_address()?, &self.rpc_provider);
268266
let call = contract
269267
.completeBridgeTransfer(FixedBytes(bridge_transfer_id.0), FixedBytes(pre_image));
270-
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
268+
send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
271269
.await
272270
.expect("Failed to send transaction");
273271
Ok(())
@@ -280,7 +278,7 @@ impl BridgeContractInitiator for EthClient {
280278
let contract =
281279
AtomicBridgeInitiator::new(self.initiator_contract_address()?, &self.rpc_provider);
282280
let call = contract.refundBridgeTransfer(FixedBytes(bridge_transfer_id.0));
283-
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
281+
send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
284282
.await
285283
.expect("Failed to send transaction");
286284
Ok(())
@@ -346,7 +344,7 @@ impl BridgeContractCounterparty for EthClient {
346344
recipient.0 .0,
347345
U256::from(amount.0),
348346
);
349-
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
347+
send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
350348
.await
351349
.expect("Failed to send transaction");
352350
Ok(())
@@ -364,7 +362,7 @@ impl BridgeContractCounterparty for EthClient {
364362
let secret: [u8; 32] = secret.0.try_into().unwrap();
365363
let call =
366364
contract.completeBridgeTransfer(FixedBytes(bridge_transfer_id.0), FixedBytes(secret));
367-
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
365+
send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
368366
.await
369367
.expect("Failed to send transaction");
370368
Ok(())
@@ -379,7 +377,7 @@ impl BridgeContractCounterparty for EthClient {
379377
&self.rpc_provider,
380378
);
381379
let call = contract.abortBridgeTransfer(FixedBytes(bridge_transfer_id.0));
382-
send_transaction(call, &send_tx_rules(), RETRIES, GAS_LIMIT)
380+
send_transaction(call, &send_transaction_rules(), RETRIES, GAS_LIMIT)
383381
.await
384382
.expect("Failed to send transaction");
385383
Ok(())

protocol-units/bridge/chains/ethereum/src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn calculate_storage_slot(key: [u8; 32], mapping_slot: U256) -> U256 {
8383
U256::from_be_slice(&hash.0)
8484
}
8585

86-
pub(crate) fn send_tx_rules() -> Vec<Box<dyn VerifyRule>> {
86+
pub(crate) fn send_transaction_rules() -> Vec<Box<dyn VerifyRule>> {
8787
let rule1: Box<dyn VerifyRule> = Box::new(SendTransactionErrorRule::<UnderPriced>::new());
8888
let rule2: Box<dyn VerifyRule> = Box::new(SendTransactionErrorRule::<InsufficentFunds>::new());
8989
vec![rule1, rule2]

protocol-units/bridge/chains/movement/src/lib.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,13 @@ impl BridgeContractCounterparty for MovementClient {
232232
self.counterparty_type_args(Call::Lock),
233233
args,
234234
);
235-
let _ = utils::send_aptos_transaction(&self.rest_client, self.signer.as_ref(), payload)
236-
.await
237-
.map_err(|_| BridgeContractCounterpartyError::LockTransferAssetsError);
235+
let _ = utils::send_and_confirm_aptos_transaction(
236+
&self.rest_client,
237+
self.signer.as_ref(),
238+
payload,
239+
)
240+
.await
241+
.map_err(|_| BridgeContractCounterpartyError::LockTransferAssetsError);
238242
Ok(())
239243
}
240244

@@ -256,9 +260,13 @@ impl BridgeContractCounterparty for MovementClient {
256260
args,
257261
);
258262

259-
let _ = utils::send_aptos_transaction(&self.rest_client, self.signer.as_ref(), payload)
260-
.await
261-
.map_err(|_| BridgeContractCounterpartyError::CompleteTransferError);
263+
let _ = utils::send_and_confirm_aptos_transaction(
264+
&self.rest_client,
265+
self.signer.as_ref(),
266+
payload,
267+
)
268+
.await
269+
.map_err(|_| BridgeContractCounterpartyError::CompleteTransferError);
262270
Ok(())
263271
}
264272

@@ -277,9 +285,13 @@ impl BridgeContractCounterparty for MovementClient {
277285
self.counterparty_type_args(Call::Abort),
278286
args,
279287
);
280-
let _ = utils::send_aptos_transaction(&self.rest_client, self.signer.as_ref(), payload)
281-
.await
282-
.map_err(|_| BridgeContractCounterpartyError::AbortTransferError);
288+
let _ = utils::send_and_confirm_aptos_transaction(
289+
&self.rest_client,
290+
self.signer.as_ref(),
291+
payload,
292+
)
293+
.await
294+
.map_err(|_| BridgeContractCounterpartyError::AbortTransferError);
283295
Ok(())
284296
}
285297

protocol-units/bridge/chains/movement/src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub struct Indexed<T> {
9494
}
9595

9696
/// Send Aptos Transaction
97-
pub async fn send_aptos_transaction(
97+
pub async fn send_and_confirm_aptos_transaction(
9898
rest_client: &RestClient,
9999
signer: &LocalAccount,
100100
payload: TransactionPayload,

protocol-units/bridge/contracts/src/AtomicBridgeInitiator.sol

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ contract AtomicBridgeInitiator is IAtomicBridgeInitiator, OwnableUpgradeable {
6666
// Update the pool balance
6767
poolBalance += totalAmount;
6868

69+
// The nonce is used to generate a unique bridge transfer id, without it
70+
// we can't guarantee the uniqueness of the id.
6971
nonce++; // increment the nonce
7072
bridgeTransferId =
7173
keccak256(abi.encodePacked(originator, recipient, hashLock, timeLock, block.number, nonce));

0 commit comments

Comments
 (0)