From 9de38414067722908db5d1e77252c15c4756166f Mon Sep 17 00:00:00 2001 From: Konrad Stepniak Date: Tue, 26 Nov 2024 10:41:42 +0100 Subject: [PATCH] docs: improve em --- .../client/src/commands/proofs.rs | 5 ++++- pallets/storage-provider/Cargo.toml | 2 +- pallets/storage-provider/src/lib.rs | 9 ++++++++- pallets/storage-provider/src/proofs.rs | 2 +- primitives/proofs/src/lib.rs | 16 ++++++++++++++++ storagext/lib/Cargo.toml | 2 +- 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/cli/polka-storage-provider/client/src/commands/proofs.rs b/cli/polka-storage-provider/client/src/commands/proofs.rs index 71afef2c1..61e4de364 100644 --- a/cli/polka-storage-provider/client/src/commands/proofs.rs +++ b/cli/polka-storage-provider/client/src/commands/proofs.rs @@ -441,8 +441,11 @@ impl ProofsCommand { let comm_r = cid::Cid::from_str(&comm_r).map_err(|_| UtilsCommandError::CommRError)?; + let sector_number = SectorNumber::try_from(sector_number) + .map_err(|_| UtilsCommandError::InvalidSectorId)?; + let replicas = vec![ReplicaInfo { - sector_id: sector_number.try_into().unwrap(), + sector_id: sector_number, comm_r: comm_r .hash() .digest() diff --git a/pallets/storage-provider/Cargo.toml b/pallets/storage-provider/Cargo.toml index 86393e528..e55088d8a 100644 --- a/pallets/storage-provider/Cargo.toml +++ b/pallets/storage-provider/Cargo.toml @@ -57,10 +57,10 @@ std = [ "frame-support/std", "frame-system/std", "pallet-balances/std", + "primitives-proofs/std", "scale-info/std", "sp-core/std", "sp-io/std", "sp-runtime/std", - "primitives-proofs/std", ] try-runtime = ["frame-support/try-runtime", "frame-system/try-runtime", "sp-runtime/try-runtime"] diff --git a/pallets/storage-provider/src/lib.rs b/pallets/storage-provider/src/lib.rs index c7a662c62..b655bc3e4 100644 --- a/pallets/storage-provider/src/lib.rs +++ b/pallets/storage-provider/src/lib.rs @@ -316,8 +316,9 @@ pub mod pallet { /// extrinsic but is not registered as one. StorageProviderNotFound, /// Emitted when trying to access an invalid sector. - InvalidPartition, InvalidSector, + /// Emitted when trying to submit PoSt for an not-existing partition for a deadline. + InvalidPartition, /// Emitted when submitting an invalid proof type. InvalidProofType, /// Emitted when the proof is invalid @@ -359,6 +360,7 @@ pub mod pallet { CouldNotTerminateDeals, /// Tried to terminate sectors that are not mutable. CannotTerminateImmutableDeadline, + /// Emitted when trying to submit PoSt with partitions containing too many sectors (>2349). TooManyReplicas, /// Inner pallet errors GeneralPalletError(crate::error::GeneralPalletError), @@ -1063,6 +1065,11 @@ pub mod pallet { } impl Pallet { + /// Gets the current deadline of the storage provider. + /// + /// If there is no Storage Provider of given AccountId returns [`Option::None`]. + /// May exceptionally return [`Option::None`] when + /// conversion between BlockNumbers fails, but technically should not ever happen. pub fn current_deadline( storage_provider: &T::AccountId, ) -> core::option::Option>> { diff --git a/pallets/storage-provider/src/proofs.rs b/pallets/storage-provider/src/proofs.rs index e34eae98a..931a9091a 100644 --- a/pallets/storage-provider/src/proofs.rs +++ b/pallets/storage-provider/src/proofs.rs @@ -14,7 +14,7 @@ use crate::partition::{PartitionNumber, MAX_PARTITIONS_PER_DEADLINE}; pub struct PoStProof { /// The proof type, currently only one type is supported. pub post_proof: RegisteredPoStProof, - /// The proof submission, to be checked in the storage provider pallet. + /// The proof submission, to be checked by [`ProofVerification::verify_post`], usually [`pallet_proofs`]. pub proof_bytes: BoundedVec>, } diff --git a/primitives/proofs/src/lib.rs b/primitives/proofs/src/lib.rs index d7aad6d85..0ce080ed3 100644 --- a/primitives/proofs/src/lib.rs +++ b/primitives/proofs/src/lib.rs @@ -25,17 +25,33 @@ where encoded } +/// Current deadline in a proving period of a Storage Provider. #[derive(Encode, Decode, TypeInfo)] pub struct CurrentDeadline { + /// Index of a deadline. + /// + /// If there are 10 deadlines if the proving period, values will be [0, 9]. + /// After proving period rolls over, it'll start from 0 again. pub deadline_index: u64, + /// Whether the deadline is open. + /// Only is false when `current_block < sp.proving_period_start`. pub open: bool, + /// [`pallet_storage_provider::DeadlineInfo::challenge`]. + /// + /// Block at which the randomness should be fetched to generate/verify Post. pub challenge_block: BlockNumber, + /// Block at which the deadline opens. pub start: BlockNumber, } sp_api::decl_runtime_apis! { pub trait StorageProviderApi where AccountId: Codec { + /// Gets the current deadline of the storage provider. + /// + /// If there is no Storage Provider of given AccountId returns [`Option::None`]. + /// May exceptionally return [`Option::None`] when + /// conversion between BlockNumbers fails, but technically should not ever happen. fn current_deadline(storage_provider: AccountId) -> core::option::Option< CurrentDeadline< <::Header as sp_runtime::traits::Header>::Number diff --git a/storagext/lib/Cargo.toml b/storagext/lib/Cargo.toml index 150d13550..fde9cea82 100644 --- a/storagext/lib/Cargo.toml +++ b/storagext/lib/Cargo.toml @@ -20,7 +20,7 @@ frame-support = { workspace = true, features = ["std"] } futures.workspace = true hex = { workspace = true, features = ["serde"] } itertools = { workspace = true } -primitives-proofs = { workspace = true, features = ["std", "serde"] } +primitives-proofs = { workspace = true, features = ["serde", "std"] } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } sha2 = { workspace = true }