Skip to main content

StateStore

Struct StateStore 

Source
pub struct StateStore { /* private fields */ }

Implementations§

Source§

impl StateStore

Source

pub fn open(dir: &Path) -> Result<StateStore, String>

Source

pub fn base(&self) -> Result<Option<u32>, String>

The snapshot ledger; there is no state before it.

Source

pub fn last(&self) -> Result<Option<u32>, String>

Last applied ledger.

Source

pub fn header(&self, sequence: u32) -> Result<Option<Vec<u8>>, String>

Header of an applied ledger.

Source

pub fn load_snapshot( &self, sequence: u32, header: &[u8], objects: impl Iterator<Item = Result<([u8; 32], Vec<u8>), String>>, ) -> Result<u64, String>

Loads a snapshot into an empty store. Objects must be in ascending key order.

Source

pub fn apply( &self, sequence: u32, header: &[u8], changes: &[StateChange], ) -> Result<(), String>

Applies the changes of ledger sequence; it must be the next one in order.

Source

pub fn apply_ledger( &self, sequence: u32, ledger: &Ledger, body: &[u8], ) -> Result<(), String>

Applies a whole ledger: changes, indexes and the ledger itself (body is its serialization) into the pending-block set, in one batch.

Source

pub fn put_evidence( &self, sequence: u32, validations: &[ValidationEvidence], ) -> Result<(), String>

Stores a ledger’s anchor evidence (quorum validations).

Source

pub fn last_evidence(&self) -> Result<Option<u32>, String>

Last ledger with anchor evidence.

Source

pub fn evidence_from( &self, sequence: u32, ) -> Result<Option<(u32, Vec<ValidationEvidence>)>, String>

The nearest anchor evidence at ledger sequence or later.

Source

pub fn tree_path(&self, key: &[u8; 32]) -> Result<TreePath, String>

Path in the state tree to a key, as of the ledger the tree corresponds to. Everything is read from one snapshot, so a loader writing at the same time cannot break consistency.

Source

pub fn levels_from(&self) -> Result<Option<u32>, String>

First ledger a path can be rebuilt at (state_path_at).

Source

pub fn backfill_levels( &self, scratch: &Path, threads: usize, progress: impl Fn(String) + Sync, ) -> Result<Option<(u32, u32)>, String>

Rebuilds the tree history from the snapshot up to levels_from, for a store that kept it only from a later ledger. Returns the range rebuilt, None if there was nothing to do.

The subtrees at LEVEL_DEPTH don’t depend on each other, and the object versions of one are a single key range, so threads workers each take a subtree, read its range once, and replay its versions in memory, noting its hash and key count at every ledger that changed it. The notes go to scratch in one batch per subtree; after a stop, the subtrees already noted are not read again. A second pass goes through the ledgers in order, puts the top of the tree together from the notes, checks it against each ledger’s AccountHash, and writes the records below the existing ones. levels_from moves down to the snapshot only once all of them are in.

Source

pub fn state_path_at(&self, key: &[u8; 32], at: u32) -> Result<TreePath, String>

Path in the state tree to a key as of an earlier ledger at. The top of the tree comes from the tree history: for each subtree at depth 3, the last hash recorded at or before at, back to the nearest full set. The key’s own subtree is rebuilt from the object versions as of at and must give the recorded hash, and the root must be the header’s AccountHash: a gap or a fault in the history is an error, never a wrong path.

Source

pub fn confirmed(&self) -> Result<Option<u32>, String>

Last ledger confirmed by a quorum; None if none yet.

Source

pub fn set_confirmed(&self, sequence: u32) -> Result<(), String>

Marks a ledger as confirmed. Only forward, and only up to the applied ledger: confirmation applies to an already verified chain.

Source

pub fn tree_ledger(&self) -> Result<Option<u32>, String>

Ledger the state tree corresponds to; None if there is no tree.

Source

pub fn drop_tree(self) -> Result<(), String>

Deletes the whole state tree (for a rebuild). The store must be reopened afterwards.

Source

pub fn tree_root(&self) -> Result<[u8; 32], String>

Root of the state tree.

Source

pub fn build_tree(&self) -> Result<(u32, usize), String>

Builds the state tree from scratch for the last applied ledger and checks the root against its AccountHash. Returns the ledger and the leaf count.

Source

pub fn indexed(&self) -> Result<Option<u32>, String>

Last ledger in the indexes.

Source

pub fn index_ledger(&self, sequence: u32, ledger: &Ledger) -> Result<(), String>

Catches up the indexes for a ledger already applied to the state; it must be the one right after the last indexed ledger.

Source

pub fn nft_from(&self) -> Result<Option<u32>, String>

First ledger indexed for NFTs as it is applied.

Source

pub fn start_nft_index(&self) -> Result<u32, String>

Starts the NFT index at the next ledger to be applied, if it hasn’t started; returns the ledger it starts at.

Source

pub fn nft_coverage(&self) -> Result<Option<u32>, String>

The ledgers the NFT index covers: from the first one backfilled up to the last applied, once the backfill has reached the live part.

Source

pub fn backfill_nfts( &self, start: u32, chunk: u32, read: &ReadLedgers<'_>, progress: &dyn Fn(u32, u32), ) -> Result<Option<(u32, u32)>, String>

Fills the NFT index for ledgers start..nft_from, chunk ledgers per batch; read returns the asked ledgers in order. Progress is stored with each batch, so a restart continues where it stopped. Returns the ledgers filled, or None if there was nothing to do.

Source

pub fn seed_nfts(&self) -> Result<(), String>

The starting point for an NFT index whose history doesn’t reach back to the first NFTs: every token in the state at the snapshot ledger, at the owner whose page holds it, as Clio fills its tables from its first ledger. The backfill then continues from the next ledger. Does nothing once the backfill has started; an interrupted seeding starts over.

Source

pub fn nft_at( &self, token: &[u8; 32], at: u32, ) -> Result<Option<(u32, [u8; 20], bool)>, String>

The token as of ledger at: the ledger of its last owner change, the owner, whether burned.

Source

pub fn nft_uri_at( &self, token: &[u8; 32], at: u32, ) -> Result<Option<Vec<u8>>, String>

The token’s URI as of ledger at.

Source

pub fn nft_txs( &self, token: &[u8; 32], lo: TxPosition, hi: TxPosition, forward: bool, limit: usize, ) -> Result<Vec<AccountTx>, String>

The token’s transactions between lo and hi inclusive, ascending (forward) or descending, at most limit.

Source

pub fn nfts_by_issuer( &self, issuer: &[u8; 20], taxon: Option<u32>, after: Option<(u32, [u8; 32])>, limit: usize, ) -> Result<Vec<[u8; 32]>, String>

Tokens minted by issuer, by taxon then token, strictly after after (taxon, token); only of taxon if given. At most limit.

Source

pub fn index_sizes(&self) -> Vec<(&'static str, u64, usize)>

On-disk size and approximate record count of each index. Fresh records not yet flushed from memory are not counted in the on-disk size.

Source

pub fn tx_location(&self, id: &[u8; 32]) -> Result<Option<(u32, u32)>, String>

The ledger and position of the transaction with this hash.

Source

pub fn ledger_by_hash(&self, hash: &[u8; 32]) -> Result<Option<u32>, String>

Ledger sequence by its hash.

Source

pub fn account_tx( &self, account: &AccountId, min: u32, max: u32, forward: bool, limit: usize, marker: Option<TxPosition>, ) -> Result<AccountTxPage, String>

Account history in ledgers min..=max: ascending (forward) or descending, at most limit, starting at marker inclusive.

Source

pub fn ensure_mpt_index(&self) -> Result<Option<usize>, String>

Builds the MPT holder index over all object versions if it does not exist yet: a single pass on first start. After that apply maintains it. Returns the number of holder versions found, or None if the index already existed.

Source

pub fn mpt_holders( &self, id: &[u8; 24], at: u32, after: Option<&[u8; 20]>, limit: usize, ) -> Result<Vec<MptHolder>, String>

Holders of issuance id as of ledger at in ascending account order, strictly after after: the account and MPToken key, at most limit.

Source

pub fn pending(&self) -> Result<Vec<(u32, Vec<u8>)>, String>

Ledgers waiting for their block, in order.

Source

pub fn pending_ledger(&self, sequence: u32) -> Result<Option<Vec<u8>>, String>

A single ledger waiting for its block.

Source

pub fn drop_pending(&self, upto: u32) -> Result<(), String>

Removes pending ledgers up to upto inclusive; their block is already written.

Source

pub fn persist(&self) -> Result<(), String>

Source

pub fn get(&self, key: &[u8; 32], at: u32) -> Result<Option<Vec<u8>>, String>

Object key as of ledger at; None if it does not exist (not created or deleted).

Source

pub fn set_old_state(&self, old: Arc<dyn OldState>)

Attaches the state before the snapshot (the version index over cold history). From then on version, get and get_many answer for its range too.

Source

pub fn old_range(&self) -> Option<(u32, u32)>

Ledgers the attached old state answers for, if one is attached and the current request may read it.

Source

pub fn serves(&self, seq: u32) -> Result<bool, String>

Whether state as of ledger seq can be read: from the snapshot on, or within the range of the attached old state.

Source

pub fn version( &self, key: &[u8; 32], at: u32, ) -> Result<Option<(u32, Vec<u8>)>, String>

The last version of key written up to ledger at: the ledger and the object, empty if it was deleted in that ledger. Below the snapshot it is read from the attached old state, within its range.

Source

pub fn get_many( &self, keys: &[[u8; 32]], at: u32, ) -> Result<Vec<Option<Vec<u8>>>, String>

Objects keys as of ledger at, in the same order. Each version read is a range seek across all LSM levels (about 0.2 ms), so large sets are read on several threads.

Source

pub fn objects_at( &self, at: u32, ) -> impl Iterator<Item = Result<([u8; 32], Vec<u8>), String>> + '_

All objects as of ledger at, in ascending key order.

Source

pub fn objects_page( &self, at: u32, after: Option<&[u8; 32]>, ) -> impl Iterator<Item = Result<([u8; 32], Vec<u8>), String>> + '_

Like objects_after, but for ledger_data pages: it jumps from key to key and finds the version at at with a seek. The cost of a page depends on its size, not on how many versions the keys along the way have piled up (LedgerHashes and busy accounts change almost every ledger).

Source

pub fn objects_after( &self, at: u32, after: Option<&[u8; 32]>, ) -> impl Iterator<Item = Result<([u8; 32], Vec<u8>), String>> + '_

Objects as of ledger at with keys strictly greater than after, in ascending key order.

Trait Implementations§

Source§

impl Debug for StateStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more