Skip to content
This repository was archived by the owner on May 4, 2026. It is now read-only.

Commit 40673ba

Browse files
Mohammad Fawazclaude
andcommitted
Document v4.0.1 changes and add intrinsics chapter
- Add `--network-retries` flag to all 7 affected CLI commands (build, run, execute, deploy, upgrade, query, synthesize) - Note that interfaces can now be declared in library packages - Add const generics restriction note to functions.md - New intrinsics chapter covering _dynamic_call, _dynamic_contains, _dynamic_get, and _dynamic_get_or_use Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8fc7e1e commit 40673ba

10 files changed

Lines changed: 272 additions & 1 deletion

File tree

β€Ždocumentation/cli/03_build.mdβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ The build also generates an **ABI file** at `build/abi.json` describing your pro
5959
The network to deploy to. Overrides the `NETWORK` environment variable.
6060
--endpoint <ENDPOINT>
6161
The endpoint to deploy to. Overrides the `ENDPOINT` environment variable.
62+
--network-retries <N>
63+
Number of times to retry a network request on transient transport failure, with
64+
exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the
65+
NETWORK_RETRIES environment variable. Defaults to 2. HTTP errors and broadcast
66+
calls are not retried.
6267
--devnet
6368
Whether the network is a devnet. If not set, defaults to the `DEVNET` environment variable.
6469
--consensus-heights <CONSENSUS_HEIGHTS>

β€Ždocumentation/cli/06_deploy.mdβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set man
135135

136136
<!-- markdown-link-check-enable -->
137137

138+
#### `--network-retries <N>`
139+
140+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.
141+
138142
#### `--devnet`
139143

140144
Specifies whether the network being deployed to is a devnet. If not set, defaults to the `DEVNET` environment variable.

β€Ždocumentation/cli/08_execute.mdβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set man
105105

106106
<!-- markdown-link-check-enable -->
107107

108+
#### `--network-retries <N>`
109+
110+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.
111+
108112
#### `--devnet`
109113

110114
Specifies whether the network being deployed to is a devnet. If not set, defaults to the `DEVNET` environment variable.

β€Ždocumentation/cli/10_query.mdβ€Ž

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ Specifies the network to deploy to. Overrides any `NETWORK` environment variable
5656

5757
The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set manually or in a `.env` file.
5858

59+
#### `--network-retries <N>`
60+
61+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.
62+
5963
#### `--latest`
6064

6165
#### `-l`
@@ -132,6 +136,10 @@ Specifies the network to deploy to. Overrides any `NETWORK` environment variable
132136

133137
The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set manually or in a `.env` file.
134138

139+
#### `--network-retries <N>`
140+
141+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.
142+
135143
#### `--confirmed`
136144

137145
#### `-c`
@@ -194,6 +202,10 @@ Specifies the network to deploy to. Overrides any `NETWORK` environment variable
194202

195203
The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set manually or in a `.env` file.
196204

205+
#### `--network-retries <N>`
206+
207+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.
208+
197209
#### `--mappings`
198210

199211
Lists all mappings defined in the latest deployed edition of the program.
@@ -224,6 +236,10 @@ Specifies the network to deploy to. Overrides any `NETWORK` environment variable
224236

225237
The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set manually or in a `.env` file.
226238

239+
#### `--network-retries <N>`
240+
241+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.
242+
227243
---
228244

229245
## `leo query committee`
@@ -240,6 +256,10 @@ Specifies the network to deploy to. Overrides any `NETWORK` environment variable
240256

241257
The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set manually or in a `.env` file.
242258

259+
#### `--network-retries <N>`
260+
261+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.
262+
243263
---
244264

245265
## `leo query mempool`
@@ -280,6 +300,10 @@ Specifies the network to deploy to. Overrides any `NETWORK` environment variable
280300

281301
The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set manually or in a `.env` file.
282302

303+
#### `--network-retries <N>`
304+
305+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.
306+
283307
---
284308

285309
## `leo query peers`
@@ -311,3 +335,7 @@ Specifies the network to deploy to. Overrides any `NETWORK` environment variable
311335
#### `--endpoint <ENDPOINT>`
312336

313337
The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set manually or in a `.env` file.
338+
339+
#### `--network-retries <N>`
340+
341+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.

β€Ždocumentation/cli/12_run.mdβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ leo run <FUNCTION_NAME> -- <INPUT_0> -- <INPUT_1> ...
7878
The network to deploy to. Overrides the `NETWORK` environment variable.
7979
--endpoint <ENDPOINT>
8080
The endpoint to deploy to. Overrides the `ENDPOINT` environment variable.
81+
--network-retries <N>
82+
Number of times to retry a network request on transient transport failure, with
83+
exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the
84+
NETWORK_RETRIES environment variable. Defaults to 2. HTTP errors and broadcast
85+
calls are not retried.
8186
--devnet
8287
Whether the network is a devnet. If not set, defaults to the `DEVNET` environment variable.
8388
--consensus-heights <CONSENSUS_HEIGHTS>

β€Ždocumentation/cli/15_upgrade.mdβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set man
4040

4141
<!-- markdown-link-check-enable -->
4242

43+
#### `--network-retries <N>`
44+
45+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.
46+
4347
#### `--devnet`
4448

4549
Specifies whether the network being deployed to is a devnet. If not set, defaults to the `DEVNET` environment variable.

β€Ždocumentation/cli/16_synthesize.mdβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Specifies the network to deploy to. Overrides any `NETWORK` environment variable
3737

3838
The endpoint to deploy to. Overrides any `ENDPOINT` environment variable set manually or in a `.env` file.
3939

40+
#### `--network-retries <N>`
41+
42+
Number of times to retry a network request on transient transport failure, with exponential backoff (1 s, 2 s, 4 s, … capped at 64 s). Overrides the `NETWORK_RETRIES` environment variable. Defaults to `2`. HTTP errors (4xx/5xx) and broadcast calls are not retried.
43+
4044
#### `--local`
4145

4246
#### `-l`

β€Ždocumentation/language/programs_in_practice/functions.mdβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ program main.aleo {
151151

152152
Acceptable types for const generic parameters include integer types, `bool`, `scalar`, `group`, `field`, and `address`.
153153

154+
:::note
155+
Const generic parameters are only valid on inlinable helper `fn` functions. They are not permitted on entry point functions inside a `program {}` block, `final fn` functions, functions annotated with `@no_inline`, or function signatures declared inside an `interface`.
156+
:::
157+
154158
### The `@no_inline` Annotation
155159

156160
By default the compiler inlines helper functions that are called only once, which reduces call overhead. To prevent this, annotate the function with `@no_inline`:

β€Ždocumentation/language/programs_in_practice/interfaces.mdβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ program must provide. Interfaces are a compile-time concept and have no impact o
1919
They are only useful as a way to enforce structural contracts β€” ensuring that any program claiming to implement
2020
an interface actually provides all required functions, records, mappings, and storage variables β€” and to enable
2121
dynamic calls, where the caller knows *what* it can call without knowing *which* program it is calling at
22-
runtime. Interfaces are declared outside the `program {}` block or in a submodule.
22+
runtime. Interfaces can be declared outside the `program {}` block, in a submodule, or in a library package
23+
(including library submodules).
2324

2425
```leo
2526
interface Transfer {
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
---
2+
id: intrinsics
3+
title: Intrinsics
4+
sidebar_label: Intrinsics
5+
---
6+
7+
[general tags]: # "intrinsic, dynamic_call, dynamic_contains, dynamic_get, dynamic_get_or_use, dynamic_dispatch, finalize"
8+
9+
Intrinsics are low-level operations built into the compiler. They complement Leo's high-level abstractions and are useful when those abstractions aren't expressive enough for a particular use case. They are prefixed with `_` to make them visually distinct from user-defined functions.
10+
11+
---
12+
13+
## `_dynamic_call`
14+
15+
Calls a function on a remote program determined at runtime, without requiring an interface definition. The target program, network, and function name are supplied as runtime values, and the full type signature is declared in the generic type parameters.
16+
17+
Only valid in transition contexts β€” it cannot be used inside `final fn` functions or `final {}` blocks.
18+
19+
### Syntax
20+
21+
```
22+
_dynamic_call::[TYPE_PARAMS](prog, net, func, ...args)
23+
```
24+
25+
- `prog` β€” the target program name, as a value of type `identifier` or a `field` representing an identifier
26+
- `net` β€” the network, as a value of type `identifier` or a `field` representing an identifier; currently only `'aleo'` is valid
27+
- `func` β€” the function name to call, as a value of type `identifier` or a `field` representing an identifier
28+
- `...args` β€” the function arguments, matching the input types declared in `TYPE_PARAMS`
29+
30+
### Type parameters
31+
32+
Type parameters follow one rule: **the last entry is the return type; all preceding entries are input types** with an optional visibility modifier (`public` or `private`). Omitting type parameters entirely means void return with compiler-inferred input visibility.
33+
34+
#### No type parameters β€” void return
35+
36+
```leo
37+
_dynamic_call(prog, net, func, x);
38+
```
39+
40+
#### Return type only β€” inputs are `private` by default
41+
42+
```leo
43+
let result: u64 = _dynamic_call::[u64](prog, net, func, x);
44+
```
45+
46+
#### Explicit input visibility
47+
48+
All type params before the last are input types. Each can carry a visibility modifier:
49+
50+
```leo
51+
// One public input, then the return type
52+
let result: u64 = _dynamic_call::[public u64, u64](prog, net, func, x);
53+
```
54+
55+
#### Multiple inputs
56+
57+
```leo
58+
let (a, b): (u32, u32) = _dynamic_call::[public u32, public u32, (u32, u32)](prog, net, func, x, y);
59+
```
60+
61+
#### Void return with input annotations
62+
63+
Use `()` as the return type:
64+
65+
```leo
66+
_dynamic_call::[public u64, ()](prog, net, func, x);
67+
```
68+
69+
#### `Final` return
70+
71+
When the called function returns a `Final`, include it in a tuple:
72+
73+
```leo
74+
let (val, f): (u32, Final) = _dynamic_call::[(u32, Final)](target, 'aleo', 'increment', val);
75+
return (val, final {
76+
f.run();
77+
});
78+
```
79+
80+
#### `dyn record` inputs and outputs
81+
82+
```leo
83+
let result: dyn record = _dynamic_call::[dyn record, dyn record](prog, net, func, token);
84+
```
85+
86+
### Restrictions
87+
88+
`_dynamic_call` is **not** allowed in `final fn` functions or `final {}` blocks.
89+
90+
---
91+
92+
## `_dynamic_contains`
93+
94+
Checks whether a key exists in a mapping belonging to another program, determined at runtime. Only valid inside `final fn` functions or `final {}` blocks.
95+
96+
### Syntax
97+
98+
```leo
99+
let exists: bool = _dynamic_contains(prog, net, mapping, key);
100+
```
101+
102+
- `prog` β€” the target program name, as a value of type `identifier` or a `field` representing an identifier
103+
- `net` β€” the network, as a value of type `identifier` or a `field` representing an identifier; currently only `'aleo'` is valid
104+
- `mapping` β€” the mapping name on the target program, as a value of type `identifier` or a `field` representing an identifier
105+
- `key` β€” a value whose type matches the target mapping's key type
106+
107+
Returns `true` if `key` is present, `false` otherwise.
108+
109+
### Example
110+
111+
```leo showLineNumbers
112+
program checker.aleo {
113+
mapping seen: address => bool;
114+
115+
fn check(prog: field, net: field, map: field, key: address) -> Final {
116+
return final { finalize_check(prog, net, map, key); };
117+
}
118+
119+
@noupgrade
120+
constructor() {}
121+
}
122+
123+
final fn finalize_check(prog: field, net: field, map: field, key: address) {
124+
let exists: bool = _dynamic_contains(prog, net, map, key);
125+
Mapping::set(seen, key, exists);
126+
}
127+
```
128+
129+
---
130+
131+
## `_dynamic_get`
132+
133+
Reads a value from a mapping belonging to another program, determined at runtime. Only valid inside `final fn` functions or `final {}` blocks.
134+
135+
Fails at runtime if the key is not present β€” use [`_dynamic_get_or_use`](#_dynamic_get_or_use) when the key may be absent.
136+
137+
### Syntax
138+
139+
```leo
140+
let val: T = _dynamic_get::[T](prog, net, mapping, key);
141+
```
142+
143+
- `prog` β€” the target program name, as a value of type `identifier` or a `field` representing an identifier
144+
- `net` β€” the network, as a value of type `identifier` or a `field` representing an identifier; currently only `'aleo'` is valid
145+
- `mapping` β€” the mapping name on the target program, as a value of type `identifier` or a `field` representing an identifier
146+
- `key` β€” a value whose type matches the target mapping's key type
147+
- `T` β€” must match the target mapping's value type
148+
149+
### Example
150+
151+
```leo showLineNumbers
152+
program reader.aleo {
153+
mapping result: address => u64;
154+
155+
fn read(prog: field, net: field, map: field, key: address) -> Final {
156+
return final { finalize_read(prog, net, map, key); };
157+
}
158+
159+
@noupgrade
160+
constructor() {}
161+
}
162+
163+
final fn finalize_read(prog: field, net: field, map: field, key: address) {
164+
let val: u64 = _dynamic_get::[u64](prog, net, map, key);
165+
Mapping::set(result, key, val);
166+
}
167+
```
168+
169+
For example, using identifier literals:
170+
171+
```leo
172+
let val: u64 = _dynamic_get::[u64]('some_program', 'aleo', 'balances', key);
173+
```
174+
175+
---
176+
177+
## `_dynamic_get_or_use`
178+
179+
Reads a value from a mapping belonging to another program, determined at runtime, returning a default value if the key is absent. Only valid inside `final fn` functions or `final {}` blocks.
180+
181+
### Syntax
182+
183+
```leo
184+
let val: T = _dynamic_get_or_use::[T](prog, net, mapping, key, default);
185+
```
186+
187+
- `prog` β€” the target program name, as a value of type `identifier` or a `field` representing an identifier
188+
- `net` β€” the network, as a value of type `identifier` or a `field` representing an identifier; currently only `'aleo'` is valid
189+
- `mapping` β€” the mapping name on the target program, as a value of type `identifier` or a `field` representing an identifier
190+
- `key` β€” a value whose type matches the target mapping's key type
191+
- `default` β€” the fallback value returned when `key` is absent; must be the same type as `T`
192+
- `T` β€” must match the target mapping's value type
193+
194+
### Example
195+
196+
```leo showLineNumbers
197+
program reader.aleo {
198+
mapping result: address => u64;
199+
200+
fn read(prog: field, net: field, map: field, key: address) -> Final {
201+
return final { finalize_read(prog, net, map, key); };
202+
}
203+
204+
@noupgrade
205+
constructor() {}
206+
}
207+
208+
final fn finalize_read(prog: field, net: field, map: field, key: address) {
209+
let val: u64 = _dynamic_get_or_use::[u64](prog, net, map, key, 0u64);
210+
Mapping::set(result, key, val);
211+
}
212+
```

0 commit comments

Comments
Β (0)