Skip to content

Commit

Permalink
Move Kzg struct and related code into new subspace-kzg crate
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Oct 2, 2024
1 parent 2b3372b commit 5ab4838
Show file tree
Hide file tree
Showing 64 changed files with 163 additions and 97 deletions.
35 changes: 28 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/pallet-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ rand = { version = "0.8.5", features = ["min_const_gen"] }
sp-io = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42" }
subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" }
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
subspace-farmer-components = { version = "0.1.0", path = "../subspace-farmer-components" }
subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding" }
subspace-farmer-components = { version = "0.1.0", path = "../subspace-farmer-components" }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space" }

[features]
Expand Down
2 changes: 1 addition & 1 deletion crates/pallet-subspace/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use std::simd::Simd;
use std::sync::{Once, OnceLock};
use std::{iter, slice};
use subspace_archiving::archiver::{Archiver, NewArchivedSegment};
use subspace_core_primitives::crypto::kzg::Kzg;
use subspace_core_primitives::pieces::{Piece, PieceOffset, Record};
use subspace_core_primitives::pos::PosSeed;
use subspace_core_primitives::pot::PotOutput;
Expand All @@ -53,6 +52,7 @@ use subspace_farmer_components::auditing::audit_sector_sync;
use subspace_farmer_components::plotting::{plot_sector, CpuRecordsEncoder, PlotSectorOptions};
use subspace_farmer_components::reading::ReadSectorRecordChunksMode;
use subspace_farmer_components::FarmerProtocolInfo;
use subspace_kzg::Kzg;
use subspace_proof_of_space::shim::ShimTable;
use subspace_proof_of_space::{Table, TableGenerator};
use subspace_verification::is_within_solution_range;
Expand Down
1 change: 1 addition & 0 deletions crates/sc-consensus-subspace-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" }
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding" }
subspace-farmer-components = { version = "0.1.0", path = "../subspace-farmer-components" }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-networking = { version = "0.1.0", path = "../subspace-networking" }
subspace-rpc-primitives = { version = "0.1.0", path = "../subspace-rpc-primitives" }
thiserror = "1.0.64"
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Weak};
use std::time::Duration;
use subspace_archiving::archiver::NewArchivedSegment;
use subspace_core_primitives::crypto::kzg::Kzg;
use subspace_core_primitives::objects::GlobalObjectMapping;
use subspace_core_primitives::pieces::{Piece, PieceIndex};
use subspace_core_primitives::segments::{HistorySize, SegmentHeader, SegmentIndex};
use subspace_core_primitives::{Blake3Hash, BlockHash, PublicKey, SlotNumber, Solution};
use subspace_erasure_coding::ErasureCoding;
use subspace_farmer_components::FarmerProtocolInfo;
use subspace_kzg::Kzg;
use subspace_networking::libp2p::Multiaddr;
use subspace_rpc_primitives::{
FarmerAppInfo, RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse,
Expand Down
1 change: 1 addition & 0 deletions crates/sc-consensus-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sp-runtime = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e
subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" }
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding" }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space" }
subspace-verification = { version = "0.1.0", path = "../subspace-verification" }
thiserror = "1.0.64"
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ use std::sync::atomic::{AtomicU16, Ordering};
use std::sync::Arc;
use std::time::Duration;
use subspace_archiving::archiver::{Archiver, NewArchivedSegment};
use subspace_core_primitives::crypto::kzg::Kzg;
use subspace_core_primitives::objects::BlockObjectMapping;
use subspace_core_primitives::segments::{RecordedHistorySegment, SegmentHeader, SegmentIndex};
use subspace_core_primitives::{BlockNumber, PublicKey};
use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::Kzg;
use tracing::{debug, info, trace, warn};

/// Number of WASM instances is 8, this is a bit lower to avoid warnings exceeding number of
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use crate::notification::{SubspaceNotificationSender, SubspaceNotificationStream
use crate::slot_worker::{NewSlotNotification, RewardSigningNotification};
use sp_consensus_subspace::ChainConstants;
use sp_runtime::traits::Block as BlockT;
use subspace_core_primitives::crypto::kzg::Kzg;
use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::Kzg;

/// State that must be shared between various consensus components.
#[derive(Clone)]
Expand Down
4 changes: 2 additions & 2 deletions crates/sc-consensus-subspace/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
// use std::task::Poll;
// use std::time::Duration;
// use subspace_archiving::archiver::Archiver;
// use subspace_core_primitives::crypto::kzg;
// use subspace_core_primitives::crypto::kzg::{Kzg};
// use subspace_kzg;
// use subspace_kzg::{Kzg};
// use subspace_core_primitives::objects::BlockObjectMapping;
// use subspace_core_primitives::{
// ArchivedHistorySegment, FlatPieces, HistorySize, Piece, PieceIndex, PieceOffset, Solution,
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ use std::num::NonZeroUsize;
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc;
use std::thread::available_parallelism;
use subspace_core_primitives::crypto::kzg::Kzg;
use subspace_core_primitives::{BlockNumber, PublicKey};
use subspace_kzg::Kzg;
use subspace_proof_of_space::Table;
use subspace_verification::{check_reward_signature, verify_solution, VerifySolutionParams};
use tokio::runtime::Handle;
Expand Down
3 changes: 3 additions & 0 deletions crates/sp-consensus-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sp-runtime-interface = { default-features = false, git = "https://github.com/sub
sp-std = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42" }
sp-timestamp = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42", default-features = false }
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives", default-features = false }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg", optional = true }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space", default-features = false }
subspace-verification = { version = "0.1.0", path = "../subspace-verification", default-features = false }
thiserror = { version = "1.0.64", optional = true }
Expand All @@ -54,7 +55,9 @@ std = [
"sp-std/std",
"sp-timestamp/std",
"subspace-core-primitives/std",
"subspace-kzg/std",
"subspace-proof-of-space/std",
"subspace-verification/kzg",
"subspace-verification/std",
"thiserror",
]
4 changes: 2 additions & 2 deletions crates/sp-consensus-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ use sp_runtime::{ConsensusEngineId, Justification};
use sp_runtime_interface::pass_by::PassBy;
use sp_runtime_interface::{pass_by, runtime_interface};
use sp_std::num::NonZeroU32;
#[cfg(feature = "std")]
use subspace_core_primitives::crypto::kzg::Kzg;
use subspace_core_primitives::pot::{PotCheckpoints, PotOutput, PotSeed};
use subspace_core_primitives::segments::{
HistorySize, SegmentCommitment, SegmentHeader, SegmentIndex,
Expand All @@ -51,6 +49,8 @@ use subspace_core_primitives::{
SolutionRange,
};
#[cfg(feature = "std")]
use subspace_kzg::Kzg;
#[cfg(feature = "std")]
use subspace_proof_of_space::chia::ChiaTable;
#[cfg(feature = "std")]
use subspace_proof_of_space::shim::ShimTable;
Expand Down
2 changes: 2 additions & 0 deletions crates/subspace-archiving/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rayon = { version = "1.10.0", optional = true }
serde = { version = "1.0.110", optional = true, features = ["derive"] }
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives", default-features = false }
subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding", default-features = false }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg", default-features = false }
thiserror = { version = "1.0.64", optional = true }

[dev-dependencies]
Expand All @@ -46,6 +47,7 @@ std = [
"serde",
"subspace-core-primitives/std",
"subspace-erasure-coding/std",
"subspace-kzg/std",
"thiserror",
]

Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-archiving/benches/archiving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand::{thread_rng, Rng};
use std::num::NonZeroUsize;
use subspace_archiving::archiver::Archiver;
use subspace_core_primitives::crypto::kzg::Kzg;
use subspace_core_primitives::pieces::Record;
use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::Kzg;

const AMOUNT_OF_DATA: usize = 5 * 1024 * 1024;
const SMALL_BLOCK_SIZE: usize = 500;
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-archiving/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use parity_scale_codec::{Compact, CompactLen, Decode, Encode, Input, Output};
#[cfg(feature = "parallel")]
use rayon::prelude::*;
use subspace_core_primitives::crypto::blake3_254_hash_to_scalar;
use subspace_core_primitives::crypto::kzg::{Kzg, Scalar};
use subspace_core_primitives::objects::{
BlockObject, BlockObjectMapping, GlobalObject, PieceObject, PieceObjectMapping,
};
Expand All @@ -41,6 +40,7 @@ use subspace_core_primitives::segments::{
};
use subspace_core_primitives::{Blake3Hash, BlockNumber, ScalarBytes};
use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::{Kzg, Scalar};

const INITIAL_LAST_ARCHIVED_BLOCK: LastArchivedBlock = LastArchivedBlock {
number: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use core::ops::{Deref, DerefMut};
use parity_scale_codec::{Encode, Output};
#[cfg(feature = "parallel")]
use rayon::prelude::*;
use subspace_core_primitives::crypto::kzg::{Commitment, Kzg, Scalar};
use subspace_core_primitives::pieces::RawRecord;
use subspace_core_primitives::ScalarBytes;
use subspace_kzg::{Commitment, Kzg, Scalar};

/// State of incremental record commitments, encapsulated to hide implementation details and
/// encapsulate tricky logic
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-archiving/src/piece_reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use alloc::vec::Vec;
#[cfg(feature = "parallel")]
use rayon::prelude::*;
use subspace_core_primitives::crypto::blake3_254_hash_to_scalar;
use subspace_core_primitives::crypto::kzg::{Commitment, Kzg, Polynomial, Scalar};
use subspace_core_primitives::pieces::{Piece, RawRecord};
use subspace_core_primitives::segments::ArchivedHistorySegment;
use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::{Commitment, Kzg, Polynomial, Scalar};

/// Reconstructor-related instantiation error
#[derive(Debug, Clone, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-archiving/src/reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use alloc::string::String;
use alloc::vec::Vec;
use core::mem;
use parity_scale_codec::Decode;
use subspace_core_primitives::crypto::kzg::Scalar;
use subspace_core_primitives::pieces::{Piece, RawRecord};
use subspace_core_primitives::segments::{
ArchivedBlockProgress, ArchivedHistorySegment, LastArchivedBlock, RecordedHistorySegment,
SegmentHeader, SegmentIndex,
};
use subspace_core_primitives::BlockNumber;
use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::Scalar;

/// Reconstructor-related instantiation error
#[derive(Debug, Clone, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-archiving/tests/integration/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::io::Write;
use std::iter;
use std::num::NonZeroUsize;
use subspace_archiving::archiver::{Archiver, ArchiverInstantiationError, SegmentItem};
use subspace_core_primitives::crypto::kzg::Kzg;
use subspace_core_primitives::objects::{BlockObject, BlockObjectMapping, PieceObject};
use subspace_core_primitives::pieces::{Piece, Record};
use subspace_core_primitives::segments::{
Expand All @@ -16,6 +15,7 @@ use subspace_core_primitives::segments::{
};
use subspace_core_primitives::Blake3Hash;
use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::Kzg;
use subspace_verification::is_piece_valid;

fn extract_data<O: Into<u64>>(data: &[u8], offset: O) -> &[u8] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use rayon::prelude::*;
use std::num::NonZeroUsize;
use subspace_archiving::archiver::Archiver;
use subspace_archiving::piece_reconstructor::{PiecesReconstructor, ReconstructorError};
use subspace_core_primitives::crypto::kzg::Kzg;
use subspace_core_primitives::objects::BlockObjectMapping;
use subspace_core_primitives::pieces::{FlatPieces, Piece, Record};
use subspace_core_primitives::segments::{ArchivedHistorySegment, RecordedHistorySegment};
use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::Kzg;

fn pieces_to_option_of_pieces(pieces: &FlatPieces) -> Vec<Option<Piece>> {
pieces.pieces().map(Some).collect()
Expand Down
Loading

0 comments on commit 5ab4838

Please sign in to comment.