diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index 878dee11..be84448c 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -1,6 +1,5 @@ #![no_std] use multiversx_sc::imports::*; -use multiversx_sc_modules::ongoing_operation::*; pub mod config; @@ -11,18 +10,15 @@ const MIN_GAS_LIMIT_FOR_SC_CALL: u64 = 10_000_000; const MAX_GAS_LIMIT_FOR_SC_CALL: u64 = 249999999; const DEFAULT_GAS_LIMIT_FOR_REFUND_CALLBACK: u64 = 20_000_000; // 20 million const DELAY_BEFORE_OWNER_CAN_CANCEL_TRANSACTION: u64 = 300; -const MIN_GAS_TO_SAVE_PROGRESS: u64 = 1_000_000; #[multiversx_sc::contract] pub trait BridgeProxyContract: config::ConfigModule + multiversx_sc_modules::pause::PauseModule - + multiversx_sc_modules::ongoing_operation::OngoingOperationModule { #[init] fn init(&self, opt_multi_transfer_address: OptionalValue) { self.set_multi_transfer_contract_address(opt_multi_transfer_address); - self.lowest_tx_id().set(1); self.set_paused(true); } @@ -41,9 +37,10 @@ pub trait BridgeProxyContract: caller == self.multi_transfer_address().get(), "Only MultiTransfer can do deposits" ); - let tx_id = self.pending_transactions().push(ð_tx); - self.payments(tx_id).set(&payment); - self.batch_id(tx_id).set(batch_id); + let next_tx_id = self.get_next_tx_id(); + self.pending_transactions().insert(next_tx_id, eth_tx); + self.payments(next_tx_id).set(&payment); + self.batch_id(next_tx_id).set(batch_id); } #[endpoint(execute)] @@ -192,53 +189,31 @@ pub trait BridgeProxyContract: } fn cleanup_transaction(&self, tx_id: usize) { - self.pending_transactions().clear_entry_unchecked(tx_id); - self.update_lowest_tx_id(); + self.pending_transactions().remove(&tx_id); self.ongoing_execution(tx_id).clear(); } - #[endpoint(updateLowestTxId)] - fn update_lowest_tx_id(&self) { - let mut new_lowest = self.lowest_tx_id().get(); - let len = self.pending_transactions().len(); - - self.run_while_it_has_gas(MIN_GAS_TO_SAVE_PROGRESS, || { - if !self.empty_element(new_lowest, len) { - return STOP_OP; - } - - new_lowest += 1; - - CONTINUE_OP - }); - - self.lowest_tx_id().set(new_lowest); - } - - fn empty_element(&self, current_index: usize, len: usize) -> bool { - current_index < len && self.pending_transactions().item_is_empty(current_index) + fn get_next_tx_id(&self) -> usize { + let mut next_tx_id = self.highest_tx_id().get(); + next_tx_id += 1; + self.highest_tx_id().set(next_tx_id); + next_tx_id } #[view(getPendingTransactionById)] fn get_pending_transaction_by_id(&self, tx_id: usize) -> EthTransaction { - self.pending_transactions() - .get_or_else(tx_id, || panic!("Invalid tx id")) + let tx = self.pending_transactions().get(&tx_id); + require!(tx.is_some(), "Invalid tx id"); + tx.unwrap() } #[view(getPendingTransactions)] fn get_pending_transactions( &self, ) -> MultiValueEncoded>> { - let lowest_tx_id = self.lowest_tx_id().get(); - let len = self.pending_transactions().len(); - let mut transactions = MultiValueEncoded::new(); - for i in lowest_tx_id..=len { - if self.pending_transactions().item_is_empty(i) { - continue; - } - let tx = self.pending_transactions().get_unchecked(i); - transactions.push(MultiValue2((i, tx))); + for (tx_id, tx) in self.pending_transactions().iter() { + transactions.push(MultiValue2((tx_id, tx))); } transactions } diff --git a/bridge-proxy/src/config.rs b/bridge-proxy/src/config.rs index 9712ae91..6c81b837 100644 --- a/bridge-proxy/src/config.rs +++ b/bridge-proxy/src/config.rs @@ -68,7 +68,7 @@ pub trait ConfigModule { fn esdt_safe_contract_address(&self) -> SingleValueMapper; #[storage_mapper("pending_transactions")] - fn pending_transactions(&self) -> VecMapper>; + fn pending_transactions(&self) -> MapMapper>; #[storage_mapper("payments")] fn payments(&self, tx_id: usize) -> SingleValueMapper>; @@ -76,9 +76,9 @@ pub trait ConfigModule { #[storage_mapper("batch_id")] fn batch_id(&self, tx_id: usize) -> SingleValueMapper; - #[view(lowestTxId)] - #[storage_mapper("lowest_tx_id")] - fn lowest_tx_id(&self) -> SingleValueMapper; + #[view(highestTxId)] + #[storage_mapper("highest_tx_id")] + fn highest_tx_id(&self) -> SingleValueMapper; #[storage_mapper("ongoingExecution")] fn ongoing_execution(&self, tx_id: usize) -> SingleValueMapper; diff --git a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs index d054bed1..2f23c082 100644 --- a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -400,7 +400,7 @@ fn multiple_deposit_test() { } #[test] -fn test_lowest_tx_id() { +fn test_highest_tx_id() { let mut test = BridgeProxyTestState::new(); test.deploy_bridge_proxy(); @@ -416,9 +416,9 @@ fn test_lowest_tx_id() { }; let call_data = ManagedSerializer::new().top_encode_to_managed_buffer(&call_data); - // Generate 100 transactions + // Generate 1600 transactions let mut transactions = Vec::new(); - for i in 1..=100 { + for i in 1..=1600 { let eth_tx = EthTransaction { from: EthAddress { raw_addr: ManagedByteArray::new_from_bytes(b"01020304050607080910"), @@ -431,8 +431,16 @@ fn test_lowest_tx_id() { }; transactions.push(eth_tx); } + test.world + .query() + .to(BRIDGE_PROXY_ADDRESS) + .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) + .highest_tx_id() + .returns(ExpectValue(0usize)) + .run(); // Deposit all transactions + let mut expected_tx_id = 1usize; for tx in &transactions { test.world .tx() @@ -446,40 +454,19 @@ fn test_lowest_tx_id() { &BigUint::from(5u64), ) .run(); - } - - // Check the lowest_tx_id - test.world - .query() - .to(BRIDGE_PROXY_ADDRESS) - .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) - .lowest_tx_id() - .returns(ExpectValue(1usize)) - .run(); - // Execute the first 50 transactions - for i in 1..=50usize { test.world - .tx() - .from(OWNER_ADDRESS) + .query() .to(BRIDGE_PROXY_ADDRESS) - .gas(200_000_000) .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) - .execute(i) + .highest_tx_id() + .returns(ExpectValue(expected_tx_id)) .run(); + expected_tx_id += 1; } - // Check the lowest_tx_id again - test.world - .query() - .to(BRIDGE_PROXY_ADDRESS) - .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) - .lowest_tx_id() - .returns(ExpectValue(51usize)) - .run(); - - // Execute transactions 75 to 100 - for i in 75..=100usize { + // Execute all transactions + for i in (1..=1600usize).rev() { test.world .tx() .from(OWNER_ADDRESS) @@ -489,15 +476,6 @@ fn test_lowest_tx_id() { .execute(i) .run(); } - - // Check the lowest_tx_id one last time - test.world - .query() - .to(BRIDGE_PROXY_ADDRESS) - .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) - .lowest_tx_id() - .returns(ExpectValue(51usize)) - .run(); } // Will be moved to integration test diff --git a/bridge-proxy/wasm/src/lib.rs b/bridge-proxy/wasm/src/lib.rs index bcfd0f92..7036dacd 100644 --- a/bridge-proxy/wasm/src/lib.rs +++ b/bridge-proxy/wasm/src/lib.rs @@ -6,10 +6,10 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 15 +// Endpoints: 14 // Async Callback (empty): 1 // Promise callbacks: 1 -// Total number of exported functions: 19 +// Total number of exported functions: 18 #![no_std] @@ -23,7 +23,6 @@ multiversx_sc_wasm_adapter::endpoints! { upgrade => upgrade deposit => deposit execute => execute - updateLowestTxId => update_lowest_tx_id getPendingTransactionById => get_pending_transaction_by_id getPendingTransactions => get_pending_transactions setMultiTransferAddress => set_multi_transfer_contract_address @@ -32,7 +31,7 @@ multiversx_sc_wasm_adapter::endpoints! { getMultiTransferAddress => multi_transfer_address getBridgedTokensWrapperAddress => bridged_tokens_wrapper_address getEsdtSafeContractAddress => esdt_safe_contract_address - lowestTxId => lowest_tx_id + highestTxId => highest_tx_id pause => pause_endpoint unpause => unpause_endpoint isPaused => paused_status diff --git a/common/sc-proxies/src/bridge_proxy_contract_proxy.rs b/common/sc-proxies/src/bridge_proxy_contract_proxy.rs index 768889b6..3cb21d18 100644 --- a/common/sc-proxies/src/bridge_proxy_contract_proxy.rs +++ b/common/sc-proxies/src/bridge_proxy_contract_proxy.rs @@ -113,15 +113,6 @@ where .original_result() } - pub fn update_lowest_tx_id( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("updateLowestTxId") - .original_result() - } - pub fn get_pending_transaction_by_id< Arg0: ProxyArg, >( @@ -210,12 +201,12 @@ where .original_result() } - pub fn lowest_tx_id( + pub fn highest_tx_id( self, ) -> TxTypedCall { self.wrapped_tx .payment(NotPayable) - .raw_call("lowestTxId") + .raw_call("highestTxId") .original_result() } diff --git a/multi-transfer-esdt/src/bridge_proxy_contract_proxy.rs b/multi-transfer-esdt/src/bridge_proxy_contract_proxy.rs index 768889b6..3cb21d18 100644 --- a/multi-transfer-esdt/src/bridge_proxy_contract_proxy.rs +++ b/multi-transfer-esdt/src/bridge_proxy_contract_proxy.rs @@ -113,15 +113,6 @@ where .original_result() } - pub fn update_lowest_tx_id( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("updateLowestTxId") - .original_result() - } - pub fn get_pending_transaction_by_id< Arg0: ProxyArg, >( @@ -210,12 +201,12 @@ where .original_result() } - pub fn lowest_tx_id( + pub fn highest_tx_id( self, ) -> TxTypedCall { self.wrapped_tx .payment(NotPayable) - .raw_call("lowestTxId") + .raw_call("highestTxId") .original_result() } diff --git a/multisig/interaction/config/aggregator-snippets.sh b/multisig/interaction/config/aggregator-snippets.sh index a4422815..3bbc3ebe 100644 --- a/multisig/interaction/config/aggregator-snippets.sh +++ b/multisig/interaction/config/aggregator-snippets.sh @@ -80,6 +80,14 @@ pauseAggregator() { --send --proxy=${PROXY} --chain=${CHAIN_ID} || return } +pauseAggregatorV2() { + CHECK_VARIABLES AGGREGATOR_v2 + + mxpy --verbose contract call ${AGGREGATOR_v2} --recall-nonce --pem=${ALICE} \ + --gas-limit=5000000 --function="pause" \ + --send --proxy=${PROXY} --chain=${CHAIN_ID} || return +} + unpauseAggregator() { CHECK_VARIABLES AGGREGATOR diff --git a/multisig/interaction/config/configs.cfg b/multisig/interaction/config/configs.cfg index 831f8b34..d82522b6 100644 --- a/multisig/interaction/config/configs.cfg +++ b/multisig/interaction/config/configs.cfg @@ -32,6 +32,11 @@ BRIDGE_PROXY=erd1qqqqqqqqqqqqqpgqk09rka2dslnf9ns5eze2s5xw2hfjxm0jzlsqzyjh28 FAUCET=erd1qqqqqqqqqqqqqpgqhhlx9mpdc92l0psszy3cf9lxhg9vzhs8zlsqjeeqqn TEST_CALLER=erd1qqqqqqqqqqqqqpgq398fy44g59se3pkmjz8tya39pz5q4tuvpqqqgwffes +#============v2 CONTRACT ADDRESSES============== +MULTISIG_v2=erd1qqqqqqqqqqqqqpgqu5asufdaxnzxhxgjheuee2mzm28y205rzcqq25xvky +AGGREGATOR_v2=erd1qqqqqqqqqqqqqpgqxgpczmmcjr64ladk2hz05gm6j73usrugzcqqmhhzd0 +BRIDGED_TOKENS_WRAPPER_v2=erd1qqqqqqqqqqqqqpgqgvx0y4c9ael8ha29cvn0c3r6ay5c9heezcqq2nejur + #============TOKENS SETTINGS============== NR_DECIMALS_CHAIN_SPECIFIC=6 NR_DECIMALS_UNIVERSAL=6 diff --git a/multisig/interaction/config/menu_functions.cfg b/multisig/interaction/config/menu_functions.cfg index 48c727c5..0d492f78 100644 --- a/multisig/interaction/config/menu_functions.cfg +++ b/multisig/interaction/config/menu_functions.cfg @@ -179,6 +179,7 @@ function upgrade-aggregator { function upgrade-wrapper { wrapper-upgrade + confirmation-with-skip setEsdtSafeOnWrapper } function upgrade-safe { @@ -215,3 +216,10 @@ function faucet-deposit { function deploy-test-caller { confirmation-with-skip deployTestCaller } + +function pause-v2-contracts { + confirmation-with-skip pauseV2 + confirmation-with-skip pauseEsdtSafeV2 + confirmation-with-skip pauseAggregatorV2 + confirmation-with-skip wrapper-pauseV2 +} diff --git a/multisig/interaction/config/multisig-snippets.sh b/multisig/interaction/config/multisig-snippets.sh index a0dade83..f48c9942 100644 --- a/multisig/interaction/config/multisig-snippets.sh +++ b/multisig/interaction/config/multisig-snippets.sh @@ -133,6 +133,14 @@ pause() { --send --proxy=${PROXY} --chain=${CHAIN_ID} } +pauseV2() { + CHECK_VARIABLES MULTISIG_v2 + + mxpy --verbose contract call ${MULTISIG_v2} --recall-nonce --pem=${ALICE} \ + --gas-limit=40000000 --function="pause" \ + --send --proxy=${PROXY} --chain=${CHAIN_ID} +} + pauseEsdtSafe() { CHECK_VARIABLES MULTISIG @@ -141,6 +149,14 @@ pauseEsdtSafe() { --send --proxy=${PROXY} --chain=${CHAIN_ID} } +pauseEsdtSafeV2() { + CHECK_VARIABLES MULTISIG_v2 + + mxpy --verbose contract call ${MULTISIG_v2} --recall-nonce --pem=${ALICE} \ + --gas-limit=40000000 --function="pauseEsdtSafe" \ + --send --proxy=${PROXY} --chain=${CHAIN_ID} +} + pauseProxy() { CHECK_VARIABLES MULTISIG @@ -223,6 +239,9 @@ initSupplyMintBurn() { MINT=$(echo "$MINT_BALANCE*10^$NR_DECIMALS_CHAIN_SPECIFIC" | bc) BURN=$(echo "$BURN_BALANCE*10^$NR_DECIMALS_CHAIN_SPECIFIC" | bc) + MINT=$(echo ${MINT%.*}) # trim decimals, if existing + BURN=$(echo ${BURN%.*}) # trim decimals, if existing + mxpy --verbose contract call ${MULTISIG} --recall-nonce --pem=${ALICE} \ --gas-limit=60000000 --function="initSupplyMintBurnEsdtSafe" \ --arguments str:${CHAIN_SPECIFIC_TOKEN} ${MINT} ${BURN} \ diff --git a/multisig/interaction/config/wrapped-snippets.sh b/multisig/interaction/config/wrapped-snippets.sh index 87a1fc0e..7a2ad727 100644 --- a/multisig/interaction/config/wrapped-snippets.sh +++ b/multisig/interaction/config/wrapped-snippets.sh @@ -121,6 +121,14 @@ wrapper-pause() { --send --proxy=${PROXY} --chain=${CHAIN_ID} || return } +wrapper-pauseV2() { + CHECK_VARIABLES BRIDGED_TOKENS_WRAPPER_v2 + + mxpy --verbose contract call ${BRIDGED_TOKENS_WRAPPER_v2} --recall-nonce --pem=${ALICE} \ + --gas-limit=5000000 --function="pause" \ + --send --proxy=${PROXY} --chain=${CHAIN_ID} || return +} + wrapper-upgrade() { CHECK_VARIABLES BRIDGED_TOKENS_WRAPPER BRIDGED_TOKENS_WRAPPER_WASM diff --git a/multisig/interaction/script.sh b/multisig/interaction/script.sh index 84e5fb17..b4e3f493 100755 --- a/multisig/interaction/script.sh +++ b/multisig/interaction/script.sh @@ -123,13 +123,17 @@ case "$1" in confirmation deploy-test-caller ;; +'pause-v2-contracts') + confirmation pause-v2-contracts + ;; + *) echo "Usage: Invalid choice: '"$1"'" echo -e echo "Choose from:" echo " { \"deploy-bridge-contracts\", " echo " \"upgrade-aggregator\", \"upgrade-wrapper\", \"upgrade-safe\", \"upgrade-multi-transfer\", \"upgrade-proxy\", \"upgrade-multisig\" " - echo " \"pause-contracts\", \"unpause-contracts\", \"add-relayer\", \"remove-relayer\", " + echo " \"pause-contracts\", \"unpause-contracts\", \"add-relayer\", \"remove-relayer\", \"pause-v2-contracts\", " echo " \"set-safe-max-tx\", \"set-safe-batch-block-duration\", \"change-quorum\", \"set-swap-fee\", " echo " \"whitelist-token\", \"whitelist-native-token\", \"remove-whitelist-token\", \"upgrade-wrapper-universal-token\", \"upgrade-wrapper-chain-specific-token\", " echo " \"mint-chain-specific\", \"init-supply-mint-burn\", " diff --git a/multisig/src/bridge_proxy_contract_proxy.rs b/multisig/src/bridge_proxy_contract_proxy.rs index 768889b6..3cb21d18 100644 --- a/multisig/src/bridge_proxy_contract_proxy.rs +++ b/multisig/src/bridge_proxy_contract_proxy.rs @@ -113,15 +113,6 @@ where .original_result() } - pub fn update_lowest_tx_id( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("updateLowestTxId") - .original_result() - } - pub fn get_pending_transaction_by_id< Arg0: ProxyArg, >( @@ -210,12 +201,12 @@ where .original_result() } - pub fn lowest_tx_id( + pub fn highest_tx_id( self, ) -> TxTypedCall { self.wrapped_tx .payment(NotPayable) - .raw_call("lowestTxId") + .raw_call("highestTxId") .original_result() }