Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [
]

[workspace.dependencies]
ab-chacha8 = { version = "0.1.0", path = "shared/ab-chacha8" }
actix-web = { version = "4.9.0", default-features = false }
aes = "0.9.0-pre.2"
anyhow = "1.0.89"
Expand Down Expand Up @@ -108,6 +109,7 @@ mmr-gadget = { git = "https://github.com/subspace/polkadot-sdk", rev = "e8311328
mmr-rpc = { git = "https://github.com/subspace/polkadot-sdk", rev = "e831132867930ca90a7088c7246301ab29f015ba" }
multihash = "0.19.1"
nohash-hasher = "0.2.0"
no-panic = "0.1.35"
num-traits = { version = "0.2.18", default-features = false }
num_cpus = "1.16.0"
ouroboros = "0.18.4"
Expand Down
87 changes: 80 additions & 7 deletions crates/pallet-subspace/src/extensions/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ use parity_scale_codec::{Decode, Encode};
use scale_info::prelude::fmt;
use sp_consensus_slots::Slot;
use sp_consensus_subspace::SignedVote;
use sp_runtime::Weight;
use sp_runtime::traits::{AsSystemOriginSigner, Dispatchable, NumberFor};
use sp_runtime::transaction_validity::TransactionSource;
use sp_runtime::transaction_validity::{
InvalidTransaction, TransactionSource, TransactionValidityError, UnknownTransaction,
ValidTransaction,
};
use sp_std::collections::btree_map::BTreeMap;
use subspace_core_primitives::pieces::PieceOffset;
use subspace_core_primitives::sectors::SectorIndex;
Expand Down Expand Up @@ -82,11 +86,14 @@ mod benchmarks {
(Option<T::AccountId>, RewardSignature),
>::default());

let result;
#[block]
{
SubspaceExtension::<T>::do_check_vote(&signed_vote, TransactionSource::InBlock)
.unwrap();
}
result =
SubspaceExtension::<T>::do_check_vote(&signed_vote, TransactionSource::InBlock);
};

handle_error(result);
}

#[benchmark]
Expand Down Expand Up @@ -132,11 +139,15 @@ mod benchmarks {
*signed_vote.vote.slot(),
Some(reward_address),
));

let result;
#[block]
{
SubspaceExtension::<T>::do_check_vote(&signed_vote, TransactionSource::InBlock)
.unwrap();
}
result =
SubspaceExtension::<T>::do_check_vote(&signed_vote, TransactionSource::InBlock);
};

handle_error(result);
}

impl_benchmark_test_suite!(
Expand All @@ -145,3 +156,65 @@ mod benchmarks {
crate::mock::Test
);
}

fn handle_error(result: Result<(ValidTransaction, Weight), TransactionValidityError>) {
// This exhaustive match is required because the production runtime does not generate debug impls.
if let Err(e) = result {
match e {
TransactionValidityError::Invalid(e) => match e {
InvalidTransaction::Call => {
log::error!("Invalid transaction: Call");
}
InvalidTransaction::Payment => {
log::error!("Invalid transaction: Payment");
panic!("Invalid transaction: Payment");
}
InvalidTransaction::Future => {
log::error!("Invalid transaction: Future");
}
InvalidTransaction::Stale => {
log::error!("Invalid transaction: Stale");
}
InvalidTransaction::BadProof => {
log::error!("Invalid transaction: BadProof");
}
InvalidTransaction::AncientBirthBlock => {
log::error!("Invalid transaction: AncientBirthBlock");
}
InvalidTransaction::ExhaustsResources => {
log::error!("Invalid transaction: ExhaustsResources");
}
InvalidTransaction::Custom(e) => {
log::error!("Invalid transaction: Custom({})", e);
}
InvalidTransaction::BadMandatory => {
log::error!("Invalid transaction: BadMandatory");
}
InvalidTransaction::MandatoryValidation => {
log::error!("Invalid transaction: MandatoryValidation");
}
InvalidTransaction::BadSigner => {
log::error!("Invalid transaction: BadSigner");
}
InvalidTransaction::IndeterminateImplicit => {
log::error!("Invalid transaction: IndeterminateImplicit");
}
InvalidTransaction::UnknownOrigin => {
log::error!("Invalid transaction: UnknownOrigin");
}
},
TransactionValidityError::Unknown(e) => match e {
UnknownTransaction::CannotLookup => {
log::error!("Unknown transaction: CannotLookup");
}
UnknownTransaction::NoUnsignedValidator => {
log::error!("Unknown transaction: NoUnsignedValidator");
}
UnknownTransaction::Custom(e) => {
log::error!("Unknown transaction: Custom({})", e);
}
},
}
panic!("Error: {e:?}");
}
}
2 changes: 1 addition & 1 deletion crates/sp-consensus-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ std = [
"sp-weights/std",
"subspace-core-primitives/std",
"subspace-kzg/std",
"subspace-proof-of-space/std",
"subspace-proof-of-space/alloc",
"subspace-verification/kzg",
"subspace-verification/std",
"thiserror/std",
Expand Down
8 changes: 7 additions & 1 deletion crates/subspace-core-primitives/src/solutions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Solutions-related data structures and functions.

use crate::pieces::{PieceOffset, Record, RecordCommitment, RecordWitness};
use crate::pos::PosProof;
use crate::pos::{PosProof, PosSeed};
use crate::sectors::SectorIndex;
use crate::segments::{HistorySize, SegmentIndex};
use crate::{PublicKey, ScalarBytes};
Expand Down Expand Up @@ -227,6 +227,12 @@ impl ChunkWitness {
pub const SIZE: usize = 48;
}

/// Proof-of-time verifier trait, used in abundance backports.
pub trait SolutionPotVerifier {
/// Check whether proof created earlier is valid
fn is_proof_valid(seed: &PosSeed, challenge_index: u32, proof: &PosProof) -> bool;
}

/// Farmer solution for slot challenge.
#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down
43 changes: 21 additions & 22 deletions crates/subspace-proof-of-space/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,51 @@ version = "0.1.0"
authors = ["Nazar Mokrynskyi <[email protected]>"]
edition.workspace = true
include = [
"/benches",
"/src",
"/Cargo.toml",
]

[package.metadata.docs.rs]
all-features = true

[lib]
# Necessary for CLI options to work on benches
bench = false

[dependencies]
ab-chacha8.workspace = true
blake3 = { workspace = true, default-features = false }
chacha20.workspace = true
chacha20 = { workspace = true, optional = true }
derive_more = { workspace = true, features = ["full"] }
parking_lot = { workspace = true, optional = true }
rayon = { workspace = true, optional = true }
seq-macro.workspace = true
sha2.workspace = true
spin.workspace = true
seq-macro = { workspace = true, optional = true }
sha2 = { workspace = true, optional = true }
subspace-core-primitives.workspace = true

[dev-dependencies]
bitvec.workspace = true
chacha20.workspace = true
criterion.workspace = true
hex.workspace = true
rayon.workspace = true
seq-macro.workspace = true
sha2.workspace = true

[[bench]]
name = "pos"
harness = false

[features]
default = ["std"]
std = [
# TODO: `std` will not be necessary once 1.8.3+ is released with https://github.com/BLAKE3-team/BLAKE3/pull/469
"blake3/std",
"chacha20/std",
"derive_more/std",
# In no-std environment we use `spin`
"parking_lot",
"sha2/std",
"subspace-core-primitives/std",
default = []
alloc = [
"dep:chacha20",
"dep:seq-macro",
]
# Enabling this feature exposes quality search on `chiapos` module as well as enables support for K=15..=25 (by default
# only K=20 is exposed)
full-chiapos = [
"dep:sha2",
]
parallel = [
"alloc",
"dep:rayon",
]

# The std and no_std features are mutually exclusive, so when checking for unused dependencies,
# ignore the `spin` dependency, which is only used in no_std.
[package.metadata.cargo-udeps.ignore]
normal = ["spin"]
Loading
Loading