From e751b34d10627b3a9cba4e8eb353d38ae14bcde3 Mon Sep 17 00:00:00 2001 From: dandanlen <3168260+dandanlen@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:47:55 +0100 Subject: [PATCH] fix: dont ignore deposits (#4173) --- .../pallets/cf-ingress-egress/src/lib.rs | 16 ++++++++-- .../pallets/cf-ingress-egress/src/tests.rs | 31 ++++++++++--------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/state-chain/pallets/cf-ingress-egress/src/lib.rs b/state-chain/pallets/cf-ingress-egress/src/lib.rs index cd95228e28..f0b40eb4e4 100644 --- a/state-chain/pallets/cf-ingress-egress/src/lib.rs +++ b/state-chain/pallets/cf-ingress-egress/src/lib.rs @@ -29,6 +29,7 @@ use cf_traits::{ use frame_support::{ pallet_prelude::*, sp_runtime::{DispatchError, Saturating, TransactionOutcome}, + transactional, }; use frame_system::pallet_prelude::*; pub use pallet::*; @@ -465,12 +466,20 @@ pub mod pallet { deposit_witnesses { Self::process_single_deposit( - deposit_address, + deposit_address.clone(), asset, amount, - deposit_details, + deposit_details.clone(), block_height, - )?; + ) + .unwrap_or_else(|_| { + Self::deposit_event(Event::::DepositIgnored { + deposit_address, + asset, + amount, + deposit_details, + }); + }); } Ok(()) } @@ -680,6 +689,7 @@ impl, I: 'static> Pallet { } /// Completes a single deposit request. + #[transactional] fn process_single_deposit( deposit_address: TargetChainAccount, asset: TargetChainAsset, diff --git a/state-chain/pallets/cf-ingress-egress/src/tests.rs b/state-chain/pallets/cf-ingress-egress/src/tests.rs index 8a10e59eb0..c3c3557545 100644 --- a/state-chain/pallets/cf-ingress-egress/src/tests.rs +++ b/state-chain/pallets/cf-ingress-egress/src/tests.rs @@ -1,6 +1,6 @@ use crate::{ mock::*, Call as PalletCall, ChannelAction, ChannelIdCounter, CrossChainMessage, - DepositChannelLookup, DepositChannelPool, DepositWitness, DisabledEgressAssets, Error, + DepositChannelLookup, DepositChannelPool, DepositWitness, DisabledEgressAssets, Event as PalletEvent, FailedVaultTransfers, FetchOrTransfer, MinimumDeposit, Pallet, ScheduledEgressCcm, ScheduledEgressFetchOrTransfer, TargetChainAccount, VaultTransfer, }; @@ -20,7 +20,7 @@ use cf_traits::{ DepositApi, EgressApi, GetBlockHeight, }; use frame_support::{ - assert_noop, assert_ok, + assert_ok, traits::{Hooks, OriginTrait}, }; use sp_core::H160; @@ -606,19 +606,20 @@ fn multi_use_deposit_address_different_blocks() { .then_execute_at_next_block(|(_, deposit_address)| { // Closing the channel should invalidate the deposit address. IngressEgress::expire_channel(deposit_address); - assert_noop!( - IngressEgress::process_deposits( - RuntimeOrigin::root(), - vec![DepositWitness { - deposit_address, - asset: eth::Asset::Eth, - amount: 1, - deposit_details: Default::default() - }], - Default::default() - ), - Error::::InvalidDepositAddress - ); + assert_ok!(IngressEgress::process_deposits( + RuntimeOrigin::root(), + vec![DepositWitness { + deposit_address, + asset: eth::Asset::Eth, + amount: 1, + deposit_details: Default::default() + }], + Default::default() + ),); + assert!(matches!( + cf_test_utilities::last_event::(), + RuntimeEvent::IngressEgress(crate::Event::DepositIgnored { .. }), + )); }); }