#storage #transaction #version

bin+lib papyrus_storage

A storage implementation for a Starknet node

11 releases

new 0.2.0-rc4 Dec 4, 2023
0.2.0-rc3 Nov 26, 2023
0.1.2-alpha Oct 24, 2023
0.0.5 Sep 13, 2023
0.0.3 Jul 27, 2023

#1740 in Magic Beans

Download history 1647/week @ 2023-08-14 2905/week @ 2023-08-21 3952/week @ 2023-08-28 3203/week @ 2023-09-04 3618/week @ 2023-09-11 3458/week @ 2023-09-18 2392/week @ 2023-09-25 3753/week @ 2023-10-02 2802/week @ 2023-10-09 2860/week @ 2023-10-16 4221/week @ 2023-10-23 5250/week @ 2023-10-30 11288/week @ 2023-11-06 9583/week @ 2023-11-13 7012/week @ 2023-11-20 4741/week @ 2023-11-27

33,608 downloads per month
Used in native_blockifier

Custom license

355KB
7K SLoC

papyrus-storage

Description

papyrus-storage provides a writing and reading interface for various Starknet data structures to a database, designed specifically for Papyrus, a Starknet node.


lib.rs:

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, StarknetVersion};    // Import the header API.
use starknet_api::block::{BlockHeader, BlockNumber};
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()));

Dependencies

~27–42MB
~688K SLoC