Struct snarkos_storage::ledger::Ledger [−][src]
pub struct Ledger<T: TransactionScheme, P: LoadableMerkleParameters, S: Storage> { pub current_block_height: AtomicU32, pub ledger_parameters: Arc<P>, pub cm_merkle_tree: ArcSwap<MerkleTree<P>>, pub storage: S, pub _transaction: PhantomData<T>, }
Fields
current_block_height: AtomicU32
ledger_parameters: Arc<P>
cm_merkle_tree: ArcSwap<MerkleTree<P>>
storage: S
_transaction: PhantomData<T>
Implementations
Create a fresh blockchain, optionally at the specified path. Warning: if specified, any existing storage at that location is removed.
Open the blockchain storage at a particular path.
Open the blockchain storage at a particular path as a secondary read-only instance.
Get the latest block height of the chain.
Get the latest number of blocks in the chain.
Get the height of the best block on the chain.
Get the stored old connected peers.
pub fn save_peer_book_to_storage(
&self,
peers_serialized: Vec<u8>
) -> Result<(), StorageError>
pub fn save_peer_book_to_storage(
&self,
peers_serialized: Vec<u8>
) -> Result<(), StorageError>
Store the connected peers.
Attempt to catch the secondary read-only storage instance with the primary instance.
Get the latest block in the chain.
Get a block given the block hash.
pub fn get_block_from_block_number(
&self,
block_number: u32
) -> Result<Block<T>, StorageError>
pub fn get_block_from_block_number(
&self,
block_number: u32
) -> Result<Block<T>, StorageError>
Get a block given the block number.
Get the block hash given a block number.
Get the block number given a block hash.
pub fn get_block_transactions(
&self,
block_hash: &BlockHeaderHash
) -> Result<DPCTransactions<T>, StorageError>
pub fn get_block_transactions(
&self,
block_hash: &BlockHeaderHash
) -> Result<DPCTransactions<T>, StorageError>
Get the list of transaction ids given a block hash.
pub fn get_child_block_hashes(
&self,
parent_header: &BlockHeaderHash
) -> Result<Vec<BlockHeaderHash>, StorageError>
pub fn get_child_block_hashes(
&self,
parent_header: &BlockHeaderHash
) -> Result<Vec<BlockHeaderHash>, StorageError>
Find the potential child block hashes given a parent block header.
Returns the block number of a conflicting block that has already been mined.
Remove a block and it’s related data from the storage.
De-commit the latest block and return its header hash.
Remove the latest block.
Remove the latest num_blocks
blocks.
Returns true if the block for the given block header hash exists.
pub fn get_block_header(
&self,
block_hash: &BlockHeaderHash
) -> Result<BlockHeader, StorageError>
pub fn get_block_header(
&self,
block_hash: &BlockHeaderHash
) -> Result<BlockHeader, StorageError>
Get a block header given the block hash.
Returns true if the block corresponding to this block’s previous_block_hash exists.
Returns the latest shared block header hash. If the block locator hashes are for a side chain, returns the common point of fork. If the block locator hashes are for the canon chain, returns the latest block header hash.
Returns a list of block locator hashes. The purpose of this method is to detect wrong branches in the caller’s canon chain.
Get the block’s path/origin.
pub fn longest_child_path(
&self,
block_hash: BlockHeaderHash
) -> Result<Vec<BlockHeaderHash>, StorageError>
pub fn longest_child_path(
&self,
block_hash: BlockHeaderHash
) -> Result<Vec<BlockHeaderHash>, StorageError>
Returns the path length and the longest path of children from the given block header
Get the current commitment index
Get the current serial number index
Get the current memo index
Get the current ledger digest
Get the set of past ledger digests
Get serial number index.
Get commitment index
Get memo index
pub fn rebuild_merkle_tree(
&self,
additional_cms: Vec<(T::Commitment, usize)>
) -> Result<(), StorageError>
pub fn rebuild_merkle_tree(
&self,
additional_cms: Vec<(T::Commitment, usize)>
) -> Result<(), StorageError>
Build a new commitment merkle tree from the stored commitments
Rebuild the stored merkle tree with the current stored commitments
Insert a block into storage without canonizing/committing it.
Commit/canonize a particular block.
Insert a block into the storage and commit as part of the longest chain.
Returns true if the block exists in the canon chain.
Returns true if the block corresponding to this block’s previous_block_hash is in the canon chain.
Revert the chain to the state before the fork.
Get the stored memory pool transactions.
pub fn store_to_memory_pool(
&self,
transactions_serialized: Vec<u8>
) -> Result<(), StorageError>
pub fn store_to_memory_pool(
&self,
transactions_serialized: Vec<u8>
) -> Result<(), StorageError>
Store the memory pool transactions.
pub fn get_record_commitments(
&self,
limit: Option<usize>
) -> Result<Vec<Vec<u8>>, StorageError>
pub fn get_record_commitments(
&self,
limit: Option<usize>
) -> Result<Vec<Vec<u8>>, StorageError>
Get all stored record commitments of the node
pub fn get_record<R: RecordScheme>(
&self,
record_commitment: &[u8]
) -> Result<Option<R>, StorageError>
pub fn get_record<R: RecordScheme>(
&self,
record_commitment: &[u8]
) -> Result<Option<R>, StorageError>
Get a transaction bytes given the transaction id.
Get a transaction bytes given the transaction id.
Get a transaction bytes given the transaction id.
Removes a record from storage.
pub fn get_transaction_location(
&self,
transaction_id: &[u8]
) -> Result<Option<TransactionLocation>, StorageError>
pub fn get_transaction_location(
&self,
transaction_id: &[u8]
) -> Result<Option<TransactionLocation>, StorageError>
Returns a transaction location given the transaction ID if it exists. Returns None
otherwise.
Returns a transaction given the transaction ID if it exists. Returns None
otherwise.
Returns a transaction in bytes given a transaction ID.
Returns true if the transaction has internal parameters that already exist in the ledger.
Validates the storage of the canon blocks, their child-parent relationships, and their transactions; starts
at the current block height and goes down until the genesis block, making sure that the block-related data
stored in the database is coherent. The optional limit restricts the number of blocks to check, as
it is likely that any issues are applicable only to the last few blocks. The fix
argument determines whether
the validation process should also attempt to fix the issues it encounters.
Trait Implementations
impl<T: TransactionScheme, P: LoadableMerkleParameters, S: Storage> LedgerScheme for Ledger<T, P, S>
impl<T: TransactionScheme, P: LoadableMerkleParameters, S: Storage> LedgerScheme for Ledger<T, P, S>
Instantiates a new ledger with a genesis block.
Return the parameters used to construct the ledger Merkle tree.
Return a digest of the latest ledger Merkle tree.
Check that st_{ts} is a valid digest for some (past) ledger state.
Returns true if the given commitment exists in the ledger.
Returns true if the given serial number exists in the ledger.
Returns true if the given memo exists in the ledger.
Returns the Merkle path to the latest ledger digest for a given commitment, if it exists in the ledger.
fn verify_cm(
_parameters: &Arc<Self::MerkleParameters>,
digest: &Self::MerkleTreeDigest,
cm: &Self::Commitment,
witness: &Self::MerklePath
) -> bool
fn verify_cm(
_parameters: &Arc<Self::MerkleParameters>,
digest: &Self::MerkleTreeDigest,
cm: &Self::Commitment,
witness: &Self::MerklePath
) -> bool
Returns true if the given Merkle path is a valid witness for the given ledger digest and commitment.
type Block = Block<Self::Transaction>
type Commitment = T::Commitment
type MerkleParameters = P
type MerklePath = MerklePath<Self::MerkleParameters>
type MerkleTreeDigest = MerkleTreeDigest<Self::MerkleParameters>
type SerialNumber = T::SerialNumber
type Transaction = T
Auto Trait Implementations
impl<T, P, S> RefUnwindSafe for Ledger<T, P, S> where
P: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
<<P as MerkleParameters>::H as CRH>::Output: RefUnwindSafe,
impl<T, P, S> UnwindSafe for Ledger<T, P, S> where
P: RefUnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
<<P as MerkleParameters>::H as CRH>::Output: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted.
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
Causes self
to use its Octal
implementation when Debug
-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
Pipes by value. This is generally the method you want to use. Read more
Borrows self
and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self
and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
R: 'a,
B: 'a + ?Sized,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
R: 'a,
B: 'a + ?Sized,
Borrows self
, then passes self.borrow()
into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
R: 'a,
B: 'a + ?Sized,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
R: 'a,
B: 'a + ?Sized,
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
R: 'a,
U: 'a + ?Sized,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
R: 'a,
U: 'a + ?Sized,
Borrows self
, then passes self.as_ref()
into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
R: 'a,
U: 'a + ?Sized,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
R: 'a,
U: 'a + ?Sized,
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.deref()
into the pipe function.
type Output = T
type Output = T
Should always be Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B>
of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B>
of a value. Read more
Immutable access to the AsRef<R>
view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R>
view of a value. Read more
Immutable access to the Deref::Target
of a value. Read more
Mutable access to the Deref::Target
of a value. Read more
Calls .tap()
only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more
pub fn vzip(self) -> V