Skip to content
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

Reimplement OutboundQueue pallet #851

Merged
merged 29 commits into from
Jun 17, 2023
Merged

Reimplement OutboundQueue pallet #851

merged 29 commits into from
Jun 17, 2023

Conversation

vgeddes
Copy link
Collaborator

@vgeddes vgeddes commented May 31, 2023

The existing implementation was deficient in that it dropped messages if the maximum number of pending messages was breached. Due to the nature of our bridging design and related weight calculations, there is a hard limit on the number of outgoing messages which can be committed per block. Any messages beyond that limit need to be buffered somewhere, or dropped.

Dropping messages is bad for many reasons:

  • Potential loss of funds if user's messages are dropped rather than being sent over the bridge
  • Cross-chain governance messages could be dropped, leading to loss of control over the bridge.

The new implementation takes advantage of a new generalised message queueing pallet in Substrate: MessageQueue. Its main responsibility is to store pending messages in a PoV-efficient manner, and coordinate their processing by other pallets. It never drops messages.

At a very high-level, the messaging flow now looks like this

  • Message is first submitted to OutboundQueue via OutboundQueue::submit
  • OutboundQueue forwards message to MessageQueue
  • MessageQueue hooks back into OutboundQueue to process the message when there is enough remaining weight in the block

Other improvements:

  • The snowbridge-query-events tool is no longer needed, since the pallet stores the committed messages in a way that GSRPC can now query using normal storage queries.
  • The final process of producing a message commitment is much more efficient and easier to benchmark, by doing some of the processing when a message is first initially submitted.

Todo:

  • Update cumulus runtimes
  • Update relayer

Cumulus companion PR: Snowfork/cumulus#36

Fixes: SNO-488, SNO-511, SNO-474

@codecov
Copy link

codecov bot commented May 31, 2023

Codecov Report

Patch coverage: 48.80% and project coverage change: +1.21 🎉

Comparison is base (f48605c) 64.44% compared to head (e648446) 65.65%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #851      +/-   ##
==========================================
+ Coverage   64.44%   65.65%   +1.21%     
==========================================
  Files          10       45      +35     
  Lines         225     1581    +1356     
  Branches       52       54       +2     
==========================================
+ Hits          145     1038     +893     
- Misses         60      523     +463     
  Partials       20       20              
Impacted Files Coverage Δ
core/packages/contracts/src/NativeTokensTypes.sol 100.00% <ø> (ø)
core/packages/contracts/src/OutboundQueue.sol 100.00% <ø> (ø)
core/packages/contracts/src/SovereignTreasury.sol 0.00% <ø> (ø)
core/packages/contracts/src/TokenVault.sol 100.00% <ø> (ø)
core/packages/contracts/src/Vault.sol 63.63% <ø> (ø)
parachain/pallets/control/src/lib.rs 0.00% <0.00%> (ø)
parachain/pallets/control/src/weights.rs 0.00% <0.00%> (ø)
...in/pallets/ethereum-beacon-client/src/functions.rs 100.00% <ø> (ø)
...achain/pallets/ethereum-beacon-client/src/impls.rs 0.00% <0.00%> (ø)
...hain/pallets/outbound-queue/runtime-api/src/lib.rs 0.00% <0.00%> (ø)
... and 35 more

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

core/packages/contracts/src/OutboundQueue.sol Show resolved Hide resolved
if (amount == 0) {
revert InvalidAmount();
}

vault.deposit(msg.sender, token, amount);

bytes memory payload = NativeTokensTypes.Mint(token, dest, recipient, amount);
outboundQueue.submit{ value: msg.value }(assetHubParaID, payload);
bytes memory payload = NativeTokensTypes.Mint(address(registry), token, dest, recipient, amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

So the registry is now the dummy address that we will use to configure Statemine/Bridgehub?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, indeed.

All assets transferred across the bridge to Asset Hub should have a Location of the form: /GlobalConsensus(Ethereum)/AccountKey20(Registry)/AccountKey20(TokenContractAddress)

vgeddes and others added 10 commits June 12, 2023 10:14
* Add previous Merkle proof verifier

* Switch BeefyClient to previous MerkleProof verifier

* Switch ParachainClient to previous MerkleProof verifier

* Remove unused function

* Update polkadot to include BEEFY revert

* Remove note about not checking index

* Remove leading underscore

* Don't sort hash pairs when generating test data

* Print logs from forge test

* wat

* Fix library function signatures

* Remove test logs

* Use internal modifier in Bitfield

* Revert modifier so that BeefyClient test works

* Guard against short proofs
@yrong
Copy link
Contributor

yrong commented Jun 15, 2023

@doubledup @vgeddes
Seems #861 is merged here. I remember when coordinate with paritytech/substrate#12857 there are several changes in relayer side I made as following:
https://github.com/Snowfork/snowbridge/pull/780/files#diff-f8e330734941339a0ff763ff8d35f39639595660b175b591697a38163a436ba2

But I can not find the counterpart revert in this PR, is that not required or we missed here?

@doubledup
Copy link
Contributor

@yrong That's exactly right, I missed that in #861. Thanks for catching it!

@vgeddes
Copy link
Collaborator Author

vgeddes commented Jun 15, 2023

@doubledup @vgeddes Seems #861 is merged here. I remember when coordinate with paritytech/substrate#12857 there are several changes in relayer side I made as following: https://github.com/Snowfork/snowbridge/pull/780/files#diff-f8e330734941339a0ff763ff8d35f39639595660b175b591697a38163a436ba2

But I can not find the counterpart revert in this PR, is that not required or we missed here?

Thanks Ron, I definitely overlooked those changes. As the relayer is currently failing when it tries to call BeefyClient.submitFinal.

@vgeddes vgeddes marked this pull request as ready for review June 16, 2023 21:30
@vgeddes vgeddes merged commit cbc5fa5 into main Jun 17, 2023
@vgeddes vgeddes deleted the vincent/outbound-queue branch June 17, 2023 00:08
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.

4 participants