Skip to content

Commit

Permalink
lp-gateway: Rename message_proof vars to message_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian committed Aug 16, 2024
1 parent 85f23a3 commit 4b6cc1d
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pallets/liquidity-pools-gateway/src/message_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,24 +293,24 @@ impl<T: Config> Pallet<T> {
}

/// Gets the message proof for a message.
pub(crate) fn get_message_proof(message: T::Message) -> MessageHash {
pub(crate) fn get_message_hash(message: T::Message) -> MessageHash {
match message.get_message_hash() {
None => message
.to_proof_message()
.get_message_hash()
.expect("message proof ensured by 'to_message_proof'"),
.expect("message hash ensured by 'to_proof_message'"),
Some(proof) => proof,
}
}

/// Upserts an inbound entry for a particular message, increasing the
/// relevant counts accordingly.
pub(crate) fn upsert_pending_entry(
message_proof: MessageHash,
message_hash: MessageHash,
router_id: &T::RouterId,
new_inbound_entry: InboundEntry<T>,
) -> DispatchResult {
PendingInboundEntries::<T>::try_mutate(message_proof, router_id, |storage_entry| {
PendingInboundEntries::<T>::try_mutate(message_hash, router_id, |storage_entry| {
match storage_entry {
None => {
*storage_entry = Some(new_inbound_entry);
Expand All @@ -328,7 +328,7 @@ impl<T: Config> Pallet<T> {
/// were received, and if so, decreases the counts accordingly and executes
/// the message.
pub(crate) fn execute_if_requirements_are_met(
message_proof: MessageHash,
message_hash: MessageHash,
router_ids: &[T::RouterId],
session_id: T::SessionId,
expected_proof_count: u32,
Expand All @@ -338,7 +338,7 @@ impl<T: Config> Pallet<T> {
let mut votes = 0;

for router_id in router_ids {
match PendingInboundEntries::<T>::get(message_proof, router_id) {
match PendingInboundEntries::<T>::get(message_hash, router_id) {
// We expected one InboundEntry for each router, if that's not the case,
// we can return.
None => return Ok(()),
Expand All @@ -359,7 +359,7 @@ impl<T: Config> Pallet<T> {
}

if let Some(msg) = message {
Self::execute_post_voting_dispatch(message_proof, router_ids, expected_proof_count)?;
Self::execute_post_voting_dispatch(message_hash, router_ids, expected_proof_count)?;

T::InboundMessageHandler::handle(domain_address, msg)?;
}
Expand All @@ -370,12 +370,12 @@ impl<T: Config> Pallet<T> {
/// Decreases the counts for inbound entries and removes them if the
/// counts reach 0.
pub(crate) fn execute_post_voting_dispatch(
message_proof: MessageHash,
message_hash: MessageHash,
router_ids: &[T::RouterId],
expected_proof_count: u32,
) -> DispatchResult {
for router_id in router_ids {
PendingInboundEntries::<T>::try_mutate(message_proof, router_id, |storage_entry| {
PendingInboundEntries::<T>::try_mutate(message_hash, router_id, |storage_entry| {
match storage_entry {
None => {
// This case cannot be reproduced in production since this function is
Expand Down Expand Up @@ -428,7 +428,7 @@ impl<T: Config> Pallet<T> {
return (Err(e.into()), weight.saturating_mul(count));
}

let message_proof = Self::get_message_proof(submessage.clone());
let message_hash = Self::get_message_hash(submessage.clone());

let inbound_entry: InboundEntry<T> = InboundEntry::create(
submessage,
Expand All @@ -441,12 +441,12 @@ impl<T: Config> Pallet<T> {
return (Err(e), weight.saturating_mul(count));
}

if let Err(e) = Self::upsert_pending_entry(message_proof, &router_id, inbound_entry) {
if let Err(e) = Self::upsert_pending_entry(message_hash, &router_id, inbound_entry) {
return (Err(e), weight.saturating_mul(count));
}

match Self::execute_if_requirements_are_met(
message_proof,
message_hash,
&router_ids,
session_id,
expected_proof_count,
Expand All @@ -468,15 +468,15 @@ impl<T: Config> Pallet<T> {
) -> DispatchResult {
let router_ids = Self::get_router_ids_for_domain(destination)?;

let message_proof = message.to_proof_message();
let proof_message = message.to_proof_message();
let mut message_opt = Some(message);

for router_id in router_ids {
// Ensure that we only send the actual message once, using one router.
// The remaining routers will send the message proof.
let router_msg = match message_opt.take() {
Some(m) => m,
None => message_proof.clone(),
None => proof_message.clone(),
};

// We are using the sender specified in the pallet config so that we can
Expand Down

0 comments on commit 4b6cc1d

Please sign in to comment.