Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Apply the same format rule (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest authored May 24, 2022
1 parent 525a24f commit 8ff2a37
Show file tree
Hide file tree
Showing 53 changed files with 523 additions and 542 deletions.
58 changes: 27 additions & 31 deletions bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ pub mod source {
impl<BridgedHeaderHash> Size for FromBridgedChainMessagesDeliveryProof<BridgedHeaderHash> {
fn size_hint(&self) -> u32 {
u32::try_from(
self.storage_proof
.iter()
.fold(0usize, |sum, node| sum.saturating_add(node.len())),
self.storage_proof.iter().fold(0usize, |sum, node| sum.saturating_add(node.len())),
)
.unwrap_or(u32::MAX)
}
Expand Down Expand Up @@ -310,7 +308,7 @@ pub mod source {
) -> Result<(), Self::Error> {
// reject message if lane is blocked
if !ThisChain::<B>::is_message_accepted(submitter, lane) {
return Err(MESSAGE_REJECTED_BY_OUTBOUND_LANE)
return Err(MESSAGE_REJECTED_BY_OUTBOUND_LANE);
}

// reject message if there are too many pending messages at this lane
Expand All @@ -319,7 +317,7 @@ pub mod source {
.latest_generated_nonce
.saturating_sub(lane_outbound_data.latest_received_nonce);
if pending_messages > max_pending_messages {
return Err(TOO_MANY_PENDING_MESSAGES)
return Err(TOO_MANY_PENDING_MESSAGES);
}

// Do the dispatch-specific check. We assume that the target chain uses
Expand Down Expand Up @@ -348,7 +346,7 @@ pub mod source {

// compare with actual fee paid
if *delivery_and_dispatch_fee < minimal_fee_in_this_tokens {
return Err(TOO_LOW_FEE)
return Err(TOO_LOW_FEE);
}

Ok(())
Expand All @@ -370,7 +368,7 @@ pub mod source {
) -> Result<(), &'static str> {
let weight_limits = BridgedChain::<B>::message_weight_limits(&payload.call);
if !weight_limits.contains(&payload.weight.into()) {
return Err("Incorrect message weight declared")
return Err("Incorrect message weight declared");
}

// The maximal size of extrinsic at Substrate-based chain depends on the
Expand All @@ -384,7 +382,7 @@ pub mod source {
// transaction also contains signatures and signed extensions. Because of this, we reserve
// 1/3 of the the maximal extrinsic weight for this data.
if payload.call.len() > maximal_message_size::<B>() as usize {
return Err("The message is too large to be sent over the lane")
return Err("The message is too large to be sent over the lane");
}

Ok(())
Expand Down Expand Up @@ -515,9 +513,7 @@ pub mod target {
impl<BridgedHeaderHash> Size for FromBridgedChainMessagesProof<BridgedHeaderHash> {
fn size_hint(&self) -> u32 {
u32::try_from(
self.storage_proof
.iter()
.fold(0usize, |sum, node| sum.saturating_add(node.len())),
self.storage_proof.iter().fold(0usize, |sum, node| sum.saturating_add(node.len())),
)
.unwrap_or(u32::MAX)
}
Expand Down Expand Up @@ -752,7 +748,7 @@ pub mod target {
// (this bounds maximal capacity of messages vec below)
let messages_in_the_proof = nonces_difference.saturating_add(1);
if messages_in_the_proof != MessageNonce::from(messages_count) {
return Err(MessageProofError::MessagesCountMismatch)
return Err(MessageProofError::MessagesCountMismatch);
}

messages_in_the_proof
Expand Down Expand Up @@ -791,7 +787,7 @@ pub mod target {

// Now we may actually check if the proof is empty or not.
if proved_lane_messages.lane_state.is_none() && proved_lane_messages.messages.is_empty() {
return Err(MessageProofError::Empty)
return Err(MessageProofError::Empty);
}

// We only support single lane messages in this schema
Expand Down Expand Up @@ -823,13 +819,13 @@ mod tests {
struct OnThisChainBridge;

impl MessageBridge for OnThisChainBridge {
const RELAYER_FEE_PERCENT: u32 = 10;
const THIS_CHAIN_ID: ChainId = *b"this";
type BridgedChain = BridgedChain;
type ThisChain = ThisChain;

const BRIDGED_CHAIN_ID: ChainId = *b"brdg";
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";

type ThisChain = ThisChain;
type BridgedChain = BridgedChain;
const RELAYER_FEE_PERCENT: u32 = 10;
const THIS_CHAIN_ID: ChainId = *b"this";

fn bridged_balance_to_this_balance(
bridged_balance: BridgedChainBalance,
Expand All @@ -848,13 +844,13 @@ mod tests {
struct OnBridgedChainBridge;

impl MessageBridge for OnBridgedChainBridge {
const RELAYER_FEE_PERCENT: u32 = 20;
const THIS_CHAIN_ID: ChainId = *b"brdg";
type BridgedChain = ThisChain;
type ThisChain = BridgedChain;

const BRIDGED_CHAIN_ID: ChainId = *b"this";
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";

type ThisChain = BridgedChain;
type BridgedChain = ThisChain;
const RELAYER_FEE_PERCENT: u32 = 20;
const THIS_CHAIN_ID: ChainId = *b"brdg";

fn bridged_balance_to_this_balance(
_this_balance: ThisChainBalance,
Expand Down Expand Up @@ -978,17 +974,17 @@ mod tests {
struct ThisChain;

impl ChainWithMessages for ThisChain {
type Hash = ();
type AccountId = ThisChainAccountId;
type Signer = ThisChainSigner;
type Balance = ThisChainBalance;
type Hash = ();
type Signature = ThisChainSignature;
type Signer = ThisChainSigner;
type Weight = frame_support::weights::Weight;
type Balance = ThisChainBalance;
}

impl ThisChainWithMessages for ThisChain {
type Origin = ThisChainOrigin;
type Call = ThisChainCall;
type Origin = ThisChainOrigin;

fn is_message_accepted(_send_origin: &Self::Origin, lane: &LaneId) -> bool {
lane == TEST_LANE_ID
Expand Down Expand Up @@ -1039,17 +1035,17 @@ mod tests {
struct BridgedChain;

impl ChainWithMessages for BridgedChain {
type Hash = ();
type AccountId = BridgedChainAccountId;
type Signer = BridgedChainSigner;
type Balance = BridgedChainBalance;
type Hash = ();
type Signature = BridgedChainSignature;
type Signer = BridgedChainSigner;
type Weight = frame_support::weights::Weight;
type Balance = BridgedChainBalance;
}

impl ThisChainWithMessages for BridgedChain {
type Origin = BridgedChainOrigin;
type Call = BridgedChainCall;
type Origin = BridgedChainOrigin;

fn is_message_accepted(_send_origin: &Self::Origin, _lane: &LaneId) -> bool {
unreachable!()
Expand Down
2 changes: 1 addition & 1 deletion bin/runtime-common/src/messages_benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ fn grow_trie<H: Hasher>(mut root: H::Out, mdb: &mut MemoryDB<H>, trie_size: Proo
.expect("record_all_keys should not fail in benchmarks");
let size: usize = proof_recorder.drain().into_iter().map(|n| n.data.len()).sum();
if size > minimal_trie_size as _ {
return root
return root;
}

let mut trie = TrieDBMutV1::<H>::from_existing(mdb, &mut root)
Expand Down
68 changes: 34 additions & 34 deletions modules/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
dispatch_result: false,
unspent_weight: 0,
dispatch_fee_paid_during_dispatch: false,
}
};
},
};

Expand All @@ -198,7 +198,7 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
expected_version,
message.spec_version,
));
return dispatch_result
return dispatch_result;
}

// now that we have spec version checked, let's decode the call
Expand All @@ -212,7 +212,7 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
id,
);
Self::deposit_event(Event::MessageCallDecodeFailed(source_chain, id));
return dispatch_result
return dispatch_result;
},
};

Expand Down Expand Up @@ -245,7 +245,7 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
target_signature,
);
Self::deposit_event(Event::MessageSignatureMismatch(source_chain, id));
return dispatch_result
return dispatch_result;
}

log::trace!(target: "runtime::bridge-dispatch", "Target Account: {:?}", &target_account);
Expand All @@ -270,7 +270,7 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
call,
);
Self::deposit_event(Event::MessageCallRejected(source_chain, id));
return dispatch_result
return dispatch_result;
}

// verify weight
Expand All @@ -293,14 +293,14 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
expected_weight,
message.weight,
));
return dispatch_result
return dispatch_result;
}

// pay dispatch fee right before dispatch
let pay_dispatch_fee_at_target_chain =
message.dispatch_fee_payment == DispatchFeePayment::AtTargetChain;
if pay_dispatch_fee_at_target_chain &&
pay_dispatch_fee(&origin_account, message.weight).is_err()
if pay_dispatch_fee_at_target_chain
&& pay_dispatch_fee(&origin_account, message.weight).is_err()
{
log::trace!(
target: "runtime::bridge-dispatch",
Expand All @@ -315,7 +315,7 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
origin_account,
message.weight,
));
return dispatch_result
return dispatch_result;
}
dispatch_result.dispatch_fee_paid_during_dispatch = pay_dispatch_fee_at_target_chain;

Expand Down Expand Up @@ -383,8 +383,8 @@ where
},
CallOrigin::SourceAccount(ref source_account_id) => {
ensure!(
sender_origin == &RawOrigin::Signed(source_account_id.clone()) ||
sender_origin == &RawOrigin::Root,
sender_origin == &RawOrigin::Signed(source_account_id.clone())
|| sender_origin == &RawOrigin::Root,
BadOrigin
);
Ok(Some(source_account_id.clone()))
Expand Down Expand Up @@ -496,42 +496,42 @@ mod tests {
}

impl frame_system::Config for TestRuntime {
type Origin = Origin;
type Index = u64;
type Call = Call;
type AccountData = ();
type AccountId = AccountId;
type BaseCallFilter = frame_support::traits::Everything;
type BlockHashCount = BlockHashCount;
type BlockLength = ();
type BlockNumber = u64;
type BlockWeights = ();
type Call = Call;
type DbWeight = ();
type Event = Event;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type Index = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type OnKilledAccount = ();
type BaseCallFilter = frame_support::traits::Everything;
type SystemWeightInfo = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type SS58Prefix = ();
type OnNewAccount = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Origin = Origin;
type PalletInfo = PalletInfo;
type SS58Prefix = ();
type SystemWeightInfo = ();
type Version = ();
}

impl Config for TestRuntime {
type Event = Event;
type AccountIdConverter = AccountIdConverter;
type BridgeMessageId = BridgeMessageId;
type SourceChainAccountId = AccountId;
type TargetChainAccountPublic = TestAccountPublic;
type TargetChainSignature = TestSignature;
type Call = Call;
type CallFilter = TestCallFilter;
type EncodedCall = EncodedCall;
type AccountIdConverter = AccountIdConverter;
type Event = Event;
type SourceChainAccountId = AccountId;
type TargetChainAccountPublic = TestAccountPublic;
type TargetChainSignature = TestSignature;
}

#[derive(Decode, Encode)]
Expand Down
4 changes: 2 additions & 2 deletions modules/fee-market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}

if count == 0 {
return None
return None;
}
Some((count, orders_locked_collateral))
}
Expand All @@ -456,7 +456,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
if let Some((_, orders_locked_collateral)) = Self::occupied(who) {
let free_collateral =
relayer_locked_collateral.saturating_sub(orders_locked_collateral);
return Self::collateral_to_order_capacity(free_collateral)
return Self::collateral_to_order_capacity(free_collateral);
}
Self::collateral_to_order_capacity(relayer_locked_collateral)
}
Expand Down
8 changes: 4 additions & 4 deletions modules/fee-market/src/s2s/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ where
// if we'll accept some message that has declared that the `fee` has been paid but
// it isn't actually paid, then it'll lead to problems with delivery confirmation
// payments (see `pay_relayer_rewards` && `confirmation_relayer` in particular)
return Err(NON_ZERO_MESSAGE_FEE_CANT_BE_PAID_BY_NONE)
return Err(NON_ZERO_MESSAGE_FEE_CANT_BE_PAID_BY_NONE);
},
None => {
// message lane verifier has accepted the message before, so this message
// is unpaid **by design**
// => let's just do nothing
return Ok(())
return Ok(());
},
};

Expand Down Expand Up @@ -255,7 +255,7 @@ pub(crate) fn do_slash<T: Config<I>, I: 'static>(
report,
);
log::trace!("Slash {:?} amount: {:?}", who, amount);
return amount
return amount;
},
Err(e) => {
crate::Pallet::<T, I>::update_relayer_after_slash(who, locked_collateral, report);
Expand All @@ -273,7 +273,7 @@ pub(crate) fn do_reward<T: Config<I>, I: 'static>(
reward: BalanceOf<T, I>,
) {
if reward.is_zero() {
return
return;
}

let pay_result = <T as Config<I>>::Currency::transfer(
Expand Down
Loading

0 comments on commit 8ff2a37

Please sign in to comment.