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
33,608 downloads per month
Used in native_blockifier
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