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

Parachain support #130

Merged
merged 188 commits into from
Nov 28, 2023
Merged

Parachain support #130

merged 188 commits into from
Nov 28, 2023

Conversation

JoshOrndorff
Copy link
Contributor

@JoshOrndorff JoshOrndorff commented Oct 16, 2023

This PR is the bulk of the effort to enable parachain support (including template runtime and node and dev service).

Some prerequisites include #100 and #131.
Followups include #144, #146, #147, #149, and eventually even #148.

Parachain Core crate

The core of this PR is the tuxedo-parachain-core crate. It is an extention to the pre-existing tuxedo-core crate that adds types and methods relevant to the parachain protocol.

One design goal is that sovereign chain developers should not have to compile any of the heavy Polkadot or Cumulus crates. Therefore the parachain code is in a separate crate. The new crate has a re-export of the tuxedo-core crate. This allows parachain developers to depend only on tuxedo-parachain-core and not risk mis-matching versions.

Validate Block function and register_validate_block! macro.

This PR also contains a working PoC of the validate_block function that will be used to validate parachain block on the relay chain validators. While the current implementation is good enough for testing, it still has a few security checks disabled, especially checking timestamp inherent, that need to be properly addressed before it is ready for any serious use.

There are some tricks about shared memory involved in the parahcains protocol that do not need to be exposed to parachain runtime developers. For this reason, we wrap the validate_block function's implementation that does the unsafe memory operations internally. This is the same in FRAME.

Parachain Inherent Piece

Another addition is a Tuxedo piece in the wardrobe called the "parachain piece". This piece is modeled after the timestamp piece and it is responsible for handling the parachain inherent. This piece is atypical in one important way: it has side effects. Specifically, it writes the relay chain parent number to a fixed storage location. The effects are isolated by a clean mutator interface. Still this design is not 100% UTXO native, and better ideas are welcome in followups.

Template Runtime

There is a new feature called parachain in the tuxedo-template-runtime. When this feature is enabled the runtime has the parachain piece and validate_block function included.

Parachain Node

This PR is +11k lines of code, and a huge amount of that is in the parachain template node. This node is mostly copied directly from the upstream parachain template node in the SDK repo. This is the same approach we took in the sovereign node.

The only customized aspects are the inherent data providers, and the dev service.

Dev Service

The dev service is a way to test the parachain runtime without a backing relay chain. This is a technique that I invented in Moonbeam in moonbeam-foundation/moonbeam#204, moonbeam-foundation/moonbeam#260, and a few others.

First I built this into the existing sovereign node with a feature called mock-parachain. It is working there, but I think it is not that useful, and should probably be removed. Later I decided it made more sense to have the dev service in the parachain node, so it is there also.

@bkchr
Copy link

bkchr commented Oct 16, 2023

We now derive serialize and deserialize in no std. This is probably your problem here, as you only implement on std.

Joshy Orndorff added 3 commits October 20, 2023 11:58
parachain_node/src/service.rs Outdated Show resolved Hide resolved
wardrobe/parachain/src/lib.rs Outdated Show resolved Hide resolved
wardrobe/parachain/src/lib.rs Show resolved Hide resolved
wardrobe/parachain/src/lib.rs Outdated Show resolved Hide resolved
wardrobe/parachain/src/lib.rs Outdated Show resolved Hide resolved
tuxedo-parachain-core/src/lib.rs Outdated Show resolved Hide resolved
tuxedo-parachain-core/src/lib.rs Outdated Show resolved Hide resolved
tuxedo-parachain-core/src/lib.rs Outdated Show resolved Hide resolved
tuxedo-parachain-core/src/validate_block.rs Outdated Show resolved Hide resolved
tuxedo-parachain-core/src/validate_block.rs Show resolved Hide resolved
JoshOrndorff and others added 2 commits November 28, 2023 14:10
Co-authored-by: Matteo Muraca <56828990+muraca@users.noreply.github.com>
JoshOrndorff and others added 7 commits November 28, 2023 14:28
Co-authored-by: Matteo Muraca <56828990+muraca@users.noreply.github.com>
Co-authored-by: Matteo Muraca <56828990+muraca@users.noreply.github.com>
Co-authored-by: Matteo Muraca <56828990+muraca@users.noreply.github.com>
The only dev service is now in the parachain node.
@JoshOrndorff
Copy link
Contributor Author

Okay, I've addressed the review. There is a lot left to do here, but this is blocking several other things, and it is working pretty well. I'm going to merge it so other PRs can be resolved and we can get our first parachain milestone complete.

@JoshOrndorff JoshOrndorff merged commit 0653fbe into main Nov 28, 2023
6 checks passed
@JoshOrndorff JoshOrndorff deleted the joshy-parachain branch November 28, 2023 21:26
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