Skip to content

Commit

Permalink
removed std from genesis transactions
Browse files Browse the repository at this point in the history
warning: this commit introduces first block hack for timestamp

Signed-off-by: muraca <mmuraca247@gmail.com>
  • Loading branch information
muraca committed Nov 29, 2023
1 parent 067ffd4 commit 4fc4964
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 29 deletions.
1 change: 0 additions & 1 deletion tuxedo-core/aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ pub fn tuxedo_constraint_checker(attrs: TokenStream, body: TokenStream) -> Token
)*
}

#[cfg(feature = "std")]
fn genesis_transactions() -> Vec<tuxedo_core::types::Transaction<#verifier, #outer_type>> {
let mut all_transactions: Vec<tuxedo_core::types::Transaction<#verifier, #outer_type>> = Vec::new();

Expand Down
4 changes: 0 additions & 4 deletions tuxedo-core/src/inherents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ pub trait TuxedoInherent<V, C: ConstraintChecker<V>>: Sized {
);

/// Return the genesis transactions that are required for this inherent.
#[cfg(feature = "std")]
fn genesis_transactions() -> Vec<Transaction<V, C>> {
Vec::new()
}
Expand Down Expand Up @@ -150,7 +149,6 @@ pub trait InherentInternal<V, C: ConstraintChecker<V>>: Sized {
);

/// Return the genesis transactions that are required for the inherents.
#[cfg(feature = "std")]
fn genesis_transactions() -> Vec<Transaction<V, C>>;
}

Expand Down Expand Up @@ -203,7 +201,6 @@ impl<V: Verifier, C: ConstraintChecker<V>, T: TuxedoInherent<V, C> + 'static> In
<T as TuxedoInherent<V, C>>::check_inherent(importing_inherent_data, inherent, results)
}

#[cfg(feature = "std")]
fn genesis_transactions() -> Vec<Transaction<V, C>> {
<T as TuxedoInherent<V, C>>::genesis_transactions()
}
Expand All @@ -230,7 +227,6 @@ impl<V, C: ConstraintChecker<V>> InherentInternal<V, C> for () {
)
}

#[cfg(feature = "std")]
fn genesis_transactions() -> Vec<Transaction<V, C>> {
Vec::new()
}
Expand Down
19 changes: 8 additions & 11 deletions tuxedo-template-runtime/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ pub use super::WASM_BINARY;
use super::{
kitties::{KittyData, Parent},
money::Coin,
Transaction,
OuterConstraintCheckerInherentHooks, Transaction,
};
use hex_literal::hex;
use sp_std::{vec, vec::Vec};
use tuxedo_core::verifier::{SigCheck, ThresholdMultiSignature, UpForGrabs};
use tuxedo_core::{
inherents::InherentInternal,
verifier::{SigCheck, ThresholdMultiSignature, UpForGrabs},
};

const SHAWN_PUB_KEY_BYTES: [u8; 32] =
hex!("d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67");
Expand All @@ -23,9 +26,7 @@ pub fn development_genesis_transactions() -> Vec<Transaction> {
let signatories = vec![SHAWN_PUB_KEY_BYTES.into(), ANDREW_PUB_KEY_BYTES.into()];

// The inherents are computed using the appropriate method, and placed before the extrinsics.
let mut genesis_transactions = Vec::new();
// TODO restore this once inherent genesis can work with no_std
// OuterConstraintCheckerInherentHooks::genesis_transactions();
let mut genesis_transactions = OuterConstraintCheckerInherentHooks::genesis_transactions();

genesis_transactions.extend([
// Money Transactions
Expand Down Expand Up @@ -98,9 +99,7 @@ mod tests {
},
};

// TODO restore this once inherent genesis can work with no_std
// let inherents_len = OuterConstraintCheckerInherentHooks::genesis_transactions().len();
let inherents_len = 0;
let inherents_len = OuterConstraintCheckerInherentHooks::genesis_transactions().len();

let tx = development_genesis_transactions()
.get(inherents_len)
Expand Down Expand Up @@ -144,9 +143,7 @@ mod tests {
},
};

// TODO restore this once inherent genesis can work with no_std
// let inherents_len = OuterConstraintCheckerInherentHooks::genesis_transactions().len();
let inherents_len = 0;
let inherents_len = OuterConstraintCheckerInherentHooks::genesis_transactions().len();

let tx = development_genesis_transactions()
.get(1 + inherents_len)
Expand Down
5 changes: 2 additions & 3 deletions tuxedo-template-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ pub enum OuterConstraintChecker {
/// Checks that one winning claim came earlier than all the other claims, and thus
/// the losing claims can be removed from storage.
PoeDispute(poe::PoeDispute),
// TODO restore this once inherent genesis can work with no_std
// /// Set the block's timestamp via an inherent extrinsic.
// SetTimestamp(timestamp::SetTimestamp<Runtime>),
/// Set the block's timestamp via an inherent extrinsic.
SetTimestamp(timestamp::SetTimestamp<Runtime>),
/// Upgrade the Wasm Runtime
RuntimeUpgrade(runtime_upgrade::RuntimeUpgrade),

Expand Down
13 changes: 3 additions & 10 deletions wardrobe/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ impl<T: TimestampConfig + 'static, V: Verifier + From<UpForGrabs>> ConstraintChe

// Compare the new timestamp to the previous timestamp
ensure!(
new_timestamp.time >= old_timestamp.time + T::MINIMUM_TIME_INTERVAL,
old_timestamp.block == 0 // first block hack
|| new_timestamp.time >= old_timestamp.time + T::MINIMUM_TIME_INTERVAL,
Self::Error::TimestampTooOld
);

Expand Down Expand Up @@ -302,20 +303,12 @@ impl<V: Verifier + From<UpForGrabs>, T: TimestampConfig + 'static> TuxedoInheren
}
}

#[cfg(feature = "std")]
fn genesis_transactions() -> Vec<Transaction<V, Self>> {
use std::time::{Duration, SystemTime};
let time = SystemTime::UNIX_EPOCH
.elapsed()
.expect("Time went backwards!")
.saturating_sub(Duration::from_millis(T::MINIMUM_TIME_INTERVAL))
.as_millis() as u64;

vec![Transaction {
inputs: Vec::new(),
peeks: Vec::new(),
outputs: vec![Output {
payload: Timestamp::new(time, 0).into(),
payload: Timestamp::new(0, 0).into(),
verifier: UpForGrabs.into(),
}],
checker: Self::default(),
Expand Down

0 comments on commit 4fc4964

Please sign in to comment.