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

Starknet Chain Client: Add Block Methods #373

Merged
merged 10 commits into from
May 23, 2024

Conversation

augustbleeds
Copy link
Collaborator

@augustbleeds augustbleeds commented Mar 14, 2024

https://smartcontract-it.atlassian.net/browse/BCI-2676

Adding 3 block-related methods so RTSP can begin playing around with fetching blocks and the Batch() method to lay the groundwork for the rest of the methods. Rest of the process should be straightforward after this PR.

Added the ChainId method as well. Turns out the starknet.go provider automatically caches the chainId after first request, so our implementation uses the batchCall always

Original Design Doc: https://docs.google.com/document/d/10jsfp7_VqDv2GFGILmTX2ey-p_yaFyvxPaVszL6kg6g/edit

Open Questions:

  • For batch calls, the user will need to iterate through the batchElem array and cast the Result interface to the expected return type. This seems like a weird user experience so I'm open to feedback on how to improve this. RESOLVED

Args: []interface{}{
starknetrpc.BlockID{Hash: h},
},
Result: &FinalizedBlock{},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i learned the result is stored within the same BatchElem type.

and that you need to allocate the memory for the type you expect to be returned, which is json deserialized from the RPC

// used to create batch requests
type StarknetBatchBuilder interface {
RequestBlockByHash(h *felt.Felt) (StarknetBatchBuilder, error)
// RequestBlockByNumber(id uint64) (StarknetBatchBuilder, error)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will be uncommented as the corresponding methods in the chain client are implemented

Provider: starknetrpc.NewProvider(c),
lggr: lggr,
Provider: starknetrpc.NewProvider(c),
EthClient: c,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add the ethrpc client to the struct so we can take advantage of its batch call capabilities!

return b.args
}

type StarknetChainClient interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How different is this from using what we have in client.go/Reader? We should be able to share the interfaces

Copy link
Collaborator Author

@augustbleeds augustbleeds Mar 19, 2024

Choose a reason for hiding this comment

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

there's definitely some possibility for re-using the reader client methods. but if you mean to combine the interfaces, we've made it a design decision that chain client interface is distinct and set apart because it is dictated by the customer (atlas now) needs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For this PR specifically, we introduced BlockByHash and BlockHashAndNumber.

In terms of replacing, re-using the existing calls, I didn't remove/replace BlockByHash (returns txs) with the already written BlockWithTxHashes (returns tx hashes) because we need the block with txs.

I can simplify the logic of LatestBlockHeight to call BlockHashAndNumber, though. Would you like me to do that?

@augustbleeds augustbleeds marked this pull request as draft March 28, 2024 13:59
@augustbleeds augustbleeds merged commit b1f31c0 into develop May 23, 2024
16 of 18 checks passed
@augustbleeds augustbleeds deleted the augustus.first-chain-client-method branch May 23, 2024 16:20
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.

5 participants