Address grumbles in eras PR (#782)

* Address grumbles

* Fix hash
This commit is contained in:
Gav Wood
2018-09-20 23:18:47 +02:00
committed by GitHub
parent 67bf1a6eaa
commit ebb688f81f
10 changed files with 42 additions and 35 deletions
+2 -2
View File
@@ -33,7 +33,7 @@ use client::{Client, CallExecutor};
use primitives::{
AccountId, Block, BlockId, BlockNumber, Hash, Index, InherentData, SessionKey, Timestamp, UncheckedExtrinsic
};
use sr_primitives::{transaction_validity::TransactionValidity, traits::{GetHeight, BlockNumberToHash}};
use sr_primitives::{transaction_validity::TransactionValidity, traits::{CurrentHeight, BlockNumberToHash}};
use substrate_primitives::{Blake2Hasher, RlpCodec};
/// Build new blocks.
@@ -48,7 +48,7 @@ pub trait BlockBuilder {
/// Trait encapsulating the node API.
///
/// All calls should fail when the exact runtime is unknown.
pub trait Api: GetHeight<BlockNumber=BlockNumber> + BlockNumberToHash<BlockNumber=BlockNumber,Hash=Hash> {
pub trait Api: CurrentHeight<BlockNumber=BlockNumber> + BlockNumberToHash<BlockNumber=BlockNumber,Hash=Hash> {
/// The block builder for this API type.
type BlockBuilder: BlockBuilder;
+1 -1
View File
@@ -401,7 +401,7 @@ impl<C> bft::Proposer<Block> for Proposer<C>
=> MisbehaviorKind::BftDoubleCommit(round as u32, (h1, s1.signature), (h2, s2.signature)),
}
};
let payload = (next_index, Call::Consensus(ConsensusCall::report_misbehavior(report)), self.client.genesis_hash());
let payload = (next_index, Call::Consensus(ConsensusCall::report_misbehavior(report)), Era::immortal(), self.client.genesis_hash());
let signature = self.local_key.sign(&payload.encode()).into();
next_index += 1;
+4 -3
View File
@@ -83,11 +83,12 @@ mod tests {
fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
match xt.signed {
Some((signed, index)) => {
let payload = (index, xt.function, GENESIS_HASH);
let era = Era::mortal(256, 0);
let payload = (index, xt.function, era, GENESIS_HASH);
let pair = Pair::from(Keyring::from_public(Public::from_raw(signed.clone().into())).unwrap());
let signature = pair.sign(&payload.encode()).into();
UncheckedExtrinsic {
signature: Some((balances::address::Address::Id(signed), signature, payload.0, Era::mortal(256, 0))),
signature: Some((balances::address::Address::Id(signed), signature, payload.0, era)),
function: payload.1,
}
}
@@ -309,7 +310,7 @@ mod tests {
construct_block(
2,
block1(false).1,
hex!("60efe1a65e7c79041b02e56ec122d6eaedfa476e0a9f6f1f68eb0c8f402c4514").into(),
hex!("0acf8b3c169ce8f16faf5610f646f371681dcc3b544d3dd05036dbae7890e399").into(),
None,
vec![
CheckedExtrinsic {
+5 -5
View File
@@ -46,7 +46,7 @@ use transaction_pool::{Readiness, scoring::{Change, Choice}, VerifiedFor, Extrin
use node_api::Api;
use primitives::{AccountId, BlockId, Block, Hash, Index, BlockNumber};
use runtime::{Address, UncheckedExtrinsic};
use sr_primitives::traits::{Bounded, Checkable, Hash as HashT, BlakeTwo256, Lookup, GetHeight, BlockNumberToHash};
use sr_primitives::traits::{Bounded, Checkable, Hash as HashT, BlakeTwo256, Lookup, CurrentHeight, BlockNumberToHash};
pub use transaction_pool::{Options, Status, LightStatus, VerifiedTransaction as VerifiedTransactionOps};
pub use error::{Error, ErrorKind, Result};
@@ -123,10 +123,10 @@ impl<A> ChainApi<A> where
///
/// This is due for removal when #721 lands
pub struct LocalContext<'a, A: 'a>(&'a Arc<A>);
impl<'a, A: 'a + Api> GetHeight for LocalContext<'a, A> {
impl<'a, A: 'a + Api> CurrentHeight for LocalContext<'a, A> {
type BlockNumber = BlockNumber;
fn get_height(&self) -> BlockNumber {
self.0.get_height()
fn current_height(&self) -> BlockNumber {
self.0.current_height()
}
}
impl<'a, A: 'a + Api> BlockNumberToHash for LocalContext<'a, A> {
@@ -140,7 +140,7 @@ impl<'a, A: 'a + Api> Lookup for LocalContext<'a, A> {
type Source = Address;
type Target = AccountId;
fn lookup(&self, a: Address) -> ::std::result::Result<AccountId, &'static str> {
self.0.lookup(&BlockId::number(self.get_height()), a).unwrap_or(None).ok_or("error with lookup")
self.0.lookup(&BlockId::number(self.current_height()), a).unwrap_or(None).ok_or("error with lookup")
}
}