Skip to content

Commit a711f61

Browse files
yoavGrsclaude
andauthored
apollo_storage: implement TxExecutionInfoStorageReader and TxExecutionInfoStorageWriter (#13926)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 800713d commit a711f61

2 files changed

Lines changed: 71 additions & 2 deletions

File tree

crates/apollo_storage/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,6 @@ impl FileHandlers<RW> {
921921
}
922922

923923
#[cfg(feature = "os_input")]
924-
#[expect(dead_code)]
925924
fn append_tx_execution_infos(&self, tx_execution_infos: &TxExecutionInfos) -> LocationInFile {
926925
self.clone().tx_execution_infos.append(tx_execution_infos)
927926
}
@@ -1022,7 +1021,6 @@ impl<Mode: TransactionKind> FileHandlers<Mode> {
10221021
}
10231022

10241023
#[cfg(feature = "os_input")]
1025-
#[expect(dead_code)]
10261024
// Returns the transaction execution infos at the given location or an error in case they don't
10271025
// exist.
10281026
pub(crate) fn get_tx_execution_infos_unchecked(

crates/apollo_storage/src/tx_execution_info.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
//! Storage for transaction execution info per block (input to the starknet OS).
22
33
use blockifier::transaction::objects::TransactionExecutionInfo;
4+
use starknet_api::block::BlockNumber;
45

56
use crate::compression_utils::{compress, decompress};
67
use crate::db::serialization::{StorageSerde, StorageSerdeError};
8+
use crate::db::table_types::Table;
9+
use crate::db::{TransactionKind, RW};
10+
use crate::{OffsetKind, StorageResult, StorageTxn};
711

812
/// Per-block container of transaction execution infos, stored as a compressed JSON blob.
913
#[derive(Debug)]
@@ -22,3 +26,70 @@ impl StorageSerde for TxExecutionInfos {
2226
serde_json::from_slice(&data).ok().map(TxExecutionInfos)
2327
}
2428
}
29+
30+
/// Interface for reading transaction execution infos from storage.
31+
pub trait TxExecutionInfoStorageReader<Mode: TransactionKind> {
32+
/// Returns the transaction execution infos for the given block, or `None` if not stored.
33+
fn get_tx_execution_infos(
34+
&self,
35+
block_number: BlockNumber,
36+
) -> StorageResult<Option<Vec<TransactionExecutionInfo>>>;
37+
}
38+
39+
/// Interface for writing transaction execution infos to storage.
40+
pub trait TxExecutionInfoStorageWriter
41+
where
42+
Self: Sized,
43+
{
44+
/// Appends the transaction execution infos for the given block to storage.
45+
fn append_tx_execution_infos(
46+
self,
47+
block_number: BlockNumber,
48+
tx_execution_infos: Vec<TransactionExecutionInfo>,
49+
) -> StorageResult<Self>;
50+
51+
/// Removes the transaction execution infos for the given block from storage.
52+
/// If no entry exists for the block, returns without error.
53+
fn revert_tx_execution_infos(self, block_number: BlockNumber) -> StorageResult<Self>;
54+
}
55+
56+
impl<Mode: TransactionKind> TxExecutionInfoStorageReader<Mode> for StorageTxn<'_, Mode> {
57+
fn get_tx_execution_infos(
58+
&self,
59+
block_number: BlockNumber,
60+
) -> StorageResult<Option<Vec<TransactionExecutionInfo>>> {
61+
let table = self.open_table(&self.tables.tx_execution_infos)?;
62+
let Some(location) = table.get(&self.txn, &block_number)? else {
63+
return Ok(None);
64+
};
65+
Ok(Some(self.file_handlers.get_tx_execution_infos_unchecked(location)?.0))
66+
}
67+
}
68+
69+
impl TxExecutionInfoStorageWriter for StorageTxn<'_, RW> {
70+
fn append_tx_execution_infos(
71+
self,
72+
block_number: BlockNumber,
73+
tx_execution_infos: Vec<TransactionExecutionInfo>,
74+
) -> StorageResult<Self> {
75+
let file_offset_table = self.txn.open_table(&self.tables.file_offsets)?;
76+
let tx_execution_infos_table = self.open_table(&self.tables.tx_execution_infos)?;
77+
78+
let infos = TxExecutionInfos(tx_execution_infos);
79+
let location = self.file_handlers.append_tx_execution_infos(&infos);
80+
tx_execution_infos_table.upsert(&self.txn, &block_number, &location)?;
81+
file_offset_table.upsert(
82+
&self.txn,
83+
&OffsetKind::TxExecutionInfo,
84+
&location.next_offset(),
85+
)?;
86+
87+
Ok(self)
88+
}
89+
90+
fn revert_tx_execution_infos(self, block_number: BlockNumber) -> StorageResult<Self> {
91+
let tx_execution_infos_table = self.open_table(&self.tables.tx_execution_infos)?;
92+
tx_execution_infos_table.delete(&self.txn, &block_number)?;
93+
Ok(self)
94+
}
95+
}

0 commit comments

Comments
 (0)