|
| 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