Skip to content

Commit c5f04e7

Browse files
apenzkmzabaluev
authored andcommitted
docs: update READMEs (#685)
Co-authored-by: Mikhail Zabaluev <[email protected]>
1 parent 8bd5218 commit c5f04e7

File tree

7 files changed

+52
-8
lines changed

7 files changed

+52
-8
lines changed

protocol-units/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ We identify the following protocol unit categories:
77
- [Cryptography](./cryptography): Protocol units concerned with cryptographic operations. Cryptography and data structure-related utilities are members of this category.
88
- [Execution](./execution): Protocol units concerned with execution. Block executors and related unities are members of this category.
99
- [Movement REST service](./movement-rest): Protocol units to support Movement's REST API. `movement-rest` provides additional Movement REST API endpoints.
10-
- [Settlement](./settlement): Protocol units concerned with settlement. Movement's multi-commitment rollup and related settlement utilities are members of this category.
10+
- [Settlement](./settlement/README.md): Protocol units concerned with settlement, such as Movement's Multi-Commitment Rollup (MCR).
1111
- [Storage](./storage): Protocol units concerned with storage. `jelly-move`, `move-access-log`, and `mpt-move` are members of this category.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
`sequencing`
2+
3+
- [Mempool Sequencer](./memseq/sequencer/README.md): Basic sequencer that orders transactions from a mempool into blocks.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
`Mempool Sequencer`
2+
3+
The `Memseq` module is responsible for managing a mempool and sequencing transactions into blocks.
4+
5+
It is intended for use of a centralized sequencer node that manages a mempool.

protocol-units/sequencing/memseq/sequencer/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::path::PathBuf;
1414
use std::sync::Arc;
1515
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
1616

17+
/// The `Memseq` module is responsible for managing a mempool and sequencing transactions into blocks.
1718
#[derive(Clone)]
1819
pub struct Memseq<T: MempoolTransactionOperations> {
1920
/// The mempool to get transactions from.
@@ -67,6 +68,7 @@ impl<T: MempoolTransactionOperations> Memseq<T> {
6768
}
6869

6970
impl Memseq<RocksdbMempool> {
71+
/// Attempts to create a new Memseq instance with a RocksDB mempool, given a path, block size, and building time.
7072
pub fn try_move_rocks(
7173
path: PathBuf,
7274
block_size: u32,
@@ -95,6 +97,7 @@ impl<T: MempoolTransactionOperations> Sequencer for Memseq<T> {
9597
Ok(())
9698
}
9799

100+
/// Waits for the next block to be built, either when the block size is reached or the building time expires.
98101
async fn wait_for_next_block(&self) -> Result<Option<Block>, anyhow::Error> {
99102
let mut transactions = Vec::with_capacity(self.block_size as usize);
100103

@@ -154,6 +157,7 @@ pub mod test {
154157
use mempool_util::MempoolTransaction;
155158
use tempfile::tempdir;
156159

160+
/// Tests that the block is built when the building time expires, even if the block size is not reached.
157161
#[tokio::test]
158162
async fn test_wait_for_next_block_building_time_expires() -> Result<(), anyhow::Error> {
159163
let dir = tempdir()?;
@@ -179,6 +183,7 @@ pub mod test {
179183
Ok(())
180184
}
181185

186+
/// Tests error propagation when publishing transactions to the mempool.
182187
#[tokio::test]
183188
async fn test_publish_error_propagation() -> Result<(), anyhow::Error> {
184189
let mempool = MockMempool;
@@ -197,6 +202,7 @@ pub mod test {
197202
Ok(())
198203
}
199204

205+
/// Tests concurrent access to the Memseq instance using spawned tasks.
200206
#[tokio::test]
201207
async fn test_concurrent_access_spawn() -> Result<(), anyhow::Error> {
202208
let dir = tempdir()?;
@@ -221,6 +227,7 @@ pub mod test {
221227
Ok(())
222228
}
223229

230+
/// Tests concurrent access to the Memseq instance using futures.
224231
#[tokio::test]
225232
async fn test_concurrent_access_futures() -> Result<(), anyhow::Error> {
226233
let dir = tempdir()?;
@@ -247,6 +254,7 @@ pub mod test {
247254
Ok(())
248255
}
249256

257+
/// Tests the creation of a Memseq instance with a RocksDB mempool and verifies the block size and building time.
250258
#[tokio::test]
251259
async fn test_try_move_rocks() -> Result<(), anyhow::Error> {
252260
let dir = tempdir()?;
@@ -264,6 +272,7 @@ pub mod test {
264272
Ok(())
265273
}
266274

275+
/// Tests the initialization of the Memseq instance and verifies its fields.
267276
#[tokio::test]
268277
async fn test_memseq_initialization() -> Result<(), anyhow::Error> {
269278
let dir = tempdir()?;
@@ -285,6 +294,7 @@ pub mod test {
285294
Ok(())
286295
}
287296

297+
/// Tests the with_block_size and with_building_time_ms methods.
288298
#[tokio::test]
289299
async fn test_memseq_with_methods() -> Result<(), anyhow::Error> {
290300
let dir = tempdir()?;
@@ -312,6 +322,7 @@ pub mod test {
312322
Ok(())
313323
}
314324

325+
/// Tests that no block is built when there are no transactions in the mempool.
315326
#[tokio::test]
316327
async fn test_wait_for_next_block_no_transactions() -> Result<(), anyhow::Error> {
317328
let dir = tempdir()?;
@@ -326,6 +337,7 @@ pub mod test {
326337
Ok(())
327338
}
328339

340+
/// Tests the basic functionality of the Memseq instance, including publishing transactions and waiting for the next block.
329341
#[tokio::test]
330342
async fn test_memseq() -> Result<(), anyhow::Error> {
331343
let dir = tempdir()?;
@@ -347,6 +359,7 @@ pub mod test {
347359
Ok(())
348360
}
349361

362+
/// Tests that the Memseq instance respects the block size limit when building blocks.
350363
#[tokio::test]
351364
async fn test_respects_size() -> Result<(), anyhow::Error> {
352365
let dir = tempdir()?;
@@ -380,6 +393,7 @@ pub mod test {
380393
Ok(())
381394
}
382395

396+
/// Tests that the Memseq instance respects the building time limit when waiting for the next block.
383397
#[tokio::test]
384398
async fn test_wait_next_block_respects_time() -> Result<(), anyhow::Error> {
385399
let dir = tempdir()?;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `settlement`
2+
3+
- [MCR](./mcr/README.md) : Multi-Commitment Rollup (MCR) settlement.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# MCR - Multi-Commit Rollup
2+
3+
**MCR** implements a staking-based settlement where validators commit L2-blocks on Layer 1 (L1).
4+
5+
Validators stake tokens to participate in block validation. They commit to L2-blocks on L1, and the contract on L1 tracks block commitments, epochs, and stake. The contracts also manage validators and custodian staking and unstaking. The contract validates if commitments have reached two-thirds supermajority stake, and rewards or slashes validators based on their actions.
6+
7+
For further details see the [RFC for MCR](https://github.com/movementlabsxyz/rfcs/pull/29) and the [MIP-34](https://github.com/movementlabsxyz/MIP/blob/main/MIP/mip-34).
8+
9+
## Architecture
10+
11+
- [Contracts](./contracts/README.md): Includes settlement contracts for block commitments, staking contracts for validator management, token contracts for custody.
12+
- **Manager**: Manages block commitments by batching and submitting them, interacts with clients, and processes commitment events (acceptance or rejection) for the settlement system.
13+
- **Setup**: Prepares local environments or deploys contracts, manages configuration for local and deployment setups, and ensures contract deployment when needed.
14+
- **Runner**: Orchestrates the setup and execution of configuration tasks, applies setup steps, and logs processes for debugging.
15+
- **Client**: Handles interaction with the MCR system by posting block commitments, streaming commitment data, and managing Ethereum blockchain interactions.

protocol-units/settlement/mcr/contracts/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# MRC
2-
- **RFC**: [RFC MCR](https://github.com/movementlabsxyz/rfcs/pulls)
1+
# MCR - L1 contract
32

43
This directory contains the implementation of the MRC settlement smart contract. To test the contract, run:
54

@@ -16,14 +15,19 @@ For a given block height, MCR selects the earliest block commitment that matches
1615
2. Tracking commitments for each block height until one exceeds the supermajority of stake.
1716

1817
## Proof of Correctness
18+
19+
> To proof: For a given block height, MCR selects the earliest block commitment that matches the supermajority of stake-
20+
1921
The stake is fixed for an epoch, so only commitments for a specific block height are considered, allowing for a straightforward proof.
2022

21-
Let $C$ represent all possible commitments, and $C'$ be an ordered subset of $C$. MCR returns $c_i \in C'$, the earliest commitment matching the supermajority of stake, defined as:
23+
**Commitment**. Let $v: C \to V$ map a commitment to its validator, where $C$ represent all possible commitments and $V$ is the set of validators. Since commitments are ordered by L1 in the L1-blocks, let $C'$ be an ordered subset of $C$ with $k$ elements (i.e. up to the $k$-th commitment).
24+
25+
**Stake**. Let $s: V \to \mathbb{N}$ map a validator to their stake and $S(C',i) = \sum_{j = 1}^{i} s(v(c_j))$ the cumulative stake up to the $i$-th commitment. $S$ is non-decreasing as $S(C',i) = S(C',i - 1) + s(v(c_i))$.
26+
27+
We require that
2228

2329
$$
24-
\delta(C') = \frac{2}{3} \times \sum_{c \in C'} s(v(c)),
30+
S(C',i) > \frac{2}{3} TotalStake = \frac{2}{3} \times \sum_{u \in V} s(u),
2531
$$
2632

27-
where $v: C \to V$ maps a commitment to its validator and $s: V \to \mathbb{N}$ maps a validator to their stake. Define $\sigma'(C', i) = \sum_{j = 0}^{i} s(v(c_j))$, the cumulative stake up to the $i$-th commitment. $\sigma'$ is non-decreasing as $\sigma(C', i) = \sigma(C', i - 1) + s(v(c_i))$.
28-
29-
If $\sigma(C', i) \geq \delta(C')$, then $c_i$ is the earliest commitment where the supermajority is met, since any earlier commitment $c_j$ for $j < i$ would violate the non-decreasing nature of $\sigma'$.
33+
If $S(C', i)$ satisfies the condition, and $S(C',i-1)$ does not, then $c_i$ is returned by MCR. Due to the non-decreasing nature of $S$ with $i$, $c_i$ is the earliest commitment that can be returned.

0 commit comments

Comments
 (0)