Skip to content

Commit d2ebd02

Browse files
viviveeveeEric Swanson
andauthored
feat: update agent and add log_visibility support (#3782)
Co-authored-by: Eric Swanson <[email protected]>
1 parent 4a2960e commit d2ebd02

File tree

39 files changed

+216
-108
lines changed

39 files changed

+216
-108
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ different replica version or different replica options.
5050

5151
It doesn't apply to `--pocketic` because PocketIC does not yet persist any data.
5252

53+
### feat: `log_visibility` canister setting
54+
55+
Adds support for the `log_visibility` canister setting, which configures which users are allowed to read a canister's logs.
56+
Valid options are `controllers` and `public`. The setting can be used with the `--log-visibility` flag in `dfx canister create`
57+
and `dfx canister update-settings`, or in `dfx.json` under `canisters[].initialization_values.log_visibility`.
58+
5359
## Dependencies
5460

5561
### Frontend canister

Cargo.lock

Lines changed: 16 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ license = "Apache-2.0"
2121
[workspace.dependencies]
2222
candid = "0.10.4"
2323
candid_parser = "0.1.4"
24-
ic-agent = { git = "https://github.com/dfinity/agent-rs.git", rev = "8273d321e9a09fd8373bd4e38b0676ec6ad9c260" }
24+
ic-agent = "0.36.0"
2525
ic-asset = { path = "src/canisters/frontend/ic-asset" }
2626
ic-cdk = "0.13.1"
27-
ic-identity-hsm = { git = "https://github.com/dfinity/agent-rs.git", rev = "8273d321e9a09fd8373bd4e38b0676ec6ad9c260" }
28-
ic-utils = { git = "https://github.com/dfinity/agent-rs.git", rev = "8273d321e9a09fd8373bd4e38b0676ec6ad9c260" }
27+
ic-identity-hsm = "0.36.0"
28+
ic-utils = "0.36.0"
2929

3030
aes-gcm = "0.10.3"
3131
anyhow = "1.0.56"

docs/cli-reference/dfx-canister.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ You can use the following options with the `dfx canister create` command.
255255
| `--memory-allocation <memory>` | Specifies how much memory the canister is allowed to use in total. This should be a value in the range [0..12 GiB]. A setting of 0 means the canister will have access to memory on a “best-effort” basis: It will only be charged for the memory it uses, but at any point in time may stop running if it tries to allocate more memory when there isn’t space available on the subnet. |
256256
| `--reserved-cycles-limit <limit>` | Specifies the upper limit for the canister's reserved cycles. |
257257
| `--wasm-memory-limit <limit>` | Specifies a soft upper limit for the canister's heap memory. |
258+
| `--log-visibility <visibility>` | Specifies who is allowed to read the canister's logs. Can be either "controllers" or "public". |
258259
| `--no-wallet` | Performs the call with the user Identity as the Sender of messages. Bypasses the Wallet canister. Enabled by default. |
259260
| `--with-cycles <number-of-cycles>` | Specifies the initial cycle balance to deposit into the newly created canister. The specified amount needs to take the canister create fee into account. This amount is deducted from the wallet's cycle balance. |
260261
| `--specified-id <PRINCIPAL>` | Attempts to create the canister with this Canister ID |
@@ -993,6 +994,7 @@ You can specify the following options for the `dfx canister update-settings` com
993994
| `--memory-allocation <allocation>` | Specifies how much memory the canister is allowed to use in total. This should be a value in the range [0..12 GiB]. A setting of 0 means the canister will have access to memory on a “best-effort” basis: It will only be charged for the memory it uses, but at any point in time may stop running if it tries to allocate more memory when there isn’t space available on the subnet. |
994995
| `--reserved-cycles-limit <limit>` | Specifies the upper limit of the canister's reserved cycles. |
995996
| `--wasm-memory-limit <limit>` | Specifies a soft upper limit for the canister's heap memory. |
997+
| `--log-visibility <visibility>` | Specifies who is allowed to read the canister's logs. Can be either "controllers" or "public". |
996998
| `--remove-controller <principal>` | Removes a principal from the list of controllers of the canister. |
997999
| `--freezing-threshold <seconds>` | Set the [freezing threshold](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-create_canister) in seconds for a canister. This should be a value in the range [0..2^64^-1]. Very long thresholds require the `--confirm-very-long-freezing-threshold` option. |
9981000
| `-y`, `--yes` | Skips yes/no checks by answering 'yes'. Such checks can result in loss of control, so this is not recommended outside of CI. |

docs/dfx-json-schema.json

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"integer",
9595
"string"
9696
],
97-
"pattern": "^[0-9]+( *([KkMmGgTtPpEeZzYy]i?)?B)?$"
97+
"pattern": "^[0-9]+( *([KkMmGgTtPpEeZzYy]i?)?[Bb])?$"
9898
},
9999
"CanisterDeclarationsConfig": {
100100
"title": "Declarations Configuration",
@@ -136,6 +136,13 @@
136136
}
137137
}
138138
},
139+
"CanisterLogVisibility": {
140+
"type": "string",
141+
"enum": [
142+
"controllers",
143+
"public"
144+
]
145+
},
139146
"CanisterMetadataSection": {
140147
"title": "Canister Metadata Configuration",
141148
"description": "Configures a custom metadata section for the canister wasm. dfx uses the first definition of a given name matching the current network, ignoring any of the same name that follow.",
@@ -209,7 +216,7 @@
209216
},
210217
"package": {
211218
"title": "Package Name",
212-
"description": "Name of the rust package that compiles to this canister's Wasm binary.",
219+
"description": "Name of the rust package that compiles to this canister's Wasm.",
213220
"type": "string"
214221
},
215222
"type": {
@@ -410,6 +417,7 @@
410417
"default": {
411418
"compute_allocation": null,
412419
"freezing_threshold": null,
420+
"log_visibility": null,
413421
"memory_allocation": null,
414422
"reserved_cycles_limit": null,
415423
"wasm_memory_limit": null
@@ -440,7 +448,6 @@
440448
"optimize": {
441449
"title": "Optimize Canister Wasm",
442450
"description": "Invoke wasm level optimizations after building the canister. Optimization level can be set to \"cycles\" to optimize for cycle usage, \"size\" to optimize for binary size, or any of \"O4, O3, O2, O1, O0, Oz, Os\". Disabled by default. If this option is specified, the `shrink` option will be ignored.",
443-
"default": null,
444451
"anyOf": [
445452
{
446453
"$ref": "#/definitions/WasmOptLevel"
@@ -463,7 +470,6 @@
463470
"pullable": {
464471
"title": "Pullable",
465472
"description": "Defines required properties so that this canister is ready for `dfx deps pull` by other projects.",
466-
"default": null,
467473
"anyOf": [
468474
{
469475
"$ref": "#/definitions/Pullable"
@@ -476,7 +482,6 @@
476482
"remote": {
477483
"title": "Remote Configuration",
478484
"description": "Used to mark the canister as 'remote' on certain networks.",
479-
"default": null,
480485
"anyOf": [
481486
{
482487
"$ref": "#/definitions/ConfigCanistersCanisterRemote"
@@ -505,7 +510,6 @@
505510
"tech_stack": {
506511
"title": "Tech Stack",
507512
"description": "Defines the tech stack used to build this canister.",
508-
"default": null,
509513
"anyOf": [
510514
{
511515
"$ref": "#/definitions/TechStack"
@@ -637,7 +641,6 @@
637641
"nodes": {
638642
"title": "Available Nodes",
639643
"description": "Addresses of nodes to connect to (in case discovery from seeds is not possible/sufficient).",
640-
"default": null,
641644
"type": [
642645
"array",
643646
"null"
@@ -917,7 +920,6 @@
917920
"compute_allocation": {
918921
"title": "Compute Allocation",
919922
"description": "Must be a number between 0 and 100, inclusively. It indicates how much compute power should be guaranteed to this canister, expressed as a percentage of the maximum compute power that a single canister can allocate.",
920-
"default": null,
921923
"anyOf": [
922924
{
923925
"$ref": "#/definitions/PossiblyStr_for_uint64"
@@ -930,16 +932,26 @@
930932
"freezing_threshold": {
931933
"title": "Freezing Threshold",
932934
"description": "Freezing threshould of the canister, measured in seconds. Valid inputs are numbers (seconds) or strings parsable by humantime (e.g. \"15days 2min 2s\").",
933-
"default": null,
934935
"type": [
935936
"string",
936937
"null"
937938
]
938939
},
940+
"log_visibility": {
941+
"title": "Log Visibility",
942+
"description": "Specifies who is allowed to read the canister's logs.\n\nCan be \"public\" or \"controllers\".",
943+
"anyOf": [
944+
{
945+
"$ref": "#/definitions/CanisterLogVisibility"
946+
},
947+
{
948+
"type": "null"
949+
}
950+
]
951+
},
939952
"memory_allocation": {
940953
"title": "Memory Allocation",
941954
"description": "Maximum memory (in bytes) this canister is allowed to occupy. Can be specified as an integer, or as an SI unit string (e.g. \"4KB\", \"2 MiB\")",
942-
"default": null,
943955
"anyOf": [
944956
{
945957
"$ref": "#/definitions/Byte"
@@ -952,7 +964,6 @@
952964
"reserved_cycles_limit": {
953965
"title": "Reserved Cycles Limit",
954966
"description": "Specifies the upper limit of the canister's reserved cycles balance.\n\nReserved cycles are cycles that the system sets aside for future use by the canister. If a subnet's storage exceeds 450 GiB, then every time a canister allocates new storage bytes, the system sets aside some amount of cycles from the main balance of the canister. These reserved cycles will be used to cover future payments for the newly allocated bytes. The reserved cycles are not transferable and the amount of reserved cycles depends on how full the subnet is.\n\nA setting of 0 means that the canister will trap if it tries to allocate new storage while the subnet's memory usage exceeds 450 GiB.",
955-
"default": null,
956967
"type": [
957968
"integer",
958969
"null"
@@ -963,7 +974,6 @@
963974
"wasm_memory_limit": {
964975
"title": "Wasm Memory Limit",
965976
"description": "Specifies a soft limit (in bytes) on the Wasm memory usage of the canister.\n\nUpdate calls, timers, heartbeats, installs, and post-upgrades fail if the Wasm memory usage exceeds this limit. The main purpose of this setting is to protect against the case when the canister reaches the hard 4GiB limit.\n\nMust be a number of bytes between 0 and 2^48 (i.e. 256 TiB), inclusive. Can be specified as an integer, or as an SI unit string (e.g. \"4KB\", \"2 MiB\")",
966-
"default": null,
967977
"anyOf": [
968978
{
969979
"$ref": "#/definitions/Byte"

docs/networks-json-schema.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"nodes": {
4747
"title": "Available Nodes",
4848
"description": "Addresses of nodes to connect to (in case discovery from seeds is not possible/sufficient).",
49-
"default": null,
5049
"type": [
5150
"array",
5251
"null"

e2e/tests-dfx/create.bash

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ teardown() {
328328
"memory_allocation": "2 GiB",
329329
"reserved_cycles_limit": 1000000000000,
330330
"wasm_memory_limit": "1 GiB",
331+
"log_visibility": "public",
331332
}' dfx.json | sponge dfx.json
332333
dfx_start
333334
assert_command dfx deploy e2e_project_backend --no-wallet
@@ -337,4 +338,17 @@ teardown() {
337338
assert_contains 'Reserved cycles limit: 1_000_000_000_000'
338339
assert_contains 'Wasm memory limit: 1_073_741_824'
339340
assert_contains 'Freezing threshold: 604_800'
341+
assert_contains 'Log visibility: public'
342+
}
343+
344+
@test "create with default settings" {
345+
dfx_start
346+
assert_command dfx deploy e2e_project_backend
347+
assert_command dfx canister status e2e_project_backend
348+
assert_contains 'Memory allocation: 0'
349+
assert_contains 'Compute allocation: 0'
350+
assert_contains 'Reserved cycles limit: 5_000_000_000_000'
351+
assert_contains 'Wasm memory limit: 0'
352+
assert_contains 'Freezing threshold: 2_592_000'
353+
assert_contains 'Log visibility: controllers'
340354
}

e2e/tests-dfx/update_settings.bash

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ teardown() {
6161
assert_contains "Canister exceeded its current Wasm memory limit of 8 bytes"
6262
}
6363

64+
@test "set log visibility" {
65+
dfx_new
66+
dfx_start
67+
assert_command dfx deploy e2e_project_backend
68+
assert_command dfx canister status e2e_project_backend
69+
assert_contains "Log visibility: controllers"
70+
assert_command dfx canister update-settings e2e_project_backend --log-visibility public
71+
assert_command dfx canister status e2e_project_backend
72+
assert_contains "Log visibility: public"
73+
assert_command dfx canister update-settings e2e_project_backend --log-visibility controllers
74+
assert_command dfx canister status e2e_project_backend
75+
assert_contains "Log visibility: controllers"
76+
}
77+
6478
@test "set controller" {
6579
# Create two identities
6680
assert_command dfx identity new --storage-mode plaintext alice

src/canisters/frontend/ic-asset/src/canister_api/methods/batch.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub(crate) async fn create_batch(canister: &Canister<'_>) -> Result<Nat, AgentEr
2828
.with_arg(&create_batch_args)
2929
.build()
3030
.map(|result: (CreateBatchResponse,)| (result.0.batch_id,))
31-
.call_and_wait()
3231
.await;
3332
match response {
3433
Ok((batch_id,)) => break Ok(batch_id),
@@ -57,13 +56,7 @@ pub(crate) async fn submit_commit_batch<T: CandidType + Sync>(
5756
.build();
5857

5958
loop {
60-
match canister
61-
.update(method_name)
62-
.with_arg(&arg)
63-
.build()
64-
.call_and_wait()
65-
.await
66-
{
59+
match canister.update(method_name).with_arg(&arg).build().await {
6760
Ok(()) => return Ok(()),
6861
Err(agent_err) if !retryable(&agent_err) => {
6962
return Err(agent_err);
@@ -107,7 +100,6 @@ pub(crate) async fn compute_evidence(
107100
.with_arg(arg)
108101
.build()
109102
.map(|result: (Option<ByteBuf>,)| (result.0,))
110-
.call_and_wait()
111103
.await
112104
{
113105
Ok(x) => return Ok(x.0),

src/dfx-core/src/canister/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ YOU WILL LOSE ALL DATA IN THE CANISTER.
6868
.with_raw_arg(args.to_vec())
6969
.with_mode(mode);
7070
install_builder
71-
.call_and_wait()
7271
.await
7372
.map_err(CanisterInstallError::InstallWasmError)
7473
}
@@ -87,7 +86,6 @@ YOU WILL LOSE ALL DATA IN THE CANISTER.
8786
Argument::from_candid((install_args,)),
8887
0,
8988
)
90-
.call_and_wait()
9189
.await
9290
.map_err(CanisterInstallError::InstallWasmError)
9391
}

0 commit comments

Comments
 (0)