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: Starknet data source validation with improvements #5030

Conversation

xJonathanLEI
Copy link
Contributor

Long overdue follow-up PR of #4895 to resolve this comment from @mangas.

Main changes:

  1. renames block_handlers to block_handler (and type changed from Vec<_> to Option<_>) because it makes more sense.
  2. implements data source validation with validate() (this function previously always returns an empty array).

Also adds data source validation tests to chain/starknet/src/chain.rs, similar to those found in chain/near/src/chain.rs. This does not include trigger filter tests in chain/near/src/chain.rs though - trigger filter hasn't been implemented for Starknet, as noted in the original PR, and should be addressed with another follow-up PR.

In the process of implementing validation, I noticed that the DataSource trait has a method address() that returns a Option<&[u8]>, which is impossible to implement with the previous use of FieldElement in the data source, as this type doesn't have a [u8] backing. The type uses the Montgomery representation internally for fast finite field mulitplication, at the cost of slower (de)serialization. However, in graph-node, this type is only used for equality comparison, which calls for a type that's backed by a u8 array instead.

Therefore, this PR also adds a new type Felt that's a wrapper around [u8; 32], and replaces any FieldElement occurrence. The starknet-ff dependency is also removed.

@fordN fordN requested a review from mangas November 30, 2023 16:15
@xJonathanLEI
Copy link
Contributor Author

xJonathanLEI commented Dec 4, 2023

Just finished implementing block and event trigger filter, which depends on the Felt type introduced in this PR. Will submit as follow-up once this gets reviewed and merged.

Currently, an array of block handlers is allowed, but only the first one
is actually used. This can easily cause confusion for end users.

While this is technically a breaking change, it should be fine as the
support for Starknet isn't official yet.
Currently, the native `FieldElement` type is used for Starknet data
sources, which uses the Montgomery representation internally for fast
finite field mulitplication, at the cost of slower (de)serialization.
However, in `graph-node`, this type is only used for equality
comparison, which calls for a type that's backed by a `u8` array
instead.

In fact, the `graph::blockchain::DataSource` trait requires the return
type of its `address()` method to be `Option<&[u8]>`, which necessitates
the use of `u8`-backed types (currently the Starknet data source simply
returnes `None`).

This commit adds a new type `Felt` that's a wrapper around `[u8; 32]`,
and replaces any `FieldElement` occurrence. The `starknet-ff` dependency
is also removed.
@xJonathanLEI xJonathanLEI force-pushed the dev/starknet_ds_validation branch from e0d0bd7 to 31777b0 Compare January 22, 2024 15:48
@xJonathanLEI
Copy link
Contributor Author

Thanks @mangas for the review and approval. I've rebased the branch to the latest master (f016503e3) due to conflicts introduced by dependabot bumping starknet-ff, as we're removing it completely here. No changes were made other than resolving this specific conflict.

@incrypto32 incrypto32 changed the base branch from master to krishna/v0.34.0 January 22, 2024 16:42
@xJonathanLEI
Copy link
Contributor Author

Hi @incrypto32, I noticed that the base branch has been changed to the v0.34.0 tree. Will this get ported to master once it's reviewed and merged? Asking cuz I have a follow-up PR that depends on this one, so it would be nice if these changes are available on master soon too. Thanks!

@incrypto32
Copy link
Member

Yes @xJonathanLEI, will be merged to master once the release goes out

@xJonathanLEI
Copy link
Contributor Author

Thanks for confirming!

@incrypto32 incrypto32 merged commit 4b412f7 into graphprotocol:krishna/v0.34.0 Jan 22, 2024
7 checks passed
@xJonathanLEI xJonathanLEI deleted the dev/starknet_ds_validation branch January 22, 2024 18:04
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.

3 participants