From 692e6c83670898cd0e959ce678039f1cd2786800 Mon Sep 17 00:00:00 2001 From: Konrad Stepniak Date: Fri, 19 Jul 2024 11:56:11 +0000 Subject: [PATCH] fix(pallet-market): emit event when slashing a deal --- pallets/market/src/lib.rs | 6 ++++++ pallets/market/src/test.rs | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/pallets/market/src/lib.rs b/pallets/market/src/lib.rs index 12f4f1f71..2a123d636 100644 --- a/pallets/market/src/lib.rs +++ b/pallets/market/src/lib.rs @@ -372,6 +372,10 @@ pub mod pallet { unsuccessful: BoundedVec<(DealId, DealSettlementError), MaxSettleDeals>, }, /// Deal was slashed. + /// It means that the `provider_collateral` was burned and the entire client's lockup returned. + /// + /// Currently it's emitted only when a deal was supposed to be activated on a given block, but was not. + /// [`Hooks::on_finalize`] checks deals and slashes them when necessary. DealSlashed(DealId), /// Deal has been terminated. @@ -1400,6 +1404,8 @@ pub mod pallet { log::error!(target: LOG_TARGET, "on_finalize: invariant violated, cannot slash the deal {}", deal_id); continue; }; + + Self::deposit_event(Event::::DealSlashed(deal_id)); } DealState::Active(_) => { log::info!( diff --git a/pallets/market/src/test.rs b/pallets/market/src/test.rs index b08ab7e7a..7b7d3e118 100644 --- a/pallets/market/src/test.rs +++ b/pallets/market/src/test.rs @@ -947,6 +947,16 @@ fn verifies_deals_on_block_finalization() { ); assert!(!DealsForBlock::::get(&bob_start_block).contains(&bob_deal_id)); + assert_eq!( + events(), + [ + RuntimeEvent::Balances(pallet_balances::Event::::Withdraw { + who: Market::account_id(), + amount: 15 + }), + RuntimeEvent::Market(Event::::DealSlashed(bob_deal_id)) + ] + ) }); }