Skip to content

Commit

Permalink
refactor(papyrus_storage): fix CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonLStarkWare committed Dec 25, 2024
1 parent 2c727c5 commit ab03de4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions crates/papyrus_storage/src/body/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,24 +381,25 @@ type AddressToTransactionIndexTableCursor<'txn> = DbCursor<
type TransactionMetadataTableCursor<'txn> =
DbCursor<'txn, RO, TransactionIndex, VersionZeroWrapper<TransactionMetadata>, SimpleTable>;

/// interface for updating the events in the storage.
/// Interface for updating the events in the storage.
pub trait EventStorageWriter
where
Self: Sized,
{
/// Appends the events of an entire block to the storage.
// To enforce that no commit happen after a failure, we consume and return Self on success.
fn append_events(
self,
block_number: BlockNumber,
block_events: Vec<Vec<Event>>,
block_events: &[&[Event]],
) -> StorageResult<Self>;
}

impl EventStorageWriter for StorageTxn<'_, RW> {
fn append_events(
self,
block_number: BlockNumber,
block_events: Vec<Vec<Event>>,
block_events: &[&[Event]],
) -> StorageResult<Self> {
let markers_table = self.open_table(&self.tables.markers)?;
update_marker(&self.txn, &markers_table, block_number)?;
Expand All @@ -408,15 +409,15 @@ impl EventStorageWriter for StorageTxn<'_, RW> {
let address_to_transaction_index =
self.open_table(&self.tables.address_to_transaction_index)?;

for (index, transaction_events) in block_events.iter().enumerate() {
for (index, &transaction_events) in block_events.iter().enumerate() {
let transaction_index =
TransactionIndex(block_number, TransactionOffsetInBlock(index));
let event_offset = self.file_handlers.append_events(&transaction_events.clone());
let event_offset = self.file_handlers.append_events(transaction_events);
events_table.append(&self.txn, &transaction_index, &event_offset)?;
for even in transaction_events {
for event in transaction_events {
address_to_transaction_index.insert(
&self.txn,
&(even.from_address, transaction_index),
&(event.from_address, transaction_index),
&NoValue,
)?;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ impl FileHandlers<RW> {
}

// Appends an event to the corresponding file and returns its location.
fn append_events(&self, events: &Vec<Event>) -> LocationInFile {
self.clone().events.append(events)
fn append_events(&self, events: &[Event]) -> LocationInFile {
self.clone().events.append(&events.to_vec())
}

// TODO(dan): Consider 1. flushing only the relevant files, 2. flushing concurrently.
Expand Down

0 comments on commit ab03de4

Please sign in to comment.