Skip to content

Commit

Permalink
Rename Ethereum Headers to AuraHeader (paritytech#354)
Browse files Browse the repository at this point in the history
* Rename Header to AuraHeader

This prevents some type conflicts with the PolkadotJS Apps types.

* Fix test and benchmark builds

* Update AuraHeader in types.json
  • Loading branch information
HCastano authored and serban300 committed Apr 10, 2024
1 parent 776557b commit 8bdf9e2
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 91 deletions.
6 changes: 3 additions & 3 deletions bridges/bin/rialto-runtime/src/kovan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions bridges/bin/rialto-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions bridges/bin/rialto-runtime/src/rialto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion bridges/modules/ethereum/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions bridges/modules/ethereum/src/finality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>>,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -298,7 +298,7 @@ mod tests {
(Default::default(), &[]),
Default::default(),
None,
&Header::default(),
&AuraHeader::default(),
0,
),
Err(Error::NotValidator),
Expand Down
10 changes: 5 additions & 5 deletions bridges/modules/ethereum/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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(
Expand Down
40 changes: 20 additions & 20 deletions bridges/modules/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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,
Expand All @@ -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
}

Expand Down Expand Up @@ -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>>,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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],
) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1044,26 +1044,26 @@ 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());
header.parent_hash = example_header().compute_hash();
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());
header.parent_hash = example_header_parent().compute_hash();
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());
Expand Down
12 changes: 8 additions & 4 deletions bridges/modules/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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))
}

Expand All @@ -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(
Expand Down
Loading

0 comments on commit 8bdf9e2

Please sign in to comment.