Skip to content

Commit

Permalink
try to implement runtime apis
Browse files Browse the repository at this point in the history
  • Loading branch information
th7nder committed Nov 22, 2024
1 parent b352242 commit ab5b468
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 13 deletions.
4 changes: 4 additions & 0 deletions cli/polka-storage-provider/client/src/commands/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion cli/polka-storage/storagext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
10 changes: 10 additions & 0 deletions cli/polka-storage/storagext/src/clients/storage_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,19 @@ pub trait StorageProviderClientExt {
fn retrieve_registered_storage_providers(
&self,
) -> impl Future<Output = Result<Vec<String>, subxt::Error>>;


fn current_deadline(&self, account_id: &AccountId32) -> impl Future<Output = Result<u64, subxt::Error>>;
}

impl StorageProviderClientExt for crate::runtime::client::Client {
async fn current_deadline(&self, account_id: &AccountId32) -> Result<u64, subxt::Error> {
// 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,
Expand Down
10 changes: 1 addition & 9 deletions pallets/storage-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,6 @@ pub mod pallet {
)
.map_err(|e| Error::<T>::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();
Expand Down Expand Up @@ -766,7 +762,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:
Expand All @@ -792,10 +788,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,
Expand Down
3 changes: 2 additions & 1 deletion primitives/proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -31,4 +32,4 @@ workspace = true
[features]
clap = ["dep:clap", "std"]
default = ["std"]
std = ["cid/scale-codec", "codec/std", "dep:storage-proofs-core", "scale-info/std", "sp-core/std", "sp-runtime/std", "sp-std/std"]
std = ["cid/scale-codec", "codec/std", "dep:storage-proofs-core", "sp-api/std", "scale-info/std", "sp-core/std", "sp-runtime/std", "sp-std/std"]
9 changes: 8 additions & 1 deletion primitives/proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod randomness;
mod traits;
mod types;

use codec::Encode;
use codec::{Codec, Encode};
pub use traits::*;
pub use types::*;

Expand All @@ -23,3 +23,10 @@ where
encoded[31] &= 0x3f;
encoded
}

sp_api::decl_runtime_apis! {
pub trait StorageProviderApi<AccountId> where AccountId: Codec
{
fn current_deadline(storage_provider: AccountId) -> u64;
}
}
2 changes: 1 addition & 1 deletion primitives/proofs/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ pub struct ActiveDeal<AccountId> {
pub piece_cid: Cid,
/// Real size of the data
pub piece_size: u64,
}
}
3 changes: 3 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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 = ["chain-error", "derive"] }
docify = { workspace = true }
hex-literal = { workspace = true, optional = true }
Expand Down Expand Up @@ -128,6 +130,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",
Expand Down
6 changes: 6 additions & 0 deletions runtime/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ impl Runtime {
}

impl_runtime_apis! {
impl primitives_proofs::StorageProviderApi<Block, AccountId> for Runtime {
fn current_deadline(storage_provider: AccountId) -> u64 {
0
}
}

impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
Runtime::impl_slot_duration()
Expand Down

0 comments on commit ab5b468

Please sign in to comment.