Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[VID] AvidM integration #2579

Merged
merged 29 commits into from
Feb 26, 2025
Merged

[VID] AvidM integration #2579

merged 29 commits into from
Feb 26, 2025

Conversation

mrain
Copy link
Contributor

@mrain mrain commented Feb 11, 2025

Closes #2600

This PR:

Integrate the efficient AvidM scheme.

  • New VID scheme ships with Epoch upgrade.
  • Underlying it's currently using keccak256 hash function. Should also consider poseidon2.

Temporarily disable hotshot test_1 b/c #2664

This PR does not:

Key places to review:

deepugami pushed a commit to deepugami/espresso-sequencer that referenced this pull request Feb 13, 2025
Copy link
Contributor

Unable to build without Cargo.lock file.

This means that after this change 3rd party projects may have
difficulties using crates in this repo as a dependency. If this
isn't easy to fix please open an issue so we can fix it later.

For the first failing build see: https://github.com/EspressoSystems/espresso-sequencer/actions/runs/13417524682

To reproduce locally run

cargo generate-lockfile
cargo check --all-targets

This PR can still be merged.

@mrain mrain marked this pull request as ready for review February 21, 2025 15:10
@mrain mrain requested review from lukaszrzasik and ss-es February 21, 2025 15:10
@mrain mrain requested a review from bfish713 February 21, 2025 15:34
Copy link
Contributor

@lukaszrzasik lukaszrzasik left a comment

Choose a reason for hiding this comment

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

I reviewed the HS part mainly. It looks good to me but I'd like to wait with the approval until somebody else reviews the sequencer part and crypto.

Comment on lines 334 to 338
/// Type alias to avoid complexity
pub type PayloadWithMetadata<TYPES> = (
<TYPES as NodeType>::BlockPayload,
<<TYPES as NodeType>::BlockPayload as BlockPayload<TYPES>>::Metadata,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a suggestion: could we use a struct with named fields instead of a tuple? I find it easier to reason about the code when I see a name instead of .0 or .1.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to Lucas' suggestion. This seems like it should be a struct with payload and metadata fields

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now wrapped as a struct: 015aa10

@@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
test_suites:
- test-ci-1
# - test-ci-1 temporarily disabled for (https://github.com/EspressoSystems/espresso-sequencer/issues/2664)
Copy link
Contributor

Choose a reason for hiding this comment

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

is the test currently hanging or not?

I think we should continue to run this if you moved the calculation out of spawn_blocking and it works. or, at most, I think we should maybe #[ignore] the specific tests that aren't working

the workflows aren't well-organized so this is disabling some integration tests too

Copy link
Contributor

Choose a reason for hiding this comment

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

spawn_blocking is still there. The conclusion was that the real problem is in the test code. There is a ticket for that: #2664

tokio::task::spawn_blocking(move || advz_commitment(&encoded_txns, num_nodes));
let join_handle = tokio::task::spawn_blocking(move || {
let encoded_tx_len = encoded_txns.len();
advz_scheme(num_nodes).commit_only(encoded_txns).map(VidCommitment::V0).unwrap_or_else(|err| panic!("VidScheme::commit_only failure:(num_storage_nodes,payload_byte_len)=({num_nodes},{encoded_tx_len}) error: {err}"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it matters either way, but is this keeping the same logic?

the new version seems much less readable to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is annoying. Good that VID is removed in the recent merge. a2657f8

.as_ref()
.as_ref(),
.var_size_bytes(
<TestBlockHeader as BlockHeader<TestTypes>>::payload_commitment(self).as_ref(),
Copy link
Contributor

Choose a reason for hiding this comment

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

no objection here, but wondering: is this just a cleanup for tests or was the commitment required to be changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh this shall be a fixed_size_bytes. 015aa10
Commitments won't change, as those actual types in the sequencer.

@@ -5,5 +5,6 @@
// along with the HotShot repository. If not, see <https://mit-license.org/>.

mod tests_1 {
automod::dir!("tests/tests_1");
// These tests are temporarily disabled for the following issue: <https://github.com/EspressoSystems/espresso-sequencer/issues/2664>
// automod::dir!("tests/tests_1");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should revert this here and just add an #[ignore] for the specific test that was failing (test_da_task?)

Comment on lines 334 to 338
/// Type alias to avoid complexity
pub type PayloadWithMetadata<TYPES> = (
<TYPES as NodeType>::BlockPayload,
<<TYPES as NodeType>::BlockPayload as BlockPayload<TYPES>>::Metadata,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to Lucas' suggestion. This seems like it should be a struct with payload and metadata fields

Comment on lines +16 to +17
/// Helper function for AvidM scheme to parse a namespace table.
/// If the namespace table is invalid, it returns a default single entry namespace table.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add even a rough description of what a valid namespace table is and/or what the layout should be?

e.g. I assume that bytes is an array with namespace tables at the start and payload_byte_len bytes at the end, but it would be nice to have this written down here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is mostly copied from the sequencer repo. Add a link to it 015aa10

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use NsTable::ns_range() which does exactly this already.

@@ -813,7 +815,7 @@ impl BlockHeader<SeqTypes> for Header {
height = parent_leaf.block_header().block_number() + 1,
parent_view = ?parent_leaf.view_number(),
payload_commitment,
payload_size = VidSchemeType::get_payload_byte_len(&_vid_common),
// payload_size = ADVZScheme::get_payload_byte_len(&_vid_common),
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be deleted? (not just commented out)

I think there's a few lines that were commented out in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted: 015aa10

@mrain mrain requested a review from alxiong February 24, 2025 17:28
Copy link
Contributor

@alxiong alxiong left a comment

Choose a reason for hiding this comment

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

@mrain crate vid is directly copied over without new addition, right? anything I should pay special attention to?

vid/rustfmt.toml Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: is it a good idea to have sub-crate rustfmt? or should we just forgo this. (personally I like this config but feels intrusive to impose on the entire monorepo)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @rob-maron do you have any suggestion here?

Copy link
Contributor

Choose a reason for hiding this comment

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

does this work as you'd expect? i.e. does the formatting in this file apply to the vid crate (and only the vid crate) if you run cargo fmt from the workspace root?

if so I feel like it's completely fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Locally on my side it works well and only applies to the vid crate.

type VidResult<T> = Result<T, VidError>;

/// Trait definition for a Verifiable Information Dispersal (VID) scheme.
pub trait VidScheme {
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: we already have trait jf_vid::VidScheme (and used everywhere), would it be confusing to migrate? or can we try to unify the two and stablize this trait to avoid future disruption?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Old trait doesn't take weight distribution. My plan is to migrate them into the new VID crate.

Comment on lines +16 to +17
/// Helper function for AvidM scheme to parse a namespace table.
/// If the namespace table is invalid, it returns a default single entry namespace table.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use NsTable::ns_range() which does exactly this already.

@mrain mrain merged commit a312872 into main Feb 26, 2025
53 checks passed
@mrain mrain deleted the cl/newvid branch February 26, 2025 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[VID Upgrade] new VID scheme integration
6 participants