Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic PoT verification #1918

Merged
merged 7 commits into from
Sep 4, 2023
Merged
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
45 changes: 37 additions & 8 deletions Cargo.lock

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

33 changes: 5 additions & 28 deletions crates/pallet-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ use sp_runtime::DispatchError;
use sp_std::collections::btree_map::BTreeMap;
use sp_std::prelude::*;
use subspace_core_primitives::crypto::Scalar;
#[cfg(feature = "pot")]
use subspace_core_primitives::PotProof;
use subspace_core_primitives::{
ArchivedHistorySegment, HistorySize, PublicKey, Randomness, RewardSignature, SectorId,
SectorIndex, SegmentHeader, SegmentIndex, SolutionRange,
};
#[cfg(feature = "pot")]
use subspace_core_primitives::{PotProof, PotSeed};
use subspace_solving::REWARD_SIGNING_CONTEXT;
#[cfg(not(feature = "pot"))]
use subspace_verification::derive_randomness;
Expand Down Expand Up @@ -154,7 +154,7 @@ mod pallet {
use sp_std::prelude::*;
use subspace_core_primitives::crypto::Scalar;
use subspace_core_primitives::{
HistorySize, PotSeed, Randomness, SectorIndex, SegmentHeader, SegmentIndex, SolutionRange,
HistorySize, Randomness, SectorIndex, SegmentHeader, SegmentIndex, SolutionRange,
};

pub(super) struct InitialSolutionRanges<T: Config> {
Expand Down Expand Up @@ -490,10 +490,6 @@ mod pallet {
#[pallet::getter(fn root_plot_public_key)]
pub(super) type RootPlotPublicKey<T> = StorageValue<_, FarmerPublicKey>;

/// Future proof of time seed, essentially output of parent block's future proof of time.
#[pallet::storage]
pub(super) type FuturePotSeed<T> = StorageValue<_, PotSeed>;

#[pallet::hooks]
impl<T: Config> Hooks<T::BlockNumber> for Pallet<T> {
fn on_initialize(block_number: T::BlockNumber) -> Weight {
Expand Down Expand Up @@ -788,22 +784,6 @@ impl<T: Config> Pallet<T> {
}

fn do_initialize(block_number: T::BlockNumber) {
#[cfg(feature = "pot")]
frame_system::Pallet::<T>::deposit_log(DigestItem::future_pot_seed(
if block_number.is_one() {
PotSeed::from_genesis_block_hash(
frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero())
.as_ref()
.try_into()
.expect("Genesis block hash length must match, panic otherwise"),
)
} else {
FuturePotSeed::<T>::get().expect(
"Is set at the end of `do_initialize` of every block after genesis; qed",
)
},
));

let pre_digest = <frame_system::Pallet<T>>::digest()
.logs
.iter()
Expand Down Expand Up @@ -940,14 +920,11 @@ impl<T: Config> Pallet<T> {
));
}

// TODO: Take adjustment of iterations into account once we have it
#[cfg(feature = "pot")]
frame_system::Pallet::<T>::deposit_log(DigestItem::pot_slot_iterations(
PotSlotIterations::<T>::get().expect("Always instantiated during genesis; qed"),
));
// TODO: Once we have entropy injection, it might take effect right here and should be
// accounted for
#[cfg(feature = "pot")]
FuturePotSeed::<T>::put(pre_digest.pot_info().future_proof_of_time().seed());
}

fn do_finalize(_block_number: T::BlockNumber) {
Expand Down Expand Up @@ -1105,7 +1082,7 @@ impl<T: Config> Pallet<T> {
#[cfg(feature = "pot")]
pub fn pot_parameters() -> PotParameters {
PotParameters::V0 {
iterations: PotSlotIterations::<T>::get()
slot_iterations: PotSlotIterations::<T>::get()
.expect("Always instantiated during genesis; qed"),
// TODO: This is where adjustment for number of iterations and entropy injection will
// happen for runtime API calls
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async-oneshot = "0.5.0"
futures = "0.3.28"
futures-timer = "3.0.2"
jsonrpsee = { version = "0.16.2", features = ["server", "macros"] }
lru = "0.10.0"
lru = "0.11.0"
parity-scale-codec = "3.6.5"
parking_lot = "0.12.1"
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fork-tree = { version = "3.0.0", git = "https://github.com/subspace/substrate",
futures = "0.3.28"
futures-timer = "3.0.2"
log = "0.4.19"
lru = "0.10.0"
lru = "0.11.0"
parking_lot = "0.12.1"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71", version = "0.10.0-dev" }
rand = "0.8.5"
Expand Down
Loading
Loading