From 7e0e166991121adabd444da4ae71406320099922 Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 8 Aug 2023 07:37:56 +0800 Subject: [PATCH] Format rust codes (#920) * Format rust codes * Explicit rust nightly version --- hooks/pre-commit | 6 +- .../pallets/ethereum-beacon-client/src/lib.rs | 5 +- .../ethereum-beacon-client/src/tests.rs | 65 +++++++++++++++---- parachain/pallets/outbound-queue/src/lib.rs | 2 +- parachain/primitives/beacon/src/receipt.rs | 22 +++---- parachain/primitives/core/src/outbound.rs | 13 ++-- parachain/primitives/ethereum/src/header.rs | 15 ++--- .../primitives/router/src/inbound/mod.rs | 20 +++--- .../primitives/router/src/outbound/mod.rs | 7 +- 9 files changed, 99 insertions(+), 56 deletions(-) diff --git a/hooks/pre-commit b/hooks/pre-commit index 64c17cda6170d..6720b3ed70a53 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -4,8 +4,8 @@ set -e # checks that the cumulus submodule is in sync with our substrate dependencies check_duplicate_versions() { - local duplicates=`grep -Ei "source = \"git.*$1" cumulus/Cargo.lock parachain/Cargo.lock | sed 's/\.git//g' | sort -u` - local version_count=`echo "$duplicates" | awk -F':' '{for (i=2; i, update: Box) -> DispatchResult { + pub fn force_checkpoint( + origin: OriginFor, + update: Box, + ) -> DispatchResult { ensure_root(origin)?; Self::process_checkpoint_update(&update)?; Ok(()) diff --git a/parachain/pallets/ethereum-beacon-client/src/tests.rs b/parachain/pallets/ethereum-beacon-client/src/tests.rs index 64d2a958f73b8..057941570e1b8 100644 --- a/parachain/pallets/ethereum-beacon-client/src/tests.rs +++ b/parachain/pallets/ethereum-beacon-client/src/tests.rs @@ -422,7 +422,10 @@ fn submit_update_in_current_period() { new_tester().execute_with(|| { assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(update.clone()))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(update.clone()) + )); let block_root: H256 = update.finalized_header.hash_tree_root().unwrap(); assert!(>::contains_key(block_root)); }); @@ -459,7 +462,10 @@ fn submit_update_in_next_period() { RuntimeOrigin::signed(1), Box::new(sync_committee_update.clone()) )); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(update.clone()))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(update.clone()) + )); let block_root: H256 = update.finalized_header.clone().hash_tree_root().unwrap(); assert!(>::contains_key(block_root)); }); @@ -558,9 +564,15 @@ fn submit_update_with_sync_committee_in_next_period() { new_tester().execute_with(|| { assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); assert!(!>::exists()); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(update.clone()))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(update.clone()) + )); assert!(>::exists()); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(next_update.clone()))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(next_update.clone()) + )); let last_finalized_state = FinalizedBeaconState::::get(LatestFinalizedBlockRoot::::get()).unwrap(); let last_synced_period = compute_period(last_finalized_state.slot); @@ -614,7 +626,10 @@ fn submit_update_execution_headers_too_far_behind() { let far_ahead_finalized_header_slot = finalized_header_update.finalized_header.slot + (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH * 2) as u64; assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(finalized_header_update))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(finalized_header_update) + )); assert_ok!(EthereumBeaconClient::submit_execution_header( RuntimeOrigin::signed(1), Box::new(execution_header_update) @@ -706,7 +721,10 @@ fn submit_execution_header_update() { new_tester().execute_with(|| { assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(finalized_header_update))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(finalized_header_update) + )); assert_ok!(EthereumBeaconClient::submit_execution_header( RuntimeOrigin::signed(1), Box::new(execution_header_update.clone()) @@ -728,7 +746,10 @@ fn submit_execution_header_update_invalid_ancestry_proof() { new_tester().execute_with(|| { assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(finalized_header_update))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(finalized_header_update) + )); assert_err!( EthereumBeaconClient::submit_execution_header( RuntimeOrigin::signed(1), @@ -748,7 +769,10 @@ fn submit_execution_header_update_invalid_execution_header_proof() { new_tester().execute_with(|| { assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(finalized_header_update))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(finalized_header_update) + )); assert_err!( EthereumBeaconClient::submit_execution_header( RuntimeOrigin::signed(1), @@ -770,7 +794,10 @@ fn submit_execution_header_update_that_skips_block() { new_tester().execute_with(|| { assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(finalized_header_update))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(finalized_header_update) + )); assert_ok!(EthereumBeaconClient::submit_execution_header( RuntimeOrigin::signed(1), Box::new(execution_header_update.clone()) @@ -797,7 +824,10 @@ fn submit_execution_header_update_that_is_also_finalized_header_which_is_not_sto new_tester().execute_with(|| { assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(finalized_header_update))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(finalized_header_update) + )); assert_err!( EthereumBeaconClient::submit_execution_header( RuntimeOrigin::signed(1), @@ -818,7 +848,10 @@ fn submit_execution_header_update_that_is_also_finalized_header_which_is_stored_ new_tester().execute_with(|| { assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(finalized_header_update))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(finalized_header_update) + )); let block_root: H256 = execution_header_update.header.hash_tree_root().unwrap(); @@ -849,7 +882,10 @@ fn submit_execution_header_not_finalized() { new_tester().execute_with(|| { assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint)); - assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(finalized_header_update))); + assert_ok!(EthereumBeaconClient::submit( + RuntimeOrigin::signed(1), + Box::new(finalized_header_update) + )); >::mutate(>::get(), |x| { let prev = x.unwrap(); @@ -857,7 +893,10 @@ fn submit_execution_header_not_finalized() { }); assert_err!( - EthereumBeaconClient::submit_execution_header(RuntimeOrigin::signed(1), Box::new(update)), + EthereumBeaconClient::submit_execution_header( + RuntimeOrigin::signed(1), + Box::new(update) + ), Error::::HeaderNotFinalized ); }); diff --git a/parachain/pallets/outbound-queue/src/lib.rs b/parachain/pallets/outbound-queue/src/lib.rs index cafef3a705643..3fa48cbf3d098 100644 --- a/parachain/pallets/outbound-queue/src/lib.rs +++ b/parachain/pallets/outbound-queue/src/lib.rs @@ -79,7 +79,7 @@ pub struct PreparedMessage { } /// Convert message into an ABI-encoded form for delivery to the InboundQueue contract on Ethereum -impl From for Token { +impl From for Token { fn from(x: PreparedMessage) -> Token { Token::Tuple(vec![ Token::Uint(u32::from(x.origin).into()), diff --git a/parachain/primitives/beacon/src/receipt.rs b/parachain/primitives/beacon/src/receipt.rs index 728b00e7d1fc5..0588f3f73f715 100644 --- a/parachain/primitives/beacon/src/receipt.rs +++ b/parachain/primitives/beacon/src/receipt.rs @@ -25,14 +25,13 @@ fn apply_merkle_proof(proof: &[Vec]) -> Option<(H256, Vec)> { }; let item_to_prove: mpt::ShortNode = rlp::decode(first_bytes).ok()?; - let final_hash: Option<[u8; 32]> = - iter.try_fold(keccak_256(first_bytes), |acc, x| { - let node: Box = x.as_slice().try_into().ok()?; - if (*node).contains_hash(acc.into()) { - return Some(keccak_256(x)) - } - None - }); + let final_hash: Option<[u8; 32]> = iter.try_fold(keccak_256(first_bytes), |acc, x| { + let node: Box = x.as_slice().try_into().ok()?; + if (*node).contains_hash(acc.into()) { + return Some(keccak_256(x)) + } + None + }); final_hash.map(|hash| (hash.into(), item_to_prove.value)) } @@ -44,7 +43,8 @@ mod tests { #[test] fn test_verify_receipt_proof() { - let root: H256 = hex!("fd5e397a84884641f53c496804f24b5276cbb8c5c9cfc2342246be8e3ce5ad02").into(); + let root: H256 = + hex!("fd5e397a84884641f53c496804f24b5276cbb8c5c9cfc2342246be8e3ce5ad02").into(); // Valid proof let proof_receipt5 = vec!( @@ -80,7 +80,8 @@ mod tests { #[test] fn test_verify_receipt_proof_with_intermediate_short_node() { - let root: H256 = hex!("d128e3a57142d2bf15bc0cbcac7ad54f40750d571b5c3097e425882c10c9ba66").into(); + let root: H256 = + hex!("d128e3a57142d2bf15bc0cbcac7ad54f40750d571b5c3097e425882c10c9ba66").into(); let proof_receipt263 = vec![ hex!("f90131a00d3cb8d3f57ac1c0e12918a2ebe0cafed8c273577b9dd73e7ed1079b403ef494a0678b9835b834f8a287c0dd33a8fca9146e456ca688555ed4ec1361a2180b778da0fe42da181a46677a043b3d9d4b8bb05a6a17b7b5c010c17e7c1d31cfb7c4f911a0c89f0e2c53241cdb578e1f2b4caf6ba36e00500bdc57fecd66b84a6a58394c19a086c3c1fae5a0575940b5d38e111c469d07883106c26856f3ef608469a2081f13a06c5992ff00aab6226a70a032fd2f571ba22f797321f45e2daa73020d638d21b0a050861e9503ef68728f6c90a44f7fe1bceb2a9bdab6957bbe7136166bd849561ea006aa6eaca8a07e57176e9aa41e6a09edfb7678d1a112404e0ec779d7e567e82ea0bb0b430d303ba21b0af11c487b8a218bd75db54c98940b3f11bad8ff47cad3ef8080808080808080").to_vec(), @@ -92,5 +93,4 @@ mod tests { ]; assert!(verify_receipt_proof(root, &proof_receipt263).is_some()); } - } diff --git a/parachain/primitives/core/src/outbound.rs b/parachain/primitives/core/src/outbound.rs index f2bae1a3ded7a..98e6665810109 100644 --- a/parachain/primitives/core/src/outbound.rs +++ b/parachain/primitives/core/src/outbound.rs @@ -217,11 +217,14 @@ impl AgentExecuteCommand { /// ABI-encode the sub-command pub fn abi_encode(&self) -> Vec { match self { - AgentExecuteCommand::TransferToken { token, recipient, amount } => - ethabi::encode(&[Token::Uint(self.index().into()), - Token::Bytes(ethabi::encode(&[Token::Address(*token), - Token::Address(*recipient), - Token::Uint(U256::from(*amount))]))]), + AgentExecuteCommand::TransferToken { token, recipient, amount } => ethabi::encode(&[ + Token::Uint(self.index().into()), + Token::Bytes(ethabi::encode(&[ + Token::Address(*token), + Token::Address(*recipient), + Token::Uint(U256::from(*amount)), + ])), + ]), } } } diff --git a/parachain/primitives/ethereum/src/header.rs b/parachain/primitives/ethereum/src/header.rs index 4b388e8fef9b8..2dad41ac247b4 100644 --- a/parachain/primitives/ethereum/src/header.rs +++ b/parachain/primitives/ethereum/src/header.rs @@ -102,14 +102,13 @@ impl Header { }; let item_to_prove: mpt::ShortNode = rlp::decode(first_bytes).ok()?; - let final_hash: Option<[u8; 32]> = - iter.try_fold(keccak_256(first_bytes), |acc, x| { - let node: Box = x.as_slice().try_into().ok()?; - if (*node).contains_hash(acc.into()) { - return Some(keccak_256(x)) - } - None - }); + let final_hash: Option<[u8; 32]> = iter.try_fold(keccak_256(first_bytes), |acc, x| { + let node: Box = x.as_slice().try_into().ok()?; + if (*node).contains_hash(acc.into()) { + return Some(keccak_256(x)) + } + None + }); final_hash.map(|hash| (hash.into(), item_to_prove.value)) } diff --git a/parachain/primitives/router/src/inbound/mod.rs b/parachain/primitives/router/src/inbound/mod.rs index 4c6f48346abdf..650944eaeb02a 100644 --- a/parachain/primitives/router/src/inbound/mod.rs +++ b/parachain/primitives/router/src/inbound/mod.rs @@ -14,8 +14,8 @@ use xcm_executor::traits::ConvertLocation; const MINIMUM_DEPOSIT: u128 = 1; /// Messages from Ethereum are versioned. This is because in future, -/// we may want to evolve the protocol so that the ethereum side sends XCM messages directly. Instead -/// having BridgeHub transcode the messages into XCM. +/// we may want to evolve the protocol so that the ethereum side sends XCM messages directly. +/// Instead having BridgeHub transcode the messages into XCM. #[derive(Clone, Encode, Decode, RuntimeDebug)] pub enum VersionedMessage { V1(MessageV1), @@ -40,7 +40,7 @@ pub enum Command { /// The address of the ERC20 token to be bridged over to AssetHub token: H160, /// The stable ID of the `ForeignAssets::create` extrinsic - create_call_index: [u8; 2] + create_call_index: [u8; 2], }, /// Send a token to AssetHub or another parachain SendToken { @@ -51,7 +51,7 @@ pub enum Command { /// The destination for the transfer destination: Destination, /// Amount to transfer - amount: u128 + amount: u128, }, } @@ -60,13 +60,13 @@ pub enum Command { pub enum Destination { /// The funds will be deposited into account `id` on AssetHub AccountId32 { id: [u8; 32] }, - /// The funds will deposited into the sovereign account of destination parachain `para_id` on AssetHub, - /// Account `id` on the destination parachain will receive the funds via a reserve-backed transfer. - /// See https://github.com/paritytech/xcm-format#depositreserveasset + /// The funds will deposited into the sovereign account of destination parachain `para_id` on + /// AssetHub, Account `id` on the destination parachain will receive the funds via a + /// reserve-backed transfer. See https://github.com/paritytech/xcm-format#depositreserveasset ForeignAccountId32 { para_id: u32, id: [u8; 32] }, - /// The funds will deposited into the sovereign account of destination parachain `para_id` on AssetHub, - /// Account `id` on the destination parachain will receive the funds via a reserve-backed transfer. - /// See https://github.com/paritytech/xcm-format#depositreserveasset + /// The funds will deposited into the sovereign account of destination parachain `para_id` on + /// AssetHub, Account `id` on the destination parachain will receive the funds via a + /// reserve-backed transfer. See https://github.com/paritytech/xcm-format#depositreserveasset ForeignAccountId20 { para_id: u32, id: [u8; 20] }, } diff --git a/parachain/primitives/router/src/outbound/mod.rs b/parachain/primitives/router/src/outbound/mod.rs index 6b37bda97e17c..df771a4385d9b 100644 --- a/parachain/primitives/router/src/outbound/mod.rs +++ b/parachain/primitives/router/src/outbound/mod.rs @@ -135,7 +135,8 @@ where log::info!(target: "xcm::ethereum_blob_exporter", "message validated: location = {local_sub_location:?}, agent_id = '{agent_id:?}'"); - // TODO (SNO-581): Make sure we charge fees for message delivery. Currently this is set to zero. + // TODO (SNO-581): Make sure we charge fees for message delivery. Currently this is set to + // zero. Ok((ticket.encode(), MultiAssets::default())) } @@ -227,9 +228,7 @@ impl<'a, Call> XcmConverter<'a, Call> { Ok(execution_fee) } - fn native_tokens_unlock_message( - &mut self, - ) -> Result { + fn native_tokens_unlock_message(&mut self) -> Result { use XcmConverterError::*; let (assets, beneficiary) = if let WithdrawAsset(reserved_assets) = self.next()? { if reserved_assets.len() == 0 {