Skip to content

Commit

Permalink
Merge pull request #37 from availproject/miguel/common_avail_core
Browse files Browse the repository at this point in the history
Miguel/common avail core
  • Loading branch information
fmiguelgarcia authored Jul 25, 2023
2 parents 544cc3e + 95e18e6 commit 2e04970
Show file tree
Hide file tree
Showing 28 changed files with 177 additions and 153 deletions.
42 changes: 3 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ hash256-std-hasher = { version = "0.15.2", default-features = false }
hex = { version = "0.4", optional = true, default-features = false, features = ["alloc", "serde"] }
log = { version = "0.4.8", default-features = false }
serde = { version = "1", optional = true, features = ["derive"] }
static_assertions = "1.1.0"
thiserror-no-std = "2.0.2"

# Substrate
Expand All @@ -20,6 +21,7 @@ codec = { package = "parity-scale-codec", version = "3", default-features = fals
scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-arithmetic = { version = "*", default-features = false }
sp-core = { version = "*", default-features = false }
sp-io = { version = "*", default-features = false }
sp-std = { version = "*", default-features = false }
sp-trie = { version = "*", default-features = false }

Expand All @@ -42,6 +44,7 @@ std = [
"scale-info/std",
"log/std",
"sp-core/std",
"sp-io/std",
"sp-std/std",
"sp-trie/std",
"sp-arithmetic/std",
Expand Down
4 changes: 2 additions & 2 deletions core/src/asdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

use codec::{Compact, Decode, Encode, EncodeLike, Error, Input};
use scale_info::{build::Fields, meta_type, Path, StaticTypeInfo, Type, TypeInfo, TypeParameter};
use sp_core::blake2_256;
#[cfg(feature = "runtime")]
use sp_runtime::{
generic::CheckedExtrinsic,
Expand All @@ -36,6 +35,8 @@ use sp_std::{
vec::Vec,
};

use sp_io::hashing::blake2_256;

use crate::{traits::GetAppId, AppId, OpaqueExtrinsic};

/// Current version of the [`UncheckedExtrinsic`] encoded format.
Expand Down Expand Up @@ -537,7 +538,6 @@ where

#[cfg(test)]
mod tests {
use sp_core::blake2_256;
use sp_runtime::{
codec::{Decode, Encode},
testing::TestSignature as TestSig,
Expand Down
5 changes: 4 additions & 1 deletion core/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use core::num::NonZeroU32;
use sp_arithmetic::Perbill;
use static_assertions::const_assert;

pub mod well_known_keys {
/// Public params used to generate Kate commitment
Expand All @@ -9,7 +11,8 @@ pub mod well_known_keys {
/// by Operational extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(90);

pub const BLOCK_CHUNK_SIZE: u32 = 32;
const_assert!(BLOCK_CHUNK_SIZE.get() > 0);
pub const BLOCK_CHUNK_SIZE: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(32) };

/// Money matters.
pub mod currency {
Expand Down
2 changes: 1 addition & 1 deletion core/src/data_lookup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};

use crate::{ensure, AppId};

mod compact;
pub mod compact;
use compact::CompactDataLookup;

pub type DataLookupRange = Range<u32>;
Expand Down
6 changes: 4 additions & 2 deletions core/src/data_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ where

fn try_from(merkle_proof: &MerkleProof<H, T>) -> Result<Self, Self::Error> {
use crate::ensure;
use sp_core::keccak_256;
use DataProofTryFromError::*;

use sp_io::hashing::keccak_256;

let root = <[u8; 32]>::try_from(merkle_proof.root.as_ref())
.map_err(|_| InvalidRoot)?
.into();
Expand Down Expand Up @@ -102,7 +103,8 @@ where
mod test {
use crate::Keccak256;
use hex_literal::hex;
use sp_core::{keccak_256, H512};
use sp_core::H512;
use sp_io::hashing::keccak_256;
use sp_std::cmp::min;
use test_case::test_case;

Expand Down
15 changes: 7 additions & 8 deletions core/src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,15 @@ where
}
}

impl<N: HeaderBlockNumber, H: HeaderHash> ExtendedHeader<Digest, HeaderExtension> for Header<N, H> {
type Hash = <H as HashT>::Output;
type Number = N;

impl<N: HeaderBlockNumber, H: HeaderHash>
ExtendedHeader<N, <H as HashT>::Output, Digest, HeaderExtension> for Header<N, H>
{
/// Creates new header.
fn new(
n: Self::Number,
extrinsics: Self::Hash,
state: Self::Hash,
parent: Self::Hash,
n: N,
extrinsics: <H as HashT>::Output,
state: <H as HashT>::Output,
parent: <H as HashT>::Output,
digest: Digest,
extension: HeaderExtension,
) -> Self {
Expand Down
5 changes: 3 additions & 2 deletions core/src/keccak256.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use scale_info::TypeInfo;
use sp_core::{keccak_256, Hasher, RuntimeDebug};
use sp_core::{Hasher, RuntimeDebug};

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
Expand All @@ -15,7 +15,8 @@ impl Hasher for Keccak256 {
const LENGTH: usize = 32;

fn hash(s: &[u8]) -> Self::Out {
keccak_256(s).into()
let keccak_out = sp_io::hashing::keccak_256(s);
keccak_out.into()
}
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/sha2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_core::{hashing::sha2_256, Hasher, RuntimeDebug};
use sp_core::{Hasher, RuntimeDebug};

/// Sha2 256 wrapper which supports `beefy-merkle-tree::Hasher`.
#[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)]
Expand All @@ -14,7 +14,8 @@ impl Hasher for ShaTwo256 {
const LENGTH: usize = 32;

fn hash(s: &[u8]) -> Self::Out {
sha2_256(s).into()
let sha2_out = sp_io::hashing::sha2_256(s);
sha2_out.into()
}
}

Expand Down
13 changes: 11 additions & 2 deletions core/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use codec::{Codec, Decode};
use sp_arithmetic::traits::AtLeast32BitUnsigned;
use sp_arithmetic::traits::Saturating;
use sp_core::U256;
use sp_std::{convert::TryFrom, fmt::Debug, hash::Hash as StdHash};

Expand All @@ -11,12 +12,20 @@ pub use extended_header::*;

/// Header block number trait.
pub trait HeaderBlockNumber:
AtLeast32BitUnsigned + Codec + StdHash + Copy + Into<U256> + TryFrom<U256> + Debug + Eq
AtLeast32BitUnsigned + Codec + StdHash + Copy + Into<U256> + TryFrom<U256> + Debug + Eq + Saturating
{
}

impl<
T: AtLeast32BitUnsigned + Codec + StdHash + Copy + Into<U256> + TryFrom<U256> + Debug + Eq,
T: AtLeast32BitUnsigned
+ Codec
+ StdHash
+ Copy
+ Into<U256>
+ TryFrom<U256>
+ Debug
+ Eq
+ Saturating,
> HeaderBlockNumber for T
{
}
Expand Down
24 changes: 9 additions & 15 deletions core/src/traits/extended_header.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
/// Extended header access
pub trait ExtendedHeader<D, E> {
/// Header number.
type Number;

/// Header hash type
type Hash;

pub trait ExtendedHeader<Number, Hash, Digest, Extension> {
/// Creates new header.
fn new(
number: Self::Number,
extrinsics_root: Self::Hash,
state_root: Self::Hash,
parent_hash: Self::Hash,
digest: D,
extension: E,
number: Number,
extrinsics_root: Hash,
state_root: Hash,
parent_hash: Hash,
digest: Digest,
extension: Extension,
) -> Self;

fn extension(&self) -> &E;
fn extension(&self) -> &Extension;

fn set_extension(&mut self, extension: E);
fn set_extension(&mut self, extension: Extension);
}
26 changes: 16 additions & 10 deletions kate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,49 @@ license = "Apache-2.0"

[dependencies]
# Pending to review
poly-multiproof = { git = "https://github.com/availproject/poly-multiproof", default-features = false, tag = "v0.0.1" }
poly-multiproof = { git = "https://github.com/availproject/poly-multiproof", default-features = false, tag = "v0.0.1", optional = true }

# Internal
avail-core = { path = "../core", default-features = false, feature = "runtime" }
dusk-plonk = { git = "https://github.com/availproject/plonk.git", tag = "v0.12.0-polygon-2", optional = true }
kate-recovery = { path = "recovery", default-features = false }

dusk-plonk = { git = "https://github.com/availproject/plonk.git", tag = "v0.12.0-polygon-2", optional = true }

# Parity & Substrate
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
sp-arithmetic = { version = "*", default-features = false }
sp-core = { version = "*", default-features = false, optional = true }
sp-core = { version = "*", default-features = false }

# 3rd-party
derive_more = { version = "0.99.17", default-features = false, features = ["constructor"] }
dusk-bytes = { version = "0.1.6", default-features = false }
static_assertions = "1.1.0"
thiserror-no-std = "2.0.2"

dusk-bytes = { version = "0.1.6", default-features = false, optional = true }
hex = { version = "0.4", optional = true, default-features = false, features = ["alloc", "serde"] }
hex-literal = { version = "0.3.4", optional = true }
log = { version = "0.4.8", optional = true }
nalgebra = { version = "0.32.2", default-features = false }
nalgebra = { version = "0.32.2", default-features = false, optional = true }
once_cell = { version = "1.8.0", optional = true }
rand = { version = "0.8.5", default-features = false, optional = true }
rand = { version = "0.8", default-features = false, features = ["alloc", "small_rng"], optional = true }
rand_chacha = { version = "0.3", default-features = false, optional = true }
rayon = { version = "1.5.2", optional = true }
serde = { version = "1", optional = true, features = ["derive"] }
serde_json = { version = "1", optional = true }
static_assertions = "1.1.0"
thiserror-no-std = "2.0.2"

[dev-dependencies]
criterion = "0.5.1"
criterion = { version = "0.5.1", default-features = false }
proptest = "1"
serde_json = "1"
test-case = "1.2.3"

[features]
default = ["std"]
alloc = ["dusk-plonk/alloc", "nalgebra/alloc"]
parallel = ["rayon"]
parallel = [
"rayon",
"criterion/rayon",
]

std = [
"parallel",
Expand All @@ -61,6 +66,7 @@ std = [
"rand/std",
"log",
"dusk-plonk/std",
"dusk-bytes",
"avail-core/std",
"sp-arithmetic/std",
"sp-core/std",
Expand Down
Loading

0 comments on commit 2e04970

Please sign in to comment.