Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ imports_granularity = "Crate"
reorder_imports = true
# Consistency
newline_style = "Unix"
normalize_comments = true
normalize_doc_attributes = true
# Misc
chain_width = 80
spaces_around_ranges = false
binop_separator = "Back"
reorder_impl_items = false
match_arm_leading_pipes = "Preserve"
match_arm_leading_pipes = "Never"
match_arm_blocks = false
match_block_trailing_comma = true
trailing_comma = "Vertical"
trailing_semicolon = false
trailing_semicolon = true
use_field_init_shorthand = true
# Format comments
comment_width = 100
Expand Down
8 changes: 4 additions & 4 deletions bridges/bin/runtime-common/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ where
has_failed || !SubmitFinalityProofHelper::<T, I>::was_successful(bundled_block_number);

if !has_failed {
return
return;
}

// let's slash registered relayer
Expand Down Expand Up @@ -176,7 +176,7 @@ where
!SubmitParachainHeadsHelper::<T, ParachainsInstance>::was_successful(&update);

if !has_failed {
return
return;
}

// let's slash registered relayer
Expand Down Expand Up @@ -465,7 +465,7 @@ mod tests {
type ToPostDispatch = u64;
fn validate(_who: &u64, call: &MockCall) -> (u64, TransactionValidity) {
if call.data <= 1 {
return (1, InvalidTransaction::Custom(1).into())
return (1, InvalidTransaction::Custom(1).into());
}

(1, Ok(ValidTransaction { priority: 1, ..Default::default() }))
Expand Down Expand Up @@ -493,7 +493,7 @@ mod tests {
type ToPostDispatch = u64;
fn validate(_who: &u64, call: &MockCall) -> (u64, TransactionValidity) {
if call.data <= 2 {
return (2, InvalidTransaction::Custom(2).into())
return (2, InvalidTransaction::Custom(2).into());
}

(2, Ok(ValidTransaction { priority: 2, ..Default::default() }))
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 @@ -48,7 +48,7 @@ fn prepare_inbound_message<LaneId>(

// 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
2 changes: 1 addition & 1 deletion bridges/modules/beefy/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn verify_signatures<T: Config<I>, I: 'static>(
if authority.verify(sig, &msg) {
missing_signatures = missing_signatures.saturating_sub(1);
if missing_signatures == 0 {
break
break;
}
} else {
tracing::debug!(
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 @@ -154,7 +154,7 @@ impl<T: Config<I>, I: 'static> SubmitFinalityProofHelper<T, I> {
"Cannot finalize obsolete header"
);

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

Expand All @@ -168,7 +168,7 @@ impl<T: Config<I>, I: 'static> SubmitFinalityProofHelper<T, I> {
"Cannot finalize header signed by unknown authority set"
);

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

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

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

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

let result = SubmitFinalityProofHelper::<T, I>::check_obsolete_from_extension(&call_info);
Expand Down
2 changes: 0 additions & 2 deletions bridges/modules/messages/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ impl<T: Config<I>, I: 'static> ReceiveMessagesProofSetup<T, I> {
mod benchmarks {
use super::*;

//
// Benchmarks that are used directly by the runtime calls weight formulae.
//

Expand Down Expand Up @@ -501,7 +500,6 @@ mod benchmarks {
assert!(T::is_relayer_rewarded(&relayer2_id));
}

//
// Benchmarks that the runtime developers may use for proper pallet configuration.
//

Expand Down
16 changes: 8 additions & 8 deletions bridges/modules/messages/src/call_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,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 @@ -131,7 +131,7 @@ impl<
best_stored_nonce: inbound_lane_data.last_delivered_nonce(),
},
unrewarded_relayers: unrewarded_relayers_occupation::<T, I>(&inbound_lane_data),
})
});
}

None
Expand All @@ -157,19 +157,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<MessagesCallInfo<T::LaneId>> {
if let Some(info) = self.receive_messages_proof_info() {
return Some(MessagesCallInfo::ReceiveMessagesProof(info))
return Some(MessagesCallInfo::ReceiveMessagesProof(info));
}

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

None
Expand All @@ -195,7 +195,7 @@ impl<
"Rejecting messages transaction on halted pallet"
);

return sp_runtime::transaction_validity::InvalidTransaction::Call.into()
return sp_runtime::transaction_validity::InvalidTransaction::Call.into();
},
Some(MessagesCallInfo::ReceiveMessagesProof(proof_info))
if proof_info
Expand All @@ -207,7 +207,7 @@ impl<
"Rejecting obsolete messages delivery transaction"
);

return sp_runtime::transaction_validity::InvalidTransaction::Stale.into()
return sp_runtime::transaction_validity::InvalidTransaction::Stale.into();
},
Some(MessagesCallInfo::ReceiveMessagesDeliveryProof(proof_info))
if proof_info.is_obsolete() =>
Expand All @@ -218,7 +218,7 @@ impl<
"Rejecting obsolete messages confirmation transaction"
);

return sp_runtime::transaction_validity::InvalidTransaction::Stale.into()
return sp_runtime::transaction_validity::InvalidTransaction::Stale.into();
},
_ => {},
}
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 @@ -151,10 +151,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 @@ -191,18 +191,18 @@ impl<S: InboundLaneStorage> InboundLane<S> {
) -> ReceptionResult<Dispatch::DispatchLevelResult> {
let mut data = self.storage.data();
if Some(nonce) != data.last_delivered_nonce().checked_add(1) {
return ReceptionResult::InvalidNonce
return ReceptionResult::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 ReceptionResult::TooManyUnrewardedRelayers
return ReceptionResult::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 ReceptionResult::TooManyUnconfirmedMessages
return ReceptionResult::TooManyUnconfirmedMessages;
}

// then, dispatch message
Expand Down
12 changes: 6 additions & 6 deletions bridges/modules/messages/src/outbound_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ impl<S: OutboundLaneStorage> OutboundLane<S> {
end: latest_delivered_nonce,
};
if confirmed_messages.total_messages() == 0 {
return Ok(None)
return Ok(None);
}
if confirmed_messages.end > data.latest_generated_nonce {
return Err(ReceptionConfirmationError::FailedToConfirmFutureMessages)
return Err(ReceptionConfirmationError::FailedToConfirmFutureMessages);
}
if confirmed_messages.total_messages() > max_allowed_messages {
// that the relayer has declared correct number of messages that the proof contains (it
Expand All @@ -159,7 +159,7 @@ impl<S: OutboundLaneStorage> OutboundLane<S> {
max_allowed=%max_allowed_messages,
"Messages delivery proof contains too many messages to confirm"
);
return Err(ReceptionConfirmationError::TryingToConfirmMoreMessagesThanExpected)
return Err(ReceptionConfirmationError::TryingToConfirmMoreMessagesThanExpected);
}

ensure_unrewarded_relayers_are_correct(confirmed_messages.end, relayers)?;
Expand Down Expand Up @@ -203,18 +203,18 @@ fn ensure_unrewarded_relayers_are_correct<RelayerId>(
// unrewarded relayer entry must have at least 1 unconfirmed message
// (guaranteed by the `InboundLane::receive_message()`)
if entry.messages.end < entry.messages.begin {
return Err(ReceptionConfirmationError::EmptyUnrewardedRelayerEntry)
return Err(ReceptionConfirmationError::EmptyUnrewardedRelayerEntry);
}
// every entry must confirm range of messages that follows previous entry range
// (guaranteed by the `InboundLane::receive_message()`)
if expected_entry_begin != Some(entry.messages.begin) {
return Err(ReceptionConfirmationError::NonConsecutiveUnrewardedRelayerEntries)
return Err(ReceptionConfirmationError::NonConsecutiveUnrewardedRelayerEntries);
}
expected_entry_begin = entry.messages.end.checked_add(1);
// entry can't confirm messages larger than `inbound_lane_data.latest_received_nonce()`
// (guaranteed by the `InboundLane::receive_message()`)
if entry.messages.end > latest_received_nonce {
return Err(ReceptionConfirmationError::FailedToConfirmFutureMessages)
return Err(ReceptionConfirmationError::FailedToConfirmFutureMessages);
}
}

Expand Down
4 changes: 2 additions & 2 deletions bridges/modules/messages/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn verify_messages_proof<T: Config<I>, I: 'static>(
// receiving proofs where end < begin is ok (if proof includes outbound lane state)
let messages_in_the_proof = nonces_range.saturating_len();
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 @@ -92,7 +92,7 @@ pub fn verify_messages_proof<T: Config<I>, I: 'static>(

// 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 keys.
Expand Down
8 changes: 4 additions & 4 deletions bridges/modules/parachains/src/call_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<T: Config<I>, I: 'static> SubmitParachainHeadsHelper<T, I> {
stored_best_head.best_head_hash.at_relay_block_number,
update.at_relay_block.0
);
return Err(InvalidTransaction::Stale.into())
return Err(InvalidTransaction::Stale.into());
},
};

Expand All @@ -130,7 +130,7 @@ impl<T: Config<I>, I: 'static> SubmitParachainHeadsHelper<T, I> {
stored_best_head.best_head_hash.at_relay_block_number,
update.at_relay_block.0
);
return Err(InvalidTransaction::Stale.into())
return Err(InvalidTransaction::Stale.into());
}

improved_by
Expand All @@ -149,7 +149,7 @@ impl<T: Config<I>, I: 'static> SubmitParachainHeadsHelper<T, I> {
parachain proof is missing from the storage."
);

return Err(InvalidTransaction::Call.into())
return Err(InvalidTransaction::Call.into());
}

Ok(improved_by)
Expand Down Expand Up @@ -237,7 +237,7 @@ pub trait CallSubType<T: Config<I, RuntimeCall = Self>, I: 'static>:
};

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

SubmitParachainHeadsHelper::<T, I>::check_obsolete_from_extension(&update)
Expand Down
12 changes: 6 additions & 6 deletions bridges/modules/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ pub mod pallet {
},
);
Self::deposit_event(Event::MissingParachainHead { parachain });
continue
continue;
},
Err(e) => {
tracing::trace!(
Expand All @@ -482,7 +482,7 @@ pub mod pallet {
"The read of head of parachain has failed"
);
Self::deposit_event(Event::MissingParachainHead { parachain });
continue
continue;
},
};

Expand All @@ -502,7 +502,7 @@ pub mod pallet {
parachain_head_hash,
actual_parachain_head_hash,
});
continue
continue;
}

// convert from parachain head into stored parachain head data
Expand All @@ -517,7 +517,7 @@ pub mod pallet {
"The head of parachain has been provided, but it is not tracked by the pallet"
);
Self::deposit_event(Event::UntrackedParachainRejected { parachain });
continue
continue;
},
};

Expand Down Expand Up @@ -657,7 +657,7 @@ pub mod pallet {
parachain,
parachain_head_hash: new_head_hash,
});
return Err(())
return Err(());
}

// verify that the parachain head data size is <= `MaxParaHeadDataSize`
Expand All @@ -679,7 +679,7 @@ pub mod pallet {
parachain_head_size: e.value_size as _,
});

return Err(())
return Err(());
},
};

Expand Down
2 changes: 1 addition & 1 deletion bridges/modules/relayers/src/extension/grandpa_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ where
?relayer,
"Relayer has submitted invalid GRANDPA chain finality proof"
);
return false
return false;
}

// there's a conflict between how bridge GRANDPA pallet works and a `utility.batchAll`
Expand Down
Loading
Loading