Skip to content

Commit 8d35d9b

Browse files
authored
(ol): Add basic types (#1085)
* (ol): Add basic types * Revert ol-chain-types * (ol/chain-types): Add chain types * (ol/chain-types): Enhance types * Derive IntEnum for TxTypeId * Add a basic OLLog struct
1 parent ecb209c commit 8d35d9b

File tree

12 files changed

+627
-2
lines changed

12 files changed

+627
-2
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ members = [
4848
"crates/l1tx",
4949
"crates/ledger-types",
5050
"crates/mpt",
51-
"crates/ol-chain-types",
51+
"crates/ol/chain-types",
52+
"crates/ol/state-types",
5253
"crates/ol-chainstate-types",
5354
"crates/params",
5455
"crates/primitives",
@@ -182,7 +183,9 @@ strata-ledger-types = { path = "crates/ledger-types" }
182183
strata-mmr = { path = "crates/util/mmr" }
183184
strata-mpt = { path = "crates/mpt" }
184185
strata-ol-chain-types = { path = "crates/ol-chain-types" }
186+
strata-ol-chain-types-new = { path = "crates/ol/chain-types" }
185187
strata-ol-chainstate-types = { path = "crates/ol-chainstate-types" }
188+
strata-ol-state-types = { path = "crates/ol/state-types" }
186189
strata-params = { path = "crates/params" }
187190
strata-primitives = { path = "crates/primitives" }
188191
strata-proofimpl-checkpoint = { path = "crates/proof-impl/checkpoint" }

crates/acct-types/src/id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ impl_opaque_thin_wrapper!(SubjectId => RawSubjectId);
4545
pub type RawAccountTypeId = u16;
4646

4747
/// Distinguishes between account types.
48-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, IntEnum)]
4948
#[repr(u16)]
49+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, IntEnum)]
5050
pub enum AccountTypeId {
5151
/// "Inert" account type for a stub that exists but does nothing, but store
5252
/// balance.

crates/ol/chain-types/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
int-enum.workspace = true
10+
11+
strata-acct-types.workspace = true
12+
strata-asm-common.workspace = true
13+
strata-primitives.workspace = true
14+
strata-snark-acct-types.workspace = true
15+
16+
[lints]
17+
workspace = true

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

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
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+
61+
/// Slot the block was created for.
62+
slot: Slot,
63+
64+
/// Epoch the block was created in.
65+
epoch: Epoch,
66+
67+
/// Parent block id.
68+
parent_blkid: OLBlockId,
69+
70+
/// Root of the block body.
71+
body_root: Buf32,
72+
73+
/// Root of the block logs.
74+
logs_root: Buf32,
75+
76+
/// The state root resulting after the block execution.
77+
state_root: Buf32,
78+
}
79+
80+
impl OLBlockHeader {
81+
pub fn new(
82+
timestamp: u64,
83+
slot: Slot,
84+
epoch: Epoch,
85+
parent_blkid: OLBlockId,
86+
body_root: Buf32,
87+
logs_root: Buf32,
88+
state_root: Buf32,
89+
) -> Self {
90+
Self {
91+
timestamp,
92+
slot,
93+
epoch,
94+
parent_blkid,
95+
body_root,
96+
logs_root,
97+
state_root,
98+
}
99+
}
100+
101+
pub fn timestamp(&self) -> u64 {
102+
self.timestamp
103+
}
104+
105+
pub fn slot(&self) -> u64 {
106+
self.slot
107+
}
108+
109+
pub fn epoch(&self) -> u32 {
110+
self.epoch
111+
}
112+
113+
pub fn parent_blkid(&self) -> Buf32 {
114+
self.parent_blkid
115+
}
116+
117+
pub fn body_root(&self) -> Buf32 {
118+
self.body_root
119+
}
120+
121+
pub fn logs_root(&self) -> Buf32 {
122+
self.logs_root
123+
}
124+
125+
pub fn state_root(&self) -> Buf32 {
126+
self.state_root
127+
}
128+
}
129+
130+
/// OL block body containing transactions and l1 updates
131+
#[derive(Clone, Debug)]
132+
pub struct OLBlockBody {
133+
/// The transactions contained in an OL block.
134+
tx_segment: OLTxSegment,
135+
136+
/// Updates from L1.
137+
l1_update: L1Update,
138+
}
139+
140+
impl OLBlockBody {
141+
pub fn new(tx_segment: OLTxSegment, l1_update: L1Update) -> Self {
142+
Self {
143+
tx_segment,
144+
l1_update,
145+
}
146+
}
147+
148+
pub fn txs(&self) -> &[OLTransaction] {
149+
self.tx_segment.txs()
150+
}
151+
152+
pub fn l1_update(&self) -> &L1Update {
153+
&self.l1_update
154+
}
155+
156+
pub fn tx_segment(&self) -> &OLTxSegment {
157+
&self.tx_segment
158+
}
159+
}
160+
161+
#[derive(Clone, Debug)]
162+
pub struct OLTxSegment {
163+
/// Transactions in the segment.
164+
txs: Vec<OLTransaction>,
165+
// Add other attributes.
166+
}
167+
168+
impl OLTxSegment {
169+
pub fn new(txs: Vec<OLTransaction>) -> Self {
170+
Self { txs }
171+
}
172+
173+
pub fn txs(&self) -> &[OLTransaction] {
174+
&self.txs
175+
}
176+
}
177+
178+
/// Represents an update from L1.
179+
#[derive(Clone, Debug)]
180+
pub struct L1Update {
181+
/// The state root before applying updates from L1.
182+
pub preseal_state_root: Buf32,
183+
184+
/// L1 height the manifests are read upto.
185+
pub new_l1_blk_height: u64,
186+
187+
/// L1 block hash the manifests are read upto.
188+
pub new_l1_blkid: Buf32,
189+
190+
/// Manifests from last l1 height to the new l1 height.
191+
pub manifests: Vec<AsmManifest>,
192+
}
193+
194+
impl L1Update {
195+
pub fn new(
196+
preseal_state_root: Buf32,
197+
new_l1_blk_height: u64,
198+
new_l1_blkid: Buf32,
199+
manifests: Vec<AsmManifest>,
200+
) -> Self {
201+
Self {
202+
preseal_state_root,
203+
new_l1_blk_height,
204+
new_l1_blkid,
205+
manifests,
206+
}
207+
}
208+
209+
pub fn preseal_state_root(&self) -> Buf32 {
210+
self.preseal_state_root
211+
}
212+
213+
pub fn new_l1_blk_height(&self) -> u64 {
214+
self.new_l1_blk_height
215+
}
216+
217+
pub fn new_l1_blkid(&self) -> Buf32 {
218+
self.new_l1_blkid
219+
}
220+
}
221+
222+
/// A manifest containing ASM data corresponding to a L1 block.
223+
#[derive(Debug, Clone)]
224+
pub struct AsmManifest {
225+
/// L1 block id.
226+
l1blkid: Buf32,
227+
228+
/// Logs from ASM STF.
229+
logs: Vec<AsmLogEntry>,
230+
}
231+
232+
impl AsmManifest {
233+
pub fn new(l1blkid: Buf32, logs: Vec<AsmLogEntry>) -> Self {
234+
Self { l1blkid, logs }
235+
}
236+
237+
pub fn l1blkid(&self) -> Buf32 {
238+
self.l1blkid
239+
}
240+
241+
pub fn logs(&self) -> &[AsmLogEntry] {
242+
&self.logs
243+
}
244+
}

0 commit comments

Comments
 (0)