Skip to content

Commit

Permalink
chore: combine primitives (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
cernicc authored Nov 29, 2024
1 parent 93b49f3 commit b76eeac
Show file tree
Hide file tree
Showing 86 changed files with 653 additions and 650 deletions.
200 changes: 91 additions & 109 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ repository = "https://github.com/eigerco/polka-storage"

[workspace]
members = [
"cli/polka-storage-provider/client",
"cli/polka-storage-provider/common",
"cli/polka-storage-provider/server",
"lib/polka-storage-proofs",
"maat",
"mater/cli",
Expand All @@ -20,9 +17,11 @@ members = [
"pallets/proofs",
"pallets/randomness",
"pallets/storage-provider",
"primitives/commitment",
"primitives/proofs",
"primitives",
"runtime",
"storage-provider/client",
"storage-provider/common",
"storage-provider/server",
"storage/polka-index",
"storagext/cli",
"storagext/lib",
Expand Down Expand Up @@ -93,7 +92,7 @@ rand_chacha = { version = "0.3.1", default-features = false }
rand_xorshift = "0.3"
rocksdb = { version = "0.21" }
scale-info = { version = "2.11.1", default-features = false }
sealed = "0.6.0"
sealed = { version = "0.6.0", default-features = false }
serde = { version = "1.0.197", default-features = false }
serde-big-array = { version = "0.3.2" }
serde_derive = { version = "1.0.117" }
Expand Down Expand Up @@ -137,10 +136,9 @@ pallet-proofs = { path = "pallets/proofs", default-features = false }
pallet-randomness = { path = "pallets/randomness", default-features = false }
pallet-storage-provider = { path = "pallets/storage-provider", default-features = false }
polka-storage-proofs = { path = "lib/polka-storage-proofs", default-features = false }
polka-storage-provider-common = { path = "cli/polka-storage-provider/common" }
polka-storage-provider-common = { path = "storage-provider/common" }
polka-storage-runtime = { path = "runtime" }
primitives-commitment = { path = "primitives/commitment" }
primitives-proofs = { path = "primitives/proofs", default-features = false }
primitives = { path = "primitives", default-features = false }
storagext = { path = "storagext/lib" }

# FileCoin proofs
Expand Down Expand Up @@ -214,7 +212,6 @@ frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-s
frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409-2", default-features = false }

# FRAME Pallets
# TODO(#457,@cernicc,17/10/2024): Switch to BABE
pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409-2", default-features = false }
pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409-2", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2409-2", default-features = false }
Expand Down
6 changes: 2 additions & 4 deletions lib/polka-storage-proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ version = "0.1.0"
# Permanently used crates.
bls12_381 = { workspace = true }
pairing = { workspace = true }
primitives-commitment = { workspace = true }
primitives-proofs = { workspace = true }
primitives = { workspace = true }
rand_xorshift = { workspace = true }

# Crates are only imported on feature 'std'.
Expand Down Expand Up @@ -53,8 +52,7 @@ std = [
"dep:storage-proofs-porep",
"dep:storage-proofs-post",
"dep:thiserror",
"primitives-commitment/std",
"primitives-proofs/std",
"primitives/std",
"rand/std",
"scale-info?/std",
]
Expand Down
2 changes: 1 addition & 1 deletion lib/polka-storage-proofs/src/porep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod sealer;
use bellperson::groth16;
use blstrs::Bls12;
use filecoin_proofs::{DefaultPieceHasher, SectorShapeBase};
use primitives_proofs::RegisteredSealProof;
use primitives::proofs::RegisteredSealProof;
use rand::rngs::OsRng;
use storage_proofs_core::{compound_proof::CompoundProof, proof::ProofScheme};
use storage_proofs_porep::stacked::StackedDrg;
Expand Down
32 changes: 16 additions & 16 deletions lib/polka-storage-proofs/src/porep/sealer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ use filecoin_proofs::{
DefaultPieceHasher, PaddedBytesAmount, PoRepConfig, SealCommitPhase1Output,
SealPreCommitOutput, SealPreCommitPhase1Output, SectorShapeBase, UnpaddedBytesAmount,
};
use primitives_commitment::{
piece::{PaddedPieceSize, PieceInfo},
CommD, CommP, CommR, Commitment,
use primitives::{
commitment::{
piece::{PaddedPieceSize, PieceInfo},
CommD, CommP, CommR, Commitment,
},
proofs::RegisteredSealProof,
sector::SectorNumber,
};
use primitives_proofs::{RegisteredSealProof, SectorNumber};
use storage_proofs_core::{compound_proof, compound_proof::CompoundProof};
use storage_proofs_porep::stacked::{self, StackedCompound, StackedDrg};

Expand Down Expand Up @@ -445,16 +448,15 @@ mod test {
fn padding_for_sector(#[case] piece_sizes: Vec<usize>) {
let sealer = Sealer::new(RegisteredSealProof::StackedDRG2KiBV1P1);

let piece_infos: Vec<(Cursor<Vec<u8>>, primitives_commitment::piece::PieceInfo)> =
piece_sizes
.into_iter()
.map(|size| {
let (piece_bytes, piece_info) =
piece_with_random_data(PaddedBytesAmount(size as u64));
let piece_infos: Vec<(Cursor<Vec<u8>>, PieceInfo)> = piece_sizes
.into_iter()
.map(|size| {
let (piece_bytes, piece_info) =
piece_with_random_data(PaddedBytesAmount(size as u64));

(Cursor::new(piece_bytes), piece_info)
})
.collect();
(Cursor::new(piece_bytes), piece_info)
})
.collect();

// Create a file-like sector where non-occupied bytes are 0
let sector_size = sealer.porep_config.sector_size.0 as usize;
Expand All @@ -474,9 +476,7 @@ mod test {
}

/// Generates a piece of `size` and a PieceInfo for it
fn piece_with_random_data(
size: PaddedBytesAmount,
) -> (Vec<u8>, primitives_commitment::piece::PieceInfo) {
fn piece_with_random_data(size: PaddedBytesAmount) -> (Vec<u8>, PieceInfo) {
let rng = &mut XorShiftRng::from_seed(filecoin_proofs::TEST_SEED);

let piece_size: UnpaddedBytesAmount = size.into();
Expand Down
2 changes: 1 addition & 1 deletion lib/polka-storage-proofs/src/post/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use filecoin_proofs::{
as_safe_commitment, parameters::window_post_setup_params, PoStType, PrivateReplicaInfo,
SectorShapeBase,
};
use primitives_proofs::{RegisteredPoStProof, SectorNumber};
use primitives::{proofs::RegisteredPoStProof, sector::SectorNumber};
use rand::rngs::OsRng;
use storage_proofs_core::compound_proof::{self, CompoundProof};
use storage_proofs_post::fallback::{
Expand Down
5 changes: 2 additions & 3 deletions maat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ bs58.workspace = true
cid.workspace = true
futures.workspace = true
hex = { workspace = true }
primitives = { workspace = true, features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["std"] }
storagext = { workspace = true }
subxt = { workspace = true, features = ["substrate-compat"] }
thiserror.workspace = true
tokio = { workspace = true, features = ["full"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }

primitives-proofs = { workspace = true, features = ["serde"] }
storagext = { workspace = true }

zombienet-configuration.workspace = true
zombienet-sdk.workspace = true
zombienet-support.workspace = true
Expand Down
12 changes: 6 additions & 6 deletions maat/tests/real_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::BTreeSet;

use cid::Cid;
use maat::*;
use primitives_proofs::SectorSize;
use primitives::sector::SectorSize;
use storagext::{
clients::ProofsClientExt,
runtime::runtime_types::{
Expand Down Expand Up @@ -38,7 +38,7 @@ where
.register_storage_provider(
charlie,
peer_id.clone(),
primitives_proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1,
primitives::proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1,
true,
)
.await
Expand All @@ -57,11 +57,11 @@ where
assert_eq!(event.info.sector_size, SectorSize::_2KiB);
assert_eq!(
event.info.window_post_proof_type,
primitives_proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1
primitives::proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1
);
assert_eq!(
event.info.window_post_partition_sectors,
primitives_proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1
primitives::proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1
.window_post_partitions_sector()
);
}
Expand Down Expand Up @@ -227,7 +227,7 @@ where
Cid::try_from("bagboea4b5abcaqolcsygu5o756srf7l4pzzagml5r3wa3o6ahoo5vixummsev6rf").unwrap();

let sectors_pre_commit_info = vec![SectorPreCommitInfo {
seal_proof: primitives_proofs::RegisteredSealProof::StackedDRG2KiBV1P1,
seal_proof: primitives::proofs::RegisteredSealProof::StackedDRG2KiBV1P1,
sector_number: 1.into(),
sealed_cid,
deal_ids: vec![0],
Expand Down Expand Up @@ -330,7 +330,7 @@ where
proof:
storagext::runtime::runtime_types::pallet_storage_provider::proofs::PoStProof {
post_proof:
primitives_proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1,
primitives::proofs::RegisteredPoStProof::StackedDRGWindow2KiBV1P1,
proof_bytes: "beef".to_string().into_bounded_byte_vec(),
},
},
Expand Down
5 changes: 2 additions & 3 deletions pallets/market/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ codec = { workspace = true, default-features = false, features = ["derive"] }
hex = { workspace = true, default-features = false, features = ["alloc"] }
log = { workspace = true }
multihash-codetable = { workspace = true, features = ["blake2b"] }
primitives-commitment = { workspace = true }
primitives-proofs = { workspace = true, default-features = false }
primitives = { workspace = true }
scale-info = { workspace = true, default-features = false, features = ["derive"] }
thiserror = { workspace = true, default-features = false }

Expand Down Expand Up @@ -60,7 +59,7 @@ std = [
"frame-system/std",
"hex/std",
"pallet-balances/std",
"primitives-proofs/std",
"primitives/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
Expand Down
2 changes: 1 addition & 1 deletion pallets/market/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use codec::{Decode, Encode};
use primitives_commitment::{piece::PaddedPieceSizeError, CommitmentError};
use primitives::commitment::{piece::PaddedPieceSizeError, CommitmentError};
use scale_info::TypeInfo;

// Clone and PartialEq required because of the BoundedVec<(DealId, DealSettlementError)>
Expand Down
18 changes: 10 additions & 8 deletions pallets/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ pub mod pallet {
PalletId,
};
use frame_system::{pallet_prelude::*, Config as SystemConfig, Pallet as System};
use primitives_commitment::{
commd::compute_unsealed_sector_commitment,
piece::{PaddedPieceSize, PieceInfo},
CommP, Commitment, CommitmentError,
};
use primitives_proofs::{
ActiveDeal, ActiveSector, DealId, Market, RegisteredSealProof, SectorDeal, SectorNumber,
SectorSize, StorageProviderValidation, MAX_DEALS_PER_SECTOR, MAX_SECTORS_PER_CALL,
use primitives::{
commitment::{
commd::compute_unsealed_sector_commitment,
piece::{PaddedPieceSize, PieceInfo},
CommP, Commitment, CommitmentError,
},
pallets::{ActiveDeal, ActiveSector, Market, SectorDeal, StorageProviderValidation},
proofs::RegisteredSealProof,
sector::{SectorNumber, SectorSize},
DealId, MAX_DEALS_PER_SECTOR, MAX_SECTORS_PER_CALL,
};
use scale_info::TypeInfo;
use sp_arithmetic::traits::BaseArithmetic;
Expand Down
2 changes: 1 addition & 1 deletion pallets/market/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use frame_support::{
PalletId,
};
use frame_system::{self as system, pallet_prelude::BlockNumberFor};
use primitives_proofs::{Randomness, RegisteredPoStProof};
use primitives::{pallets::Randomness, proofs::RegisteredPoStProof};
use sp_core::Pair;
use sp_runtime::{
traits::{ConstU32, ConstU64, IdentifyAccount, IdentityLookup, Verify},
Expand Down
10 changes: 6 additions & 4 deletions pallets/market/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use frame_support::{
traits::Currency,
BoundedVec,
};
use primitives_commitment::{CommP, Commitment};
use primitives_proofs::{
ActiveDeal, ActiveSector, DealId, Market as MarketTrait, RegisteredSealProof, SectorDeal,
SectorNumber, MAX_DEALS_PER_SECTOR,
use primitives::{
commitment::{CommP, Commitment},
pallets::{ActiveDeal, ActiveSector, Market as MarketTrait, SectorDeal},
proofs::RegisteredSealProof,
sector::SectorNumber,
DealId, MAX_DEALS_PER_SECTOR,
};
use sp_core::H256;
use sp_runtime::AccountId32;
Expand Down
4 changes: 2 additions & 2 deletions pallets/proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ frame-system.workspace = true
log = { workspace = true }
num-bigint = { workspace = true }
polka-storage-proofs = { workspace = true, features = ["substrate"] }
primitives-commitment = { workspace = true }
primitives-proofs = { workspace = true }
primitives = { workspace = true }
rand = { workspace = true, features = ["alloc"] }
rand_chacha = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
Expand Down Expand Up @@ -63,6 +62,7 @@ std = [
"frame-support/std",
"frame-system/std",
"polka-storage-proofs/std",
"primitives/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
Expand Down
10 changes: 6 additions & 4 deletions pallets/proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ pub mod pallet {

use frame_support::{pallet_prelude::*, sp_runtime::BoundedBTreeMap};
use frame_system::pallet_prelude::*;
use primitives_proofs::{
ProofVerification, ProverId, PublicReplicaInfo, RawCommitment, RegisteredPoStProof,
RegisteredSealProof, SectorNumber, Ticket, MAX_POST_PROOF_BYTES, MAX_SEAL_PROOF_BYTES,
MAX_SECTORS_PER_PROOF,
use primitives::{
commitment::RawCommitment,
pallets::ProofVerification,
proofs::{ProverId, PublicReplicaInfo, RegisteredPoStProof, RegisteredSealProof, Ticket},
sector::SectorNumber,
MAX_POST_PROOF_BYTES, MAX_SEAL_PROOF_BYTES, MAX_SECTORS_PER_PROOF,
};

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion pallets/proofs/src/porep/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bls12_381::Scalar as Fr;
use num_bigint::BigUint;
use primitives_proofs::RegisteredSealProof;
use primitives::proofs::RegisteredSealProof;
use sha2::{Digest, Sha256};

use crate::Vec;
Expand Down
8 changes: 6 additions & 2 deletions pallets/proofs/src/porep/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
mod config;

use config::{Config, PoRepID};
use primitives_proofs::{ProverId, RawCommitment, RegisteredSealProof, SectorNumber, Ticket};
use primitives::{
commitment::RawCommitment,
proofs::{ProverId, RegisteredSealProof, Ticket},
sector::SectorNumber,
};
use sha2::{Digest, Sha256};

use crate::{
Expand Down Expand Up @@ -248,7 +252,7 @@ fn generate_inclusion_input(challenge: usize) -> Fr {

#[cfg(test)]
mod tests {
use primitives_proofs::{RegisteredSealProof, SectorNumber};
use primitives::{proofs::RegisteredSealProof, sector::SectorNumber};

use super::{ProofScheme, PublicInputs, Tau};

Expand Down
2 changes: 1 addition & 1 deletion pallets/proofs/src/post/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use primitives_proofs::RegisteredPoStProof;
use primitives::proofs::RegisteredPoStProof;

pub struct Config {
/// Size of the sector in bytes.
Expand Down
9 changes: 5 additions & 4 deletions pallets/proofs/src/post/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ mod config;
use config::Config;
use frame_support::{pallet_prelude::*, sp_runtime::BoundedBTreeMap};
use polka_storage_proofs::get_partitions_for_window_post;
use primitives_commitment::NODE_SIZE;
use primitives_proofs::{
PublicReplicaInfo, RawCommitment, RegisteredPoStProof, SectorNumber, Ticket,
MAX_SECTORS_PER_PROOF,
use primitives::{
commitment::RawCommitment,
proofs::{PublicReplicaInfo, RegisteredPoStProof, Ticket},
sector::SectorNumber,
MAX_SECTORS_PER_PROOF, NODE_SIZE,
};
use sha2::{Digest, Sha256};

Expand Down
7 changes: 5 additions & 2 deletions pallets/proofs/src/tests/porep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use codec::{Decode, Encode};
use frame_support::{assert_noop, assert_ok};
use hex::FromHex;
use polka_storage_proofs::{Bls12, VerifyingKey};
use primitives_proofs::{
ProofVerification, ProverId, RawCommitment, RegisteredSealProof, SectorNumber, Ticket,
use primitives::{
commitment::RawCommitment,
pallets::ProofVerification,
proofs::{ProverId, RegisteredSealProof, Ticket},
sector::SectorNumber,
};
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
Expand Down
Loading

0 comments on commit b76eeac

Please sign in to comment.