Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

NAlgebra replaces custom grid #33

Merged
merged 35 commits into from
Jul 20, 2023
Merged

Conversation

fmiguelgarcia
Copy link
Collaborator

@fmiguelgarcia fmiguelgarcia commented Jun 20, 2023

Replaces Grid by NAlgebra

It replaces the grid type by the NAlgebra Matrix.

Avail-Core is now shared by LC & node

No more duplicate code is needed, and avail-core can be safely shared between LC (or any other std system) and the avail node, where WASM and STD is needed.

  • New feature flag runtime on Avail-core enables the capabilities requires to integrate into our Avail's runtime.
  • Clean Cargo.toml files of unused dependencies.

DataLookup refactor

It has been refactored to simplify the runtime, but the expected serialization format is kept. It improves and simplifies its code, and keeps compatibility of 3rd parties which read from rpc (using serde serialization) or directly from header (using codec).

Code Safety

  • Replace String type used as error (like Result<..., String>) by a custom error using thiserror (non-std)
  • Use const_assert to ensure constants constraints with no impact on runtime.

Dedup Coded

  • KateRecovery::Index has been replaced completely by DataLookup.
  • Dimesion has been deduped.
  • AppDataIndex superseded by DataLookup

Other improvements

  • Add Clippy to our CI.
  • New macros ensure and fail in avail-core removes the needed of frame-support.
  • AppId, BlockLenghtColumns, and BlockLenghtRows strong types remove From impl to keep it strong.
  • kzg benchmark has been superseded by reconstruct.
  • UT simplification using test_case crate.
  • sparce_slice_reader removes the needed of duplicate padded data before decode it. It will reduces the memory footprint of the node & LC.

@fmiguelgarcia fmiguelgarcia self-assigned this Jun 20, 2023
@fmiguelgarcia fmiguelgarcia marked this pull request as ready for review July 10, 2023 09:17
@fmiguelgarcia fmiguelgarcia changed the title [WIP] NAlgebra replaces custom grid NAlgebra replaces custom grid Jul 10, 2023
@fmiguelgarcia fmiguelgarcia changed the base branch from will/grid-refactor to main July 10, 2023 09:21
@fmiguelgarcia fmiguelgarcia changed the base branch from main to will/grid-refactor July 10, 2023 13:58
Copy link
Collaborator

@Aphoh Aphoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would appreciate less use of unsafe, but this can be solved pretty easily with some util const fns or a little macro. Overall LGTM.

.cloned()
}

pub fn projected_range_of(&self, app_id: AppId, chunk_size: u32) -> Option<DataLookupRange> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these projected ranges actually used?


#[derive(Encode, Decode, TypeInfo, Constructor, Debug, Clone)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct CompactDataLookup {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CompactDataLookup here is actually less compact. Every scale-encoded vec starts with a compact integer size, then the items, so the size here is redundant and less compact. Do we really need the range types in here? I never felt like the end range greatly complicated anything.

use DataProofTryFromError::*;

let root = <[u8; 32]>::try_from(merkle_proof.root.as_ref())
.map_err(|_| InvalidRoot)?
.into();
let leaf = sha2_256(merkle_proof.leaf.as_ref()).into();
let leaf = keccak_256(merkle_proof.leaf.as_ref()).into();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a completely unrelated change, no? Shouldn't this be in another PR/discussion?

@@ -269,7 +268,7 @@ impl<N: HeaderBlockNumber, H: HeaderHash> ExtendedHeader for Header<N, H> {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "runtime"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good as long as we're sure runtime gets turned on for CI tests

use serde::{Deserialize, Serialize};

/// Keccak 256 wrapper which supports `beefy-merkle-tree::Hasher`.
#[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this belongs in another PR right?

.extend_columns(2)
.unwrap();
let grid = EvaluationGrid::from_extrinsics(exts, 4, 256, 256, seed)?
.extend_columns(unsafe { NonZeroU16::new_unchecked(2) })?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use NonZeroU16::new(2).expect("2>0") instead of using unsafe. This can also be done with a const function like it was done in kate-grid so that the check is actually done at compile time, using a match:

const fn new_nz(a: u16) -> NonZeroU16 {
    match a {
        0 => [][0],
        b => NonZeroU16::new(b).unwrap(),
    }
}

or something like that.

codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
dusk-bytes = "0.1.6"
# Internals
avail-core = { path = "../../core", default-features = false }
dusk-plonk = { git = "https://github.com/availproject/plonk.git", tag = "v0.12.0-polygon-2" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agh still need to move kate-recovery to use the multiproof apis...

let (rows, cols) = self.evals.shape();
// SAFETY: We cannot construct an `EvaluationGrid` with any dimension `< 1` or `> u16::MAX`
debug_assert!(rows <= usize::from(u16::MAX) && cols <= usize::from(u16::MAX));
unsafe { Dimensions::new_unchecked(rows as u16, cols as u16) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really don't need an unsafe here... Just new with an expect is the right thing to do here.

#[allow(clippy::integer_arithmetic)]
let h_mul: usize = rows / usize::from(NonZeroU16::get(orig_dims.rows()));
#[allow(clippy::integer_arithmetic)]
let row_from_lineal_index = |cols, lineal_index| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misspelling? row_from_linear_index?

// Round the height up to a power of 2 for ffts
let height = round_up_power_of_2(current_height);
let height = current_height
.checked_next_power_of_two()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is aaaaawesome

@Aphoh Aphoh merged commit 544cc3e into will/grid-refactor Jul 20, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants