diff --git a/cli/artifacts/metadata.scale b/cli/artifacts/metadata.scale index 39038327f..4e0ecf17c 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 3b96f2f2c..42e7afb8c 100644 --- a/cli/polka-storage/storagext/src/runtime/display/storage_provider.rs +++ b/cli/polka-storage/storagext/src/runtime/display/storage_provider.rs @@ -115,16 +115,22 @@ impl std::fmt::Display for Event { ) .collect::() )), - Event::PartitionFaulty { + Event::PartitionsFaulty { owner, - partition, - sectors, + faulty_partitions, } => f.write_fmt(format_args!( - "Faulty Partition: {{ owner: {}, partition: {}, sectors: [{}] }}", + "Faulty Partitions: {{ owner: {}, faulty_partitions: [{}] }}", owner, - partition, itertools::Itertools::intersperse( - sectors.0.iter().map(|recovery| format!("{}", recovery)), + faulty_partitions.iter().map(|(partition, sectors)| format!( + "{{ partition: {}, sectors: {} }}", + partition, + itertools::Itertools::intersperse( + sectors.iter().map(|sector| format!("{}", sector)), + ", ".to_string() + ) + .collect::() + )), ", ".to_string() ) .collect::() diff --git a/docs/src/architecture/pallets/storage-provider.md b/docs/src/architecture/pallets/storage-provider.md index 0ee5971ff..b8fe02a5f 100644 --- a/docs/src/architecture/pallets/storage-provider.md +++ b/docs/src/architecture/pallets/storage-provider.md @@ -343,10 +343,9 @@ The Storage Provider Pallet emits the following events: - `deadline` - The deadline to which the recovered sectors are assigned. - `partition` - Partition number within the deadline containing the recovered sectors. - `sectors` - Sectors in the partition being declared as recovered. -- `PartitionFaulty` - It was detected that a storage provider has not submitted their PoSt on time and has marked some sectors as faulty. +- `PartitionsFaulty` - It was detected that a storage provider has not submitted their PoSt on time and has marked some partitions and sectors as faulty. - `owner` - SS58 address of the storage provider. - - `partition` - Partition number for which the PoSt was missed. - - `sectors` - The sectors in the partition declared faulty by the system. + - `faulty_partitions` - A map with partition numbers and the sectors associated with the partition number that are faulty. - `SectorsTerminated` - A storage provider has terminated some sectors. - `owner` - SS58 address of the storage provider. - `terminations` - An array with information about the terminated sectors. This information includes: diff --git a/pallets/storage-provider/src/lib.rs b/pallets/storage-provider/src/lib.rs index 3ba72c802..26c2dc0f1 100644 --- a/pallets/storage-provider/src/lib.rs +++ b/pallets/storage-provider/src/lib.rs @@ -35,7 +35,11 @@ pub mod pallet { extern crate alloc; - use alloc::{vec, vec::Vec}; + use alloc::{ + collections::{BTreeMap, BTreeSet}, + vec, + vec::Vec, + }; use core::fmt::Debug; use cid::Cid; @@ -293,10 +297,10 @@ pub mod pallet { recoveries: BoundedVec>, }, /// Emitted when an SP doesn't submit Windowed PoSt in time and PoSt hook marks partitions as faulty - PartitionFaulty { + PartitionsFaulty { owner: T::AccountId, - partition: PartitionNumber, - sectors: BoundedBTreeSet>, + // No need to be bounded as we are creating the sets ourselves + faulty_partitions: BTreeMap>, }, /// Emitted when an SP terminates some sectors. SectorsTerminated { @@ -1231,9 +1235,9 @@ pub mod pallet { } log::info!(target: LOG_TARGET, "block: {:?}, checking storage provider {:?} deadline: {:?}", - current_block, - storage_provider, - current_deadline.idx, + current_block, + storage_provider, + current_deadline.idx, ); let Ok(deadline) = @@ -1244,7 +1248,10 @@ pub mod pallet { continue; }; - let mut faulty_partitions = 0; + let mut faulty_partitions_amount = 0; + // Create collection for fault partitions, 1 event per SP + let mut faulty_partitions: BTreeMap> = + BTreeMap::new(); for (partition_number, partition) in deadline.partitions.iter_mut() { if partition.sectors.len() == 0 { continue; @@ -1278,24 +1285,23 @@ pub mod pallet { current_block, storage_provider, partition_number, new_faults.len()); if new_faults.len() > 0 { - Self::deposit_event(Event::PartitionFaulty { - owner: storage_provider.clone(), - partition: *partition_number, - sectors: new_faults.try_into() - .expect("new_faults.len() <= MAX_SECTORS, cannot be more new faults than all of the sectors in partition"), - }); - faulty_partitions += 1; + faulty_partitions.insert(*partition_number, new_faults); + faulty_partitions_amount += 1; } } // TODO(@th7nder,[#106,#187],08/08/2024): figure out slashing amounts (for continued faults, new faults). - if faulty_partitions > 0 { + if faulty_partitions_amount > 0 { log::warn!(target: LOG_TARGET, "block: {:?}, sp: {:?}, deadline: {:?} - should have slashed {} partitions...", current_block, storage_provider, current_deadline.idx, - faulty_partitions, + faulty_partitions_amount, ); + Self::deposit_event(Event::PartitionsFaulty { + owner: storage_provider.clone(), + faulty_partitions, + }) } else { log::info!(target: LOG_TARGET, "block: {:?}, sp: {:?}, deadline: {:?} - all proofs submitted on time.", current_block, diff --git a/pallets/storage-provider/src/tests/post_hook.rs b/pallets/storage-provider/src/tests/post_hook.rs index 1950979d3..aab3f8432 100644 --- a/pallets/storage-provider/src/tests/post_hook.rs +++ b/pallets/storage-provider/src/tests/post_hook.rs @@ -1,5 +1,7 @@ extern crate alloc; +use alloc::collections::{BTreeMap, BTreeSet}; + use frame_support::{assert_ok, pallet_prelude::Get}; use primitives_proofs::{DealId, SectorNumber}; use sp_core::bounded_vec; @@ -68,16 +70,18 @@ fn marks_partitions_as_faulty() { let partition = &deadline.partitions[&0]; let expected_sectors = sector_set::(&[first_sector_number, second_sector_number]); - + let faulty_sectors = BTreeSet::from([ + SectorNumber::new(first_sector_number).unwrap(), + SectorNumber::new(second_sector_number).unwrap(), + ]); assert_eq!(partition.faults.len(), 2); assert_eq!(expected_sectors, partition.faults); assert_eq!( events(), [RuntimeEvent::StorageProvider( - Event::::PartitionFaulty { + Event::::PartitionsFaulty { owner: account(storage_provider), - partition: 0, - sectors: expected_sectors.clone() + faulty_partitions: BTreeMap::from([(0u32, faulty_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 2bcc73cc9..85737c987 100644 --- a/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs +++ b/pallets/storage-provider/src/tests/pre_commit_sector_hook.rs @@ -1,5 +1,8 @@ extern crate alloc; +use alloc::collections::{BTreeMap, BTreeSet}; + +use primitives_proofs::SectorNumber; use sp_core::bounded_vec; use super::new_test_ext; @@ -79,10 +82,12 @@ fn pre_commit_hook_slashed_deal() { assert_eq!( events(), [ - RuntimeEvent::StorageProvider(Event::::PartitionFaulty { + RuntimeEvent::StorageProvider(Event::::PartitionsFaulty { owner: account(storage_provider), - partition: 0, - sectors: sector_set(&[2]) + faulty_partitions: BTreeMap::from([( + 0, + BTreeSet::from([SectorNumber::new(2).unwrap()]) + )]), }), RuntimeEvent::StorageProvider(Event::::SectorSlashed { owner: account(storage_provider),