Skip to content

Add Guide: Replay & Dry Run XCMs with Full Logging Using Chopsticks #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

raymondkfcheung
Copy link

@raymondkfcheung raymondkfcheung commented Jun 18, 2025

This PR adds a new guide under the Polkadot SDK documentation that explains how to replay and dry-run XCMs using Chopsticks with full logging enabled.

The tutorial covers:

  • Capturing and locating the XCM to replay
  • Forking relevant chains at the correct block height
  • Replaying the XCM using TypeScript
  • Dry-running the XCM using TypeScript
  • Debugging with full trace and error output

This addresses Issue #488 by providing a step-by-step developer workflow for XCM observability and debugging in a local environment.

@raymondkfcheung raymondkfcheung requested a review from a team as a code owner June 18, 2025 13:56
@raymondkfcheung raymondkfcheung changed the title Ray add chopsticks Add Guide: Replay XCMs with Full Logging Using Chopsticks Jun 18, 2025

* Launch Chopsticks using the chain config files

* All config files should have `runtime-log-level: 5` set to enable detailed execution logs for debugging.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A not-at-all trivial comment. Logs only work if the runtime was compiled with logs. debug and release profiles work, production profile doesn't. Live chain runtimes, or most of them at least, have been compiled with the production profile. This means people need to manually compile the runtimes with the release profile, or we can provide them with the correct runtimes with logs. I would go for the second one and try to push teams to publish release runtimes alongside every release.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with instructions on how to compile the runtime.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second approach is at polkadot-fellows/runtimes#767

### 3. Replay the XCM

```ts
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use PAPI here to align with the latest tools

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

--p acala
```

### 3. Replay the XCM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just want to replay the XCM, you can get the tx from the indexer (subscan for example) and use PAPI's api.txFromCallData() to get the same transaction and execute it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll find a real world example.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed and the real world example is at here.

Comment on lines 79 to 91
const tx = api.tx.polkadotXcm.send(
{
V5: {
parents: 1,
interior: 'Here'
}
},
{
V5: [
{ SetTopic: '0x' + '00'.repeat(28) + '12345678' }
]
}
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message doesn't do much. Also, send() is probably not what you want, it's usually execute(). send() will automatically add a DescendOrigin instruction which will affect the behavior of the real message. Most XCMs in the wild are cross-chain transfers which start with a local execute().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed. The working sample is at here.


* Chopsticks is running on port `8000`
* Your're connected to a chain that supports `polkadotXcm.send` (e.g. a Polkadot Asset Hub fork)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add screenshots of the chopsticks logs when you execute an XCM

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the console log

</a>
</div>
<div class="card">
<a href="/learn/learn-xcm/">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this link correct? I believe it should be /develop/interoperability/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, updated.

@eshaben eshaben requested a review from nhussein11 June 19, 2025 03:37
mkdir -p ~/projects && cd ~/projects
git clone [email protected]:polkadot-fellows/runtimes.git
cd runtimes
cargo build --release -p asset-hub-polkadot-runtime
Copy link

@acatangiu acatangiu Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cargo build --release -p asset-hub-polkadot-runtime
cargo build --debug -p asset-hub-polkadot-runtime

or is all logging enabled even for --release?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped --release


```bash
mkdir -p ~/projects/replay-xcm-tests/wasms
cp target/release/wbuild/asset-hub-polkadot-runtime/asset_hub_polkadot_runtime.compact.compressed.wasm ~/projects/replay-xcm-tests/wasms/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same everywhere

Suggested change
cp target/release/wbuild/asset-hub-polkadot-runtime/asset_hub_polkadot_runtime.compact.compressed.wasm ~/projects/replay-xcm-tests/wasms/
cp target/debug/wbuild/asset-hub-polkadot-runtime/asset_hub_polkadot_runtime.compact.compressed.wasm ~/projects/replay-xcm-tests/wasms/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@raymondkfcheung raymondkfcheung changed the title Add Guide: Replay XCMs with Full Logging Using Chopsticks Add Guide: Replay & Dry Run XCMs with Full Logging Using Chopsticks Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants