paritytech / cumulus

Write Parachains on Substrate
GNU General Public License v3.0
620 stars 380 forks source link

Cumulus Runtime #5

Open rphmeier opened 5 years ago

rphmeier commented 5 years ago

We will want a runtime component for parachains to handle incoming messages.

The module will look something like this.

trait OnMessages {
    fn on_messages(messages: Vec<polkadot::IncomingMessage>);
}

trait Trait {
    type OnMessages: OnMessages;
}

struct<T: Trait> Module<T> {
    // defines an inherent for the incoming messages to be passed. the incoming messages are passed to `T::OnMessages::on_messages`.
}
rphmeier commented 5 years ago

Worth taking a look at the polkadot/runtime/parachains implementation of Upward messages for inspiration: we'll want a custom Origin::InboundMessage for the calls that this module produces.

gavofyork commented 4 years ago

i'll take this.

rphmeier commented 4 years ago

On the runtime side it's up to you - only the notes I left in the issue above.

Take a look at the cumulus-collator crate which Basti authored - this is invoked by polkadot-collator, which automatically fetches the messages from the network and feeds them to the polkadot_collator::ParachainContext, which cumulus-collator provides. So it should be possible to feed it into an inherent data.

bkchr commented 4 years ago

Yeah, the node side should be relative easy. If we have the runtime side, we can just feed the ingress data into the inherent data on the node side. Or better would be to have a dedicated runtime call to create the inherent, as we don't store it in the block. Otherwise we don't know which extrinsic we should remove from the block.

gavofyork commented 4 years ago

A runtime call to create the inherent? You mean exposing an additional runtime API:

type Messages = Vec<Vec<u8>>;
enum Endpoint { Relay, Para(ParaId) }
trait BatchIncoming {
  /// Accepts a bunch of `messages` from various endpoints and creates an inherent extrinsic suitable for introducing into this runtime in order to dispatch the messages.
  fn batch_incoming(messages: Vec<(Endpoint, Messages)>) -> Vec<u8>;
}
bkchr commented 4 years ago

Yeah, exposing an additional runtime API.

gavofyork commented 4 years ago

Would that be an optimal API ^^^?

bkchr commented 4 years ago

The current collator interface only gets messages from other parachains, but no messages from the relay chain.

So something like:

trait CollatorApi {
    fn create_inherent(messages: Vec<(ParaId, Message)>) -> Block::Extrinsic;
}

should work.

ParaId is defined as Id in polkadot-parachain and Message is defined in polkadot-primitives/parachain

rphmeier commented 4 years ago

We should get messages from the relay chain as well now

bkchr commented 4 years ago

https://github.com/paritytech/polkadot/blob/master/collator/src/lib.rs#L149 how?

rphmeier commented 4 years ago

Yeah, that'll require an upstream PR and a PolkadotApi alteration - not saying it should be done only in Cumulus, just that we should support it at some point.

At a minimum, we can have the runtime interface accommodate relay-chain messages (upwards and downwards) without actually passing them through, yet.

gavofyork commented 4 years ago

so: polkadot validators explicitly check that the inherent extrinsic which contains message data is valid?

rphmeier commented 4 years ago

how i'd like it to work: the validation function should contain the block body (sans inherent), and accepts the messages as argument. as a first step, it constructs the actual block body by constructing the inherent from the passed messages.

gavofyork commented 4 years ago

It begins: https://github.com/paritytech/cumulus/pull/16