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: use cycles ledger to create canisters #3473

Conversation

sesi200
Copy link
Contributor

@sesi200 sesi200 commented Dec 7, 2023

Description

This PR makes dfx use the cycles ledger to create canisters when no wallet is configured.

Fixes SDK-1173

How Has This Been Tested?

Added e2e

Checklist:

  • The title of this PR complies with Conventional Commits.
  • I have NOT edited the CHANGELOG accordingly because this will be gated behind a feature flag
  • I have made corresponding changes to the documentation.

@sesi200 sesi200 changed the title Sdk 1173 dfx deploy canister create create new canisters using the principals cycles feat: use cycles ledger to create canisters Dec 7, 2023
@sesi200 sesi200 marked this pull request as ready for review December 8, 2023 09:41
@sesi200 sesi200 requested review from chenyan-dfinity and a team as code owners December 8, 2023 09:41
}

let cycles = with_cycles.unwrap_or(CANISTER_CREATE_FEE + CANISTER_INITIAL_CYCLE_BALANCE);
let result = agent
Copy link
Member

Choose a reason for hiding this comment

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

Please set created_at_time, so that it's an idempotent operation, and wrap this call in retry logic. This will reduce the likelihood of burning cycles creating a canister but not storing the canister id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm setting and logging the created_at_time now so the result will be recoverable. I don't think it makes sense to add a loop because there is no error for which a retry really makes sense (except for whatever the agent can retry on its own).

Choose a reason for hiding this comment

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

Though it is possible to handle all of this by making the user retry their command (this time specifying --created-at-time and altering the command to create or deploy a single canister), in a case where we have an idempotent operation, in my opinion it's better to handle that retry in code.

As for determine when to retry, you are correct: it is difficult. A guess is AgentError::TimeoutWaitingForResponse() | AgentError::TransportError(_), here: https://github.com/dfinity/sdk/blob/master/src/dfx/src/lib/retryable.rs#L6.

Regarding "whatever the agent can retry on its own", the agent does not retry TransportError because it can't.
(See https://github.com/dfinity/agent-rs/blob/main/ic-agent/src/agent/http_transport/reqwest_transport.rs#L88 for an example, and up the call stack). It can't because after sending the initial request, there exists a class of errors for which it can't know if the server received the request and is executing it or not, and the agent doesn't know if the request is idempotent or not.

Relying on the agent's retry mechanisms also means relying on those mechanisms to be correct. They may or may not be. For example, Agent's fn wait doesn't retry if fn poll returns an Err, and fn poll will return an error right away in the case of connection timeout when making the read_state call.

Given the above, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idempotency argument makes sense. I'll use retryable for now and if we find a better heuristic we can always impove it

@sesi200 sesi200 merged commit 3b7d576 into master Jan 10, 2024
172 checks passed
@sesi200 sesi200 deleted the SDK-1173-dfx-deploy-canister-create-create-new-canisters-using-the-principals-cycles branch January 10, 2024 10:13
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.

3 participants