Rename param and update comment (#1108)

* Rename param in `confirm_delivery`

* Fix typo

* Update comment

* Fix review issue
This commit is contained in:
bear
2021-09-06 14:05:10 +08:00
committed by Bastian Köcher
parent 88fa487631
commit e20163c4ea
3 changed files with 10 additions and 12 deletions
+1 -3
View File
@@ -136,9 +136,7 @@ impl<S: InboundLaneStorage> InboundLane<S> {
return ReceivalResult::TooManyUnconfirmedMessages; return ReceivalResult::TooManyUnconfirmedMessages;
} }
// dispatch message before updating anything in the storage. If dispatch would panic, // then, dispatch message
// (which should not happen in the runtime) then we simply won't consider message as
// delivered (no changes to the inbound lane storage have been made).
let dispatch_result = P::dispatch( let dispatch_result = P::dispatch(
relayer_at_this_chain, relayer_at_this_chain,
DispatchMessage { DispatchMessage {
+1 -1
View File
@@ -352,7 +352,7 @@ pub mod pallet {
// if someone tries to pay for already-delivered message, we're rejecting this intention // if someone tries to pay for already-delivered message, we're rejecting this intention
// (otherwise this additional fee will be locked forever in relayers fund) // (otherwise this additional fee will be locked forever in relayers fund)
// //
// if someone tries to pay for not-yet-sent message, we're rejeting this intention, or // if someone tries to pay for not-yet-sent message, we're rejecting this intention, or
// we're risking to have mess in the storage // we're risking to have mess in the storage
let lane = outbound_lane::<T, I>(lane_id); let lane = outbound_lane::<T, I>(lane_id);
ensure!( ensure!(
@@ -101,40 +101,40 @@ impl<S: OutboundLaneStorage> OutboundLane<S> {
pub fn confirm_delivery<RelayerId>( pub fn confirm_delivery<RelayerId>(
&mut self, &mut self,
max_allowed_messages: MessageNonce, max_allowed_messages: MessageNonce,
latest_received_nonce: MessageNonce, latest_delivered_nonce: MessageNonce,
relayers: &VecDeque<UnrewardedRelayer<RelayerId>>, relayers: &VecDeque<UnrewardedRelayer<RelayerId>>,
) -> ReceivalConfirmationResult { ) -> ReceivalConfirmationResult {
let mut data = self.storage.data(); let mut data = self.storage.data();
if latest_received_nonce <= data.latest_received_nonce { if latest_delivered_nonce <= data.latest_received_nonce {
return ReceivalConfirmationResult::NoNewConfirmations; return ReceivalConfirmationResult::NoNewConfirmations;
} }
if latest_received_nonce > data.latest_generated_nonce { if latest_delivered_nonce > data.latest_generated_nonce {
return ReceivalConfirmationResult::FailedToConfirmFutureMessages; return ReceivalConfirmationResult::FailedToConfirmFutureMessages;
} }
if latest_received_nonce - data.latest_received_nonce > max_allowed_messages { if latest_delivered_nonce - data.latest_received_nonce > max_allowed_messages {
// that the relayer has declared correct number of messages that the proof contains (it is // that the relayer has declared correct number of messages that the proof contains (it is
// checked outside of the function). But it may happen (but only if this/bridged chain storage is // checked outside of the function). But it may happen (but only if this/bridged chain storage is
// corrupted, though) that the actual number of confirmed messages if larger than declared. // corrupted, though) that the actual number of confirmed messages if larger than declared.
// This would mean that 'reward loop' will take more time than the weight formula accounts, // This would mean that 'reward loop' will take more time than the weight formula accounts,
// so we can't allow that. // so we can't allow that.
return ReceivalConfirmationResult::TryingToConfirmMoreMessagesThanExpected( return ReceivalConfirmationResult::TryingToConfirmMoreMessagesThanExpected(
latest_received_nonce - data.latest_received_nonce, latest_delivered_nonce - data.latest_received_nonce,
); );
} }
let dispatch_results = let dispatch_results =
match extract_dispatch_results(data.latest_received_nonce, latest_received_nonce, relayers) { match extract_dispatch_results(data.latest_received_nonce, latest_delivered_nonce, relayers) {
Ok(dispatch_results) => dispatch_results, Ok(dispatch_results) => dispatch_results,
Err(extract_error) => return extract_error, Err(extract_error) => return extract_error,
}; };
let prev_latest_received_nonce = data.latest_received_nonce; let prev_latest_received_nonce = data.latest_received_nonce;
data.latest_received_nonce = latest_received_nonce; data.latest_received_nonce = latest_delivered_nonce;
self.storage.set_data(data); self.storage.set_data(data);
ReceivalConfirmationResult::ConfirmedMessages(DeliveredMessages { ReceivalConfirmationResult::ConfirmedMessages(DeliveredMessages {
begin: prev_latest_received_nonce + 1, begin: prev_latest_received_nonce + 1,
end: latest_received_nonce, end: latest_delivered_nonce,
dispatch_results, dispatch_results,
}) })
} }