mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 20:31:04 +00:00
CheckInherentError can now report when something would be valid (#1204)
* CheckInherentError can now report when something would be valid * set timestamp inherent to next valid block time * return max timestamp for valid-after when checking
This commit is contained in:
committed by
Bastian Köcher
parent
93b212d2cc
commit
9bccc9661c
@@ -6,7 +6,6 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
[dependencies]
|
||||
hex-literal = "0.1.0"
|
||||
serde = { version = "1.0", default-features = false }
|
||||
parity-codec-derive = { version = "2.1", default-features = false }
|
||||
parity-codec = { version = "2.1", default-features = false }
|
||||
substrate-primitives = { path = "../../core/primitives", default-features = false }
|
||||
sr-std = { path = "../../core/sr-std", default-features = false }
|
||||
@@ -28,7 +27,6 @@ std = [
|
||||
"sr-primitives/std",
|
||||
"srml-consensus/std",
|
||||
"serde/std",
|
||||
"parity-codec-derive/std",
|
||||
"parity-codec/std",
|
||||
"substrate-primitives/std",
|
||||
"srml-system/std",
|
||||
|
||||
@@ -46,8 +46,6 @@ extern crate sr_primitives as runtime_primitives;
|
||||
extern crate srml_system as system;
|
||||
extern crate srml_consensus as consensus;
|
||||
extern crate parity_codec as codec;
|
||||
#[macro_use]
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
use codec::HasCompact;
|
||||
use runtime_support::{StorageValue, Parameter};
|
||||
@@ -136,7 +134,8 @@ impl<T: Trait> ProvideInherent for Module<T> {
|
||||
type Call = Call<T>;
|
||||
|
||||
fn create_inherent_extrinsics(data: Self::Inherent) -> Vec<(u32, Self::Call)> {
|
||||
vec![(T::TIMESTAMP_SET_POSITION, Call::set(data.into()))]
|
||||
let next_time = ::rstd::cmp::max(data, Self::now() + Self::block_period());
|
||||
vec![(T::TIMESTAMP_SET_POSITION, Call::set(next_time.into()))]
|
||||
}
|
||||
|
||||
fn check_inherent<Block: BlockT, F: Fn(&Block::Extrinsic) -> Option<&Self::Call>>(
|
||||
@@ -152,8 +151,11 @@ impl<T: Trait> ProvideInherent for Module<T> {
|
||||
_ => return Err(CheckInherentError::Other("No valid timestamp inherent in block".into())),
|
||||
}.into().as_();
|
||||
|
||||
let minimum = (Self::now() + Self::block_period()).as_();
|
||||
if t > data.as_() + MAX_TIMESTAMP_DRIFT {
|
||||
Err(CheckInherentError::TimestampInFuture(t))
|
||||
Err(CheckInherentError::Other("Timestamp too far in future to accept".into()))
|
||||
} else if t < minimum {
|
||||
Err(CheckInherentError::ValidAtTimestamp(minimum))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user