Skip to content

Commit eaaa266

Browse files
committed
(ol/chain-types): Add chain types
1 parent 54acd89 commit eaaa266

File tree

10 files changed

+445
-65
lines changed

10 files changed

+445
-65
lines changed

Cargo.lock

Lines changed: 18 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ strata-ledger-types = { path = "crates/ledger-types" }
171171
strata-mmr = { path = "crates/util/mmr" }
172172
strata-mpt = { path = "crates/mpt" }
173173
strata-ol-chain-types = { path = "crates/ol-chain-types" }
174+
strata-ol-chain-types-new = { path = "crates/ol/chain-types" }
174175
strata-ol-chainstate-types = { path = "crates/ol-chainstate-types" }
175176
strata-ol-state-types = { path = "crates/ol/state-types" }
176177
strata-primitives = { path = "crates/primitives" }

crates/ol/chain-types/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
# TODO: replace the older ol-chain-types crate with this and remove "-new" suffix
3+
# "-new" is added to maintain compatibility with existing code without disruptive changes
4+
name = "strata-ol-chain-types-new"
5+
version = "0.1.0"
6+
edition = "2024"
7+
8+
[dependencies]
9+
strata-acct-types.workspace = true
10+
strata-asm-common.workspace = true
11+
strata-primitives.workspace = true
12+
strata-snark-acct-types.workspace = true
13+
14+
[lints]
15+
workspace = true

crates/ol/chain-types/src/block.rs

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
use strata_asm_common::AsmLogEntry;
2+
use strata_primitives::buf::{Buf32, Buf64};
3+
4+
use crate::{Epoch, OLBlockId, OLTransaction, Slot};
5+
6+
/// The Orchestration Layer(OL) block.
7+
#[derive(Clone, Debug)]
8+
pub struct OLBlock {
9+
signed_header: SignedOLBlockHeader,
10+
body: OLBlockBody,
11+
}
12+
13+
impl OLBlock {
14+
pub fn new(signed_header: SignedOLBlockHeader, body: OLBlockBody) -> Self {
15+
Self {
16+
signed_header,
17+
body,
18+
}
19+
}
20+
21+
pub fn body(&self) -> &OLBlockBody {
22+
&self.body
23+
}
24+
25+
pub fn signed_header(&self) -> &SignedOLBlockHeader {
26+
&self.signed_header
27+
}
28+
29+
pub fn header(&self) -> &OLBlockHeader {
30+
self.signed_header.header()
31+
}
32+
}
33+
34+
/// OL Block header with signature.
35+
#[derive(Clone, Debug)]
36+
pub struct SignedOLBlockHeader {
37+
header: OLBlockHeader,
38+
signature: Buf64,
39+
}
40+
41+
impl SignedOLBlockHeader {
42+
pub fn new(header: OLBlockHeader, signature: Buf64) -> Self {
43+
Self { header, signature }
44+
}
45+
46+
pub fn header(&self) -> &OLBlockHeader {
47+
&self.header
48+
}
49+
50+
pub fn signature(&self) -> Buf64 {
51+
self.signature
52+
}
53+
}
54+
55+
/// OL Block header without signature.
56+
#[derive(Clone, Debug)]
57+
pub struct OLBlockHeader {
58+
/// The timestamp the block was created at.
59+
timestamp: u64,
60+
/// Slot the block was created for.
61+
slot: Slot,
62+
/// Epoch the block was created in.
63+
epoch: Epoch,
64+
/// Parent block id.
65+
parent_blk_id: OLBlockId,
66+
/// Root of the block body.
67+
body_root: Buf32,
68+
/// Root of the block logs.
69+
logs_root: Buf32,
70+
/// The state root resulting after the block execution.
71+
state_root: Buf32,
72+
}
73+
74+
impl OLBlockHeader {
75+
pub fn new(
76+
timestamp: u64,
77+
slot: Slot,
78+
epoch: Epoch,
79+
parent_blk_id: OLBlockId,
80+
body_root: Buf32,
81+
logs_root: Buf32,
82+
state_root: Buf32,
83+
) -> Self {
84+
Self {
85+
timestamp,
86+
slot,
87+
epoch,
88+
parent_blk_id,
89+
body_root,
90+
logs_root,
91+
state_root,
92+
}
93+
}
94+
95+
pub fn timestamp(&self) -> u64 {
96+
self.timestamp
97+
}
98+
99+
pub fn slot(&self) -> u64 {
100+
self.slot
101+
}
102+
103+
pub fn epoch(&self) -> u32 {
104+
self.epoch
105+
}
106+
107+
pub fn parent_blk_id(&self) -> Buf32 {
108+
self.parent_blk_id
109+
}
110+
111+
pub fn body_root(&self) -> Buf32 {
112+
self.body_root
113+
}
114+
115+
pub fn logs_root(&self) -> Buf32 {
116+
self.logs_root
117+
}
118+
119+
pub fn state_root(&self) -> Buf32 {
120+
self.state_root
121+
}
122+
}
123+
124+
/// OL block body containing transactions and l1 updates
125+
#[derive(Clone, Debug)]
126+
pub struct OLBlockBody {
127+
/// The transactions contained in an OL block.
128+
txs: Vec<OLTransaction>,
129+
/// Updates from L1
130+
l1_update: L1Update,
131+
}
132+
133+
impl OLBlockBody {
134+
pub fn new(txs: Vec<OLTransaction>, l1_update: L1Update) -> Self {
135+
Self { txs, l1_update }
136+
}
137+
138+
pub fn txs(&self) -> &[OLTransaction] {
139+
&self.txs
140+
}
141+
142+
pub fn l1_update(&self) -> &L1Update {
143+
&self.l1_update
144+
}
145+
}
146+
147+
/// Represents an update from L1.
148+
#[derive(Clone, Debug)]
149+
pub struct L1Update {
150+
/// The state root before applying updates from L1.
151+
pub preseal_state_root: Buf32,
152+
153+
/// L1 height the manifests are read upto.
154+
pub new_l1_blk_height: u64,
155+
156+
/// L1 block hash the manifests are read upto.
157+
pub new_l1_blk_hash: Buf32,
158+
159+
/// Manifests from last l1 height to the new l1 height.
160+
pub manifests: Vec<AsmManifest>,
161+
}
162+
163+
impl L1Update {
164+
pub fn new(
165+
preseal_state_root: Buf32,
166+
new_l1_blk_height: u64,
167+
new_l1_blk_hash: Buf32,
168+
manifests: Vec<AsmManifest>,
169+
) -> Self {
170+
Self {
171+
preseal_state_root,
172+
new_l1_blk_height,
173+
new_l1_blk_hash,
174+
manifests,
175+
}
176+
}
177+
178+
pub fn preseal_state_root(&self) -> Buf32 {
179+
self.preseal_state_root
180+
}
181+
182+
pub fn new_l1_blk_height(&self) -> u64 {
183+
self.new_l1_blk_height
184+
}
185+
186+
pub fn new_l1_blk_hash(&self) -> Buf32 {
187+
self.new_l1_blk_hash
188+
}
189+
}
190+
191+
/// A manifest containing ASM data corresponding to a L1 block.
192+
#[derive(Debug, Clone)]
193+
pub struct AsmManifest {
194+
/// L1 block id.
195+
blockid: Buf32,
196+
197+
/// Logs from ASM STF.
198+
logs: Vec<AsmLogEntry>,
199+
}
200+
201+
impl AsmManifest {
202+
pub fn new(blockid: Buf32, logs: Vec<AsmLogEntry>) -> Self {
203+
Self { blockid, logs }
204+
}
205+
206+
pub fn blockid(&self) -> &Buf32 {
207+
&self.blockid
208+
}
209+
210+
pub fn logs(&self) -> &[AsmLogEntry] {
211+
&self.logs
212+
}
213+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
use strata_primitives::buf::Buf32;
2+
3+
/// Type aliases for clarity
4+
pub type Slot = u64;
5+
pub type Epoch = u32;
6+
pub type OLBlockId = Buf32;
7+
pub type L1BlockId = Buf32;
8+
9+
/// Commitment to a block by ID at a particular slot.
10+
#[derive(Clone, Debug)]
11+
pub struct OLBlockCommitment {
12+
slot: Slot,
13+
blkid: OLBlockId,
14+
}
15+
16+
impl OLBlockCommitment {
17+
pub fn new(slot: Slot, blkid: OLBlockId) -> Self {
18+
Self { slot, blkid }
19+
}
20+
21+
pub fn slot(&self) -> Slot {
22+
self.slot
23+
}
24+
25+
pub fn blkid(&self) -> &OLBlockId {
26+
&self.blkid
27+
}
28+
}
29+
30+
/// Commitment to the terminal block of a particular epoch.
31+
#[derive(Clone, Debug)]
32+
pub struct EpochCommitment {
33+
epoch: Epoch,
34+
terminal_block: OLBlockCommitment,
35+
}
36+
37+
impl EpochCommitment {
38+
pub fn new(epoch: Epoch, terminal_block: OLBlockCommitment) -> Self {
39+
Self {
40+
epoch,
41+
terminal_block,
42+
}
43+
}
44+
45+
pub fn epoch(&self) -> Epoch {
46+
self.epoch
47+
}
48+
49+
pub fn terminal_block(&self) -> &OLBlockCommitment {
50+
&self.terminal_block
51+
}
52+
53+
pub fn terminal_slot(&self) -> Slot {
54+
self.terminal_block.slot()
55+
}
56+
57+
pub fn terminal_blkid(&self) -> &OLBlockId {
58+
self.terminal_block.blkid()
59+
}
60+
}
61+
62+
/// Commitment to an L1 block by ID at a particular height.
63+
/// Useful since Bitcoin blocks do not include height in their header.
64+
#[derive(Clone, Debug)]
65+
pub struct L1BlockCommitment {
66+
height: u32,
67+
blkid: L1BlockId,
68+
}
69+
70+
impl L1BlockCommitment {
71+
pub fn new(height: u32, blkid: L1BlockId) -> Self {
72+
Self { height, blkid }
73+
}
74+
75+
pub fn height(&self) -> u32 {
76+
self.height
77+
}
78+
79+
pub fn blkid(&self) -> &L1BlockId {
80+
&self.blkid
81+
}
82+
}

crates/ol/chain-types/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! All the types related to OL chain.
2+
mod block;
3+
mod common;
4+
mod transaction;
5+
6+
pub use block::*;
7+
pub use common::*;
8+
pub use transaction::*;

0 commit comments

Comments
 (0)