mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 04:01:02 +00:00
Use different chain primitives in Millau (#517)
This commit is contained in:
committed by
Bastian Köcher
parent
20fc30404a
commit
6dc267393a
@@ -12,23 +12,39 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
bp-message-lane = { path = "../message-lane", default-features = false }
|
||||
bp-runtime = { path = "../runtime", default-features = false }
|
||||
fixed-hash = { version = "0.6.1", default-features = false }
|
||||
hash256-std-hasher = { version = "0.15.2", default-features = false }
|
||||
impl-codec = { version = "0.4.2", default-features = false }
|
||||
impl-serde = { version = "0.3.1", optional = true }
|
||||
parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] }
|
||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
|
||||
# Substrate Based Dependencies
|
||||
|
||||
frame-support = { version = "2.0", default-features = false }
|
||||
sp-api = { version = "2.0", default-features = false }
|
||||
sp-core = { version = "2.0", default-features = false }
|
||||
sp-io = { version = "2.0", default-features = false }
|
||||
sp-runtime = { version = "2.0", default-features = false }
|
||||
sp-std = { version = "2.0", default-features = false }
|
||||
sp-trie = { version = "2.0", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"bp-message-lane/std",
|
||||
"bp-runtime/std",
|
||||
"fixed-hash/std",
|
||||
"frame-support/std",
|
||||
"hash256-std-hasher/std",
|
||||
"impl-codec/std",
|
||||
"impl-serde",
|
||||
"parity-util-mem/std",
|
||||
"serde",
|
||||
"sp-api/std",
|
||||
"sp-core/std",
|
||||
"sp-io/std",
|
||||
"sp-runtime/std",
|
||||
"sp-std/std",
|
||||
"sp-trie/std",
|
||||
]
|
||||
|
||||
@@ -20,18 +20,56 @@
|
||||
// Runtime-generated DecodeLimit::decode_all_With_depth_limit
|
||||
#![allow(clippy::unnecessary_mut_passed)]
|
||||
|
||||
mod millau_hash;
|
||||
|
||||
use bp_message_lane::MessageNonce;
|
||||
use bp_runtime::Chain;
|
||||
use frame_support::{weights::Weight, RuntimeDebug};
|
||||
use sp_core::Hasher as HasherT;
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, IdentifyAccount, Verify},
|
||||
traits::{IdentifyAccount, Verify},
|
||||
MultiSignature, MultiSigner,
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
use sp_trie::{trie_types::Layout, TrieConfiguration};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub use millau_hash::MillauHash;
|
||||
|
||||
/// Millau Hasher (Blake2-256 ++ Keccak-256) implementation.
|
||||
#[derive(PartialEq, Eq, Clone, Copy, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub struct BlakeTwoAndKeccak256;
|
||||
|
||||
impl sp_core::Hasher for BlakeTwoAndKeccak256 {
|
||||
type Out = MillauHash;
|
||||
type StdHasher = hash256_std_hasher::Hash256StdHasher;
|
||||
const LENGTH: usize = 64;
|
||||
|
||||
fn hash(s: &[u8]) -> Self::Out {
|
||||
let mut combined_hash = MillauHash::default();
|
||||
combined_hash.as_mut()[..32].copy_from_slice(&sp_io::hashing::blake2_256(s));
|
||||
combined_hash.as_mut()[32..].copy_from_slice(&sp_io::hashing::keccak_256(s));
|
||||
combined_hash
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_runtime::traits::Hash for BlakeTwoAndKeccak256 {
|
||||
type Output = MillauHash;
|
||||
|
||||
fn trie_root(input: Vec<(Vec<u8>, Vec<u8>)>) -> Self::Output {
|
||||
Layout::<BlakeTwoAndKeccak256>::trie_root(input)
|
||||
}
|
||||
|
||||
fn ordered_trie_root(input: Vec<Vec<u8>>) -> Self::Output {
|
||||
Layout::<BlakeTwoAndKeccak256>::ordered_trie_root(input)
|
||||
}
|
||||
}
|
||||
|
||||
/// Maximal weight of single Millau block.
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 2_000_000_000_000;
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 10_000_000_000;
|
||||
/// Portion of block reserved for regular transactions.
|
||||
pub const AVAILABLE_BLOCK_RATIO: u32 = 75;
|
||||
/// Maximal weight of single Millau extrinsic (65% of maximum block weight = 75% for regular
|
||||
@@ -39,16 +77,16 @@ pub const AVAILABLE_BLOCK_RATIO: u32 = 75;
|
||||
pub const MAXIMUM_EXTRINSIC_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT / 100 * (AVAILABLE_BLOCK_RATIO as Weight - 10);
|
||||
|
||||
/// Maximal number of unconfirmed messages at inbound lane.
|
||||
pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 128;
|
||||
pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 1024;
|
||||
|
||||
/// Block number type used in Millau.
|
||||
pub type BlockNumber = u32;
|
||||
pub type BlockNumber = u64;
|
||||
|
||||
/// Hash type used in Millau.
|
||||
pub type Hash = <BlakeTwo256 as HasherT>::Out;
|
||||
pub type Hash = <BlakeTwoAndKeccak256 as HasherT>::Out;
|
||||
|
||||
/// The type of an object that can produce hashes on Millau.
|
||||
pub type Hasher = BlakeTwo256;
|
||||
pub type Hasher = BlakeTwoAndKeccak256;
|
||||
|
||||
/// The header type used by Millau.
|
||||
pub type Header = sp_runtime::generic::Header<BlockNumber, Hasher>;
|
||||
@@ -84,7 +122,7 @@ pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::Account
|
||||
pub type AccountSigner = MultiSigner;
|
||||
|
||||
/// Balance of an account.
|
||||
pub type Balance = u128;
|
||||
pub type Balance = u64;
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
/// API for querying information about Millau headers from the Bridge Pallet instance.
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use parity_util_mem::MallocSizeOf;
|
||||
use sp_runtime::traits::CheckEqual;
|
||||
|
||||
// `sp_core::H512` can't be used, because it doesn't implement `CheckEqual`, which is required
|
||||
// by `frame_system::Trait::Hash`.
|
||||
|
||||
fixed_hash::construct_fixed_hash! {
|
||||
/// Hash type used in Millau chain.
|
||||
#[derive(MallocSizeOf)]
|
||||
pub struct MillauHash(64);
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl_serde::impl_fixed_hash_serde!(MillauHash, 64);
|
||||
|
||||
impl_codec::impl_fixed_hash_codec!(MillauHash, 64);
|
||||
|
||||
impl CheckEqual for MillauHash {
|
||||
#[cfg(feature = "std")]
|
||||
fn check_equal(&self, other: &Self) {
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
if self != other {
|
||||
println!(
|
||||
"Hash: given={}, expected={}",
|
||||
HexDisplay::from(self.as_fixed_bytes()),
|
||||
HexDisplay::from(other.as_fixed_bytes()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn check_equal(&self, other: &Self) {
|
||||
use frame_support::Printable;
|
||||
|
||||
if self != other {
|
||||
"Hash not equal".print();
|
||||
self.as_bytes().print();
|
||||
other.as_bytes().print();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user