You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: rust/basic_bitcoin/README.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Basic Bitcoin
1
+
# Basic Bitcoin
2
2
3
3
This tutorial will walk you through how to deploy a sample [canister smart contract](https://internetcomputer.org/docs/current/developer-docs/multi-chain/bitcoin/overview)**that can send and receive Bitcoin** on the Internet Computer.
4
4
@@ -14,7 +14,7 @@ of the Internet Computer.
14
14
15
15
For a deeper understanding of the ICP < > BTC integration, see the [Bitcoin integration documentation](https://wiki.internetcomputer.org/wiki/Bitcoin_Integration).
Copy file name to clipboardExpand all lines: rust/basic_dao/README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Certain system parameters, like the number of `Yes` votes needed to pass a propo
10
10
11
11
View the [canister service definition](https://github.com/dfinity/examples/blob/master/rust/basic_dao/src/basic_dao/src/basic_dao.did) for more details.
Copy file name to clipboardExpand all lines: rust/dip721-nft-container/README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ A running instance of the Rust canister for demonstration purposes is available
86
86
The interface is meant to be programmatic, but the Rust version additionally contains HTTP functionality so you can view a metadata file at `<canister URL>/<NFT ID>/<file ID>`.
87
87
It contains six NFTs, so you can look at items from `<canister URL>/0/0` to `<canister URL>/5/0`.
88
88
89
-
###Prerequisites
89
+
## Prerequisites
90
90
91
91
-[x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
92
92
-[x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
Copy file name to clipboardExpand all lines: rust/nft-wallet/README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This is an NFT wallet example dapp that utilizes minted NFTs from the Rust dip721-nft-container. Among some of its essential features, the wallet can register NFTs, transfer out NFTs, and check how many NFTs it contains. This dapp includes a frontend UI for interaction.
4
4
5
-
###Prerequisites
5
+
## Prerequisites
6
6
7
7
-[x] Install the [IC
8
8
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.
Copy file name to clipboardExpand all lines: rust/performance_counters/README.md
+1-4
Original file line number
Diff line number
Diff line change
@@ -31,10 +31,7 @@ In the future, ICP might expose more performance counters.
31
31
32
32
## Prerequisites
33
33
34
-
## Prerequisites
35
-
36
-
-[x] Install the [IC
37
-
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.
34
+
-[x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.
38
35
-[x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
Copy file name to clipboardExpand all lines: rust/periodic_tasks/README.md
+38-37
Original file line number
Diff line number
Diff line change
@@ -14,21 +14,17 @@ The example consists of two canisters named `heartbeat` and `timer`, both implem
14
14
## Prerequisites
15
15
This example requires an installation of:
16
16
17
-
-[x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/index.mdx).
17
+
-[x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
18
18
-[x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
19
19
20
-
###Example 1:
20
+
## Example 1: heartbeats and timers
21
21
22
-
-####Step 1: Begin by opening a terminal window and navigating into the project's directory.
22
+
-### Step 1: Setup project environment
23
23
24
-
```sh
25
-
cd examples/rust/periodic_tasks
26
-
```
27
-
28
-
-#### Step 2: Start a clean local Internet Computer replica and a web server:
24
+
Navigate into the folder containing the project's files and start a local instance of the replica with the command:
29
25
30
26
```sh
31
-
dfx stop
27
+
cd examples/rust/periodic_tasks
32
28
dfx start --clean
33
29
```
34
30
@@ -37,18 +33,18 @@ This terminal will stay blocked, printing log messages, until the `Ctrl+C` is pr
37
33
Example output:
38
34
39
35
```sh
40
-
% dfx stop &&dfx start --clean
36
+
dfx start --clean
41
37
[...]
42
38
Dashboard: http://localhost:63387/_/dashboard
43
39
```
44
40
45
-
-#### Step 3: Open another terminal window in the same directory:
41
+
-#### Step 2: Open another terminal window in the same directory:
46
42
47
43
```sh
48
44
cd examples/rust/periodic_tasks
49
45
```
50
46
51
-
-#### Step 4: Compile and deploy `heartbeat` and `timer` canisters, setting the interval for periodic tasks to 10s:
47
+
-#### Step 3: Compile and deploy the`heartbeat` and `timer` canisters, setting the interval for periodic tasks to 10s:
52
48
53
49
```sh
54
50
dfx deploy heartbeat --argument 10
@@ -77,25 +73,25 @@ URLs:
77
73
timer: http://127.0.0.1/...
78
74
```
79
75
80
-
-#### Step 5: After 10s, observe similar non-zero counters in both canisters:
76
+
-#### Step 4: After 10s, observe similar non-zero counters in both canisters:
81
77
82
78
```sh
83
79
dfx canister call heartbeat counter
84
80
dfx canister call timer counter
85
81
```
86
82
87
-
Note, as the canisters deployed one by one, there might be a minor discrepancy in the counters.
83
+
Note: As the canisters deployed one by one, there might be a minor discrepancy in the counters.
88
84
89
85
Example output:
90
86
91
87
```sh
92
-
% dfx canister call heartbeat counter
88
+
% dfx canister call heartbeat counter
93
89
(8 : nat32)
94
-
% dfx canister call timer counter
90
+
% dfx canister call timer counter
95
91
(7 : nat32)
96
92
```
97
93
98
-
-#### Step 6: Compare the amount of cycles used to schedule the periodic task with 10s interval:
94
+
-#### Step 5: Compare the amount of cycles used to schedule the periodic task with 10s interval:
99
95
100
96
```sh
101
97
dfx canister call heartbeat cycles_used
@@ -115,36 +111,40 @@ For periodic tasks with 10 sec intervals, the `heartbeat` canister uses *more* c
115
111
116
112
Not only do timers use fewer cycles, but they are also more composable. As there is no global state or methods to export, different libraries with timers could be easily used in the same project.
117
113
118
-
Also, timers provide isolation between the scheduling logic and the periodic task. If the periodic task fails, all the changes made by this task will be reverted, but the timers library state will be updated, i.e. the failed task will be removed from the list of timers to execute.
114
+
Also, timers provide isolation between the scheduling logic and the periodic task. If the periodic task fails, all the changes made by this task will be reverted, but the timers library state will be updated, i.e., the failed task will be removed from the list of timers to execute.
119
115
120
116
For such isolation of execution and scheduling contexts, the internal timers library uses self-canister calls:
121
117
122
-
```rust
123
-
# Thisisapseudo-codeofaselfcall:
124
-
ic_cdk::call(ic_cdk::id(), "periodic_task", ());
125
-
```
118
+
```rust
119
+
# Thisisapseudo-codeofaselfcall:
120
+
ic_cdk::call(ic_cdk::id(), "periodic_task", ());
121
+
```
122
+
123
+
Despite the [costs](https://internetcomputer.org/docs/current/developer-docs/gas-cost) associated with such self-canister calls, the timers library still uses fewer cycles than the heartbeats.
126
124
127
-
Despite the [costs](https://internetcomputer.org/docs/current/developer-docs/production/computation-and-storage-costs) associated with such self-canister calls, the timers library still uses fewer cycles than the heartbeats.
125
+
## Example 2: Cycles usage for tasks with 1s interval
128
126
129
-
### Example 2: Cycles usage for tasks with 1s interval
130
127
128
+
-### Step 1: Setup project environment
131
129
132
-
-#### Step 1: Open a new terminal window in the example root directory:
130
+
Navigate into the folder containing the project's files and start a local instance of the replica with the command:
133
131
134
132
```sh
135
133
cd examples/rust/periodic_tasks
134
+
dfx start --clean
136
135
```
137
136
138
-
-#### Step 2: Start a clean local Internet Computer replica and a web server:
137
+
This terminal will stay blocked, printing log messages, until the `Ctrl+C` is pressed or `dfx stop` command is run.
138
+
139
+
Example output:
139
140
140
141
```sh
141
-
dfx stop
142
142
dfx start --clean
143
+
[...]
144
+
Dashboard: http://localhost:63387/_/dashboard
143
145
```
144
146
145
-
This terminal will stay blocked, printing log messages, until the `Ctrl+C` is pressed or `dfx stop` command is run.
146
-
147
-
-#### Step 3: Open another terminal window in the same directory:
147
+
-#### Step 2: Open another terminal window in the same directory:
148
148
149
149
```sh
150
150
cd examples/rust/periodic_tasks
@@ -153,12 +153,12 @@ cd examples/rust/periodic_tasks
153
153
Example output:
154
154
155
155
```sh
156
-
% dfx stop &&dfx start --clean
156
+
dfx start --clean
157
157
[...]
158
158
Dashboard: http://localhost:63387/_/dashboard
159
159
```
160
160
161
-
-#### Step 4:. Compile and deploy `heartbeat` and `timer` canisters, setting the interval for periodic tasks to 1s:
161
+
-#### Step 3:. Compile and deploy `heartbeat` and `timer` canisters, setting the interval for periodic tasks to 1s:
162
162
163
163
```sh
164
164
dfx deploy --argument 1 heartbeat
@@ -187,25 +187,25 @@ URLs:
187
187
timer: http://127.0.0.1/...
188
188
```
189
189
190
-
-#### Step 5: After a few seconds, observe similar non-zero counters in both canisters:
190
+
-#### Step 4: After a few seconds, observe similar non-zero counters in both canisters:
191
191
192
192
```sh
193
193
dfx canister call heartbeat counter
194
194
dfx canister call timer counter
195
195
```
196
196
197
-
Note, as the canisters deployed one by one, there might be a minor discrepancy in the counters.
197
+
Note: As the canisters deployed one by one, there might be a minor discrepancy in the counters.
198
198
199
199
Example output:
200
200
201
201
```sh
202
-
% dfx canister call heartbeat counter
202
+
% dfx canister call heartbeat counter
203
203
(8 : nat32)
204
-
% dfx canister call timer counter
204
+
% dfx canister call timer counter
205
205
(9 : nat32)
206
206
```
207
207
208
-
-#### Step 6: Compare the number of cycles used to schedule the periodic task with 1s interval:
208
+
-#### Step 5: Compare the number of cycles used to schedule the periodic task with 1s interval:
209
209
210
210
```sh
211
211
dfx canister call heartbeat cycles_used
@@ -230,6 +230,7 @@ Also, there is no isolation between the scheduling logic and the periodic task.
230
230
For such isolation of execution and scheduling contexts, the timers library uses internal self-canister calls as described in `Demo 1`. Due to the [costs](https://internetcomputer.org/docs/current/developer-docs/production/computation-and-storage-costs) associated with such self-canister calls, `timer` canister uses more cycles for very frequent periodic tasks.
231
231
232
232
## Further learning
233
+
233
234
1. Have a look at the locally running dashboard. The URL is at the end of the `dfx start` command: `Dashboard: http://localhost/...`
234
235
2. Check out `heartbeat` and `timer` canisters Candid user interface. The URLs are at the end of the `dfx deploy` command: `heartbeat: http://127.0.0.1/...`
235
236
3. Find which interval makes even the costs of running periodic tasks in the `timer` and `heartbeat` canisters: `dfx deploy heartbeat --argument 5 && dfx deploy timer --argument 5`
0 commit comments