-
Notifications
You must be signed in to change notification settings - Fork 382
client fix: filter buggy transaction not included in the ethereum block #3267
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9288bf2
client fix: filter buggy tx not included in the eth block
librelois 19e5238
test: test client fix against old runtime
librelois cc3a42f
typo
librelois a00cc7b
test: ensure txHash filed is properly populated
librelois e3e1b7c
test: buggy xcm message at on_initialize with regular eth tx after
librelois f12fefc
client fix: ensure trace match tx status
librelois 73ff323
Merge branch 'master' into elois-client-tracing-filter-buggy-tx
librelois 0842f21
Revert "fix: eth-xcm transactions are not included in the ethereum bl…
librelois 6b2928f
comply biome format
librelois e71d95d
Merge branch 'master' into elois-client-tracing-filter-buggy-tx
stiiifff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| import { beforeAll, customDevRpcRequest, describeSuite, expect } from "@moonwall/cli"; | ||
| import { ALITH_ADDRESS, CHARLETH_ADDRESS, alith } from "@moonwall/util"; | ||
| import { hexToNumber, parseEther } from "viem"; | ||
| import { | ||
| ERC20_TOTAL_SUPPLY, | ||
| XcmFragment, | ||
| type XcmFragmentConfig, | ||
| expectEVMResult, | ||
| injectEncodedHrmpMessageAndSeal, | ||
| injectHrmpMessage, | ||
| injectHrmpMessageAndSeal, | ||
| sovereignAccountOfSibling, | ||
| } from "../../helpers"; | ||
|
|
||
| describeSuite({ | ||
| id: "T21", | ||
| title: "Trace ERC20 xcm #2", | ||
| foundationMethods: "dev", | ||
| testCases: ({ context, it }) => { | ||
| let erc20ContractAddress: string; | ||
| let eventEmitterAddress: `0x${string}`; | ||
| let ethXcmTxHash: string; | ||
| let regularEthTxHash: string; | ||
| beforeAll(async () => { | ||
| const { contractAddress, status } = await context.deployContract!("ERC20WithInitialSupply", { | ||
| args: ["ERC20", "20S", ALITH_ADDRESS, ERC20_TOTAL_SUPPLY], | ||
| }); | ||
| erc20ContractAddress = contractAddress; | ||
| expect(status).eq("success"); | ||
|
|
||
| const paraId = 888; | ||
| const paraSovereign = sovereignAccountOfSibling(context, paraId); | ||
| const amountTransferred = 1_000_000n; | ||
|
|
||
| // Get pallet indices | ||
| const metadata = await context.polkadotJs().rpc.state.getMetadata(); | ||
| const balancesPalletIndex = metadata.asLatest.pallets | ||
| .find(({ name }) => name.toString() === "Balances")! | ||
| .index.toNumber(); | ||
| const erc20XcmPalletIndex = metadata.asLatest.pallets | ||
| .find(({ name }) => name.toString() === "Erc20XcmBridge")! | ||
| .index.toNumber(); | ||
|
|
||
| // Send some native tokens to the sovereign account of paraId (to pay fees) | ||
| await context | ||
| .polkadotJs() | ||
| .tx.balances.transferAllowDeath(paraSovereign, parseEther("1")) | ||
| .signAndSend(alith); | ||
| await context.createBlock(); | ||
|
|
||
| // Send some erc20 tokens to the sovereign account of paraId | ||
| const rawTx = await context.writeContract!({ | ||
| contractName: "ERC20WithInitialSupply", | ||
| contractAddress: erc20ContractAddress as `0x${string}`, | ||
| functionName: "transfer", | ||
| args: [paraSovereign, amountTransferred], | ||
| rawTxOnly: true, | ||
| }); | ||
| const { result } = await context.createBlock(rawTx); | ||
| expectEVMResult(result!.events, "Succeed"); | ||
| expect( | ||
| await context.readContract!({ | ||
| contractName: "ERC20WithInitialSupply", | ||
| contractAddress: erc20ContractAddress as `0x${string}`, | ||
| functionName: "balanceOf", | ||
| args: [paraSovereign], | ||
| }) | ||
| ).equals(amountTransferred); | ||
|
|
||
| // Create an XCM message that try to transfer more than available | ||
| const failedConfig: XcmFragmentConfig = { | ||
| assets: [ | ||
| { | ||
| multilocation: { | ||
| parents: 0, | ||
| interior: { | ||
| X1: { PalletInstance: Number(balancesPalletIndex) }, | ||
| }, | ||
| }, | ||
| fungible: 1_700_000_000_000_000n, | ||
| }, | ||
| { | ||
| multilocation: { | ||
| parents: 0, | ||
| interior: { | ||
| X2: [ | ||
| { | ||
| PalletInstance: erc20XcmPalletIndex, | ||
| }, | ||
| { | ||
| AccountKey20: { | ||
| network: null, | ||
| key: erc20ContractAddress, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| fungible: amountTransferred * 2n, // Try to transfer twice the available amount | ||
| }, | ||
| ], | ||
| beneficiary: CHARLETH_ADDRESS, | ||
| }; | ||
|
|
||
| const failedXcmMessage = new XcmFragment(failedConfig) | ||
| .withdraw_asset() | ||
| .clear_origin() | ||
| .buy_execution() | ||
| .deposit_asset(2n) | ||
| .as_v3(); | ||
|
|
||
| // Mock the reception of the failed xcm message N times | ||
| // N should be high enough to fill IdleMaxServiceWeigh | ||
| // The goal is to have at least one XCM message queud for next block on_initialize | ||
| for (let i = 0; i < 20; i++) { | ||
| await injectHrmpMessage(context, paraId, { | ||
| type: "XcmVersionedXcm", | ||
| payload: failedXcmMessage, | ||
| }); | ||
| } | ||
| await context.createBlock(); | ||
|
|
||
| // By calling deployContract() a new block will be created, | ||
| // including the ethereum-xcm transaction (on_initialize) + regular ethereum transaction | ||
| const { contractAddress: eventEmitterAddress_ } = await context.deployContract!( | ||
| "EventEmitter", | ||
| { | ||
| from: alith.address, | ||
| } as any | ||
| ); | ||
| eventEmitterAddress = eventEmitterAddress_; | ||
|
|
||
| // The old buggy runtime rollback the eth-xcm tx because XCM executor rollback evm reverts | ||
| regularEthTxHash = (await context.viem().getBlock()).transactions[0]; | ||
|
|
||
| // Get the latest block events | ||
| const block = await context.polkadotJs().rpc.chain.getBlock(); | ||
| const allRecords = await context.polkadotJs().query.system.events.at(block.block.header.hash); | ||
|
|
||
| // Compute XCM message ID | ||
| const messageHash = context.polkadotJs().createType("XcmVersionedXcm", failedXcmMessage).hash; | ||
|
|
||
| // Find messageQueue.Processed event with matching message ID | ||
| const processedEvent = allRecords.find( | ||
| ({ event }) => | ||
| event.section === "messageQueue" && | ||
| event.method === "Processed" && | ||
| event.data[0].toString() === messageHash.toHex() | ||
| ); | ||
|
|
||
| expect(processedEvent).to.not.be.undefined; | ||
| }); | ||
|
|
||
| // IMPORTANT: this test will fail once we will merge https://github.com/moonbeam-foundation/moonbeam/pull/3258 | ||
| it({ | ||
| id: "T01", | ||
| title: "should doesn't include the failed ERC20 xcm transaction in block trace", | ||
| test: async function () { | ||
| const number = await context.viem().getBlockNumber(); | ||
| const trace = await customDevRpcRequest("debug_traceBlockByNumber", [ | ||
| number.toString(), | ||
| { tracer: "callTracer" }, | ||
| ]); | ||
|
|
||
| // Verify that only the regular eth transaction is included in the block trace. | ||
| expect(trace.length).to.eq(1); | ||
|
|
||
| // 1st traced transaction is regular ethereum transaction. | ||
| // - `From` is Alith's adddress. | ||
| // - `To` is the ethereum contract address. | ||
| const txHash = trace[0].txHash; | ||
| expect(txHash).to.eq(regularEthTxHash); | ||
| const call = trace[0].result; | ||
| expect(call.from).to.eq(alith.address.toLowerCase()); | ||
| expect(call.to).to.eq(eventEmitterAddress.toLowerCase()); | ||
| expect(call.type).be.eq("CREATE"); | ||
| }, | ||
| }); | ||
| }, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.