Skip to content

Commit dae2c45

Browse files
authored
Merge pull request #3490 from autonomys/fix-xdm-weight-too-early
Only take XDM weight tags if we've actually taken an inbox response
2 parents de39008 + b47b9da commit dae2c45

File tree

1 file changed

+7
-4
lines changed
  • domains/pallets/messenger/src

1 file changed

+7
-4
lines changed

domains/pallets/messenger/src/fees.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,17 @@ impl<T: Config> Pallet<T> {
142142
let mut inbox_fees = BalanceOf::<T>::zero();
143143
let mut removed_weight_tags = vec![];
144144
while let Some(nonce) = current_nonce {
145-
// note weight tags for inbox response messages
146-
removed_weight_tags.push((dst_chain_id, (channel_id, nonce)));
147-
148-
// for every inbox response we take, distribute the reward to the operators.
149145
if InboxResponses::<T>::take((dst_chain_id, channel_id, nonce)).is_none() {
146+
// Make the loop efficient, by breaking as soon as there are no more responses.
147+
// If we didn't break here, we'd spend a lot of CPU hashing missing StorageMap
148+
// keys.
150149
break;
151150
}
152151

152+
// Note removed weight tags for inbox response messages.
153+
removed_weight_tags.push((dst_chain_id, (channel_id, nonce)));
154+
155+
// For every inbox response we take, distribute the reward to the operators.
153156
if let Some(inbox_fee) = InboxFee::<T>::take((dst_chain_id, (channel_id, nonce))) {
154157
inbox_fees = inbox_fees.saturating_add(inbox_fee);
155158
}

0 commit comments

Comments
 (0)