Crate papyrus_storage

source ·
Expand description

A storage implementation for a Starknet node.

This crate provides a writing and reading interface for various Starknet data structures to a database. Enables at most one writing operation and multiple reading operations concurrently. The underlying storage is implemented using the libmdbx crate.

§Disclaimer

This crate is still under development and is not keeping backwards compatibility with previous versions. Breaking changes are expected to happen in the near future.

§Quick Start

To use this crate, open a storage by calling open_storage to get a StorageWriter and a StorageReader and use them to create StorageTxn instances. The actual functionality is implemented on the transaction in multiple traits.

use papyrus_storage::open_storage;
use papyrus_storage::header::{HeaderStorageReader, HeaderStorageWriter};    // Import the header API.
use starknet_api::block::{BlockHeader, BlockNumber, StarknetVersion};
use starknet_api::core::ChainId;

let db_config = DbConfig {
    path_prefix: dir,
    chain_id: ChainId("SN_MAIN".to_owned()),
    enforce_file_exists: false,
    min_size: 1 << 20,    // 1MB
    max_size: 1 << 35,    // 32GB
    growth_step: 1 << 26, // 64MB
};
let (reader, mut writer) = open_storage(storage_config)?;
writer
    .begin_rw_txn()?                                            // Start a RW transaction.
    .append_header(BlockNumber(0), &BlockHeader::default())?    // Append a header.
    .commit()?;                                                 // Commit the changes.

let header = reader.begin_ro_txn()?.get_block_header(BlockNumber(0))?;  // Read the header.
assert_eq!(header, Some(BlockHeader::default()));

Re-exports§

Modules§

  • Interface for handling data related to the base layer.
  • Interface for handling data related to Starknet block bodies.
  • Interface for handling data related to Starknet compiled classes (Cairo assembly, or CASM).
  • Basic structs for interacting with the db.
  • Interface for handling data related to Starknet block headers.
  • Interface for handling append only data that is backed up by mmap file directly. Data is serialized directly into the mmap file. The caller must ensure that:
  • Interface for handling data related to Starknet state.
  • module for external utils, such as dumping a storage table to a file

Structs§

  • A struct for the statistics of the tables in the database.
  • A struct for the configuration of the storage.
  • A struct for starting RO transactions (StorageTxn) to the storage.
  • A struct for interacting with the storage. The actually functionality is implemented on the transaction in multiple traits.
  • A struct for starting RW transactions (StorageTxn) to the storage. There is a single non clonable writer instance, to make sure there is only one write transaction at any given moment.

Enums§

Constants§

  • The current version of the storage blocks code. Major change requires a re-sync, minor change means a versioned value changed an re-sync is not required. This version is only checked for storages that store transactions (StorageScope::FullArchive).
  • The current version of the storage state code. Major change requires a re-sync, minor change means a versioned value changed an re-sync is not required.

Functions§

Type Aliases§

  • A type alias that maps to std::result::Result<T, StorageError>.