mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 14:57:56 +00:00
Rename Ethereum Headers to AuraHeader (#354)
* Rename Header to AuraHeader This prevents some type conflicts with the PolkadotJS Apps types. * Fix test and benchmark builds * Update AuraHeader in types.json
This commit is contained in:
committed by
Bastian Köcher
parent
750a369273
commit
5163f62df4
@@ -16,7 +16,7 @@
|
||||
|
||||
use crate::exchange::EthereumTransactionInclusionProof;
|
||||
|
||||
use bp_eth_poa::{Address, Header, RawTransaction, U256};
|
||||
use bp_eth_poa::{Address, AuraHeader, RawTransaction, U256};
|
||||
use bp_header_chain::BaseHeaderChain;
|
||||
use frame_support::RuntimeDebug;
|
||||
use hex_literal::hex;
|
||||
@@ -95,8 +95,8 @@ pub fn genesis_validators() -> Vec<Address> {
|
||||
}
|
||||
|
||||
/// Genesis header of the Kovan chain.
|
||||
pub fn genesis_header() -> Header {
|
||||
Header {
|
||||
pub fn genesis_header() -> AuraHeader {
|
||||
AuraHeader {
|
||||
parent_hash: Default::default(),
|
||||
timestamp: 0,
|
||||
number: 0,
|
||||
|
||||
@@ -526,7 +526,7 @@ impl_runtime_apis! {
|
||||
(finalized_block.number, finalized_block.hash)
|
||||
}
|
||||
|
||||
fn is_import_requires_receipts(header: bp_eth_poa::Header) -> bool {
|
||||
fn is_import_requires_receipts(header: bp_eth_poa::AuraHeader) -> bool {
|
||||
BridgeRialto::is_import_requires_receipts(header)
|
||||
}
|
||||
|
||||
@@ -546,7 +546,7 @@ impl_runtime_apis! {
|
||||
(finalized_block.number, finalized_block.hash)
|
||||
}
|
||||
|
||||
fn is_import_requires_receipts(header: bp_eth_poa::Header) -> bool {
|
||||
fn is_import_requires_receipts(header: bp_eth_poa::AuraHeader) -> bool {
|
||||
BridgeKovan::is_import_requires_receipts(header)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use crate::exchange::EthereumTransactionInclusionProof;
|
||||
|
||||
use bp_eth_poa::{Address, Header, RawTransaction, U256};
|
||||
use bp_eth_poa::{Address, AuraHeader, RawTransaction, U256};
|
||||
use bp_header_chain::BaseHeaderChain;
|
||||
use frame_support::RuntimeDebug;
|
||||
use hex_literal::hex;
|
||||
@@ -70,8 +70,8 @@ pub fn genesis_validators() -> Vec<Address> {
|
||||
/// ```bash
|
||||
/// $ http localhost:8545 jsonrpc=2.0 id=1 method=eth_getBlockByNumber params:='["earliest", false]' -v
|
||||
/// ```
|
||||
pub fn genesis_header() -> Header {
|
||||
Header {
|
||||
pub fn genesis_header() -> AuraHeader {
|
||||
AuraHeader {
|
||||
parent_hash: Default::default(),
|
||||
timestamp: 0,
|
||||
number: 0,
|
||||
|
||||
@@ -218,7 +218,7 @@ benchmarks_instance! {
|
||||
}
|
||||
}
|
||||
|
||||
fn initialize_bench<T: Trait<I>, I: Instance>(num_validators: usize) -> Header {
|
||||
fn initialize_bench<T: Trait<I>, I: Instance>(num_validators: usize) -> AuraHeader {
|
||||
// Initialize storage with some initial header
|
||||
let initial_header = build_genesis_header(&validator(0));
|
||||
let initial_difficulty = initial_header.difficulty;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::Storage;
|
||||
use bp_eth_poa::{public_to_address, Address, Header, HeaderId, SealedEmptyStep, H256};
|
||||
use bp_eth_poa::{public_to_address, Address, AuraHeader, HeaderId, SealedEmptyStep, H256};
|
||||
use codec::{Decode, Encode};
|
||||
use sp_io::crypto::secp256k1_ecdsa_recover;
|
||||
use sp_runtime::RuntimeDebug;
|
||||
@@ -37,7 +37,7 @@ pub struct CachedFinalityVotes<Submitter> {
|
||||
pub stopped_at_finalized_sibling: bool,
|
||||
/// Header ancestors that were read while we have been searching for
|
||||
/// cached votes entry. Newest header has index 0.
|
||||
pub unaccounted_ancestry: VecDeque<(HeaderId, Option<Submitter>, Header)>,
|
||||
pub unaccounted_ancestry: VecDeque<(HeaderId, Option<Submitter>, AuraHeader)>,
|
||||
/// Cached finality votes, if they have been found. The associated
|
||||
/// header is not included into `unaccounted_ancestry`.
|
||||
pub votes: Option<FinalityVotes<Submitter>>,
|
||||
@@ -86,7 +86,7 @@ pub fn finalize_blocks<S: Storage>(
|
||||
header_validators: (HeaderId, &[Address]),
|
||||
id: HeaderId,
|
||||
submitter: Option<&S::Submitter>,
|
||||
header: &Header,
|
||||
header: &AuraHeader,
|
||||
two_thirds_majority_transition: u64,
|
||||
) -> Result<FinalityEffects<S::Submitter>, Error> {
|
||||
// compute count of voters for every unfinalized block in ancestry
|
||||
@@ -145,7 +145,7 @@ fn prepare_votes<Submitter>(
|
||||
best_finalized: HeaderId,
|
||||
validators: &BTreeSet<&Address>,
|
||||
id: HeaderId,
|
||||
header: &Header,
|
||||
header: &AuraHeader,
|
||||
submitter: Option<Submitter>,
|
||||
) -> Result<FinalityVotes<Submitter>, Error> {
|
||||
// if we have reached finalized block sibling, then we're trying
|
||||
@@ -243,7 +243,7 @@ fn remove_signers_votes(signers_to_remove: &BTreeSet<Address>, votes: &mut BTree
|
||||
}
|
||||
|
||||
/// Returns unique set of empty steps signers.
|
||||
fn empty_steps_signers(header: &Header) -> BTreeSet<Address> {
|
||||
fn empty_steps_signers(header: &AuraHeader) -> BTreeSet<Address> {
|
||||
header
|
||||
.empty_steps()
|
||||
.into_iter()
|
||||
@@ -298,7 +298,7 @@ mod tests {
|
||||
(Default::default(), &[]),
|
||||
Default::default(),
|
||||
None,
|
||||
&Header::default(),
|
||||
&AuraHeader::default(),
|
||||
0,
|
||||
),
|
||||
Err(Error::NotValidator),
|
||||
|
||||
@@ -19,7 +19,7 @@ use crate::finality::finalize_blocks;
|
||||
use crate::validators::{Validators, ValidatorsConfiguration};
|
||||
use crate::verification::{is_importable_header, verify_aura_header};
|
||||
use crate::{AuraConfiguration, ChangeToEnact, PruningStrategy, Storage};
|
||||
use bp_eth_poa::{Header, HeaderId, Receipt};
|
||||
use bp_eth_poa::{AuraHeader, HeaderId, Receipt};
|
||||
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
|
||||
|
||||
/// Imports bunch of headers and updates blocks finality.
|
||||
@@ -37,7 +37,7 @@ pub fn import_headers<S: Storage, PS: PruningStrategy>(
|
||||
aura_config: &AuraConfiguration,
|
||||
validators_config: &ValidatorsConfiguration,
|
||||
submitter: Option<S::Submitter>,
|
||||
headers: Vec<(Header, Option<Vec<Receipt>>)>,
|
||||
headers: Vec<(AuraHeader, Option<Vec<Receipt>>)>,
|
||||
finalized_headers: &mut BTreeMap<S::Submitter, u64>,
|
||||
) -> Result<(u64, u64), Error> {
|
||||
let mut useful = 0;
|
||||
@@ -85,7 +85,7 @@ pub fn import_header<S: Storage, PS: PruningStrategy>(
|
||||
aura_config: &AuraConfiguration,
|
||||
validators_config: &ValidatorsConfiguration,
|
||||
submitter: Option<S::Submitter>,
|
||||
header: Header,
|
||||
header: AuraHeader,
|
||||
receipts: Option<Vec<Receipt>>,
|
||||
) -> Result<(HeaderId, FinalizedHeaders<S>), Error> {
|
||||
// first check that we are able to import this header at all
|
||||
@@ -153,7 +153,7 @@ pub fn import_header<S: Storage, PS: PruningStrategy>(
|
||||
pub fn header_import_requires_receipts<S: Storage>(
|
||||
storage: &S,
|
||||
validators_config: &ValidatorsConfiguration,
|
||||
header: &Header,
|
||||
header: &AuraHeader,
|
||||
) -> bool {
|
||||
is_importable_header(storage, header)
|
||||
.map(|_| Validators::new(validators_config))
|
||||
@@ -391,7 +391,7 @@ mod tests {
|
||||
fn import_custom_block<S: Storage>(
|
||||
storage: &mut S,
|
||||
validators: &[SecretKey],
|
||||
header: Header,
|
||||
header: AuraHeader,
|
||||
) -> Result<HeaderId, Error> {
|
||||
let id = header.compute_id();
|
||||
import_header(
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#![allow(clippy::large_enum_variant)]
|
||||
|
||||
use crate::finality::{CachedFinalityVotes, FinalityVotes};
|
||||
use bp_eth_poa::{Address, Header, HeaderId, RawTransaction, RawTransactionReceipt, Receipt, H256, U256};
|
||||
use bp_eth_poa::{Address, AuraHeader, HeaderId, RawTransaction, RawTransactionReceipt, Receipt, H256, U256};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{decl_module, decl_storage, traits::Get};
|
||||
use sp_runtime::{
|
||||
@@ -91,7 +91,7 @@ pub struct StoredHeader<Submitter> {
|
||||
/// using unsigned transaction.
|
||||
pub submitter: Option<Submitter>,
|
||||
/// The block header itself.
|
||||
pub header: Header,
|
||||
pub header: AuraHeader,
|
||||
/// Total difficulty of the chain.
|
||||
pub total_difficulty: U256,
|
||||
/// The ID of set of validators that is expected to produce direct descendants of
|
||||
@@ -138,7 +138,7 @@ pub struct HeaderToImport<Submitter> {
|
||||
/// The id of the header.
|
||||
pub id: HeaderId,
|
||||
/// The header itself.
|
||||
pub header: Header,
|
||||
pub header: AuraHeader,
|
||||
/// Total chain difficulty at the header.
|
||||
pub total_difficulty: U256,
|
||||
/// New validators set and the hash of block where it has been scheduled (if applicable).
|
||||
@@ -185,7 +185,7 @@ struct PruningRange {
|
||||
pub struct ImportContext<Submitter> {
|
||||
submitter: Option<Submitter>,
|
||||
parent_hash: H256,
|
||||
parent_header: Header,
|
||||
parent_header: AuraHeader,
|
||||
parent_total_difficulty: U256,
|
||||
parent_scheduled_change: Option<ScheduledChange>,
|
||||
validators_set_id: u64,
|
||||
@@ -200,7 +200,7 @@ impl<Submitter> ImportContext<Submitter> {
|
||||
}
|
||||
|
||||
/// Returns reference to parent header.
|
||||
pub fn parent_header(&self) -> &Header {
|
||||
pub fn parent_header(&self) -> &AuraHeader {
|
||||
&self.parent_header
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ impl<Submitter> ImportContext<Submitter> {
|
||||
self,
|
||||
is_best: bool,
|
||||
id: HeaderId,
|
||||
header: Header,
|
||||
header: AuraHeader,
|
||||
total_difficulty: U256,
|
||||
enacted_change: Option<ChangeToEnact>,
|
||||
scheduled_change: Option<Vec<Address>>,
|
||||
@@ -275,7 +275,7 @@ pub trait Storage {
|
||||
/// Get imported header by its hash.
|
||||
///
|
||||
/// Returns header and its submitter (if known).
|
||||
fn header(&self, hash: &H256) -> Option<(Header, Option<Self::Submitter>)>;
|
||||
fn header(&self, hash: &H256) -> Option<(AuraHeader, Option<Self::Submitter>)>;
|
||||
/// Returns latest cached finality votes (if any) for block ancestors, starting
|
||||
/// from `parent_hash` block and stopping at genesis block, best finalized block
|
||||
/// or block where `stop_at` returns true.
|
||||
@@ -375,7 +375,7 @@ decl_module! {
|
||||
pub struct Module<T: Trait<I>, I: Instance = DefaultInstance> for enum Call where origin: T::Origin {
|
||||
/// Import single Aura header. Requires transaction to be **UNSIGNED**.
|
||||
#[weight = 0] // TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
|
||||
pub fn import_unsigned_header(origin, header: Header, receipts: Option<Vec<Receipt>>) {
|
||||
pub fn import_unsigned_header(origin, header: AuraHeader, receipts: Option<Vec<Receipt>>) {
|
||||
frame_system::ensure_none(origin)?;
|
||||
|
||||
import::import_header(
|
||||
@@ -396,7 +396,7 @@ decl_module! {
|
||||
/// This should be used with caution - passing too many headers could lead to
|
||||
/// enormous block production/import time.
|
||||
#[weight = 0] // TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
|
||||
pub fn import_signed_headers(origin, headers_with_receipts: Vec<(Header, Option<Vec<Receipt>>)>) {
|
||||
pub fn import_signed_headers(origin, headers_with_receipts: Vec<(AuraHeader, Option<Vec<Receipt>>)>) {
|
||||
let submitter = frame_system::ensure_signed(origin)?;
|
||||
let mut finalized_headers = BTreeMap::new();
|
||||
let import_result = import::import_headers(
|
||||
@@ -459,7 +459,7 @@ decl_storage! {
|
||||
ScheduledChanges: map hasher(identity) H256 => Option<ScheduledChange>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(initial_header): Header;
|
||||
config(initial_header): AuraHeader;
|
||||
config(initial_difficulty): U256;
|
||||
config(initial_validators): Vec<Address>;
|
||||
build(|config| {
|
||||
@@ -496,7 +496,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
|
||||
}
|
||||
|
||||
/// Returns true if the import of given block requires transactions receipts.
|
||||
pub fn is_import_requires_receipts(header: Header) -> bool {
|
||||
pub fn is_import_requires_receipts(header: AuraHeader) -> bool {
|
||||
import::header_import_requires_receipts(
|
||||
&BridgeStorage::<T, I>::new(),
|
||||
&T::ValidatorsConfiguration::get(),
|
||||
@@ -670,7 +670,7 @@ impl<T: Trait<I>, I: Instance> Storage for BridgeStorage<T, I> {
|
||||
FinalizedBlock::<I>::get()
|
||||
}
|
||||
|
||||
fn header(&self, hash: &H256) -> Option<(Header, Option<Self::Submitter>)> {
|
||||
fn header(&self, hash: &H256) -> Option<(AuraHeader, Option<Self::Submitter>)> {
|
||||
Headers::<T, I>::get(hash).map(|header| (header.header, header.submitter))
|
||||
}
|
||||
|
||||
@@ -840,7 +840,7 @@ impl<T: Trait<I>, I: Instance> Storage for BridgeStorage<T, I> {
|
||||
/// Initialize storage.
|
||||
#[cfg(any(feature = "std", feature = "runtime-benchmarks"))]
|
||||
pub(crate) fn initialize_storage<T: Trait<I>, I: Instance>(
|
||||
initial_header: &Header,
|
||||
initial_header: &AuraHeader,
|
||||
initial_difficulty: U256,
|
||||
initial_validators: &[Address],
|
||||
) {
|
||||
@@ -1004,7 +1004,7 @@ fn pool_configuration() -> PoolConfiguration {
|
||||
}
|
||||
|
||||
/// Return iterator of given header ancestors.
|
||||
fn ancestry<'a, S: Storage>(storage: &'a S, mut parent_hash: H256) -> impl Iterator<Item = (H256, Header)> + 'a {
|
||||
fn ancestry<'a, S: Storage>(storage: &'a S, mut parent_hash: H256) -> impl Iterator<Item = (H256, AuraHeader)> + 'a {
|
||||
sp_std::iter::from_fn(move || {
|
||||
let (header, _) = storage.header(&parent_hash)?;
|
||||
if header.number == 0 {
|
||||
@@ -1044,8 +1044,8 @@ pub(crate) mod tests {
|
||||
.rlp()
|
||||
}
|
||||
|
||||
fn example_header_with_failed_receipt() -> Header {
|
||||
let mut header = Header::default();
|
||||
fn example_header_with_failed_receipt() -> AuraHeader {
|
||||
let mut header = AuraHeader::default();
|
||||
header.number = 3;
|
||||
header.transactions_root = compute_merkle_root(vec![example_tx()].into_iter());
|
||||
header.receipts_root = compute_merkle_root(vec![example_tx_receipt(false)].into_iter());
|
||||
@@ -1053,8 +1053,8 @@ pub(crate) mod tests {
|
||||
header
|
||||
}
|
||||
|
||||
fn example_header() -> Header {
|
||||
let mut header = Header::default();
|
||||
fn example_header() -> AuraHeader {
|
||||
let mut header = AuraHeader::default();
|
||||
header.number = 2;
|
||||
header.transactions_root = compute_merkle_root(vec![example_tx()].into_iter());
|
||||
header.receipts_root = compute_merkle_root(vec![example_tx_receipt(true)].into_iter());
|
||||
@@ -1062,8 +1062,8 @@ pub(crate) mod tests {
|
||||
header
|
||||
}
|
||||
|
||||
fn example_header_parent() -> Header {
|
||||
let mut header = Header::default();
|
||||
fn example_header_parent() -> AuraHeader {
|
||||
let mut header = AuraHeader::default();
|
||||
header.number = 1;
|
||||
header.transactions_root = compute_merkle_root(vec![example_tx()].into_iter());
|
||||
header.receipts_root = compute_merkle_root(vec![example_tx_receipt(true)].into_iter());
|
||||
|
||||
@@ -19,7 +19,7 @@ pub use bp_eth_poa::signatures::secret_to_address;
|
||||
|
||||
use crate::validators::{ValidatorsConfiguration, ValidatorsSource};
|
||||
use crate::{AuraConfiguration, GenesisConfig, PruningStrategy, Trait};
|
||||
use bp_eth_poa::{Address, Header, H256, U256};
|
||||
use bp_eth_poa::{Address, AuraHeader, H256, U256};
|
||||
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
|
||||
use secp256k1::SecretKey;
|
||||
use sp_runtime::{
|
||||
@@ -89,7 +89,7 @@ impl Trait for TestRuntime {
|
||||
/// Test context.
|
||||
pub struct TestContext {
|
||||
/// Initial (genesis) header.
|
||||
pub genesis: Header,
|
||||
pub genesis: AuraHeader,
|
||||
/// Number of initial validators.
|
||||
pub total_validators: usize,
|
||||
/// Secret keys of validators, ordered by validator index.
|
||||
@@ -118,7 +118,7 @@ pub fn test_validators_config() -> ValidatorsConfiguration {
|
||||
}
|
||||
|
||||
/// Genesis header that is used in tests by default.
|
||||
pub fn genesis() -> Header {
|
||||
pub fn genesis() -> AuraHeader {
|
||||
HeaderBuilder::genesis().sign_by(&validator(0))
|
||||
}
|
||||
|
||||
@@ -128,7 +128,11 @@ pub fn run_test<T>(total_validators: usize, test: impl FnOnce(TestContext) -> T)
|
||||
}
|
||||
|
||||
/// Run test with default genesis header.
|
||||
pub fn run_test_with_genesis<T>(genesis: Header, total_validators: usize, test: impl FnOnce(TestContext) -> T) -> T {
|
||||
pub fn run_test_with_genesis<T>(
|
||||
genesis: AuraHeader,
|
||||
total_validators: usize,
|
||||
test: impl FnOnce(TestContext) -> T,
|
||||
) -> T {
|
||||
let validators = validators(total_validators);
|
||||
let addresses = validators_addresses(total_validators);
|
||||
sp_io::TestExternalities::new(
|
||||
|
||||
@@ -32,7 +32,7 @@ use crate::{HeaderToImport, Storage, Trait};
|
||||
use bp_eth_poa::{
|
||||
rlp_encode,
|
||||
signatures::{secret_to_address, sign, SignHeader},
|
||||
Address, Bloom, Header, Receipt, SealedEmptyStep, H256, U256,
|
||||
Address, AuraHeader, Bloom, Receipt, SealedEmptyStep, H256, U256,
|
||||
};
|
||||
use secp256k1::SecretKey;
|
||||
use sp_std::prelude::*;
|
||||
@@ -42,8 +42,8 @@ pub const GAS_LIMIT: u64 = 0x2000;
|
||||
|
||||
/// Test header builder.
|
||||
pub struct HeaderBuilder {
|
||||
header: Header,
|
||||
parent_header: Header,
|
||||
header: AuraHeader,
|
||||
parent_header: AuraHeader,
|
||||
}
|
||||
|
||||
impl HeaderBuilder {
|
||||
@@ -51,7 +51,7 @@ impl HeaderBuilder {
|
||||
pub fn genesis() -> Self {
|
||||
let current_step = 0u64;
|
||||
Self {
|
||||
header: Header {
|
||||
header: AuraHeader {
|
||||
gas_limit: GAS_LIMIT.into(),
|
||||
seal: vec![bp_eth_poa::rlp_encode(¤t_step), vec![]],
|
||||
..Default::default()
|
||||
@@ -93,7 +93,7 @@ impl HeaderBuilder {
|
||||
/// Creates default header on top of non-existent parent.
|
||||
#[cfg(test)]
|
||||
pub fn with_number(number: u64) -> Self {
|
||||
Self::with_parent(&Header {
|
||||
Self::with_parent(&AuraHeader {
|
||||
number: number - 1,
|
||||
seal: vec![bp_eth_poa::rlp_encode(&(number - 1)), vec![]],
|
||||
..Default::default()
|
||||
@@ -101,11 +101,11 @@ impl HeaderBuilder {
|
||||
}
|
||||
|
||||
/// Creates default header on top of given parent.
|
||||
pub fn with_parent(parent_header: &Header) -> Self {
|
||||
pub fn with_parent(parent_header: &AuraHeader) -> Self {
|
||||
let parent_step = parent_header.step().unwrap();
|
||||
let current_step = parent_step + 1;
|
||||
Self {
|
||||
header: Header {
|
||||
header: AuraHeader {
|
||||
parent_hash: parent_header.compute_hash(),
|
||||
number: parent_header.number + 1,
|
||||
gas_limit: GAS_LIMIT.into(),
|
||||
@@ -201,26 +201,26 @@ impl HeaderBuilder {
|
||||
}
|
||||
|
||||
/// Signs header by given author.
|
||||
pub fn sign_by(self, author: &SecretKey) -> Header {
|
||||
pub fn sign_by(self, author: &SecretKey) -> AuraHeader {
|
||||
self.header.sign_by(author)
|
||||
}
|
||||
|
||||
/// Signs header by given authors set.
|
||||
pub fn sign_by_set(self, authors: &[SecretKey]) -> Header {
|
||||
pub fn sign_by_set(self, authors: &[SecretKey]) -> AuraHeader {
|
||||
self.header.sign_by_set(authors)
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function for getting a genesis header which has been signed by an authority.
|
||||
pub fn build_genesis_header(author: &SecretKey) -> Header {
|
||||
pub fn build_genesis_header(author: &SecretKey) -> AuraHeader {
|
||||
let genesis = HeaderBuilder::genesis();
|
||||
genesis.header.sign_by(&author)
|
||||
}
|
||||
|
||||
/// Helper function for building a custom child header which has been signed by an authority.
|
||||
pub fn build_custom_header<F>(author: &SecretKey, previous: &Header, customize_header: F) -> Header
|
||||
pub fn build_custom_header<F>(author: &SecretKey, previous: &AuraHeader, customize_header: F) -> AuraHeader
|
||||
where
|
||||
F: FnOnce(Header) -> Header,
|
||||
F: FnOnce(AuraHeader) -> AuraHeader,
|
||||
{
|
||||
let new_header = HeaderBuilder::with_parent(&previous);
|
||||
let custom_header = customize_header(new_header.header);
|
||||
@@ -228,7 +228,7 @@ where
|
||||
}
|
||||
|
||||
/// Insert unverified header into storage.
|
||||
pub fn insert_header<S: Storage>(storage: &mut S, header: Header) {
|
||||
pub fn insert_header<S: Storage>(storage: &mut S, header: AuraHeader) {
|
||||
storage.insert_header(HeaderToImport {
|
||||
context: storage.import_context(None, &header.parent_hash).unwrap(),
|
||||
is_best: true,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::{ChangeToEnact, Storage};
|
||||
use bp_eth_poa::{Address, Header, HeaderId, LogEntry, Receipt, U256};
|
||||
use bp_eth_poa::{Address, AuraHeader, HeaderId, LogEntry, Receipt, U256};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// The hash of InitiateChange event of the validators set contract.
|
||||
@@ -65,7 +65,7 @@ impl<'a> Validators<'a> {
|
||||
|
||||
/// Returns true if header (probabilistically) signals validators change and
|
||||
/// the caller needs to provide transactions receipts to import the header.
|
||||
pub fn maybe_signals_validators_change(&self, header: &Header) -> bool {
|
||||
pub fn maybe_signals_validators_change(&self, header: &AuraHeader) -> bool {
|
||||
let (_, _, source) = self.source_at(header.number);
|
||||
|
||||
// if we are taking validators set from the fixed list, there's always
|
||||
@@ -95,7 +95,7 @@ impl<'a> Validators<'a> {
|
||||
/// current block). The second element is the immediately applied change.
|
||||
pub fn extract_validators_change(
|
||||
&self,
|
||||
header: &Header,
|
||||
header: &AuraHeader,
|
||||
receipts: Option<Vec<Receipt>>,
|
||||
) -> Result<(ValidatorsChange, ValidatorsChange), Error> {
|
||||
// let's first check if new source is starting from this header
|
||||
@@ -325,7 +325,7 @@ pub(crate) mod tests {
|
||||
// when contract is active, but bloom has no required bits set
|
||||
let config = ValidatorsConfiguration::Single(ValidatorsSource::Contract(Default::default(), Vec::new()));
|
||||
let validators = Validators::new(&config);
|
||||
let mut header = Header::default();
|
||||
let mut header = AuraHeader::default();
|
||||
header.number = u64::max_value();
|
||||
assert!(!validators.maybe_signals_validators_change(&header));
|
||||
|
||||
@@ -347,7 +347,7 @@ pub(crate) mod tests {
|
||||
(200, ValidatorsSource::Contract([3; 20].into(), vec![[3; 20].into()])),
|
||||
]);
|
||||
let validators = Validators::new(&config);
|
||||
let mut header = Header::default();
|
||||
let mut header = AuraHeader::default();
|
||||
|
||||
// when we're at the block that switches to list source
|
||||
header.number = 100;
|
||||
@@ -420,7 +420,7 @@ pub(crate) mod tests {
|
||||
let finalized_blocks = vec![(id10, None), (id100, None)];
|
||||
let header100 = StoredHeader::<u64> {
|
||||
submitter: None,
|
||||
header: Header {
|
||||
header: AuraHeader {
|
||||
number: 100,
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::error::Error;
|
||||
use crate::validators::{Validators, ValidatorsConfiguration};
|
||||
use crate::{AuraConfiguration, ImportContext, PoolConfiguration, ScheduledChange, Storage};
|
||||
use bp_eth_poa::{
|
||||
public_to_address, step_validator, Address, Header, HeaderId, Receipt, SealedEmptyStep, H256, H520, U128, U256,
|
||||
public_to_address, step_validator, Address, AuraHeader, HeaderId, Receipt, SealedEmptyStep, H256, H520, U128, U256,
|
||||
};
|
||||
use codec::Encode;
|
||||
use sp_io::crypto::secp256k1_ecdsa_recover;
|
||||
@@ -28,7 +28,7 @@ use sp_std::{vec, vec::Vec};
|
||||
/// Pre-check to see if should try and import this header.
|
||||
/// Returns error if we should not try to import this block.
|
||||
/// Returns ID of passed header and best finalized header.
|
||||
pub fn is_importable_header<S: Storage>(storage: &S, header: &Header) -> Result<(HeaderId, HeaderId), Error> {
|
||||
pub fn is_importable_header<S: Storage>(storage: &S, header: &AuraHeader) -> Result<(HeaderId, HeaderId), Error> {
|
||||
// we never import any header that competes with finalized header
|
||||
let finalized_id = storage.finalized_block();
|
||||
if header.number <= finalized_id.number {
|
||||
@@ -51,7 +51,7 @@ pub fn accept_aura_header_into_pool<S: Storage>(
|
||||
config: &AuraConfiguration,
|
||||
validators_config: &ValidatorsConfiguration,
|
||||
pool_config: &PoolConfiguration,
|
||||
header: &Header,
|
||||
header: &AuraHeader,
|
||||
receipts: Option<&Vec<Receipt>>,
|
||||
) -> Result<(Vec<TransactionTag>, Vec<TransactionTag>), Error> {
|
||||
// check if we can verify further
|
||||
@@ -157,7 +157,7 @@ pub fn verify_aura_header<S: Storage>(
|
||||
storage: &S,
|
||||
config: &AuraConfiguration,
|
||||
submitter: Option<S::Submitter>,
|
||||
header: &Header,
|
||||
header: &AuraHeader,
|
||||
) -> Result<ImportContext<S::Submitter>, Error> {
|
||||
// let's do the lightest check first
|
||||
contextless_checks(config, header)?;
|
||||
@@ -180,7 +180,7 @@ pub fn verify_aura_header<S: Storage>(
|
||||
}
|
||||
|
||||
/// Perform basic checks that only require header itself.
|
||||
fn contextless_checks(config: &AuraConfiguration, header: &Header) -> Result<(), Error> {
|
||||
fn contextless_checks(config: &AuraConfiguration, header: &AuraHeader) -> Result<(), Error> {
|
||||
let expected_seal_fields = expected_header_seal_fields(config, header);
|
||||
if header.seal.len() != expected_seal_fields {
|
||||
return Err(Error::InvalidSealArity);
|
||||
@@ -215,7 +215,7 @@ fn contextual_checks<Submitter>(
|
||||
config: &AuraConfiguration,
|
||||
context: &ImportContext<Submitter>,
|
||||
validators_override: Option<&[Address]>,
|
||||
header: &Header,
|
||||
header: &AuraHeader,
|
||||
) -> Result<u64, Error> {
|
||||
let validators = validators_override.unwrap_or_else(|| &context.validators_set().validators);
|
||||
let header_step = header.step().ok_or(Error::MissingStep)?;
|
||||
@@ -273,7 +273,7 @@ fn contextual_checks<Submitter>(
|
||||
fn validator_checks(
|
||||
config: &AuraConfiguration,
|
||||
validators: &[Address],
|
||||
header: &Header,
|
||||
header: &AuraHeader,
|
||||
header_step: u64,
|
||||
) -> Result<(), Error> {
|
||||
let expected_validator = *step_validator(validators, header_step);
|
||||
@@ -294,7 +294,7 @@ fn validator_checks(
|
||||
}
|
||||
|
||||
/// Returns expected number of seal fields in the header.
|
||||
fn expected_header_seal_fields(config: &AuraConfiguration, header: &Header) -> usize {
|
||||
fn expected_header_seal_fields(config: &AuraConfiguration, header: &AuraHeader) -> usize {
|
||||
if header.number != u64::max_value() && header.number >= config.empty_steps_transition {
|
||||
3
|
||||
} else {
|
||||
@@ -374,23 +374,23 @@ mod tests {
|
||||
const GENESIS_STEP: u64 = 42;
|
||||
const TOTAL_VALIDATORS: usize = 3;
|
||||
|
||||
fn genesis() -> Header {
|
||||
fn genesis() -> AuraHeader {
|
||||
HeaderBuilder::genesis().step(GENESIS_STEP).sign_by(&validator(0))
|
||||
}
|
||||
|
||||
fn verify_with_config(config: &AuraConfiguration, header: &Header) -> Result<ImportContext<AccountId>, Error> {
|
||||
fn verify_with_config(config: &AuraConfiguration, header: &AuraHeader) -> Result<ImportContext<AccountId>, Error> {
|
||||
run_test_with_genesis(genesis(), TOTAL_VALIDATORS, |_| {
|
||||
let storage = BridgeStorage::<TestRuntime>::new();
|
||||
verify_aura_header(&storage, &config, None, header)
|
||||
})
|
||||
}
|
||||
|
||||
fn default_verify(header: &Header) -> Result<ImportContext<AccountId>, Error> {
|
||||
fn default_verify(header: &AuraHeader) -> Result<ImportContext<AccountId>, Error> {
|
||||
verify_with_config(&test_aura_config(), header)
|
||||
}
|
||||
|
||||
fn default_accept_into_pool(
|
||||
mut make_header: impl FnMut(&[SecretKey]) -> (Header, Option<Vec<Receipt>>),
|
||||
mut make_header: impl FnMut(&[SecretKey]) -> (AuraHeader, Option<Vec<Receipt>>),
|
||||
) -> Result<(Vec<TransactionTag>, Vec<TransactionTag>), Error> {
|
||||
run_test_with_genesis(genesis(), TOTAL_VALIDATORS, |_| {
|
||||
let validators = vec![validator(0), validator(1), validator(2)];
|
||||
@@ -457,7 +457,7 @@ mod tests {
|
||||
#[test]
|
||||
fn verifies_seal_count() {
|
||||
// when there are no seals at all
|
||||
let mut header = Header::default();
|
||||
let mut header = AuraHeader::default();
|
||||
assert_eq!(default_verify(&header), Err(Error::InvalidSealArity));
|
||||
|
||||
// when there's single seal (we expect 2 or 3 seals)
|
||||
@@ -568,7 +568,7 @@ mod tests {
|
||||
#[test]
|
||||
fn verifies_step() {
|
||||
// when step is missing from seals
|
||||
let mut header = Header {
|
||||
let mut header = AuraHeader {
|
||||
seal: vec![vec![], vec![]],
|
||||
gas_limit: test_aura_config().min_gas_limit,
|
||||
parent_hash: genesis().compute_hash(),
|
||||
@@ -694,7 +694,7 @@ mod tests {
|
||||
fn pool_rejects_headers_without_required_receipts() {
|
||||
assert_eq!(
|
||||
default_accept_into_pool(|_| (
|
||||
Header {
|
||||
AuraHeader {
|
||||
number: 20_000_000,
|
||||
seal: vec![vec![], vec![]],
|
||||
gas_limit: test_aura_config().min_gas_limit,
|
||||
|
||||
@@ -68,7 +68,7 @@ pub struct HeaderId {
|
||||
/// An Aura header.
|
||||
#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub struct Header {
|
||||
pub struct AuraHeader {
|
||||
/// Parent block hash.
|
||||
pub parent_hash: H256,
|
||||
/// Block timestamp.
|
||||
@@ -182,7 +182,7 @@ pub struct SealedEmptyStep {
|
||||
pub step: u64,
|
||||
}
|
||||
|
||||
impl Header {
|
||||
impl AuraHeader {
|
||||
/// Compute id of this header.
|
||||
pub fn compute_id(&self) -> HeaderId {
|
||||
HeaderId {
|
||||
@@ -558,7 +558,7 @@ sp_api::decl_runtime_apis! {
|
||||
/// Returns number and hash of the best finalized block known to the bridge module.
|
||||
fn finalized_block() -> (u64, H256);
|
||||
/// Returns true if the import of given block requires transactions receipts.
|
||||
fn is_import_requires_receipts(header: Header) -> bool;
|
||||
fn is_import_requires_receipts(header: AuraHeader) -> bool;
|
||||
/// Returns true if header is known to the runtime.
|
||||
fn is_known_block(hash: H256) -> bool;
|
||||
}
|
||||
@@ -573,7 +573,7 @@ sp_api::decl_runtime_apis! {
|
||||
/// Returns number and hash of the best finalized block known to the bridge module.
|
||||
fn finalized_block() -> (u64, H256);
|
||||
/// Returns true if the import of given block requires transactions receipts.
|
||||
fn is_import_requires_receipts(header: Header) -> bool;
|
||||
fn is_import_requires_receipts(header: AuraHeader) -> bool;
|
||||
/// Returns true if header is known to the runtime.
|
||||
fn is_known_block(hash: H256) -> bool;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
pub use secp256k1::SecretKey;
|
||||
|
||||
use crate::{
|
||||
public_to_address, rlp_encode, step_validator, Address, Header, RawTransaction, UnsignedTransaction, H256, H520,
|
||||
U256,
|
||||
public_to_address, rlp_encode, step_validator, Address, AuraHeader, RawTransaction, UnsignedTransaction, H256,
|
||||
H520, U256,
|
||||
};
|
||||
|
||||
use secp256k1::{Message, PublicKey};
|
||||
@@ -32,9 +32,9 @@ use secp256k1::{Message, PublicKey};
|
||||
/// Utilities for signing headers.
|
||||
pub trait SignHeader {
|
||||
/// Signs header by given author.
|
||||
fn sign_by(self, author: &SecretKey) -> Header;
|
||||
fn sign_by(self, author: &SecretKey) -> AuraHeader;
|
||||
/// Signs header by given authors set.
|
||||
fn sign_by_set(self, authors: &[SecretKey]) -> Header;
|
||||
fn sign_by_set(self, authors: &[SecretKey]) -> AuraHeader;
|
||||
}
|
||||
|
||||
/// Utilities for signing transactions.
|
||||
@@ -43,7 +43,7 @@ pub trait SignTransaction {
|
||||
fn sign_by(self, author: &SecretKey, chain_id: Option<u64>) -> RawTransaction;
|
||||
}
|
||||
|
||||
impl SignHeader for Header {
|
||||
impl SignHeader for AuraHeader {
|
||||
fn sign_by(mut self, author: &SecretKey) -> Self {
|
||||
self.author = secret_to_address(author);
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
//! RPC Module
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
// The compiler doesn't think we're using the
|
||||
// code from rpc_api!
|
||||
#![allow(dead_code)]
|
||||
@@ -35,7 +34,7 @@ use crate::substrate_types::{
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bp_eth_poa::Header as SubstrateEthereumHeader;
|
||||
use bp_eth_poa::AuraHeader as SubstrateEthereumHeader;
|
||||
|
||||
type Result<T> = result::Result<T, RpcError>;
|
||||
type GrandpaAuthorityList = Vec<u8>;
|
||||
|
||||
@@ -23,7 +23,7 @@ use crate::sync_types::SubmittedHeaders;
|
||||
use crate::utils::HeaderId;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bp_eth_poa::Header as SubstrateEthereumHeader;
|
||||
use bp_eth_poa::AuraHeader as SubstrateEthereumHeader;
|
||||
use codec::{Decode, Encode};
|
||||
use jsonrpsee::raw::RawClient;
|
||||
use jsonrpsee::transport::http::HttpTransportClient;
|
||||
|
||||
@@ -23,7 +23,7 @@ use crate::utils::HeaderId;
|
||||
use codec::Encode;
|
||||
|
||||
pub use bp_eth_poa::{
|
||||
Address, Bloom, Bytes, Header as SubstrateEthereumHeader, LogEntry as SubstrateEthereumLogEntry,
|
||||
Address, AuraHeader as SubstrateEthereumHeader, Bloom, Bytes, LogEntry as SubstrateEthereumLogEntry,
|
||||
Receipt as SubstrateEthereumReceipt, TransactionOutcome as SubstrateEthereumTransactionOutcome, H256, U256,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user