diff --git a/Cargo.lock b/Cargo.lock index 2f7983943..a3f3d463f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9705,6 +9705,7 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain-primitives", "polkadot-runtime-common", + "primitives-proofs", "scale-info", "smallvec", "sp-api", @@ -11120,6 +11121,7 @@ dependencies = [ "scale-info", "serde", "serde_json", + "sp-api", "sp-core 34.0.0", "sp-runtime 39.0.0", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2407-1)", diff --git a/cli/artifacts/metadata.scale b/cli/artifacts/metadata.scale index bae422c0e..f8ecad374 100644 Binary files a/cli/artifacts/metadata.scale and b/cli/artifacts/metadata.scale differ diff --git a/cli/polka-storage-provider/client/src/commands/proofs.rs b/cli/polka-storage-provider/client/src/commands/proofs.rs index 6166282d4..b273e1fda 100644 --- a/cli/polka-storage-provider/client/src/commands/proofs.rs +++ b/cli/polka-storage-provider/client/src/commands/proofs.rs @@ -380,6 +380,10 @@ impl ProofsCommand { // need to be able to calculate deadline info and challenge // I'll hardcode it for now let randomness: [u8; 32] = if let Some(randomness) = randomness { + // 1. We need to know deadline_index as an input, which was assigned on ProveCommit, treat it as an index + // 2. We can impl_runtime_apis for current_deadline info, if it matches the index, if not, just wait another proving window. + // 3. Then get randomness for this current_deadline info block + // 4. Make the proof work. hex::decode(randomness).unwrap().try_into().unwrap() } else { [1u8; 32] diff --git a/cli/polka-storage/storagext/Cargo.toml b/cli/polka-storage/storagext/Cargo.toml index 24f6414c0..7dfb70f47 100644 --- a/cli/polka-storage/storagext/Cargo.toml +++ b/cli/polka-storage/storagext/Cargo.toml @@ -21,7 +21,7 @@ frame-support = { workspace = true, features = ["std"] } futures.workspace = true hex = { workspace = true, features = ["serde"] } itertools = { workspace = true } -primitives-proofs = { workspace = true, features = ["serde"] } +primitives-proofs = { workspace = true, features = ["std", "serde"] } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } sha2 = { workspace = true } diff --git a/cli/polka-storage/storagext/src/clients/storage_provider.rs b/cli/polka-storage/storagext/src/clients/storage_provider.rs index 790740d7a..7d1d3b8d4 100644 --- a/cli/polka-storage/storagext/src/clients/storage_provider.rs +++ b/cli/polka-storage/storagext/src/clients/storage_provider.rs @@ -98,9 +98,19 @@ pub trait StorageProviderClientExt { fn retrieve_registered_storage_providers( &self, ) -> impl Future, subxt::Error>>; + + + fn current_deadline(&self, account_id: &AccountId32) -> impl Future>; } impl StorageProviderClientExt for crate::runtime::client::Client { + async fn current_deadline(&self, account_id: &AccountId32) -> Result { + // let _ = runtime::apis().storage_provider_api().current_deadline(account_id); + // let _ = runtime::apis().account_nonce_api().account_nonce(account_id); + + Ok(0) + } + #[tracing::instrument( level = "debug", skip_all, diff --git a/pallets/storage-provider/src/lib.rs b/pallets/storage-provider/src/lib.rs index 3b39dc28e..12bf10a24 100644 --- a/pallets/storage-provider/src/lib.rs +++ b/pallets/storage-provider/src/lib.rs @@ -768,10 +768,6 @@ pub mod pallet { ) .map_err(|e| Error::::GeneralPalletError(e))?; - // TODO: - // - generate a windowed post proof for this shit (by hand) - // - generate it automatically in the pipeline - // TODO(@th7nder,#592, 19/11/2024): handle faulty and recovered sectors, we don't take them into account now let deadlines = &sp.deadlines; let mut replicas = BoundedBTreeMap::new(); @@ -805,7 +801,7 @@ pub mod pallet { replicas ); - // let entropy = owner.encode(); + let entropy = owner.encode(); // The `chain_commit_epoch` should be `current_deadline.challenge` as per: // // These issues that were filed against the original implementation: @@ -831,10 +827,6 @@ pub mod pallet { &entropy, )?; - let randomness = [1u8; 32]; - - // Questions: - // * How do we know the partition the sector was assigned to (as a caller) ? T::ProofVerification::verify_post( windowed_post.proof.post_proof, randomness, diff --git a/primitives/proofs/Cargo.toml b/primitives/proofs/Cargo.toml index df9e1f702..3916659cd 100644 --- a/primitives/proofs/Cargo.toml +++ b/primitives/proofs/Cargo.toml @@ -14,6 +14,7 @@ scale-decode = { workspace = true, default-features = false, features = ["derive scale-encode = { workspace = true, default-features = false, features = ["derive"] } scale-info = { workspace = true, default-features = false, features = ["derive"] } +sp-api = { workspace = true, default-features = false } sp-core = { workspace = true, default-features = false } sp-runtime = { workspace = true, default-features = false } sp-std = { workspace = true, default-features = false } @@ -30,4 +31,4 @@ workspace = true [features] clap = ["dep:clap", "std"] default = ["std"] -std = ["cid/scale-codec", "codec/std", "scale-info/std", "sp-core/std", "sp-runtime/std", "sp-std/std"] +std = ["cid/scale-codec", "codec/std", "scale-info/std", "sp-api/std", "sp-core/std", "sp-runtime/std", "sp-std/std"] diff --git a/primitives/proofs/src/lib.rs b/primitives/proofs/src/lib.rs index 55f0d1cd2..cf2aab1e8 100644 --- a/primitives/proofs/src/lib.rs +++ b/primitives/proofs/src/lib.rs @@ -4,7 +4,7 @@ pub mod randomness; mod traits; mod types; -use codec::Encode; +use codec::{Codec, Encode}; pub use traits::*; pub use types::*; @@ -23,3 +23,10 @@ where encoded[31] &= 0x3f; encoded } + +sp_api::decl_runtime_apis! { + pub trait StorageProviderApi where AccountId: Codec + { + fn current_deadline(storage_provider: AccountId) -> u64; + } +} \ No newline at end of file diff --git a/primitives/proofs/src/traits.rs b/primitives/proofs/src/traits.rs index 9f37a4a7f..eb248dde0 100644 --- a/primitives/proofs/src/traits.rs +++ b/primitives/proofs/src/traits.rs @@ -163,4 +163,4 @@ pub struct ActiveDeal { pub piece_cid: Cid, /// Real size of the data pub piece_size: u64, -} +} \ No newline at end of file diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index d42d16748..4205e355e 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -25,6 +25,8 @@ pallet-proofs = { workspace = true, default-features = false } pallet-randomness = { workspace = true, default-features = false } pallet-storage-provider = { workspace = true, default-features = false } +primitives-proofs = { workspace = true, default-features = false } + codec = { workspace = true, default-features = false, features = ["derive"] } docify = { workspace = true } hex-literal = { workspace = true, optional = true } @@ -127,6 +129,7 @@ std = [ "parachains-common/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", + "primitives-proofs/std", "scale-info/std", "sp-api/std", "sp-block-builder/std", diff --git a/runtime/src/apis.rs b/runtime/src/apis.rs index cbe88ea37..7f11e42f0 100644 --- a/runtime/src/apis.rs +++ b/runtime/src/apis.rs @@ -65,6 +65,12 @@ impl Runtime { } impl_runtime_apis! { + impl primitives_proofs::StorageProviderApi for Runtime { + fn current_deadline(storage_provider: AccountId) -> u64 { + 0 + } + } + impl sp_consensus_aura::AuraApi for Runtime { fn slot_duration() -> sp_consensus_aura::SlotDuration { Runtime::impl_slot_duration()