|
| 1 | +//! # In-core sealing algorithm. |
| 2 | +//! |
| 3 | +//! The in-core sealing protocol is a generalization of Polkadot JAM's part |
| 4 | +//! of the in-core computation. It ensures the following: |
| 5 | +//! |
| 6 | +//! * Given a work package, it ensures that it is *authorized* on the current |
| 7 | +//! core. |
| 8 | +//! * Participating validators would then *refine* the work package to produce |
| 9 | +//! a work report. |
| 10 | +//! * It further ensures availability, and later handle disputes. |
| 11 | +//! |
| 12 | +//! The types of the in-core sealing algorithm defined here deals with only a |
| 13 | +//! single core (in another word, there's no core ID). It is expected that |
| 14 | +//! different cores will need their own worker thread anyway. |
| 15 | +//! |
| 16 | +//! We do not have the concept of a block in this module. The algorithm works |
| 17 | +//! through a *handle*, which acts as a state machine, with always-up-to-date |
| 18 | +//! information. It's the responsibility of the handle to fetch states and to |
| 19 | +//! update states to the relay chain blocks. In practice, work packages |
| 20 | +//! usually have their own pins to specific blocks. No block building or |
| 21 | +//! transaction creation is done in this module. In all other cases, it operates |
| 22 | +//! over the current best blocks. |
| 23 | +//! |
| 24 | +//! Related to the specification, this module only handles in-core. This means |
| 25 | +//! `authorize` and `refine`, but not later stages of `accumulate` and |
| 26 | +//! `on_transfer`. |
| 27 | +//! |
| 28 | +//! ## Cycle of the worker |
| 29 | +//! |
| 30 | +//! The worker thread accepts a stream receiving work packages. Upon checking |
| 31 | +//! that the work package is authorized, it takes ownership of it, refines it to |
| 32 | +//! get the work report, and then attest it to publish on the relay chain. |
| 33 | +//! |
| 34 | +//! Another stream will receive a tuple of work packages and work reports |
| 35 | +//! already generated, and attest them. |
| 36 | +
|
| 37 | +use std::future::Future; |
| 38 | + |
| 39 | +/// Handle for the in-core sealing. |
| 40 | +/// |
| 41 | +/// This works like a state machine. Work packages usually have their own pins, |
| 42 | +/// and if not specified, it works against the best block / the most updated |
| 43 | +/// network. |
| 44 | +pub trait CoreSealHandle { |
| 45 | + /// Error type for the handle. |
| 46 | + type Error; |
| 47 | + |
| 48 | + /// A work package, pre-refine. |
| 49 | + type WorkPackage; |
| 50 | + /// A work report from a work package, post-refine. |
| 51 | + type WorkReport; |
| 52 | + |
| 53 | + /// Whether the work package is authorized on the current core. |
| 54 | + fn is_authorized(&self, work: &Self::WorkPackage) -> bool; |
| 55 | + /// Refine from a work package into a work report. |
| 56 | + fn refine( |
| 57 | + &self, |
| 58 | + work: Self::WorkPackage, |
| 59 | + ) -> impl Future<Output = Result<Self::WorkReport, Self::Error>> + Send; |
| 60 | + |
| 61 | + /// Attest to a work report and submit it. |
| 62 | + fn attest( |
| 63 | + &mut self, |
| 64 | + report: Self::WorkReport, |
| 65 | + ) -> impl Future<Output = Result<(), Self::Error>> + Send; |
| 66 | + /// Dispute a work report and submit it. |
| 67 | + fn dispute( |
| 68 | + &mut self, |
| 69 | + own: Self::WorkReport, |
| 70 | + other: Self::WorkReport, |
| 71 | + ) -> impl Future<Output = Result<(), Self::Error>> + Send; |
| 72 | +} |
0 commit comments