Skip to content

Commit

Permalink
docs: improve em
Browse files Browse the repository at this point in the history
  • Loading branch information
th7nder committed Nov 26, 2024
1 parent 42a5b00 commit 9de3841
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cli/polka-storage-provider/client/src/commands/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pallets/storage-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
9 changes: 8 additions & 1 deletion pallets/storage-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1063,6 +1065,11 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
/// 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<primitives_proofs::CurrentDeadline<BlockNumberFor<T>>> {
Expand Down
2 changes: 1 addition & 1 deletion pallets/storage-provider/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8, ConstU32<MAX_POST_PROOF_BYTES>>,
}

Expand Down
16 changes: 16 additions & 0 deletions primitives/proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,33 @@ where
encoded
}

/// Current deadline in a proving period of a Storage Provider.
#[derive(Encode, Decode, TypeInfo)]
pub struct CurrentDeadline<BlockNumber> {
/// 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<AccountId> 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<
<<Block as sp_runtime::traits::Block>::Header as sp_runtime::traits::Header>::Number
Expand Down
2 changes: 1 addition & 1 deletion storagext/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 9de3841

Please sign in to comment.