diff --git a/cli/artifacts/metadata.scale b/cli/artifacts/metadata.scale index 4e0ecf17..f2bd0875 100644 Binary files a/cli/artifacts/metadata.scale and b/cli/artifacts/metadata.scale differ diff --git a/cli/polka-storage/storagext/src/runtime/display/storage_provider.rs b/cli/polka-storage/storagext/src/runtime/display/storage_provider.rs index 42e7afb8..33a98a96 100644 --- a/cli/polka-storage/storagext/src/runtime/display/storage_provider.rs +++ b/cli/polka-storage/storagext/src/runtime/display/storage_provider.rs @@ -87,12 +87,17 @@ impl std::fmt::Display for Event { "Sectors Proven: {{ owner: {}, sectors: {:?} }}", owner, sectors, )), - Event::SectorSlashed { + Event::SectorsSlashed { owner, - sector_number, + sector_numbers, } => f.write_fmt(format_args!( "Sector Slashed: {{ owner: {}, sector_number: {} }}", - owner, sector_number, + owner, + itertools::Itertools::intersperse( + sector_numbers.iter().map(|sector| format!("{}", sector)), + ", ".to_string() + ) + .collect::(), )), Event::ValidPoStSubmitted { owner } => { f.write_fmt(format_args!("Valid PoSt Submitted: {{ owner: {} }}", owner,)) diff --git a/docs/src/architecture/pallets/storage-provider.md b/docs/src/architecture/pallets/storage-provider.md index b8fe02a5..60a43489 100644 --- a/docs/src/architecture/pallets/storage-provider.md +++ b/docs/src/architecture/pallets/storage-provider.md @@ -326,9 +326,9 @@ The Storage Provider Pallet emits the following events: - `sector_number` - The sector number that is proven. - `partition_number` - The partition number the proven sector is in. - `deadline_idx` - The deadline index assigned to the proven sector. -- `SectorSlashed` - A previously pre-committed sector, but not proven, has been slashed by the system because it has expired. +- `SectorsSlashed` - Previously pre-committed sectors, but not proven, have been slashed by the system because it has expired. - `owner` - SS58 address of the storage provider. - - `sector_number` - The sector number that has been slashed because of expiry. + - `sector_numbers` - The sector numbers that hav been slashed because of expiry. - `ValidPoStSubmitted` - A valid PoSt has been submitted by a storage provider. - `owner` - SS58 address of the storage provider. - `FaultsDeclared` - A storage provider has declared some sectors as faulty. diff --git a/pallets/storage-provider/src/lib.rs b/pallets/storage-provider/src/lib.rs index 26c2dc0f..21abb058 100644 --- a/pallets/storage-provider/src/lib.rs +++ b/pallets/storage-provider/src/lib.rs @@ -280,9 +280,10 @@ pub mod pallet { sectors: BoundedVec>, }, /// Emitted when a sector was pre-committed, but not proven, so it got slashed in the pre-commit hook. - SectorSlashed { + SectorsSlashed { owner: T::AccountId, - sector_number: SectorNumber, + // No need for a bounded collection as we produce the output ourselves. + sector_numbers: Vec, }, /// Emitted when an SP submits a valid PoSt ValidPoStSubmitted { owner: T::AccountId }, @@ -1104,18 +1105,16 @@ pub mod pallet { return; } + let mut removed_sectors = Vec::new(); log::info!(target: LOG_TARGET, "found {} expired pre committed sectors for {:?}", expired.len(), storage_provider); for sector_number in expired { // Expired sectors should be removed, because in other case they'd be processed twice in the next block. - let Ok(()) = state.remove_pre_committed_sector(sector_number) else { + if let Ok(()) = state.remove_pre_committed_sector(sector_number.clone()) { + removed_sectors.push(sector_number) + } else { log::error!(target: LOG_TARGET, "catastrophe, failed to remove sector {} for {:?}", sector_number, storage_provider); continue; }; - - Self::deposit_event(Event::::SectorSlashed { - sector_number, - owner: storage_provider.clone(), - }); } let Some(slashed_deposits) = state.pre_commit_deposits.checked_sub(&slash_amount) @@ -1132,6 +1131,10 @@ pub mod pallet { }; StorageProviders::::insert(&storage_provider, state); + Self::deposit_event(Event::::SectorsSlashed { + owner: storage_provider, + sector_numbers: removed_sectors, + }) } } diff --git a/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs b/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs index 85737c98..e625fc35 100644 --- a/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs +++ b/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs @@ -10,9 +10,9 @@ use crate::{ pallet::{Event, StorageProviders}, sector::ProveCommitSector, tests::{ - account, events, publish_deals, register_storage_provider, run_to_block, sector_set, - Balances, RuntimeEvent, RuntimeOrigin, SectorPreCommitInfoBuilder, StorageProvider, System, - Test, CHARLIE, + account, events, publish_deals, register_storage_provider, run_to_block, Balances, + RuntimeEvent, RuntimeOrigin, SectorPreCommitInfoBuilder, StorageProvider, System, Test, + CHARLIE, }, }; @@ -89,10 +89,6 @@ fn pre_commit_hook_slashed_deal() { BTreeSet::from([SectorNumber::new(2).unwrap()]) )]), }), - RuntimeEvent::StorageProvider(Event::::SectorSlashed { - owner: account(storage_provider), - sector_number: 1.into(), - }), // the slash -> withdraw is related to the usage of slash_and_burn // when slashing the SP for a failed pre_commit // this usage may need review for a proper economic balance @@ -110,6 +106,10 @@ fn pre_commit_hook_slashed_deal() { RuntimeEvent::Balances(pallet_balances::Event::::Rescinded { amount: deal_precommit_deposit }), + RuntimeEvent::StorageProvider(Event::::SectorsSlashed { + owner: account(storage_provider), + sector_numbers: vec![1.into()], + }), ] ); });