-
Notifications
You must be signed in to change notification settings - Fork 249
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
Sequencer builder #367
Sequencer builder #367
Conversation
2fa8073
to
5dc5384
Compare
aee9900
to
0546f88
Compare
0546f88
to
2fbcc23
Compare
I've done my best to keep the tests aligned, but maybe they need another pass.
Would not work with mockall. Somewhat worse API now. Would like to revisit once we remove mockall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a lot of the one-liner functions undocumented as the function name should be enough in those cases.
It would also have been nicer to link to the actual Request<stage>
impls directly, but unfortunately rustdoc does not support that.
&self, | ||
block_hash: BlockHashOrTag, | ||
) -> Result<reply::Block, SequencerError>; | ||
async fn block(&self, block: BlockId) -> Result<reply::Block, SequencerError>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted the following:
async fn block(&self, block: BlockId) -> Result<reply::Block, SequencerError>; | |
async fn block<B: Into<BlockId>>(&self, block: B)-> Result<reply::Block, SequencerError>; |
but unfortunately this does not work with the mock library. Mostly just means that callers must append .into()
themselves on some calls. Might revisit this if / when we remove mocks for channels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better probably overall but this probably would had removed the object safety from the method, which is why it cannot be used. In general there has recent-ishly been discussion on the amount of bloat this pattern creates and what kind of countermeasures it needs, for example some stdlib functions are constructed with an generic layer on top of unsized reference accepting arg: https://doc.rust-lang.org/stable/src/std/fs.rs.html#228-236
This was due to not disabling retries under test cfg. This has now been fixed. |
query_url.query_pairs_mut().extend_pairs(params); | ||
tracing::trace!(%query_url); | ||
query_url | ||
fn request(&self) -> builder::Request<builder::stage::Gateway> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be a lifetime on the return value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appears to be ellided? Or rather, it hasn't forced me to add it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add the warning then on these. I guess too many write them out by default.
Or not ... There's 41 in this repo of #[warn(rust_2018_idioms)]
. I would prefer not to add to that. As a deny this looks like:
error: hidden lifetime parameters in types are deprecated
--> crates/pathfinder/src/storage/schema/revision_0011.rs:8:37
|
8 | pub(crate) fn migrate(transaction: &Transaction) -> anyhow::Result<PostMigrationAction> {
| ^^^^^^^^^^^ expected named lifetime parameter
|
help: consider using the `'_` lifetime
|
8 | pub(crate) fn migrate(transaction: &Transaction<'_>) -> anyhow::Result<PostMigrationAction> {
| ~~~~~~~~~~~~~~~
It is most likely cargo-fixable. I don't know why this isn't enabled automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking issue for warning for rust_2018_idioms by default indicates they were being conservative.
Personally, I didn't even know this was a thing :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll create a new PR which fixes the whole codebase and adds the check to ci.
This fixes the tests from infinitely retrying on failure. Also combines the final dual stages into a single one.
Previously our only route configured on the mock server actually required query parameters to be present. This changes the setup so that the query string is optional now. Note that we still "canonicalize" the full path and query and append a `?` even if there are now query parameters. This is actually required so that we don't have to modify tests that use these kind of URLs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I really like the way queries are built now 🎉 .
Would be nice to disable those retries in tests.
`eth_contract_addresses` and `add_transaction` tests are now consistent with the actual paths that are generated for the live api.
PR with my attempt at making a request builder for the sequencer queries. It uses the typestate pattern.
Current usage:
Still todo:
Also somewhat strangely, the tests for the transaction write's fail when executed locally, but pass when using the sequencer. I suspect it has something to do with the test setup; but I haven't figured out what / how to fix it.This is due to the warp test server requiring query params be set even when there aren't any. Our previous request implementation always set these params to
[]
whereas this new one never sets them if there aren't any (None
).I've also collapsed the
block_by_hash
andblock_by_number
into a single call:block(block_id)
whereBlockId
can representHash
,Number
,Latest
andPending
.