-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract primitives for proofs
- Loading branch information
Showing
9 changed files
with
161 additions
and
94 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license-file.workspace = true | ||
name = "primitives-proofs" | ||
repository.workspace = true | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
cid = { workspace = true, default-features = false } | ||
codec = { workspace = true, default-features = false } | ||
scale-info = { workspace = true, default-features = false } | ||
|
||
sp-runtime = { workspace = true, default-features = false } | ||
sp-core = { workspace = true, default-features = false} | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"scale-info/std", | ||
"sp-runtime/std", | ||
"sp-core/std" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#![deny(unused_crate_dependencies)] | ||
|
||
mod traits; | ||
mod types; | ||
|
||
pub use traits::*; | ||
pub use types::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use cid::Cid; | ||
use codec::{Decode, Encode}; | ||
use scale_info::TypeInfo; | ||
use sp_core::ConstU32; | ||
use sp_runtime::{BoundedVec, DispatchError}; | ||
|
||
use crate::types::{DealId, RegisteredSealProof, SectorNumber}; | ||
|
||
/// Represents functions that are provided by the Market Provider Pallet | ||
pub trait Market<AccountId, BlockNumber> { | ||
/// Verifies a given set of storage deals is valid for sectors being PreCommitted. | ||
/// Computes UnsealedCID (CommD) for each sector or None for Committed Capacity sectors. | ||
fn verify_deals_for_activation( | ||
storage_provider: &AccountId, | ||
sector_deals: BoundedVec<SectorDeal<BlockNumber>, ConstU32<32>>, | ||
) -> Result<BoundedVec<Option<Cid>, ConstU32<32>>, DispatchError>; | ||
} | ||
|
||
/// Binds given Sector with the Deals that it should contain | ||
#[derive(Debug, Decode, Encode, TypeInfo, Eq, PartialEq, Clone)] | ||
pub struct SectorDeal<BlockNumber> { | ||
pub sector_number: SectorNumber, | ||
pub sector_expiry: BlockNumber, | ||
pub sector_type: RegisteredSealProof, | ||
pub deal_ids: BoundedVec<DealId, ConstU32<128>>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use codec::{Decode, Encode}; | ||
use scale_info::TypeInfo; | ||
|
||
pub type DealId = u64; | ||
|
||
pub type SectorNumber = u64; | ||
|
||
#[allow(non_camel_case_types)] | ||
#[derive(Debug, Decode, Encode, TypeInfo, Eq, PartialEq, Clone)] | ||
pub enum RegisteredSealProof { | ||
StackedDRG2KiBV1P1, | ||
} | ||
|
||
impl RegisteredSealProof { | ||
pub fn sector_size(&self) -> SectorSize { | ||
SectorSize::_2KiB | ||
} | ||
} | ||
|
||
/// SectorSize indicates one of a set of possible sizes in the network. | ||
#[derive(Encode, Decode, TypeInfo, Clone, Debug, PartialEq, Eq, Copy)] | ||
pub enum SectorSize { | ||
_2KiB, | ||
} | ||
|
||
impl SectorSize { | ||
/// Returns the size of a sector in bytes | ||
/// <https://github.com/filecoin-project/ref-fvm/blob/5659196fa94accdf1e7f10e00586a8166c44a60d/shared/src/sector/mod.rs#L40> | ||
pub fn bytes(&self) -> u64 { | ||
match self { | ||
SectorSize::_2KiB => 2 << 10, | ||
} | ||
} | ||
} |