diff --git a/bridges/bin/rialto-runtime/src/kovan.rs b/bridges/bin/rialto-runtime/src/kovan.rs index 189333a83c59..d0b59478d22e 100644 --- a/bridges/bin/rialto-runtime/src/kovan.rs +++ b/bridges/bin/rialto-runtime/src/kovan.rs @@ -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
{ } /// 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, diff --git a/bridges/bin/rialto-runtime/src/lib.rs b/bridges/bin/rialto-runtime/src/lib.rs index a00733ae74fa..8ae3faebebb4 100644 --- a/bridges/bin/rialto-runtime/src/lib.rs +++ b/bridges/bin/rialto-runtime/src/lib.rs @@ -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) } diff --git a/bridges/bin/rialto-runtime/src/rialto.rs b/bridges/bin/rialto-runtime/src/rialto.rs index 03f8c4065088..4e92e800eccd 100644 --- a/bridges/bin/rialto-runtime/src/rialto.rs +++ b/bridges/bin/rialto-runtime/src/rialto.rs @@ -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
{ /// ```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, diff --git a/bridges/modules/ethereum/src/benchmarking.rs b/bridges/modules/ethereum/src/benchmarking.rs index b088c49bec81..2dd58d664822 100644 --- a/bridges/modules/ethereum/src/benchmarking.rs +++ b/bridges/modules/ethereum/src/benchmarking.rs @@ -218,7 +218,7 @@ benchmarks_instance! { } } -fn initialize_bench, I: Instance>(num_validators: usize) -> Header { +fn initialize_bench, 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; diff --git a/bridges/modules/ethereum/src/finality.rs b/bridges/modules/ethereum/src/finality.rs index 4d836cd8a522..e53ce91ed3cf 100644 --- a/bridges/modules/ethereum/src/finality.rs +++ b/bridges/modules/ethereum/src/finality.rs @@ -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 { 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, Header)>, + pub unaccounted_ancestry: VecDeque<(HeaderId, Option, AuraHeader)>, /// Cached finality votes, if they have been found. The associated /// header is not included into `unaccounted_ancestry`. pub votes: Option>, @@ -86,7 +86,7 @@ pub fn finalize_blocks( header_validators: (HeaderId, &[Address]), id: HeaderId, submitter: Option<&S::Submitter>, - header: &Header, + header: &AuraHeader, two_thirds_majority_transition: u64, ) -> Result, Error> { // compute count of voters for every unfinalized block in ancestry @@ -145,7 +145,7 @@ fn prepare_votes( best_finalized: HeaderId, validators: &BTreeSet<&Address>, id: HeaderId, - header: &Header, + header: &AuraHeader, submitter: Option, ) -> Result, Error> { // if we have reached finalized block sibling, then we're trying @@ -243,7 +243,7 @@ fn remove_signers_votes(signers_to_remove: &BTreeSet
, votes: &mut BTree } /// Returns unique set of empty steps signers. -fn empty_steps_signers(header: &Header) -> BTreeSet
{ +fn empty_steps_signers(header: &AuraHeader) -> BTreeSet
{ header .empty_steps() .into_iter() @@ -298,7 +298,7 @@ mod tests { (Default::default(), &[]), Default::default(), None, - &Header::default(), + &AuraHeader::default(), 0, ), Err(Error::NotValidator), diff --git a/bridges/modules/ethereum/src/import.rs b/bridges/modules/ethereum/src/import.rs index 97f423b2d929..977ffd671815 100644 --- a/bridges/modules/ethereum/src/import.rs +++ b/bridges/modules/ethereum/src/import.rs @@ -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( aura_config: &AuraConfiguration, validators_config: &ValidatorsConfiguration, submitter: Option, - headers: Vec<(Header, Option>)>, + headers: Vec<(AuraHeader, Option>)>, finalized_headers: &mut BTreeMap, ) -> Result<(u64, u64), Error> { let mut useful = 0; @@ -85,7 +85,7 @@ pub fn import_header( aura_config: &AuraConfiguration, validators_config: &ValidatorsConfiguration, submitter: Option, - header: Header, + header: AuraHeader, receipts: Option>, ) -> Result<(HeaderId, FinalizedHeaders), Error> { // first check that we are able to import this header at all @@ -153,7 +153,7 @@ pub fn import_header( pub fn header_import_requires_receipts( 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( storage: &mut S, validators: &[SecretKey], - header: Header, + header: AuraHeader, ) -> Result { let id = header.compute_id(); import_header( diff --git a/bridges/modules/ethereum/src/lib.rs b/bridges/modules/ethereum/src/lib.rs index bbb2ba295619..afc5c681a39a 100644 --- a/bridges/modules/ethereum/src/lib.rs +++ b/bridges/modules/ethereum/src/lib.rs @@ -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 { /// using unsigned transaction. pub submitter: Option, /// 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 { /// 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: Option, parent_hash: H256, - parent_header: Header, + parent_header: AuraHeader, parent_total_difficulty: U256, parent_scheduled_change: Option, validators_set_id: u64, @@ -200,7 +200,7 @@ impl ImportContext { } /// 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 ImportContext { self, is_best: bool, id: HeaderId, - header: Header, + header: AuraHeader, total_difficulty: U256, enacted_change: Option, scheduled_change: Option>, @@ -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)>; + fn header(&self, hash: &H256) -> Option<(AuraHeader, Option)>; /// 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, 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>) { + pub fn import_unsigned_header(origin, header: AuraHeader, receipts: Option>) { 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>)>) { + pub fn import_signed_headers(origin, headers_with_receipts: Vec<(AuraHeader, Option>)>) { 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; } add_extra_genesis { - config(initial_header): Header; + config(initial_header): AuraHeader; config(initial_difficulty): U256; config(initial_validators): Vec
; build(|config| { @@ -496,7 +496,7 @@ impl, I: Instance> Module { } /// 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::::new(), &T::ValidatorsConfiguration::get(), @@ -670,7 +670,7 @@ impl, I: Instance> Storage for BridgeStorage { FinalizedBlock::::get() } - fn header(&self, hash: &H256) -> Option<(Header, Option)> { + fn header(&self, hash: &H256) -> Option<(AuraHeader, Option)> { Headers::::get(hash).map(|header| (header.header, header.submitter)) } @@ -840,7 +840,7 @@ impl, I: Instance> Storage for BridgeStorage { /// Initialize storage. #[cfg(any(feature = "std", feature = "runtime-benchmarks"))] pub(crate) fn initialize_storage, 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 + 'a { +fn ancestry<'a, S: Storage>(storage: &'a S, mut parent_hash: H256) -> impl Iterator + '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()); diff --git a/bridges/modules/ethereum/src/mock.rs b/bridges/modules/ethereum/src/mock.rs index 66d63d28d091..db84afacc496 100644 --- a/bridges/modules/ethereum/src/mock.rs +++ b/bridges/modules/ethereum/src/mock.rs @@ -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(total_validators: usize, test: impl FnOnce(TestContext) -> T) } /// Run test with default genesis header. -pub fn run_test_with_genesis(genesis: Header, total_validators: usize, test: impl FnOnce(TestContext) -> T) -> T { +pub fn run_test_with_genesis( + 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( diff --git a/bridges/modules/ethereum/src/test_utils.rs b/bridges/modules/ethereum/src/test_utils.rs index 37f7a7a0298b..b669856fdb44 100644 --- a/bridges/modules/ethereum/src/test_utils.rs +++ b/bridges/modules/ethereum/src/test_utils.rs @@ -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(author: &SecretKey, previous: &Header, customize_header: F) -> Header +pub fn build_custom_header(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(storage: &mut S, header: Header) { +pub fn insert_header(storage: &mut S, header: AuraHeader) { storage.insert_header(HeaderToImport { context: storage.import_context(None, &header.parent_hash).unwrap(), is_best: true, diff --git a/bridges/modules/ethereum/src/validators.rs b/bridges/modules/ethereum/src/validators.rs index e0b747fc3f02..ede479fd3788 100644 --- a/bridges/modules/ethereum/src/validators.rs +++ b/bridges/modules/ethereum/src/validators.rs @@ -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>, ) -> 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:: { submitter: None, - header: Header { + header: AuraHeader { number: 100, ..Default::default() }, diff --git a/bridges/modules/ethereum/src/verification.rs b/bridges/modules/ethereum/src/verification.rs index 115867d284e2..c9592c567efe 100644 --- a/bridges/modules/ethereum/src/verification.rs +++ b/bridges/modules/ethereum/src/verification.rs @@ -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(storage: &S, header: &Header) -> Result<(HeaderId, HeaderId), Error> { +pub fn is_importable_header(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( config: &AuraConfiguration, validators_config: &ValidatorsConfiguration, pool_config: &PoolConfiguration, - header: &Header, + header: &AuraHeader, receipts: Option<&Vec>, ) -> Result<(Vec, Vec), Error> { // check if we can verify further @@ -157,7 +157,7 @@ pub fn verify_aura_header( storage: &S, config: &AuraConfiguration, submitter: Option, - header: &Header, + header: &AuraHeader, ) -> Result, Error> { // let's do the lightest check first contextless_checks(config, header)?; @@ -180,7 +180,7 @@ pub fn verify_aura_header( } /// 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( config: &AuraConfiguration, context: &ImportContext, validators_override: Option<&[Address]>, - header: &Header, + header: &AuraHeader, ) -> Result { 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( 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, Error> { + fn verify_with_config(config: &AuraConfiguration, header: &AuraHeader) -> Result, Error> { run_test_with_genesis(genesis(), TOTAL_VALIDATORS, |_| { let storage = BridgeStorage::::new(); verify_aura_header(&storage, &config, None, header) }) } - fn default_verify(header: &Header) -> Result, Error> { + fn default_verify(header: &AuraHeader) -> Result, Error> { verify_with_config(&test_aura_config(), header) } fn default_accept_into_pool( - mut make_header: impl FnMut(&[SecretKey]) -> (Header, Option>), + mut make_header: impl FnMut(&[SecretKey]) -> (AuraHeader, Option>), ) -> Result<(Vec, Vec), 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, diff --git a/bridges/primitives/ethereum-poa/src/lib.rs b/bridges/primitives/ethereum-poa/src/lib.rs index a2a2b9366b6e..5229522b0212 100644 --- a/bridges/primitives/ethereum-poa/src/lib.rs +++ b/bridges/primitives/ethereum-poa/src/lib.rs @@ -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; } diff --git a/bridges/primitives/ethereum-poa/src/signatures.rs b/bridges/primitives/ethereum-poa/src/signatures.rs index 4d97fbcbfbd1..cab8fdfa2f43 100644 --- a/bridges/primitives/ethereum-poa/src/signatures.rs +++ b/bridges/primitives/ethereum-poa/src/signatures.rs @@ -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) -> RawTransaction; } -impl SignHeader for Header { +impl SignHeader for AuraHeader { fn sign_by(mut self, author: &SecretKey) -> Self { self.author = secret_to_address(author); diff --git a/bridges/relays/ethereum/src/rpc.rs b/bridges/relays/ethereum/src/rpc.rs index fd108f8963fe..64b70093f12d 100644 --- a/bridges/relays/ethereum/src/rpc.rs +++ b/bridges/relays/ethereum/src/rpc.rs @@ -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 = result::Result; type GrandpaAuthorityList = Vec; diff --git a/bridges/relays/ethereum/src/substrate_client.rs b/bridges/relays/ethereum/src/substrate_client.rs index 1d3e5d03199f..e6004be1f7e7 100644 --- a/bridges/relays/ethereum/src/substrate_client.rs +++ b/bridges/relays/ethereum/src/substrate_client.rs @@ -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; diff --git a/bridges/relays/ethereum/src/substrate_types.rs b/bridges/relays/ethereum/src/substrate_types.rs index 87931957ad3b..05b96c037ff1 100644 --- a/bridges/relays/ethereum/src/substrate_types.rs +++ b/bridges/relays/ethereum/src/substrate_types.rs @@ -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, };