pub struct StateStore { /* private fields */ }Implementations§
Source§impl StateStore
impl StateStore
pub fn open(dir: &Path) -> Result<StateStore, String>
Sourcepub fn base(&self) -> Result<Option<u32>, String>
pub fn base(&self) -> Result<Option<u32>, String>
The snapshot ledger; there is no state before it.
Sourcepub fn header(&self, sequence: u32) -> Result<Option<Vec<u8>>, String>
pub fn header(&self, sequence: u32) -> Result<Option<Vec<u8>>, String>
Header of an applied ledger.
Sourcepub fn load_snapshot(
&self,
sequence: u32,
header: &[u8],
objects: impl Iterator<Item = Result<([u8; 32], Vec<u8>), String>>,
) -> Result<u64, String>
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.
Sourcepub fn apply(
&self,
sequence: u32,
header: &[u8],
changes: &[StateChange],
) -> Result<(), String>
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.
Sourcepub fn apply_ledger(
&self,
sequence: u32,
ledger: &Ledger,
body: &[u8],
) -> Result<(), String>
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.
Sourcepub fn put_evidence(
&self,
sequence: u32,
validations: &[ValidationEvidence],
) -> Result<(), String>
pub fn put_evidence( &self, sequence: u32, validations: &[ValidationEvidence], ) -> Result<(), String>
Stores a ledger’s anchor evidence (quorum validations).
Sourcepub fn evidence_from(
&self,
sequence: u32,
) -> Result<Option<(u32, Vec<ValidationEvidence>)>, String>
pub fn evidence_from( &self, sequence: u32, ) -> Result<Option<(u32, Vec<ValidationEvidence>)>, String>
The nearest anchor evidence at ledger sequence or later.
Sourcepub fn tree_path(&self, key: &[u8; 32]) -> Result<TreePath, String>
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.
Sourcepub fn levels_from(&self) -> Result<Option<u32>, String>
pub fn levels_from(&self) -> Result<Option<u32>, String>
First ledger a path can be rebuilt at (state_path_at).
Sourcepub fn backfill_levels(
&self,
scratch: &Path,
threads: usize,
progress: impl Fn(String) + Sync,
) -> Result<Option<(u32, u32)>, String>
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.
Sourcepub fn state_path_at(&self, key: &[u8; 32], at: u32) -> Result<TreePath, String>
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.
Sourcepub fn confirmed(&self) -> Result<Option<u32>, String>
pub fn confirmed(&self) -> Result<Option<u32>, String>
Last ledger confirmed by a quorum; None if none yet.
Sourcepub fn set_confirmed(&self, sequence: u32) -> Result<(), String>
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.
Sourcepub fn tree_ledger(&self) -> Result<Option<u32>, String>
pub fn tree_ledger(&self) -> Result<Option<u32>, String>
Ledger the state tree corresponds to; None if there is no tree.
Sourcepub fn drop_tree(self) -> Result<(), String>
pub fn drop_tree(self) -> Result<(), String>
Deletes the whole state tree (for a rebuild). The store must be reopened afterwards.
Sourcepub fn build_tree(&self) -> Result<(u32, usize), String>
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.
Sourcepub fn index_ledger(&self, sequence: u32, ledger: &Ledger) -> Result<(), String>
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.
Sourcepub fn nft_from(&self) -> Result<Option<u32>, String>
pub fn nft_from(&self) -> Result<Option<u32>, String>
First ledger indexed for NFTs as it is applied.
Sourcepub fn start_nft_index(&self) -> Result<u32, String>
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.
Sourcepub fn nft_coverage(&self) -> Result<Option<u32>, String>
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.
Sourcepub fn backfill_nfts(
&self,
start: u32,
chunk: u32,
read: &ReadLedgers<'_>,
progress: &dyn Fn(u32, u32),
) -> Result<Option<(u32, u32)>, String>
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.
Sourcepub fn seed_nfts(&self) -> Result<(), String>
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.
Sourcepub fn nft_at(
&self,
token: &[u8; 32],
at: u32,
) -> Result<Option<(u32, [u8; 20], bool)>, String>
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.
Sourcepub fn nft_uri_at(
&self,
token: &[u8; 32],
at: u32,
) -> Result<Option<Vec<u8>>, String>
pub fn nft_uri_at( &self, token: &[u8; 32], at: u32, ) -> Result<Option<Vec<u8>>, String>
The token’s URI as of ledger at.
Sourcepub fn nft_txs(
&self,
token: &[u8; 32],
lo: TxPosition,
hi: TxPosition,
forward: bool,
limit: usize,
) -> Result<Vec<AccountTx>, String>
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.
Sourcepub fn nfts_by_issuer(
&self,
issuer: &[u8; 20],
taxon: Option<u32>,
after: Option<(u32, [u8; 32])>,
limit: usize,
) -> Result<Vec<[u8; 32]>, String>
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.
Sourcepub fn index_sizes(&self) -> Vec<(&'static str, u64, usize)>
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.
Sourcepub fn tx_location(&self, id: &[u8; 32]) -> Result<Option<(u32, u32)>, String>
pub fn tx_location(&self, id: &[u8; 32]) -> Result<Option<(u32, u32)>, String>
The ledger and position of the transaction with this hash.
Sourcepub fn ledger_by_hash(&self, hash: &[u8; 32]) -> Result<Option<u32>, String>
pub fn ledger_by_hash(&self, hash: &[u8; 32]) -> Result<Option<u32>, String>
Ledger sequence by its hash.
Sourcepub fn account_tx(
&self,
account: &AccountId,
min: u32,
max: u32,
forward: bool,
limit: usize,
marker: Option<TxPosition>,
) -> Result<AccountTxPage, String>
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.
Sourcepub fn ensure_mpt_index(&self) -> Result<Option<usize>, String>
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.
Sourcepub fn mpt_holders(
&self,
id: &[u8; 24],
at: u32,
after: Option<&[u8; 20]>,
limit: usize,
) -> Result<Vec<MptHolder>, String>
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.
Sourcepub fn pending(&self) -> Result<Vec<(u32, Vec<u8>)>, String>
pub fn pending(&self) -> Result<Vec<(u32, Vec<u8>)>, String>
Ledgers waiting for their block, in order.
Sourcepub fn pending_ledger(&self, sequence: u32) -> Result<Option<Vec<u8>>, String>
pub fn pending_ledger(&self, sequence: u32) -> Result<Option<Vec<u8>>, String>
A single ledger waiting for its block.
Sourcepub fn drop_pending(&self, upto: u32) -> Result<(), String>
pub fn drop_pending(&self, upto: u32) -> Result<(), String>
Removes pending ledgers up to upto inclusive; their block is already written.
pub fn persist(&self) -> Result<(), String>
Sourcepub fn get(&self, key: &[u8; 32], at: u32) -> Result<Option<Vec<u8>>, String>
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).
Sourcepub fn set_old_state(&self, old: Arc<dyn OldState>)
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.
Sourcepub fn old_range(&self) -> Option<(u32, u32)>
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.
Sourcepub fn serves(&self, seq: u32) -> Result<bool, String>
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.
Sourcepub fn version(
&self,
key: &[u8; 32],
at: u32,
) -> Result<Option<(u32, Vec<u8>)>, String>
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.
Sourcepub fn get_many(
&self,
keys: &[[u8; 32]],
at: u32,
) -> Result<Vec<Option<Vec<u8>>>, String>
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.
Sourcepub fn objects_at(
&self,
at: u32,
) -> impl Iterator<Item = Result<([u8; 32], Vec<u8>), String>> + '_
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.
Sourcepub fn objects_page(
&self,
at: u32,
after: Option<&[u8; 32]>,
) -> impl Iterator<Item = Result<([u8; 32], Vec<u8>), String>> + '_
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).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for StateStore
impl !RefUnwindSafe for StateStore
impl !UnwindSafe for StateStore
impl Send for StateStore
impl Sync for StateStore
impl Unpin for StateStore
impl UnsafeUnpin for StateStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].