mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 01:01:04 +00:00
Check the genesis hash in transactions regardless of era. (#3286)
* Check the genesis hash in transactions regardless of era. * Fix check-fees, too. * Undo. * Subkey supports new signing. * Remove unneeded type param. * Bump tx version * Build. * Another build fix * Build again * Cleanup * Another fix. * Fix * Fixes * 6 second blocks. * Fixes * Build fix * Fix * Fix.
This commit is contained in:
@@ -35,9 +35,8 @@ use consensus::{
|
||||
SelectChain, self,
|
||||
};
|
||||
use sr_primitives::traits::{
|
||||
Block as BlockT, Header as HeaderT, Zero, NumberFor, CurrentHeight,
|
||||
BlockNumberToHash, ApiRef, ProvideRuntimeApi,
|
||||
SaturatedConversion, One, DigestFor,
|
||||
Block as BlockT, Header as HeaderT, Zero, NumberFor,
|
||||
ApiRef, ProvideRuntimeApi, SaturatedConversion, One, DigestFor,
|
||||
};
|
||||
use sr_primitives::generic::DigestItem;
|
||||
use sr_primitives::BuildStorage;
|
||||
@@ -1521,30 +1520,6 @@ impl<B, E, Block, RA> consensus::BlockImport<Block> for Client<B, E, Block, RA>
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, E, Block, RA> CurrentHeight for Client<B, E, Block, RA> where
|
||||
B: backend::Backend<Block, Blake2Hasher>,
|
||||
E: CallExecutor<Block, Blake2Hasher>,
|
||||
Block: BlockT<Hash=H256>,
|
||||
{
|
||||
type BlockNumber = <Block::Header as HeaderT>::Number;
|
||||
fn current_height(&self) -> Self::BlockNumber {
|
||||
self.backend.blockchain().info().best_number
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, E, Block, RA> BlockNumberToHash for Client<B, E, Block, RA> where
|
||||
B: backend::Backend<Block, Blake2Hasher>,
|
||||
E: CallExecutor<Block, Blake2Hasher>,
|
||||
Block: BlockT<Hash=H256>,
|
||||
{
|
||||
type BlockNumber = <Block::Header as HeaderT>::Number;
|
||||
type Hash = Block::Hash;
|
||||
fn block_number_to_hash(&self, n: Self::BlockNumber) -> Option<Self::Hash> {
|
||||
self.block_hash(n).unwrap_or(None)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<B, E, Block, RA> BlockchainEvents<Block> for Client<B, E, Block, RA>
|
||||
where
|
||||
E: CallExecutor<Block, Blake2Hasher>,
|
||||
@@ -2698,7 +2673,7 @@ pub(crate) mod tests {
|
||||
|
||||
let current_balance = ||
|
||||
client.runtime_api().balance_of(
|
||||
&BlockId::number(client.current_height()), AccountKeyring::Alice.into()
|
||||
&BlockId::number(client.info().chain.best_number), AccountKeyring::Alice.into()
|
||||
).unwrap();
|
||||
|
||||
// G -> A1 -> A2
|
||||
@@ -2745,7 +2720,7 @@ pub(crate) mod tests {
|
||||
|
||||
let current_balance = ||
|
||||
client.runtime_api().balance_of(
|
||||
&BlockId::number(client.current_height()), AccountKeyring::Alice.into()
|
||||
&BlockId::number(client.info().chain.best_number), AccountKeyring::Alice.into()
|
||||
).unwrap();
|
||||
|
||||
// G -> A1
|
||||
|
||||
@@ -35,7 +35,7 @@ use grandpa::{
|
||||
};
|
||||
use sr_primitives::generic::BlockId;
|
||||
use sr_primitives::traits::{
|
||||
Block as BlockT, Header as HeaderT, NumberFor, One, Zero, BlockNumberToHash,
|
||||
Block as BlockT, Header as HeaderT, NumberFor, One, Zero,
|
||||
};
|
||||
use primitives::{Blake2Hasher, ed25519, H256, Pair};
|
||||
use substrate_telemetry::{telemetry, CONSENSUS_INFO};
|
||||
@@ -962,10 +962,10 @@ pub(crate) fn canonical_at_height<B, E, Block: BlockT<Hash=H256>, RA>(
|
||||
if base_is_canonical {
|
||||
return Ok(Some(base.0));
|
||||
} else {
|
||||
return Ok(client.block_number_to_hash(height));
|
||||
return Ok(client.block_hash(height).unwrap_or(None));
|
||||
}
|
||||
} else if base_is_canonical {
|
||||
return Ok(client.block_number_to_hash(height));
|
||||
return Ok(client.block_hash(height).unwrap_or(None));
|
||||
}
|
||||
|
||||
let one = NumberFor::<Block>::one();
|
||||
|
||||
@@ -25,7 +25,7 @@ use crate::codec::{Decode, Encode, Input};
|
||||
use crate::traits::{self, Member, MaybeDisplay, SignedExtension, Checkable, Extrinsic};
|
||||
use super::CheckedExtrinsic;
|
||||
|
||||
const TRANSACTION_VERSION: u8 = 2;
|
||||
const TRANSACTION_VERSION: u8 = 3;
|
||||
|
||||
/// A extrinsic right from the external world. This is unchecked and so
|
||||
/// can contain a signature.
|
||||
@@ -205,7 +205,7 @@ mod tests {
|
||||
use super::*;
|
||||
use runtime_io::blake2_256;
|
||||
use crate::codec::{Encode, Decode};
|
||||
use crate::traits::{SignedExtension, BlockNumberToHash, Lookup, CurrentHeight};
|
||||
use crate::traits::{SignedExtension, Lookup};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
struct TestContext;
|
||||
@@ -214,15 +214,6 @@ mod tests {
|
||||
type Target = u64;
|
||||
fn lookup(&self, s: u64) -> Result<u64, &'static str> { Ok(s) }
|
||||
}
|
||||
impl CurrentHeight for TestContext {
|
||||
type BlockNumber = u64;
|
||||
fn current_height(&self) -> u64 { 42 }
|
||||
}
|
||||
impl BlockNumberToHash for TestContext {
|
||||
type BlockNumber = u64;
|
||||
type Hash = u64;
|
||||
fn block_number_to_hash(&self, n: u64) -> Option<u64> { Some(n) }
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize, Encode, Decode)]
|
||||
struct TestSig(u64, Vec<u8>);
|
||||
|
||||
@@ -122,32 +122,6 @@ impl<T> Lookup for IdentityLookup<T> {
|
||||
fn lookup(&self, x: T) -> result::Result<T, &'static str> { Ok(x) }
|
||||
}
|
||||
|
||||
/// Get the "current" block number.
|
||||
pub trait CurrentHeight {
|
||||
/// The type of the block number.
|
||||
type BlockNumber;
|
||||
|
||||
/// Return the current block number. Not allowed to fail.
|
||||
fn current_height(&self) -> Self::BlockNumber;
|
||||
}
|
||||
|
||||
/// Translate a block number into a hash.
|
||||
pub trait BlockNumberToHash {
|
||||
/// The type of the block number.
|
||||
type BlockNumber: Zero;
|
||||
|
||||
/// The type of the hash.
|
||||
type Hash: Encode;
|
||||
|
||||
/// Get the hash for a given block number, or `None` if unknown.
|
||||
fn block_number_to_hash(&self, n: Self::BlockNumber) -> Option<Self::Hash>;
|
||||
|
||||
/// Get the genesis block hash; this should always be known.
|
||||
fn genesis_hash(&self) -> Self::Hash {
|
||||
self.block_number_to_hash(Zero::zero()).expect("All blockchains must know their genesis block hash; qed")
|
||||
}
|
||||
}
|
||||
|
||||
/// Extensible conversion trait. Generic over both source and destination types.
|
||||
pub trait Convert<A, B> {
|
||||
/// Make conversion.
|
||||
|
||||
Reference in New Issue
Block a user