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

chore: upgrade jsonrpsee to 0.11 #261

Merged
merged 12 commits into from
May 31, 2022
Merged

Conversation

tarrencev
Copy link
Contributor

@tarrencev tarrencev commented Apr 27, 2022

i've started the process of upgrading to 0.11 to support configuring the hyper instance to handle health checks. it's mostly just adjusting imports/namespaces. im pretty new to rust, so would appreciate any feedback / guidance. in particular, i'm struggling to case the errors to the new type

@tarrencev tarrencev force-pushed the updaterpsee branch 2 times, most recently from 4bdfe9f to 5b51086 Compare April 27, 2022 21:18
@koivunej
Copy link
Contributor

koivunej commented Apr 28, 2022

in particular, i'm struggling to case the errors to the new type

If you mean this error:

error[E0277]: the trait bound `jsonrpsee::jsonrpsee_types::error::ErrorCode: From<rpc::types::reply::ErrorCode>` is not satisfied
   --> crates/pathfinder/src/rpc/types.rs:404:29
    |
404 |                 code: ecode.into(),
    |                             ^^^^ the trait `From<rpc::types::reply::ErrorCode>` is not implemented for `jsonrpsee::jsonrpsee_types::error::ErrorCode`
    |
    = help: the following implementations were found:
              <jsonrpsee::jsonrpsee_types::error::ErrorCode as From<i32>>
    = note: required because of the requirements on the impl of `Into<jsonrpsee::jsonrpsee_types::error::ErrorCode>` for `rpc::types::reply::ErrorCode`

Looking at it, it's quite difficult to understand from the error message. Since it used to be that CallError::Custom { code: i32, ... }. To get past this on to the next error, you can just:

$ git diff
diff --git a/crates/pathfinder/src/rpc/types.rs b/crates/pathfinder/src/rpc/types.rs
index 88ed24b..1bd52f2 100644
--- a/crates/pathfinder/src/rpc/types.rs
+++ b/crates/pathfinder/src/rpc/types.rs
@@ -400,8 +400,9 @@ pub mod reply {

     impl From<ErrorCode> for Error {
         fn from(ecode: ErrorCode) -> Self {
+            let error: i32 = ecode as i32;
             Error::Call(CallError::Custom(ErrorObject {
-                code: ecode.into(),
+                code: error.into(),
                 message: Cow::Owned(ecode.to_string()),
                 data: None,
             }))

So our ErrorCode can be converted to i32 with as i32 conversion because it is defined as enum Foo { Variant = 1, ... }, and the jsonrpcsee ErrorCode has an From<i32> conversion, so it sounds like this would be at least a temporary measure to get forward. There will be a next error with the introduced ErrorObject which has ErrorObject::owned for creating it.

Hopefully this helps you forwards! Please keep asking questions but as a reminder we haven't done the upgrade yet so there might be more troublesome parts ahead!

@koivunej
Copy link
Contributor

Using ErrorObject::owned is a bit difficult as well since we need to pass the None. This seems to work ErrorObject::owned(error, Cow::Owned(ecode.to_string()), Option::<()>::None) in the setting after introducing the error: i32 from previous message, and let you on to perhaps more clear errors.

@tarrencev
Copy link
Contributor Author

@koivunej thanks so much for your feedback! I made some progress and the binary is compiling now!

@tarrencev tarrencev force-pushed the updaterpsee branch 3 times, most recently from 67ad1d0 to 91fa3b2 Compare April 28, 2022 13:36
@koivunej
Copy link
Contributor

You can just add commits for now and rebase when done, it would be easier to follow to help if need be.

crates/pathfinder/src/rpc/api.rs Outdated Show resolved Hide resolved
crates/pathfinder/src/rpc/types.rs Outdated Show resolved Hide resolved
@koivunej
Copy link
Contributor

@tarrencev I found the cause for rpc::tests::events::positional_args::get_events_with_invalid_page_size failure and fixed it in 1e86e79. The previous version looked very much the same but since the ErrorObject::owned takes a serializable object now in 0.11 (instead of RawValue in 0.6), the serde_json::value::Value needs to be given instead of it's stringified version. Pushed and cleaned up most of the tarrancev_updaterpsee branch.

@tarrencev
Copy link
Contributor Author

@tarrencev I found the cause for rpc::tests::events::positional_args::get_events_with_invalid_page_size failure and fixed it in 1e86e79. The previous version looked very much the same but since the ErrorObject::owned takes a serializable object now in 0.11 (instead of RawValue in 0.6), the serde_json::value::Value needs to be given instead of it's stringified version. Pushed and cleaned up most of the tarrancev_updaterpsee branch.

awesome. thanks for taking it on. should we close this in favor of your pr?

@koivunej
Copy link
Contributor

koivunej commented May 1, 2022

Let's just keep it these both open, I can handle the merging of the work when we are done reviewing. Thanks a lot for getting the ball rolling!

Copy link
Contributor

@kkovaacs kkovaacs left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@CHr15F0x CHr15F0x left a comment

Choose a reason for hiding this comment

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

Looking good 👍

@tarrencev
Copy link
Contributor Author

@koivunej anything i can help with to push this across the line? :)

@tarrencev tarrencev force-pushed the updaterpsee branch 2 times, most recently from 1ea7ec3 to c524e30 Compare May 7, 2022 14:29
@tarrencev tarrencev marked this pull request as ready for review May 7, 2022 14:29
@tarrencev
Copy link
Contributor Author

@koivunej @kkovaacs @CHr15F0x thanks for your help on this. i've rebased + migrated some new code to be compatible with 0.11. would be great to get this merged so we can support #194

Copy link
Contributor

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

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

Some clippy, test and doc fixes required.

@koivunej
Copy link
Contributor

koivunej commented May 9, 2022

@tarrencev We will be postponing this until we get the next release out, so nothing at the moment. Of course, feel free to handle any of the clippy/doc failures, which should be quite straight forward.

@tarrencev
Copy link
Contributor Author

@tarrencev We will be postponing this until we get the next release out, so nothing at the moment. Of course, feel free to handle any of the clippy/doc failures, which should be quite straight forward.

ok thanks for the update! i'll keep this branch in shape and work on another on top to expose the health check

@koivunej
Copy link
Contributor

koivunej commented May 9, 2022

The failed update::tests::fetch_latest_github_release must be a transient one.

@koivunej
Copy link
Contributor

koivunej commented May 9, 2022

The remaining test failures should work okay, the issue is with secrets.

@koivunej
Copy link
Contributor

Rebased to the latest, secrets are still the only issue.

Copy link
Member

@CHr15F0x CHr15F0x left a comment

Choose a reason for hiding this comment

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

LGTM!

tarrencev and others added 12 commits May 31, 2022 15:00
this is not necessarily great, since these strings were also from the
spec. however, duplication is duplication. maybe should add a comment
instead to note what the strings are used in ErrorCode.

also removes the rpc::tests::errors statics and the get_err function
used to unwrap jsonrpsee 0.6 error response.
instead of rebuilding the errorobject in the partialeq and duplicating
code, rebuild the jsonrpsee::...::Error from the ErrorCode or hardcoded
EventFilterError.

also 1) scopes down the `use` for jsonrpsee::...::Error because the file
has too many items with "error" in their name and 2) adds a debug
assertion for using From<ErrorCode> for jsonrpsee::...::Error with the
PageSizeTooBig. perhaps there's a better idea to be found for this.
@koivunej
Copy link
Contributor

Allright, thanks a lot @tarrencev! Apologies for the delay, we had some interesting times with releases and bugs in the meantime :)

@koivunej koivunej merged commit 53320a6 into eqlabs:main May 31, 2022
@tarrencev tarrencev deleted the updaterpsee branch May 31, 2022 12: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.

6 participants