23 releases (4 breaking)

new 0.4.0-dev.2 Apr 17, 2024
0.3.0 Mar 5, 2024
0.2.2 Dec 19, 2023
0.2.0-rc3 Nov 26, 2023
0.0.3 Jul 27, 2023

#101 in Magic Beans

Download history 3116/week @ 2024-01-01 3219/week @ 2024-01-08 3670/week @ 2024-01-15 4018/week @ 2024-01-22 4118/week @ 2024-01-29 5232/week @ 2024-02-05 4331/week @ 2024-02-12 4141/week @ 2024-02-19 3297/week @ 2024-02-26 3590/week @ 2024-03-04 4229/week @ 2024-03-11 4445/week @ 2024-03-18 3762/week @ 2024-03-25 3642/week @ 2024-04-01 5751/week @ 2024-04-08 5000/week @ 2024-04-15

18,959 downloads per month
Used in native_blockifier

Custom license

560KB
10K 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};    // 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()));

Dependencies

~26–42MB
~677K SLoC