Skip to content

Commit

Permalink
fix(maat): test porep proof (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
cernicc authored Nov 11, 2024
1 parent eed54f5 commit b762cdc
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 62 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

11 changes: 7 additions & 4 deletions cli/polka-storage-provider/client/src/commands/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use polka_storage_proofs::{
ZeroPaddingReader,
};
use polka_storage_provider_common::commp::{calculate_piece_commitment, CommPError};
use primitives_commitment::piece::{PaddedPieceSize, PieceInfo};
use primitives_commitment::{
piece::{PaddedPieceSize, PieceInfo},
Commitment, CommitmentKind,
};
use primitives_proofs::{derive_prover_id, RegisteredPoStProof, RegisteredSealProof};
use storagext::multipair::{MultiPairArgs, MultiPairSigner};
use subxt::tx::Signer;
Expand Down Expand Up @@ -249,7 +252,7 @@ impl ProofsCommand {
let piece_info = PieceInfo {
commitment: primitives_commitment::Commitment::from_cid(
&commp,
primitives_commitment::CommitmentKind::Piece,
CommitmentKind::Piece,
)
.map_err(|e| UtilsCommandError::InvalidPieceType(commp.to_string(), e))?,
size: piece_file_length,
Expand Down Expand Up @@ -301,8 +304,8 @@ impl ProofsCommand {
)
.map_err(|e| UtilsCommandError::GeneratePoRepError(e))?;

println!("CommR: {:?}", hex::encode(&precommit.comm_r));
println!("CommD: {:?}", hex::encode(&precommit.comm_d));
println!("CommD: {:?}", Commitment::data(precommit.comm_d).cid());
println!("CommR: {:?}", Commitment::replica(precommit.comm_r).cid());
println!("Proof: {:?}", proofs);
// We use sector size 2KiB only at this point, which guarantees to have 1 proof, because it has 1 partition in the config.
// That's why `prove_commit` will always generate a 1 proof.
Expand Down
16 changes: 1 addition & 15 deletions cli/polka-storage-provider/server/src/pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ use types::{
use crate::db::{DBError, DealDB};

const SECTOR_EXPIRATION_MARGIN: u64 = 20;
/// TODO(@th7nder,[#457, #458], 06/11/2024): Blockchain cannot give randomness until block 82.
const MINIMUM_BLOCK_WITH_RANDOMNESS_AVAILABLE: u64 = 82;

#[derive(Debug, thiserror::Error)]
pub enum PipelineError {
Expand Down Expand Up @@ -279,21 +277,9 @@ async fn precommit(

tracing::info!("Padded sector, commencing pre-commit and getting last finalized block");

let mut current_block = state.xt_client.height(true).await?;
let current_block = state.xt_client.height(true).await?;
tracing::info!("Current block: {current_block}");

if current_block < MINIMUM_BLOCK_WITH_RANDOMNESS_AVAILABLE {
tracing::info!(
"Waiting for randomness to be available at block: {}",
MINIMUM_BLOCK_WITH_RANDOMNESS_AVAILABLE
);
state
.xt_client
.wait_for_height(MINIMUM_BLOCK_WITH_RANDOMNESS_AVAILABLE, true)
.await?;
current_block = MINIMUM_BLOCK_WITH_RANDOMNESS_AVAILABLE;
}

let digest = state
.xt_client
.get_randomness(current_block)
Expand Down
2 changes: 2 additions & 0 deletions cli/polka-storage/storagext/src/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod market;
mod proofs;
mod randomness;
mod storage_provider;
mod system;

pub use market::MarketClientExt;
pub use proofs::ProofsClientExt;
pub use randomness::RandomnessClientExt;
pub use storage_provider::StorageProviderClientExt;
pub use system::SystemClientExt;
44 changes: 44 additions & 0 deletions cli/polka-storage/storagext/src/clients/proofs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use futures::Future;
use subxt::ext::sp_core::crypto::Ss58Codec;

use crate::{
runtime::{self, SubmissionResult},
PolkaStorageConfig,
};

pub trait ProofsClientExt {
fn set_porep_verifying_key<Keypair>(
&self,
account_keypair: &Keypair,
verifying_key: Vec<u8>,
wait_for_finalization: bool,
) -> impl Future<Output = Result<Option<SubmissionResult<PolkaStorageConfig>>, subxt::Error>>
where
Keypair: subxt::tx::Signer<PolkaStorageConfig>;
}

impl ProofsClientExt for crate::runtime::client::Client {
#[tracing::instrument(
level = "debug",
skip_all,
fields(
address = account_keypair.account_id().to_ss58check(),
)
)]
async fn set_porep_verifying_key<Keypair>(
&self,
account_keypair: &Keypair,
verifying_key: Vec<u8>,
wait_for_finalization: bool,
) -> Result<Option<SubmissionResult<PolkaStorageConfig>>, subxt::Error>
where
Keypair: subxt::tx::Signer<PolkaStorageConfig>,
{
let payload = runtime::tx()
.proofs()
.set_porep_verifying_key(verifying_key);

self.traced_submission(&payload, account_keypair, wait_for_finalization)
.await
}
}
12 changes: 10 additions & 2 deletions cli/polka-storage/storagext/src/runtime/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ use subxt::{blocks::Block, events::Events, OnlineClient};
use crate::PolkaStorageConfig;

/// Helper type for [`Client::traced_submission`] successful results.
#[derive(Debug)]
pub struct SubmissionResult<Config>
where
Config: subxt::Config,
{
/// Submission block hash.
pub hash: Config::Hash,

/// Submission block height.
pub height: u64,

/// Resulting extrinsic's events.
pub events: Events<Config>,
}
Expand Down Expand Up @@ -135,7 +139,11 @@ impl Client {
};

let block: Block<PolkaStorageConfig, _> = block?;
tracing::error!("checking block {}", block.hash());
tracing::debug!(
"checking block number: {} hash: {}",
block.number(),
block.hash()
);

for extrinsic in block.extrinsics().await?.iter() {
let extrinsic = extrinsic?;
Expand All @@ -147,7 +155,6 @@ impl Client {

if submitted_extrinsic_hash == extrinsic_hash {
// Extrinsic failures are placed in the same block as the extrinsic.

let failed_extrinsic_event: Option<
crate::runtime::system::events::ExtrinsicFailed,
> = block.events().await?.find_first()?;
Expand Down Expand Up @@ -178,6 +185,7 @@ impl Client {
let result = result?;
Ok(SubmissionResult {
hash: result.hash(),
height: result.number(),
events: result.events().await?,
})
}
Expand Down
4 changes: 2 additions & 2 deletions cli/polka-storage/storagext/src/types/storage_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ impl PartialEq<SectorPreCommitInfo> for RuntimeSectorPreCommitInfo<BlockNumber>
pub struct ProveCommitSector {
/// Number of a sector that has been previously pre-committed.
pub sector_number: SectorNumber,
/// Proof bytes as a hex string.
/// If empty it fails validation, it has any bytes it succeeds.
/// Raw proof bytes serialized with [`parity_scale_codec::Encode::encode`]
/// and using [`bls12_381::Bls12`] as a curve.
#[serde(with = "hex")]
pub proof: Vec<u8>,
}
Expand Down
Binary file added examples/test-data-big.car
Binary file not shown.
1 change: 1 addition & 0 deletions maat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ target-release = []
bs58.workspace = true
cid.workspace = true
futures.workspace = true
hex = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["std"] }
subxt = { workspace = true, features = ["substrate-compat"] }
Expand Down
4 changes: 4 additions & 0 deletions maat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
> According to Ancient Egyptian mythology, after the death of the body, everyone had to pass through the Hall of Judgment,
> where a person’s heart was weighed on a scale against Ma’at’s feather of truth.
> https://egyptianmuseum.org/deities-Maat
### Note

Tests will fail if the node binary is not compiled with the testnet feature flag `polka-storage-runtime/testnet`
Loading

0 comments on commit b762cdc

Please sign in to comment.