-
Notifications
You must be signed in to change notification settings - Fork 991
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
feat: Starknet data source validation with improvements #5030
Conversation
Just finished implementing block and event trigger filter, which depends on the |
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.
e0d0bd7
to
31777b0
Compare
Thanks @mangas for the review and approval. I've rebased the branch to the latest |
Hi @incrypto32, I noticed that the base branch has been changed to the |
Yes @xJonathanLEI, will be merged to master once the release goes out |
Thanks for confirming! |
Long overdue follow-up PR of #4895 to resolve this comment from @mangas.
Main changes:
block_handlers
toblock_handler
(and type changed fromVec<_>
toOption<_>
) because it makes more sense.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 inchain/near/src/chain.rs
. This does not include trigger filter tests inchain/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 methodaddress()
that returns aOption<&[u8]>
, which is impossible to implement with the previous use ofFieldElement
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, ingraph-node
, this type is only used for equality comparison, which calls for a type that's backed by au8
array instead.Therefore, this PR also adds a new type
Felt
that's a wrapper around[u8; 32]
, and replaces anyFieldElement
occurrence. Thestarknet-ff
dependency is also removed.