Skip to content

Commit e723a45

Browse files
Add Define a Scenario: Multi-Hop XCM with Manual SetTopic
1 parent 39c2dbf commit e723a45

File tree

2 files changed

+100
-4
lines changed

2 files changed

+100
-4
lines changed

llms.txt

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27873,7 +27873,7 @@ These features are available in runtimes built from **`stable2503-5` or later**.
2787327873

2787427874
- On newer runtimes, the same topic is preserved throughout a multi-hop transfer. This ensures consistent correlation of the `message_id` between origin and destination, even across multiple chains.
2787527875

27876-
## Define a Scenario: DOT to Hydration Transfer
27876+
## Define a Scenario: XCM Flow with Implicit `SetTopic`
2787727877

2787827878
We will examine the full lifecycle of a cross-chain message from Polkadot Asset Hub to Hydration, using the `limited_reserve_transfer_assets` extrinsic.
2787927879

@@ -28146,7 +28146,9 @@ During execution, the runtime adds a `SetTopic` instruction automatically. This
2814628146
</pre>
2814728147
</div>
2814828148

28149-
This forwarded message is then processed on Hydration, where the `message_id` is emitted in the `MessageQueue.Processed` event.
28149+
This forwarded message is then processed on Hydration, where the `id` is emitted in the `MessageQueue.Processed` event.
28150+
28151+
> Note: The value of `SetTopic` generated during a dry-run may differ from the one in the actual execution.
2815028152

2815128153
### Track the Message Across Chains
2815228154

@@ -28175,6 +28177,52 @@ These two fields now match on new runtimes (`stable2503-5` or later).
2817528177
<span data-ty>✅ Processed Message ID matched.</span>
2817628178
</div>
2817728179

28180+
## Define a Scenario: Multi-Hop XCM with Manual `SetTopic`
28181+
28182+
In complex XCM flows, such as multi-hop transfers that span multiple parachains, you may want to use `SetTopic` to **consistently trace the message across all involved chains**.
28183+
28184+
* **Origin chain**: Polkadot Asset Hub
28185+
* **Destination chain**: Hydration
28186+
* **Topic assignment**: Manually set via `SetTopic` instruction
28187+
* **Goal**: Transfer DOT and trace the XCM using the manually assigned `message_id`
28188+
28189+
Setting a `SetTopic` is optional. If you don't explicitly define one, the runtime will automatically generate a topic ID based on the message content (see [XCM Flow with Implicit `SetTopic`](#define-a-scenario-xcm-flow-with-implicit-settopic)). If you require custom end-to-end traceability, you may use `SetTopic` to assign `message_id`.
28190+
28191+
This pattern is demonstrated in [`multi-hop-with-set-topic.ts`](../src/multi-hop-with-set-topic.ts), where DOT is sent from Asset Hub, swapped on Hydration, and returned—**all using the same manually assigned `message_id`** for complete traceability.
28192+
28193+
Example: Multi-Hop XCM with Explicit `SetTopic`
28194+
28195+
```ts
28196+
const message = XcmVersionedXcm.V5([
28197+
// Local instructions...
28198+
28199+
// Remote hop to Hydration
28200+
XcmV5Instruction.DepositReserveAsset({
28201+
assets: XcmV5AssetFilter.Wild(XcmV5WildAsset.All()),
28202+
dest: { interior: XcmV5Junctions.X1(XcmV5Junction.Parachain(2034)), parents: 1 },
28203+
xcm: [
28204+
// remote instructions...
28205+
]
28206+
}),
28207+
28208+
// Optional: explicitly set topic ID for tracing
28209+
XcmV5Instruction.SetTopic(
28210+
Binary.fromHex("0x836c6039763718fd3db4e22484fc4bacd7ddf1c74b6067d15b297ea72d8ecf89")
28211+
),
28212+
]);
28213+
```
28214+
28215+
#### Example: Message Trace Output
28216+
28217+
```console
28218+
📦 Finalised on Polkadot Asset Hub in block #9294993: 0xa4e15ad6eae7fcd837f7a7c02a1925165bd97597fbe1ceb74adc17d3cbcf34bd
28219+
📣 Last message Sent on Polkadot Asset Hub: 0x836c6039763718fd3db4e22484fc4bacd7ddf1c74b6067d15b297ea72d8ecf89
28220+
✅ Sent message ID matched.
28221+
📦 Finalised on Hydration in block #8377216: 0x6bb6e7d69c2d574f8646f3c739d872ab832850a44659ea9401249dbe11a4c447
28222+
📣 Last message Processed on Hydration: 0x836c6039763718fd3db4e22484fc4bacd7ddf1c74b6067d15b297ea72d8ecf89
28223+
✅ Processed Message ID matched.
28224+
```
28225+
2817828226
## Workaround for Older Runtimes
2817928227

2818028228
* On **older runtimes** (prior to `stable2503-5`), the `message_id` seen in downstream `Processed` events is **not the original topic hash**, but rather a **derived `forwarded_id`**.

tutorials/interoperability/xcm-observability.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ These features are available in runtimes built from **`stable2503-5` or later**.
5353

5454
- On newer runtimes, the same topic is preserved throughout a multi-hop transfer. This ensures consistent correlation of the `message_id` between origin and destination, even across multiple chains.
5555

56-
## Define a Scenario: DOT to Hydration Transfer
56+
## Define a Scenario: XCM Flow with Implicit `SetTopic`
5757

5858
We will examine the full lifecycle of a cross-chain message from Polkadot Asset Hub to Hydration, using the `limited_reserve_transfer_assets` extrinsic.
5959

@@ -115,7 +115,9 @@ During execution, the runtime adds a `SetTopic` instruction automatically. This
115115

116116
--8<-- 'code/tutorials/interoperability/xcm-observability/forwarded-xcm.html'
117117

118-
This forwarded message is then processed on Hydration, where the `message_id` is emitted in the `MessageQueue.Processed` event.
118+
This forwarded message is then processed on Hydration, where the `id` is emitted in the `MessageQueue.Processed` event.
119+
120+
> Note: The value of `SetTopic` generated during a dry-run may differ from the one in the actual execution.
119121
120122
### Track the Message Across Chains
121123

@@ -136,6 +138,52 @@ These two fields now match on new runtimes (`stable2503-5` or later).
136138

137139
--8<-- 'code/tutorials/interoperability/xcm-observability/limited-reserve-transfer-assets-result.html'
138140

141+
## Define a Scenario: Multi-Hop XCM with Manual `SetTopic`
142+
143+
In complex XCM flows, such as multi-hop transfers that span multiple parachains, you may want to use `SetTopic` to **consistently trace the message across all involved chains**.
144+
145+
* **Origin chain**: Polkadot Asset Hub
146+
* **Destination chain**: Hydration
147+
* **Topic assignment**: Manually set via `SetTopic` instruction
148+
* **Goal**: Transfer DOT and trace the XCM using the manually assigned `message_id`
149+
150+
Setting a `SetTopic` is optional. If you don't explicitly define one, the runtime will automatically generate a topic ID based on the message content (see [XCM Flow with Implicit `SetTopic`](#define-a-scenario-xcm-flow-with-implicit-settopic)). If you require custom end-to-end traceability, you may use `SetTopic` to assign `message_id`.
151+
152+
This pattern is demonstrated in [`multi-hop-with-set-topic.ts`](../src/multi-hop-with-set-topic.ts), where DOT is sent from Asset Hub, swapped on Hydration, and returned—**all using the same manually assigned `message_id`** for complete traceability.
153+
154+
Example: Multi-Hop XCM with Explicit `SetTopic`
155+
156+
```ts
157+
const message = XcmVersionedXcm.V5([
158+
// Local instructions...
159+
160+
// Remote hop to Hydration
161+
XcmV5Instruction.DepositReserveAsset({
162+
assets: XcmV5AssetFilter.Wild(XcmV5WildAsset.All()),
163+
dest: { interior: XcmV5Junctions.X1(XcmV5Junction.Parachain(2034)), parents: 1 },
164+
xcm: [
165+
// remote instructions...
166+
]
167+
}),
168+
169+
// Optional: explicitly set topic ID for tracing
170+
XcmV5Instruction.SetTopic(
171+
Binary.fromHex("0x836c6039763718fd3db4e22484fc4bacd7ddf1c74b6067d15b297ea72d8ecf89")
172+
),
173+
]);
174+
```
175+
176+
#### Example: Message Trace Output
177+
178+
```console
179+
📦 Finalised on Polkadot Asset Hub in block #9294993: 0xa4e15ad6eae7fcd837f7a7c02a1925165bd97597fbe1ceb74adc17d3cbcf34bd
180+
📣 Last message Sent on Polkadot Asset Hub: 0x836c6039763718fd3db4e22484fc4bacd7ddf1c74b6067d15b297ea72d8ecf89
181+
✅ Sent message ID matched.
182+
📦 Finalised on Hydration in block #8377216: 0x6bb6e7d69c2d574f8646f3c739d872ab832850a44659ea9401249dbe11a4c447
183+
📣 Last message Processed on Hydration: 0x836c6039763718fd3db4e22484fc4bacd7ddf1c74b6067d15b297ea72d8ecf89
184+
✅ Processed Message ID matched.
185+
```
186+
139187
## Workaround for Older Runtimes
140188

141189
* On **older runtimes** (prior to `stable2503-5`), the `message_id` seen in downstream `Processed` events is **not the original topic hash**, but rather a **derived `forwarded_id`**.

0 commit comments

Comments
 (0)