Skip to content

Commit

Permalink
lazy niklas
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 committed Feb 16, 2024
1 parent 3d7dda8 commit f56ddc3
Show file tree
Hide file tree
Showing 305 changed files with 1,529 additions and 1,498 deletions.
4 changes: 2 additions & 2 deletions bridges/bin/runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ mod tests {
impl BridgeRuntimeFilterCall<MockCall> for FirstFilterCall {
fn validate(call: &MockCall) -> TransactionValidity {
if call.data <= 1 {
return InvalidTransaction::Custom(1).into()
return InvalidTransaction::Custom(1).into();
}

Ok(ValidTransaction { priority: 1, ..Default::default() })
Expand All @@ -189,7 +189,7 @@ mod tests {
impl BridgeRuntimeFilterCall<MockCall> for SecondFilterCall {
fn validate(call: &MockCall) -> TransactionValidity {
if call.data <= 2 {
return InvalidTransaction::Custom(2).into()
return InvalidTransaction::Custom(2).into();
}

Ok(ValidTransaction { priority: 2, ..Default::default() })
Expand Down
6 changes: 3 additions & 3 deletions bridges/bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub mod source {
// transaction also contains signatures and signed extensions. Because of this, we reserve
// 1/3 of the the maximal extrinsic size for this data.
if payload.len() > maximal_message_size::<B>() as usize {
return Err(VerificationError::MessageTooLarge)
return Err(VerificationError::MessageTooLarge);
}

Ok(())
Expand Down Expand Up @@ -299,7 +299,7 @@ pub mod target {
// receiving proofs where end < begin is ok (if proof includes outbound lane state)
let messages_in_the_proof = nonces_range.checked_len().unwrap_or(0);
if messages_in_the_proof != MessageNonce::from(messages_count) {
return Err(VerificationError::MessagesCountMismatch)
return Err(VerificationError::MessagesCountMismatch);
}

// Read messages first. All messages that are claimed to be in the proof must
Expand All @@ -322,7 +322,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(VerificationError::EmptyMessageProof)
return Err(VerificationError::EmptyMessageProof);
}

// check that the storage proof doesn't have any untouched trie nodes
Expand Down
2 changes: 1 addition & 1 deletion bridges/bin/runtime-common/src/messages_benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn prepare_inbound_message(

// if we don't need a correct message, then we may just return some random blob
if !params.is_successful_dispatch_expected {
return vec![0u8; expected_size]
return vec![0u8; expected_size];
}

// else let's prepare successful message.
Expand Down
20 changes: 10 additions & 10 deletions bridges/bin/runtime-common/src/messages_call_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl ReceiveMessagesProofInfo {
fn is_obsolete(&self, is_dispatcher_active: bool) -> bool {
// if dispatcher is inactive, we don't accept any delivery transactions
if !is_dispatcher_active {
return true
return true;
}

// transactions with zero bundled nonces are not allowed, unless they're message
Expand All @@ -96,7 +96,7 @@ impl ReceiveMessagesProofInfo {
// or if we can't accept new messages at all
self.unrewarded_relayers.free_message_slots == 0;

return !empty_transactions_allowed
return !empty_transactions_allowed;
}

// otherwise we require bundled messages to continue stored range
Expand Down Expand Up @@ -160,7 +160,7 @@ impl<T: Config<I>, I: 'static> CallHelper<T, I> {
// so if relayer slots are released, then message slots are also
// released
return post_occupation.free_message_slots >
info.unrewarded_relayers.free_message_slots
info.unrewarded_relayers.free_message_slots;
}

inbound_lane_data.last_delivered_nonce() == *info.base.bundled_range.end()
Expand Down Expand Up @@ -245,7 +245,7 @@ impl<
best_stored_nonce: inbound_lane_data.last_delivered_nonce(),
},
unrewarded_relayers: unrewarded_relayers_occupation::<T, I>(&inbound_lane_data),
})
});
}

None
Expand All @@ -269,19 +269,19 @@ impl<
bundled_range: outbound_lane_data.latest_received_nonce + 1..=
relayers_state.last_delivered_nonce,
best_stored_nonce: outbound_lane_data.latest_received_nonce,
}))
}));
}

None
}

fn call_info(&self) -> Option<CallInfo> {
if let Some(info) = self.receive_messages_proof_info() {
return Some(CallInfo::ReceiveMessagesProof(info))
return Some(CallInfo::ReceiveMessagesProof(info));
}

if let Some(info) = self.receive_messages_delivery_proof_info() {
return Some(CallInfo::ReceiveMessagesDeliveryProof(info))
return Some(CallInfo::ReceiveMessagesDeliveryProof(info));
}

None
Expand All @@ -307,7 +307,7 @@ impl<
proof_info
);

return sp_runtime::transaction_validity::InvalidTransaction::Call.into()
return sp_runtime::transaction_validity::InvalidTransaction::Call.into();
},
Some(CallInfo::ReceiveMessagesProof(proof_info))
if proof_info.is_obsolete(T::MessageDispatch::is_active()) =>
Expand All @@ -318,7 +318,7 @@ impl<
proof_info
);

return sp_runtime::transaction_validity::InvalidTransaction::Stale.into()
return sp_runtime::transaction_validity::InvalidTransaction::Stale.into();
},
Some(CallInfo::ReceiveMessagesDeliveryProof(proof_info))
if proof_info.is_obsolete() =>
Expand All @@ -329,7 +329,7 @@ impl<
proof_info,
);

return sp_runtime::transaction_validity::InvalidTransaction::Stale.into()
return sp_runtime::transaction_validity::InvalidTransaction::Stale.into();
},
_ => {},
}
Expand Down
14 changes: 7 additions & 7 deletions bridges/bin/runtime-common/src/messages_xcm_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<
return MessageDispatchResult {
unspent_weight: Weight::zero(),
dispatch_level_result: XcmBlobMessageDispatchResult::InvalidPayload,
}
};
},
};
let dispatch_level_result = match BlobDispatcher::dispatch_blob(payload) {
Expand Down Expand Up @@ -210,18 +210,18 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
) {
// skip if we dont want to handle congestion
if !H::supports_congestion_detection() {
return
return;
}

// if we have already sent the congestion signal, we don't want to do anything
if Self::is_congested_signal_sent(sender_and_lane.lane) {
return
return;
}

// if the bridge queue is not congested, we don't want to do anything
let is_congested = enqueued_messages > OUTBOUND_LANE_CONGESTED_THRESHOLD;
if !is_congested {
return
return;
}

log::info!(
Expand Down Expand Up @@ -250,18 +250,18 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
) {
// skip if we dont want to handle congestion
if !H::supports_congestion_detection() {
return
return;
}

// if we have not sent the congestion signal before, we don't want to do anything
if !Self::is_congested_signal_sent(sender_and_lane.lane) {
return
return;
}

// if the bridge queue is still congested, we don't want to do anything
let is_congested = enqueued_messages > OUTBOUND_LANE_UNCONGESTED_THRESHOLD;
if is_congested {
return
return;
}

log::info!(
Expand Down
12 changes: 6 additions & 6 deletions bridges/bin/runtime-common/src/refund_relayer_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ where
relayer,
e,
);
return slash_relayer_if_delivery_result
return slash_relayer_if_delivery_result;
}

// check if relay chain state has been updated
Expand All @@ -361,7 +361,7 @@ where
<Self::Msgs as RefundableMessagesLaneId>::Id::get(),
relayer,
);
return slash_relayer_if_delivery_result
return slash_relayer_if_delivery_result;
}

// there's a conflict between how bridge GRANDPA pallet works and a `utility.batchAll`
Expand Down Expand Up @@ -393,7 +393,7 @@ where

// do additional check
if !Self::additional_call_result_check(&relayer, &call_info) {
return slash_relayer_if_delivery_result
return slash_relayer_if_delivery_result;
}

// regarding the tip - refund that happens here (at this side of the bridge) isn't the whole
Expand Down Expand Up @@ -449,7 +449,7 @@ where
>>::MaxUnconfirmedMessagesAtInboundLane::get(
);
if bundled_messages > max_unconfirmed_messages_in_confirmation_tx {
return None
return None;
}

Some(bundled_messages)
Expand Down Expand Up @@ -516,7 +516,7 @@ where

// we only boost priority if relayer has staked required balance
if !RelayersPallet::<T::Runtime>::is_registration_active(who) {
return Ok(Default::default())
return Ok(Default::default());
}

// compute priority boost
Expand Down Expand Up @@ -722,7 +722,7 @@ where
Msgs::Id::get(),
relayer,
);
return false
return false;
}
}

Expand Down
10 changes: 5 additions & 5 deletions bridges/modules/grandpa/src/call_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<T: Config<I>, I: 'static> SubmitFinalityProofHelper<T, I> {
best_finalized,
);

return Err(Error::<T, I>::OldHeader)
return Err(Error::<T, I>::OldHeader);
}

if let Some(current_set_id) = current_set_id {
Expand All @@ -104,7 +104,7 @@ impl<T: Config<I>, I: 'static> SubmitFinalityProofHelper<T, I> {
actual_set_id,
);

return Err(Error::<T, I>::InvalidAuthoritySetId)
return Err(Error::<T, I>::InvalidAuthoritySetId);
}
}

Expand Down Expand Up @@ -135,7 +135,7 @@ pub trait CallSubType<T: Config<I, RuntimeCall = Self>, I: 'static>:
finality_target,
justification,
None,
))
));
} else if let Some(crate::Call::<T, I>::submit_finality_proof_ex {
finality_target,
justification,
Expand All @@ -146,7 +146,7 @@ pub trait CallSubType<T: Config<I, RuntimeCall = Self>, I: 'static>:
finality_target,
justification,
Some(*current_set_id),
))
));
}

None
Expand All @@ -165,7 +165,7 @@ pub trait CallSubType<T: Config<I, RuntimeCall = Self>, I: 'static>:
};

if Pallet::<T, I>::ensure_not_halted().is_err() {
return InvalidTransaction::Call.into()
return InvalidTransaction::Call.into();
}

match SubmitFinalityProofHelper::<T, I>::check_obsolete(
Expand Down
4 changes: 2 additions & 2 deletions bridges/modules/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ pub mod pallet {
next_authorities,
);

return Ok(Some(next_authorities.into()))
return Ok(Some(next_authorities.into()));
};

Ok(None)
Expand Down Expand Up @@ -656,7 +656,7 @@ where
if let Event::<T, I>::UpdatedBestFinalizedHeader { grandpa_info, .. } =
event.event.try_into().ok()?
{
return Some(grandpa_info)
return Some(grandpa_info);
}
None
})
Expand Down
10 changes: 5 additions & 5 deletions bridges/modules/messages/src/inbound_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ impl<S: InboundLaneStorage> InboundLane<S> {

if outbound_lane_data.latest_received_nonce > last_delivered_nonce {
// this is something that should never happen if proofs are correct
return None
return None;
}
if outbound_lane_data.latest_received_nonce <= data.last_confirmed_nonce {
return None
return None;
}

let new_confirmed_nonce = outbound_lane_data.latest_received_nonce;
Expand Down Expand Up @@ -173,18 +173,18 @@ impl<S: InboundLaneStorage> InboundLane<S> {
) -> ReceivalResult<Dispatch::DispatchLevelResult> {
let mut data = self.storage.get_or_init_data();
if Some(nonce) != data.last_delivered_nonce().checked_add(1) {
return ReceivalResult::InvalidNonce
return ReceivalResult::InvalidNonce;
}

// if there are more unrewarded relayer entries than we may accept, reject this message
if data.relayers.len() as MessageNonce >= self.storage.max_unrewarded_relayer_entries() {
return ReceivalResult::TooManyUnrewardedRelayers
return ReceivalResult::TooManyUnrewardedRelayers;
}

// if there are more unconfirmed messages than we may accept, reject this message
let unconfirmed_messages_count = nonce.saturating_sub(data.last_confirmed_nonce);
if unconfirmed_messages_count > self.storage.max_unconfirmed_messages() {
return ReceivalResult::TooManyUnconfirmedMessages
return ReceivalResult::TooManyUnconfirmedMessages;
}

// then, dispatch message
Expand Down
4 changes: 2 additions & 2 deletions bridges/modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub mod pallet {
// we'll need at least to read outbound lane state, kill a message and update lane state
let db_weight = T::DbWeight::get();
if !remaining_weight.all_gte(db_weight.reads_writes(1, 2)) {
return Weight::zero()
return Weight::zero();
}

// messages from lane with index `i` in `ActiveOutboundLanes` are pruned when
Expand Down Expand Up @@ -762,7 +762,7 @@ fn ensure_normal_operating_mode<T: Config<I>, I: 'static>() -> Result<(), Error<
if PalletOperatingMode::<T, I>::get() ==
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
{
return Ok(())
return Ok(());
}

Err(Error::<T, I>::NotOperatingNormally)
Expand Down
Loading

0 comments on commit f56ddc3

Please sign in to comment.