Skip to content

Commit

Permalink
Merge branch 'master' into SDK-1173-dfx-deploy-canister-create-create…
Browse files Browse the repository at this point in the history
…-new-canisters-using-the-principals-cycles
  • Loading branch information
sesi200 committed Jan 9, 2024
2 parents a6f65e9 + 6cd8c1d commit 5e2c9f5
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 175 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# UNRELEASED

### feat!: update `dfx cycles` commands with mainnet `cycles-ledger` canister ID

The `dfx cycles` command no longer needs nor accepts the `--cycles-ledger-canister-id <canister id>` parameter.

### chore: removed ic-ref from the binary cache

# 0.15.3

### fix: allow `http://localhost:*` as `connect-src` in the asset canister's CSP
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions docs/cli-reference/dfx-cycles.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ You can specify the following arguments for the `dfx cycles balance` command.
| `--owner <principal>` | Display the balance of this principal |
| `--subaccount <subaccount>` | Display the balance of this subaccount |
| `--precise` | Displays the exact balance, without scaling to trillions of cycles. |
| `--cycles-ledger-canister-id <canister id>` | Specify the ID of the cycles ledger canister. |

### Examples

> **NOTE**: None of the examples below specify the `--cycles-ledger-canister-id` option, but it is required until the cycles ledger canister ID is known.
Check the cycles balance of the selected identity.

```
Expand Down
4 changes: 1 addition & 3 deletions docs/cli-reference/dfx-ledger.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,14 @@ If no amount is specified, 10T cycles are used by default.
If you are developing locally and want to add 8T cycles to all your canisters in your procject, you can do so like this:

```
dfx ledger fabricate-cycles --all --amount 8000000000000
dfx ledger fabricate-cycles --all --cycles 8000000000000
```

The command displays output similar to the following:

```
Fabricating 8000000000000 cycles onto hello_backend
Fabricated 8000000000000 cycles, updated balance: 11_899_662_119_932 cycles
Fabricating 8000000000000 cycles onto hello_frontend
Fabricated 8000000000000 cycles, updated balance: 11_899_075_504_924 cycles
```

If you would rather only add the cycles to the canister called 'hello' and don't want to type all the zeros, you can do it like this:
Expand Down
173 changes: 86 additions & 87 deletions e2e/tests-dfx/cycles-ledger.bash

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,6 @@
"url": "https://download.dfinity.systems/ic/69e1408347723dbaa7a6cd2faa9b65c42abbe861/openssl-static-binaries/x86_64-linux/ic-nns-init.gz",
"url_template": "https://download.dfinity.systems/ic/<rev>/openssl-static-binaries/x86_64-linux/ic-nns-init.gz"
},
"ic-ref-x86_64-darwin": {
"builtin": false,
"rev": "3cc51be58784ba9b6e9a06afb4b59a11fb31c771",
"sha256": "03w92npwpvsrlh4icnq1cpz9dc54wpbqfqvzm1558vglg52nkhg1",
"type": "file",
"url": "https://download.dfinity.systems/ic-ref/ic-ref-0.0.1-a9f73dba-x86_64-darwin.tar.gz",
"url_template": "https://download.dfinity.systems/ic-ref/ic-ref-<version>-x86_64-darwin.tar.gz",
"version": "0.0.1-a9f73dba"
},
"ic-ref-x86_64-linux": {
"builtin": false,
"rev": "3cc51be58784ba9b6e9a06afb4b59a11fb31c771",
"sha256": "1962cb5kyx92ysi6pn81rl48zd1k4r12gc0xbfab5lc79rv6fjaw",
"type": "file",
"url": "https://download.dfinity.systems/ic-ref/ic-ref-0.0.1-a9f73dba-x86_64-linux.tar.gz",
"url_template": "https://download.dfinity.systems/ic-ref/ic-ref-<version>-x86_64-linux.tar.gz",
"version": "0.0.1-a9f73dba"
},
"ic-starter-x86_64-darwin": {
"builtin": false,
"rev": "69e1408347723dbaa7a6cd2faa9b65c42abbe861",
Expand Down
5 changes: 3 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tags": {
"latest": "0.15.2"
"latest": "0.15.3"
},
"versions": [
"0.5.0",
Expand Down Expand Up @@ -60,6 +60,7 @@
"0.14.4",
"0.15.0",
"0.15.1",
"0.15.2"
"0.15.2",
"0.15.3"
]
}
19 changes: 0 additions & 19 deletions scripts/update-ic-ref.sh

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/write-dfx-asset-sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ write_replica_rev
motoko_base_sha="$(calculate_sha256 "motoko-base")"
for platform in "darwin" "linux";
do
for name in "ic-ref" "icx-proxy" "ic-admin" "ic-btc-adapter" "ic-https-outcalls-adapter" "ic-nns-init" "ic-starter" "motoko" "replica" "canister_sandbox" "sandbox_launcher" "sns";
for name in "icx-proxy" "ic-admin" "ic-btc-adapter" "ic-https-outcalls-adapter" "ic-nns-init" "ic-starter" "motoko" "replica" "canister_sandbox" "sandbox_launcher" "sns";
do
if [[ "$name" == "replica" || "$name" == "canister_sandbox" ]]; then
echo "# The replica and canister_sandbox binaries must have the same revision." >>"$DFX_ASSET_SOURCES"
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dfx"
version = "0.15.1"
version = "0.15.3"
authors.workspace = true
edition.workspace = true
repository.workspace = true
Expand Down
8 changes: 0 additions & 8 deletions src/dfx/assets/dfx-asset-sources.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# generated by write-dfx-asset-sources.sh
replica-rev = '69e1408347723dbaa7a6cd2faa9b65c42abbe861'

[x86_64-darwin.ic-ref]
url = 'https://download.dfinity.systems/ic-ref/ic-ref-0.0.1-a9f73dba-x86_64-darwin.tar.gz'
sha256 = 'e1c1694579f46d544aa87f6387d7e5a4b096fe65015b1609a459efcbaf15890f'

[x86_64-darwin.icx-proxy]
url = 'https://download.dfinity.systems/ic/69e1408347723dbaa7a6cd2faa9b65c42abbe861/openssl-static-binaries/x86_64-darwin/icx-proxy-dev.gz'
sha256 = 'b07f2784abddcb54f0b0d3ce7585b9283cf814870905d58c26a1c8823ead2fdd'
Expand Down Expand Up @@ -59,10 +55,6 @@ sha256 = '3ee345fb0357ee9305e911d8aa30a00675114c3247af79bb16b8c21f8477dc3c'
url = 'https://github.com/dfinity/bitcoin-canister/releases/download/release%2F2023-10-13/ic-btc-canister.wasm.gz'
sha256 = '09f5647a45ff6d5d05b2b0ed48613fb2365b5fe6573ba0e901509c39fb9564ac'

[x86_64-linux.ic-ref]
url = 'https://download.dfinity.systems/ic-ref/ic-ref-0.0.1-a9f73dba-x86_64-linux.tar.gz'
sha256 = '5c4967764e87d1b2945b1db027422633b48f08cd01d96ba2f622753fcb62c2a4'

[x86_64-linux.icx-proxy]
url = 'https://download.dfinity.systems/ic/69e1408347723dbaa7a6cd2faa9b65c42abbe861/openssl-static-binaries/x86_64-linux/icx-proxy-dev.gz'
sha256 = '2bff6952a65e2d94f49ffa5ce03bfbd0eef0fb6ca82a839844c84fd3efa8b280'
Expand Down
9 changes: 5 additions & 4 deletions src/dfx/assets/prepare_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn write_binary_cache(
Compression::new(6),
));
for (path, bin) in bins.into_iter().chain(
["ic-ref", "moc", "mo-doc", "mo-ide"]
["moc", "mo-doc", "mo-ide"]
.map(|bin| (bin.into(), bin_tars.remove(Path::new(bin)).unwrap())),
) {
let mut header = Header::new_gnu();
Expand Down Expand Up @@ -220,13 +220,14 @@ async fn download_bin_tarballs(
sources: Arc<HashMap<String, Source>>,
) -> HashMap<PathBuf, Bytes> {
let mut map = HashMap::new();
let [motoko, ic_ref] = ["motoko", "ic-ref"].map(|pkg| {
let [motoko] = ["motoko"].map(|pkg| {
let client = client.clone();
let source = sources[pkg].clone();
spawn(download_and_check_sha(client, source))
});
let (motoko, ic_ref) = tokio::try_join!(motoko, ic_ref).unwrap();
for tar in [motoko, ic_ref] {
let (motoko,) = tokio::try_join!(motoko,).unwrap();
{
let tar = motoko;
tar_xzf(&tar, |path, content| {
map.insert(path, content);
});
Expand Down
9 changes: 1 addition & 8 deletions src/dfx/src/commands/cycles/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ pub struct CyclesBalanceOpts {
/// Get balance raw value (without upscaling to trillions of cycles).
#[arg(long)]
precise: bool,

/// Canister ID of the cycles ledger canister.
/// If not specified, the default cycles ledger canister ID will be used.
// todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262
#[arg(long)]
cycles_ledger_canister_id: Principal,
}

pub async fn exec(env: &dyn Environment, opts: CyclesBalanceOpts) -> DfxResult {
Expand All @@ -41,8 +35,7 @@ pub async fn exec(env: &dyn Environment, opts: CyclesBalanceOpts) -> DfxResult {

let subaccount = opts.subaccount.map(|x| x.0);

let balance =
cycles_ledger::balance(agent, owner, subaccount, opts.cycles_ledger_canister_id).await?;
let balance = cycles_ledger::balance(agent, owner, subaccount).await?;

if opts.precise {
println!("{} cycles.", balance);
Expand Down
7 changes: 0 additions & 7 deletions src/dfx/src/commands/cycles/top_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ pub struct TopUpOpts {
/// https://internetcomputer.org/docs/current/developer-docs/integrations/icrc-1/#transaction-deduplication-
#[arg(long)]
created_at_time: Option<u64>,

/// Canister ID of the cycles ledger canister.
/// If not specified, the default cycles ledger canister ID will be used.
// todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262
#[arg(long)]
cycles_ledger_canister_id: Principal,
}

pub async fn exec(env: &dyn Environment, opts: TopUpOpts) -> DfxResult {
Expand All @@ -58,7 +52,6 @@ pub async fn exec(env: &dyn Environment, opts: TopUpOpts) -> DfxResult {
amount,
created_at_time,
from_subaccount,
opts.cycles_ledger_canister_id,
)
.await;
if result.is_err() && opts.created_at_time.is_none() {
Expand Down
7 changes: 0 additions & 7 deletions src/dfx/src/commands/cycles/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ pub struct TransferOpts {
/// Memo.
#[arg(long)]
memo: Option<u64>,

/// Canister ID of the cycles ledger canister.
/// If not specified, the default cycles ledger canister ID will be used.
// todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262
#[arg(long)]
cycles_ledger_canister_id: Principal,
}

pub async fn exec(env: &dyn Environment, opts: TransferOpts) -> DfxResult {
Expand Down Expand Up @@ -68,7 +62,6 @@ pub async fn exec(env: &dyn Environment, opts: TransferOpts) -> DfxResult {
to_subaccount,
created_at_time,
opts.memo,
opts.cycles_ledger_canister_id,
)
.await;
if result.is_err() && opts.created_at_time.is_none() {
Expand Down
19 changes: 13 additions & 6 deletions src/dfx/src/lib/operations/cycles_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ const ICRC1_BALANCE_OF_METHOD: &str = "icrc1_balance_of";
const ICRC1_TRANSFER_METHOD: &str = "icrc1_transfer";
const SEND_METHOD: &str = "send";
const CREATE_CANISTER_METHOD: &str = "create_canister";
const CYCLES_LEDGER_CANISTER_ID: Principal =
Principal::from_slice(&[0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x02, 0x01, 0x01]);

pub async fn balance(
agent: &Agent,
owner: Principal,
subaccount: Option<icrc1::account::Subaccount>,
cycles_ledger_canister_id: Principal,
) -> DfxResult<u128> {
let canister = Canister::builder()
.with_agent(agent)
.with_canister_id(cycles_ledger_canister_id)
.with_canister_id(CYCLES_LEDGER_CANISTER_ID)
.build()?;
let arg = icrc1::account::Account { owner, subaccount };

Expand Down Expand Up @@ -75,11 +76,10 @@ pub async fn transfer(
to_subaccount: Option<icrc1::account::Subaccount>,
created_at_time: u64,
memo: Option<u64>,
cycles_ledger_canister_id: Principal,
) -> DfxResult<BlockIndex> {
let canister = Canister::builder()
.with_agent(agent)
.with_canister_id(cycles_ledger_canister_id)
.with_canister_id(CYCLES_LEDGER_CANISTER_ID)
.build()?;

let retry_policy = ExponentialBackoff::default();
Expand Down Expand Up @@ -135,11 +135,10 @@ pub async fn send(
amount: u128,
created_at_time: u64,
from_subaccount: Option<icrc1::account::Subaccount>,
cycles_ledger_canister_id: Principal,
) -> DfxResult<BlockIndex> {
let canister = Canister::builder()
.with_agent(agent)
.with_canister_id(cycles_ledger_canister_id)
.with_canister_id(CYCLES_LEDGER_CANISTER_ID)
.build()?;

let retry_policy = ExponentialBackoff::default();
Expand Down Expand Up @@ -321,3 +320,11 @@ pub async fn create_with_cycles_ledger(
Err(err) => bail!(err),
}
}

#[test]
fn ledger_canister_id_text_representation() {
assert_eq!(
Principal::from_text("um5iw-rqaaa-aaaaq-qaaba-cai").unwrap(),
CYCLES_LEDGER_CANISTER_ID
);
}

0 comments on commit 5e2c9f5

Please sign in to comment.