Add ChainTime associated type (#410)

* add HeaderTimestamp associated type

* use Header Timestamp

* rename HeaderTimestamp to ChainTime

* add unit test

* deal with clippy

* Apply suggestions from code review

Commit review suggestions

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* code review

* cargo fmt

* get rid of additional test runtime

* unit test asserts against concrete import context

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
Andreas Doerr
2020-10-13 12:23:58 +02:00
committed by Bastian Köcher
parent 253d0d4774
commit ede0ff8656
9 changed files with 154 additions and 16 deletions
+13 -1
View File
@@ -21,7 +21,8 @@ use bp_header_chain::BaseHeaderChain;
use frame_support::RuntimeDebug;
use hex_literal::hex;
use pallet_bridge_eth_poa::{
AuraConfiguration, PruningStrategy as BridgePruningStrategy, ValidatorsConfiguration, ValidatorsSource,
AuraConfiguration, ChainTime as TChainTime, PruningStrategy as BridgePruningStrategy, ValidatorsConfiguration,
ValidatorsSource,
};
use sp_std::prelude::*;
@@ -134,6 +135,17 @@ impl BridgePruningStrategy for PruningStrategy {
}
}
/// PoA Header timestamp verification against `Timestamp` pallet.
#[derive(Default, RuntimeDebug)]
pub struct ChainTime;
impl TChainTime for ChainTime {
fn is_timestamp_ahead(&self, timestamp: u64) -> bool {
let now = super::Timestamp::now();
timestamp > now
}
}
/// The Kovan Blockchain as seen by the runtime.
pub struct KovanBlockchain;
+2
View File
@@ -234,6 +234,7 @@ impl pallet_bridge_eth_poa::Trait<RialtoPoA> for Runtime {
type FinalityVotesCachingInterval = rialto_poa::FinalityVotesCachingInterval;
type ValidatorsConfiguration = rialto_poa::BridgeValidatorsConfiguration;
type PruningStrategy = rialto_poa::PruningStrategy;
type ChainTime = rialto_poa::ChainTime;
type OnHeadersSubmitted = ();
}
@@ -243,6 +244,7 @@ impl pallet_bridge_eth_poa::Trait<Kovan> for Runtime {
type FinalityVotesCachingInterval = kovan::FinalityVotesCachingInterval;
type ValidatorsConfiguration = kovan::BridgeValidatorsConfiguration;
type PruningStrategy = kovan::PruningStrategy;
type ChainTime = kovan::ChainTime;
type OnHeadersSubmitted = ();
}
+13 -1
View File
@@ -23,7 +23,8 @@ use bp_header_chain::BaseHeaderChain;
use frame_support::RuntimeDebug;
use hex_literal::hex;
use pallet_bridge_eth_poa::{
AuraConfiguration, PruningStrategy as TPruningStrategy, ValidatorsConfiguration, ValidatorsSource,
AuraConfiguration, ChainTime as TChainTime, PruningStrategy as TPruningStrategy, ValidatorsConfiguration,
ValidatorsSource,
};
use sp_std::prelude::*;
@@ -109,6 +110,17 @@ impl TPruningStrategy for PruningStrategy {
}
}
/// ChainTime provider
#[derive(Default)]
pub struct ChainTime;
impl TChainTime for ChainTime {
fn is_timestamp_ahead(&self, timestamp: u64) -> bool {
let now = super::Timestamp::now();
timestamp > now
}
}
/// The Rialto PoA Blockchain as seen by the runtime.
pub struct RialtoBlockchain;