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

fix: Ledger create canister with --next-to transferring funds too early #3760

Merged
merged 12 commits into from
May 21, 2024
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ It is possible to override this in `.ic-assets.json` like this:
}
```

### fix: Transferring funds too early in `dfx ledger create-canister` with --next-to

When creating a canister with `dfx ledger create-canister --next-to` on a canister that does not exist (e.g., aaaaa-aa), then the funds are first transferred away from the users account, but the call then fails to create the new canister, and the funds are not returned to the user's account.
fxgst marked this conversation as resolved.
Show resolved Hide resolved

## Dependencies

### Updated to [agent-rs 0.35.0](https://github.com/dfinity/agent-rs/blob/main/CHANGELOG.md#0350---2024-05-10)
Expand Down
4 changes: 4 additions & 0 deletions e2e/tests-dfx/ledger.bash
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ tc_to_num() {
assert_match "Refunded at block height"
assert_match "with message: Subnet $SUBNET_ID does not exist"

CANISTER_ID="aaaaa-aa"
assert_command dfx ledger create-canister --amount=100 --next-to "$CANISTER_ID" "$(dfx identity get-principal)"
assert_match "unable to determine subnet: Canister is not assigned to any subnet"

fxgst marked this conversation as resolved.
Show resolved Hide resolved
# Transaction Deduplication
t=$(current_time_nanoseconds)

Expand Down
9 changes: 5 additions & 4 deletions src/dfx/src/commands/ledger/create_canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ pub async fn exec(env: &dyn Environment, opts: CreateCanisterOpts) -> DfxResult

fetch_root_key_if_needed(env).await?;

let subnet_selection = opts
.subnet_selection
.into_subnet_selection_type(env)
.await?;

let height = transfer_cmc(
agent,
env.get_logger(),
Expand All @@ -86,10 +91,6 @@ pub async fn exec(env: &dyn Environment, opts: CreateCanisterOpts) -> DfxResult
.await?;
println!("Using transfer at block height {height}");

let subnet_selection = opts
.subnet_selection
.into_subnet_selection_type(env)
.await?;
let result = notify_create(agent, controller, height, subnet_selection).await;

match result {
Expand Down
Loading