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: test-data/onchain/hello1/Readme.md
+58-1Lines changed: 58 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,4 +3,61 @@
3
3
4
4
The package was deployed at bcb4367516cc4f22b7c0265db04e9b4e83b1f24b0b0455020f26e448df6fd08 firstly and then upgraded to 0x18f8f4ebada51361c6558c7cfa77cb46be72fca7caacc475dc828858becfaa75 with a new module hello1_upgrade.
5
5
6
-
No published-at field is added.
6
+
Published-at field is added for compatibility.
7
+
8
+
## Some notes
9
+
10
+
On Sui, a package's named address must always be its original (v1) package ID, not the upgraded version's ID. The `published-at` field correctly points to the latest version (for linking), but the address must remain the original.
11
+
12
+
Each package object has a `linkage_table: BTreeMap<ObjectID, UpgradeInfo>,` that maps the original package address to the (possibly upgraded) actual used package address.
13
+
14
+
15
+
AI Explanation:
16
+
17
+
Yes, exactly — the `linkage_table` is at the heart of it. Let me break down how it works:
18
+
19
+
### Sui's On-Chain Package Model
20
+
21
+
Every on-chain package object has a structure roughly like:
22
+
23
+
```
24
+
Package {
25
+
id: ObjectID, // this package's own ID
26
+
modules: BTreeMap<String, CompiledModule>,
27
+
linkage_table: BTreeMap<ObjectID, UpgradeInfo>, // key = original ID
28
+
}
29
+
```
30
+
31
+
The `linkage_table` maps **original package IDs → `UpgradeInfo`** (which contains the upgraded/actual version ID to use at runtime). This is how Sui resolves dependencies when a depended-on package has been upgraded.
32
+
33
+
### Why the named address must be the original ID
34
+
35
+
When the Move compiler builds your bytecode, **the named address (`hello1 = "0x..."`) gets baked into the compiled module as the package address**. Every cross-module reference in the bytecode uses this address — e.g., when `hello2` calls `hello1::hello1_upgrade::hello1_upgrade()`, the bytecode literally encodes a reference to the address from `[addresses] hello1`.
36
+
37
+
At publish/execution time, Sui's runtime does a lookup in the **calling package's `linkage_table`** to resolve which actual on-chain package to load:
38
+
39
+
1. It sees bytecode referencing address `0x0bcb...` (the original ID)
40
+
2. It looks up `0x0bcb...` in the `linkage_table`
41
+
3. The `linkage_table` entry says: "use version at `0x18f8...`"
42
+
4. It loads the modules from `0x18f8...`
43
+
44
+
If you set the named address to the **upgraded** ID (`0x18f8...`) instead:
45
+
46
+
1. The bytecode references `0x18f8...`
47
+
2. Sui looks up `0x18f8...` in the `linkage_table`
48
+
3.**No entry found** — because the key is always the *original* ID (`0x0bcb...`)
49
+
4. → `PublishUpgradeMissingDependency`
50
+
51
+
### The role of `published-at`
52
+
53
+
`published-at` serves a **different purpose** — it tells the **Move linker** (at build time) which on-chain package version to link against, so it can verify that the modules and functions you're calling actually exist in that version. It does **not** affect the address baked into bytecode.
54
+
55
+
So in summary:
56
+
57
+
| Concept | Value | Used by | Purpose |
58
+
|---|---|---|---|
59
+
|`[addresses] hello1`| Original ID (`0x0bcb...`) | Compiler → bytecode | Baked into bytecode; used as `linkage_table` lookup key at runtime |
60
+
|`published-at`| Latest version ID (`0x18f8...`) | Build-time linker | Verifies the dependency's modules/functions exist on-chain |
61
+
|`linkage_table` key | Original ID (`0x0bcb...`) | Runtime | Maps original → upgraded version for actual code loading |
62
+
63
+
The invariant is: **bytecode addresses must match `linkage_table` keys, which are always original package IDs**. That's why the named address must never change across upgrades.
Copy file name to clipboardExpand all lines: test-data/onchain/hello1_published_at/Readme.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,4 +3,20 @@
3
3
4
4
The package was deployed at bcb4367516cc4f22b7c0265db04e9b4e83b1f24b0b0455020f26e448df6fd08 firstly and then upgraded to 0x18f8f4ebada51361c6558c7cfa77cb46be72fca7caacc475dc828858becfaa75 with a new module hello1_upgrade.
0 commit comments