Skip to content

Commit d993251

Browse files
committed
tinyjam: some notes
1 parent f46ab22 commit d993251

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

tinyjam/src/core_seal.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

tinyjam/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
//! # Tinyjam
2+
//!
3+
//! A tiny implementation of the Polkadot JAM protocol.
4+
//!
5+
//! ## Consensus logic
6+
//!
7+
//! The consensus logic of `tinyjam` consists of three parts:
8+
//!
9+
//! * Block production and finality: to make relay chain blocks.
10+
//! * Map-reduce: the logic of refine, accumulate, and on transfer.
11+
//! * In-core sealing: guaranteeing, availability, auditing and judging.
12+
//!
13+
//! The code is structured so that the parts are swappable. You can replace
14+
//! the block production algorithm to simple Aura. Or you can disable
15+
//! map-reduce, so that the chain notes raw blobs without any functionality.
16+
17+
pub mod core_seal;
18+
119
pub struct State<Consensus> {
220
/// State of the consensus, such as Safrole.
321
pub consensus: Consensus,

0 commit comments

Comments
 (0)