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

feat(ethportal-api): add BeaconState type #1150

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

ogenev
Copy link
Member

@ogenev ogenev commented Feb 8, 2024

What was wrong?

To add support for Era files, we need to deserialize the beacon state. No BeaconState type is available in ethportal-api.

How was it fixed?

Implement BeaconState type

To-Do

@ogenev ogenev force-pushed the support-era-files branch from 89ea6ea to 73241e8 Compare February 8, 2024 16:12
@ogenev ogenev self-assigned this Feb 8, 2024
@ogenev ogenev force-pushed the support-era-files branch 3 times, most recently from cae5d3e to f104d1f Compare February 13, 2024 09:27
@ogenev ogenev changed the title feat(ethportal-api): Add BeaconState type feat(ethportal-api): add BeaconState type Feb 13, 2024
@ogenev ogenev marked this pull request as ready for review February 13, 2024 13:35
@KolbyML
Copy link
Member

KolbyML commented Feb 15, 2024

I think these test files should go in portal-test-specs.

@ogenev
Copy link
Member Author

ogenev commented Feb 19, 2024

I think these test files should go in portal-test-specs.

Hmm, not sure, those are test assets for ethereum beacon network, not related to portal network specs.

@KolbyML
Copy link
Member

KolbyML commented Feb 19, 2024

I think these test files should go in portal-test-specs.

Hmm, not sure, those are test assets for ethereum beacon network, not related to portal network specs.

The repo is just has spec in the name because of convention (execution-spec-tests and consensus-spec-tests) the repo is just for test data. Expessially with how big these test data files are. This is exactly why the portal-spec-test repo was made so we didn't need to have big test files in ethereum/trin and so other portal implementations could reuse the same test data. I am assuming since we are using these test data file other portal beacon implementations would also find value in it as well. Those reasons don't have to be mutually exlusive though to put test data there.

So the general direction should be a migration from test_assets -> portal-spec-tests for where we host our test data.

@ogenev
Copy link
Member Author

ogenev commented Feb 19, 2024

The repo is just has spec in the name because of convention (execution-spec-tests and consensus-spec-tests) the repo is just for test data. Expessially with how big these test data files are. This is exactly why the portal-spec-test repo was made so we didn't need to have big test files in ethereum/trin and so other portal implementations could reuse the same test data. I am assuming since we are using these test data file other portal beacon implementations would also find value in it as well. Those reasons don't have to be mutually exlusive though to put test data there.

So the general direction should be a migration from test_assets -> portal-spec-tests for where we host our test data.

Those test files are extracted from consensus-spec-tests repo because I don't want to add this repo as a submodule - it is very huge, we want to use a few folders and use Git Large File Storage which will complicate our workflow.

Those files here are used for testing serialization/deserialization for the BeaconState which is part of the consensus specs and is used for deserializing Era files. I don't think that we want to migrate all test_assets to portal-spec-tests because most of those files are used to test Trin-specific implementations and not all of them are part of portal specs. I think portal-test-specs should be kept only for test assets for the portal network implementation which should not include consensus and execution layer test files.

The repo is just has spec in the name because of convention (execution-spec-tests and consensus-spec-tests) the repo is just for test data.

I don't think this is true. If we just want to have a repo for storing large files for testing in trin, it should be called trin-tests. Using the same convention as execution-spec-tests and consensus-spec-tests is not a coincidence, it is because we want to accomplish the same thing for the portal - store test assets and test vectors that are used for testing portal network specs.

@njgheorghita, @morph-dev what do you think?

@morph-dev
Copy link
Collaborator

I'm not sure I have enough knowledge of beacon network and these files to provide opinion on this specific case. I'm also missing broader context of what portal-spec-tests should be (and if it should be follow the same principles as execution-spec-tests and consensus-spec-tests). With that being said, I will still give my opinion.

My feeling is that portal-spec-tests should contain test files that can/should be used by all clients in order to test their implementation of the Portal Network. Are all clients expected to deserialize Era files?!
Even if it is not required by portal network spec, but if it is expected or useful in general context (e.g. in order to verify data, build bridge, etc.), I would say they can go there (e.g. under special directory, with README file as explanation).

I also believe that we probably have some files in test_assets that we don't want to move to portal-spec-tests because they are trin specific.

Copy link
Collaborator

@njgheorghita njgheorghita left a comment

Choose a reason for hiding this comment

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

A few questions about automatically deriving traits, just to double check that there's a good reason for manually implementing them, rather than automatically deriving them.

With regards to the test assets location...
I also don't have a clear understanding of the spec repo's defined purpose.

  • Is it strictly for client-agnostic json test vectors for clients to test against?

or...

  • Is it a dump for all large test files b/c we don't want to increase the size of trin?

This is probably something that needs defining, and inscribing in the readme's, so we don't have to repeat this debate for every future test vector. For the purpose of this pr, I think it's ok to move ahead as-is (eg. test files inside trin). Let's discuss this in the next sync, figure out how we want to define what test assets go where. And then if we do decide that these test vectors are better suited in the specs repo, then we can make that change later.

use tree_hash::{Hash256, PackedEncoding, TreeHash, TreeHashType};

#[derive(Debug, Default, Clone, Copy, PartialEq, Deserialize, Serialize)]
#[serde(transparent)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a docstring here

@@ -0,0 +1,312 @@
#[cfg(test)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same reasoning as this comment .

use std::sync::Arc;
use superstruct::superstruct;
use tree_hash::{Hash256, TreeHash};
use tree_hash_derive::TreeHash;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we have a clippy lint for ordering imports into groups? eg. std first, exterior second, internal third

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what ordering we use but this can be changed in the config. I think now it is internal first, std next and external latest.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on the rustfmt documentation, the default is (what we use) to preserve the source file's import groups.

Alternative, which we could enable, is closer to what @njgheorghita said:

  1. std, core and alloc,
  2. external crates,
  3. self, super and crate imports.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think that would be nice to enable in the lint, since it is what we use throughout the majority of the codebase

}

impl BeaconState {
#[cfg(test)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Really? Why do we only want to ssz decode the state inside our tests? Is this to avoid the dead_code lint? If so, then I'd prefer to use allow[clippy::dead_code]

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it is to avoid the dead_code lint. I prefer this because that way we will not forget to remove the dead code attribute if it is not used.

Anyways, in #1167 I'm removing this.

@ogenev ogenev merged commit 4daeb49 into ethereum:master Feb 20, 2024
8 checks passed
@ogenev ogenev deleted the support-era-files branch February 20, 2024 09:41
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.

4 participants