diff --git a/runtime/src/rpc.rs b/runtime/src/rpc.rs index ddda67512..a2218bd94 100644 --- a/runtime/src/rpc.rs +++ b/runtime/src/rpc.rs @@ -939,9 +939,11 @@ pub trait ReplacePallet { /// Get all replace requests made by the given vault async fn get_old_vault_replace_requests( &self, - maybe_account_id: Option, + account_id: AccountId, ) -> Result, Error>; + async fn get_all_replace_requests(&self) -> Result, Error>; + /// Get the time difference in number of blocks between when a replace /// request is created and required completion time by a vault async fn get_replace_period(&self) -> Result; @@ -1035,35 +1037,36 @@ impl ReplacePallet for InterBtcParachain { /// Get all replace requests made by the given vault async fn get_old_vault_replace_requests( &self, - maybe_account_id: Option, + account_id: AccountId, ) -> Result, Error> { let head = self.get_finalized_block_hash().await?; - if let Some(account_id) = maybe_account_id { - let result: Vec = self - .api - .rpc() - .request("replace_getOldVaultReplaceRequests", rpc_params![account_id, head]) - .await?; - join_all( - result - .into_iter() - .map(|key| async move { self.get_replace_request(key).await.map(|value| (key, value)) }), - ) - .await - .into_iter() - .collect() - } else { - let key_addr = metadata::storage().replace().replace_requests_root(); - let mut iter = self.api.storage().iter(key_addr, DEFAULT_PAGE_SIZE, head).await?; - let mut replace_requests = Vec::new(); - while let Some((replace_id, request)) = iter.next().await? { - let key_hash = replace_id.0.as_slice(); - // last bytes are the raw key - let key = &key_hash[key_hash.len() - 32..]; - replace_requests.push((H256::from_slice(key), request)); - } - Ok(replace_requests) + let result: Vec = self + .api + .rpc() + .request("replace_getOldVaultReplaceRequests", rpc_params![account_id, head]) + .await?; + join_all( + result + .into_iter() + .map(|key| async move { self.get_replace_request(key).await.map(|value| (key, value)) }), + ) + .await + .into_iter() + .collect() + } + + async fn get_all_replace_requests(&self) -> Result, Error> { + let head = self.get_finalized_block_hash().await?; + let key_addr = metadata::storage().replace().replace_requests_root(); + let mut iter = self.api.storage().iter(key_addr, DEFAULT_PAGE_SIZE, head).await?; + let mut replace_requests = Vec::new(); + while let Some((replace_id, request)) = iter.next().await? { + let key_hash = replace_id.0.as_slice(); + // last bytes are the raw key + let key = &key_hash[key_hash.len() - 32..]; + replace_requests.push((H256::from_slice(key), request)); } + Ok(replace_requests) } async fn get_replace_period(&self) -> Result { @@ -1353,13 +1356,15 @@ pub trait RedeemPallet { async fn get_redeem_request(&self, redeem_id: H256) -> Result; - /// Get all redeem requests, if the account is specified - /// only return those for that Vault - async fn get_redeem_requests( + /// Get all redeem requests for a vault + async fn get_vault_redeem_requests( &self, - maybe_account_id: Option, + account_id: AccountId, ) -> Result, Error>; + /// Get all redeem requests + async fn get_all_redeem_requests(&self) -> Result, Error>; + async fn get_redeem_period(&self) -> Result; } @@ -1400,37 +1405,38 @@ impl RedeemPallet for InterBtcParachain { .await } - async fn get_redeem_requests( + async fn get_vault_redeem_requests( &self, - maybe_account_id: Option, + account_id: AccountId, ) -> Result, Error> { let head = self.get_finalized_block_hash().await?; - if let Some(account_id) = maybe_account_id { - let result: Vec = self - .api - .rpc() - .request("redeem_getVaultRedeemRequests", rpc_params![account_id, head]) - .await?; - join_all( - result - .into_iter() - .map(|key| async move { self.get_redeem_request(key).await.map(|value| (key, value)) }), - ) - .await - .into_iter() - .collect() - } else { - let key_addr = metadata::storage().redeem().redeem_requests_root(); - let mut iter = self.api.storage().iter(key_addr, DEFAULT_PAGE_SIZE, head).await?; - let mut redeem_requests = Vec::new(); - while let Some((redeem_id, request)) = iter.next().await? { - let key_hash = redeem_id.0.as_slice(); - // last bytes are the raw key - let key = &key_hash[key_hash.len() - 32..]; - redeem_requests.push((H256::from_slice(key), request)); - } - Ok(redeem_requests) + let result: Vec = self + .api + .rpc() + .request("redeem_getVaultRedeemRequests", rpc_params![account_id, head]) + .await?; + join_all( + result + .into_iter() + .map(|key| async move { self.get_redeem_request(key).await.map(|value| (key, value)) }), + ) + .await + .into_iter() + .collect() + } + + async fn get_all_redeem_requests(&self) -> Result, Error> { + let head = self.get_finalized_block_hash().await?; + let key_addr = metadata::storage().redeem().redeem_requests_root(); + let mut iter = self.api.storage().iter(key_addr, DEFAULT_PAGE_SIZE, head).await?; + let mut redeem_requests = Vec::new(); + while let Some((redeem_id, request)) = iter.next().await? { + let key_hash = redeem_id.0.as_slice(); + // last bytes are the raw key + let key = &key_hash[key_hash.len() - 32..]; + redeem_requests.push((H256::from_slice(key), request)); } + Ok(redeem_requests) } async fn get_redeem_period(&self) -> Result { diff --git a/vault/src/cancellation.rs b/vault/src/cancellation.rs index 344685d6a..36449d094 100644 --- a/vault/src/cancellation.rs +++ b/vault/src/cancellation.rs @@ -358,7 +358,8 @@ mod tests { async fn execute_replace(&self, replace_id: H256, merkle_proof: &[u8], raw_tx: &[u8]) -> Result<(), RuntimeError>; async fn cancel_replace(&self, replace_id: H256) -> Result<(), RuntimeError>; async fn get_new_vault_replace_requests(&self, account_id: AccountId) -> Result, RuntimeError>; - async fn get_old_vault_replace_requests(&self, maybe_account_id: Option) -> Result, RuntimeError>; + async fn get_old_vault_replace_requests(&self, account_id: AccountId) -> Result, RuntimeError>; + async fn get_all_replace_requests(&self) -> Result, RuntimeError>; async fn get_replace_period(&self) -> Result; async fn get_replace_request(&self, replace_id: H256) -> Result; async fn get_replace_dust_amount(&self) -> Result; diff --git a/vault/src/execution.rs b/vault/src/execution.rs index af9b94a53..82aa4149b 100644 --- a/vault/src/execution.rs +++ b/vault/src/execution.rs @@ -471,16 +471,23 @@ pub async fn execute_open_requests( num_confirmations: u32, payment_margin: Duration, auto_rbf: bool, - no_execute_all: bool, + execute_all: bool, ) -> Result<(), ServiceError> { let parachain_rpc = ¶chain_rpc; let vault_id = parachain_rpc.get_account_id().clone(); // get all redeem and replace requests - let (redeem_requests, replace_requests) = try_join!( - parachain_rpc.get_redeem_requests(no_execute_all.then_some(vault_id.clone())), - parachain_rpc.get_old_vault_replace_requests(no_execute_all.then_some(vault_id.clone())), - )?; + let (redeem_requests, replace_requests) = if execute_all { + try_join!( + parachain_rpc.get_all_redeem_requests(), + parachain_rpc.get_all_replace_requests(), + )? + } else { + try_join!( + parachain_rpc.get_vault_redeem_requests(vault_id.clone()), + parachain_rpc.get_old_vault_replace_requests(vault_id.clone()), + )? + }; let open_redeems = redeem_requests .into_iter() @@ -723,7 +730,8 @@ mod tests { async fn execute_redeem(&self, redeem_id: H256, merkle_proof: &[u8], raw_tx: &[u8]) -> Result<(), RuntimeError>; async fn cancel_redeem(&self, redeem_id: H256, reimburse: bool) -> Result<(), RuntimeError>; async fn get_redeem_request(&self, redeem_id: H256) -> Result; - async fn get_redeem_requests(&self, maybe_account_id: Option) -> Result, RuntimeError>; + async fn get_vault_redeem_requests(&self, account_id: AccountId) -> Result, RuntimeError>; + async fn get_all_redeem_requests(&self) -> Result, RuntimeError>; async fn get_redeem_period(&self) -> Result; } @@ -735,7 +743,8 @@ mod tests { async fn execute_replace(&self, replace_id: H256, merkle_proof: &[u8], raw_tx: &[u8]) -> Result<(), RuntimeError>; async fn cancel_replace(&self, replace_id: H256) -> Result<(), RuntimeError>; async fn get_new_vault_replace_requests(&self, account_id: AccountId) -> Result, RuntimeError>; - async fn get_old_vault_replace_requests(&self, maybe_account_id: Option) -> Result, RuntimeError>; + async fn get_old_vault_replace_requests(&self, account_id: AccountId) -> Result, RuntimeError>; + async fn get_all_replace_requests(&self) -> Result, RuntimeError>; async fn get_replace_period(&self) -> Result; async fn get_replace_request(&self, replace_id: H256) -> Result; async fn get_replace_dust_amount(&self) -> Result; diff --git a/vault/src/metrics.rs b/vault/src/metrics.rs index 2dcc8f601..d10a22043 100644 --- a/vault/src/metrics.rs +++ b/vault/src/metrics.rs @@ -220,8 +220,8 @@ impl PerCurrencyMetrics { let vault_id = &vault.vault_id; // update fee surplus if let Ok((redeem_requests, replace_requests)) = try_join!( - parachain_rpc.get_redeem_requests(Some(vault_id.account_id.clone())), - parachain_rpc.get_old_vault_replace_requests(Some(vault_id.account_id.clone())) + parachain_rpc.get_vault_redeem_requests(vault_id.account_id.clone()), + parachain_rpc.get_old_vault_replace_requests(vault_id.account_id.clone()) ) { let redeems = redeem_requests .iter() @@ -608,7 +608,7 @@ pub async fn poll_metrics Result<(), RuntimeError>; async fn cancel_redeem(&self, redeem_id: H256, reimburse: bool) -> Result<(), RuntimeError>; async fn get_redeem_request(&self, redeem_id: H256) -> Result; - async fn get_redeem_requests(&self, maybe_account_id: Option) -> Result, RuntimeError>; + async fn get_vault_redeem_requests(&self, account_id: AccountId) -> Result, RuntimeError>; + async fn get_all_redeem_requests(&self) -> Result, RuntimeError>; async fn get_redeem_period(&self) -> Result; } @@ -759,7 +760,8 @@ mod tests { async fn execute_replace(&self, replace_id: H256, merkle_proof: &[u8], raw_tx: &[u8]) -> Result<(), RuntimeError>; async fn cancel_replace(&self, replace_id: H256) -> Result<(), RuntimeError>; async fn get_new_vault_replace_requests(&self, account_id: AccountId) -> Result, RuntimeError>; - async fn get_old_vault_replace_requests(&self, maybe_account_id: Option) -> Result, RuntimeError>; + async fn get_old_vault_replace_requests(&self, account_id: AccountId) -> Result, RuntimeError>; + async fn get_all_replace_requests(&self) -> Result, RuntimeError>; async fn get_replace_period(&self) -> Result; async fn get_replace_request(&self, replace_id: H256) -> Result; async fn get_replace_dust_amount(&self) -> Result; diff --git a/vault/src/replace.rs b/vault/src/replace.rs index 1abd958e1..73ba8b59d 100644 --- a/vault/src/replace.rs +++ b/vault/src/replace.rs @@ -331,7 +331,8 @@ mod tests { async fn execute_replace(&self, replace_id: H256, merkle_proof: &[u8], raw_tx: &[u8]) -> Result<(), RuntimeError>; async fn cancel_replace(&self, replace_id: H256) -> Result<(), RuntimeError>; async fn get_new_vault_replace_requests(&self, account_id: AccountId) -> Result, RuntimeError>; - async fn get_old_vault_replace_requests(&self, maybe_account_id: Option) -> Result, RuntimeError>; + async fn get_old_vault_replace_requests(&self, account_id: AccountId) -> Result, RuntimeError>; + async fn get_all_replace_requests(&self) -> Result, RuntimeError>; async fn get_replace_period(&self) -> Result; async fn get_replace_request(&self, replace_id: H256) -> Result; async fn get_replace_dust_amount(&self) -> Result; diff --git a/vault/src/system.rs b/vault/src/system.rs index 9ce845c10..a6580399a 100644 --- a/vault/src/system.rs +++ b/vault/src/system.rs @@ -69,10 +69,10 @@ pub struct VaultServiceConfig { #[clap(long)] pub no_issue_execution: bool, - /// Don't try to execute **all** redeem and replace requests, + /// Try to execute **all** redeem and replace requests, /// the Vault will still submit proofs for their own #[clap(long)] - pub no_execute_all: bool, + pub execute_all: bool, /// Don't run the RPC API. #[clap(long)] @@ -637,7 +637,7 @@ impl VaultService { num_confirmations, self.config.payment_margin_minutes, self.config.auto_rbf, - self.config.no_execute_all, + self.config.execute_all, ); let shutdown_clone = self.shutdown.clone(); diff --git a/vault/tests/vault_integration_tests.rs b/vault/tests/vault_integration_tests.rs index 20e50388f..f08b24ddb 100644 --- a/vault/tests/vault_integration_tests.rs +++ b/vault/tests/vault_integration_tests.rs @@ -840,6 +840,7 @@ async fn test_execute_open_requests_succeeds() { 0, Duration::from_secs(0), true, + false, ) .map(Result::unwrap), assert_redeem_event(TIMEOUT, user_provider.clone(), redeem_ids[0]),