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: simplify Call implementation and enable retry logic #551

Merged
merged 8 commits into from
Jan 24, 2025

Conversation

lwshang
Copy link
Contributor

@lwshang lwshang commented Jan 22, 2025

SDK-1948

Description

Previously, such call retry logic is not possible:

async fn retry<C: SendableCall>(call_to_retry: C) {
    loop {
        match call_to_retry.call_raw().await {
            // handle
        }
    }
}

Now the implementation is simplified that CallWith* structs, ConfigurableCall and SendableCall traits/impls are removed. As a result, the prelude module is removed which was mainly for importing the two *Call traits.

The arguments are encoded once in with_arg and with_args, only the encoded_args is saved in the Call struct.
Therefore, the call can be sent multiple times.

async fn retry(call_to_retry: Call<'_, '_>) {
    loop {
        match call_to_retry.call_raw().await {
            // handle
        }
    }
}

This PR relies on dfinity/candid#593.
We need to wait for a Candid release once it's merged.
Then we can update the candid dependency in Cargo.toml.
This is Done.

How Has This Been Tested?

Added retry_calls in e2e-test/call.rs

Checklist:

  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • I have made corresponding changes to the documentation.

lwshang added a commit to dfinity/candid that referenced this pull request Jan 22, 2025
`ArgumentEncoder` now have an extra `encode_ref()` method which takes
`&self` instead of `self`.
Calling `encode_ref()` won't consume the value.

The utils functions `write_args_ref()` and `encode_args_ref()` are also
added.

This change is required in dfinity/cdk-rs#551.

We will need to make a patch release of candid once this is approved.
@lwshang lwshang marked this pull request as ready for review January 22, 2025 23:00
@lwshang lwshang requested a review from a team as a code owner January 22, 2025 23:00
Get rid of the ConfigurableCall trait and the CallWithArg, CallWithArgs, and CallWithRawArgs structs.
Instead, we now have a single Call struct that can be configured and executed using chainable methods.
@lwshang lwshang changed the title feat!: SendableCall methods take &self feat: simplify Call implementation and enable retry logic Jan 23, 2025
@lwshang lwshang merged commit d823cb5 into next Jan 24, 2025
16 of 17 checks passed
@lwshang lwshang deleted the lwshang/repeat_calls branch January 24, 2025 00:54
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.

2 participants