Struct snarkos_storage::ledger::Ledger [−][src]
Fields
current_block_height: AtomicU32
ledger_parameters: P
cm_merkle_tree: RwLock<MerkleTree<P>>
storage: S
_transaction: PhantomData<T>
Implementations
impl<T: Transaction, P: LoadableMerkleParameters, S: Storage> Ledger<T, P, S>
[src]
pub fn new_empty<PATH: AsRef<Path>>(
path: Option<PATH>
) -> Result<Self, StorageError>
[src]
path: Option<PATH>
) -> Result<Self, StorageError>
Create a fresh blockchain, optionally at the specified path. Warning: if specified, any existing storage at that location is removed.
pub fn open_at_path<PATH: AsRef<Path>>(path: PATH) -> Result<Self, StorageError>
[src]
Open the blockchain storage at a particular path.
pub fn open_secondary_at_path<PATH: AsRef<Path>>(
path: PATH
) -> Result<Self, StorageError>
[src]
path: PATH
) -> Result<Self, StorageError>
Open the blockchain storage at a particular path as a secondary read-only instance.
pub fn is_empty(&self) -> bool
[src]
Returns true if there are no blocks in the ledger.
pub fn get_current_block_height(&self) -> BlockHeight
[src]
Get the latest block height of the chain.
pub fn get_block_count(&self) -> BlockHeight
[src]
Get the latest number of blocks in the chain.
pub fn get_peer_book(&self) -> Result<Option<Vec<u8>>, StorageError>
[src]
Get the stored old connected peers.
pub fn save_peer_book_to_storage(
&self,
peers_serialized: Vec<u8>
) -> Result<(), StorageError>
[src]
&self,
peers_serialized: Vec<u8>
) -> Result<(), StorageError>
Store the connected peers.
pub fn catch_up_secondary(
&self,
update_merkle_tree: bool
) -> Result<(), StorageError>
[src]
&self,
update_merkle_tree: bool
) -> Result<(), StorageError>
Attempt to catch the secondary read-only storage instance with the primary instance.
impl<T: Transaction, P: LoadableMerkleParameters, S: Storage> Ledger<T, P, S>
[src]
pub fn get_latest_block(&self) -> Result<Block<T>, StorageError>
[src]
Get the latest block in the chain.
pub fn get_block(
&self,
block_hash: &BlockHeaderHash
) -> Result<Block<T>, StorageError>
[src]
&self,
block_hash: &BlockHeaderHash
) -> Result<Block<T>, StorageError>
Get a block given the block hash.
pub fn get_block_from_block_number(
&self,
block_number: u32
) -> Result<Block<T>, StorageError>
[src]
&self,
block_number: u32
) -> Result<Block<T>, StorageError>
Get a block given the block number.
pub fn get_block_hash(
&self,
block_number: u32
) -> Result<BlockHeaderHash, StorageError>
[src]
&self,
block_number: u32
) -> Result<BlockHeaderHash, StorageError>
Get the block hash given a block number.
pub fn get_block_number(
&self,
block_hash: &BlockHeaderHash
) -> Result<u32, StorageError>
[src]
&self,
block_hash: &BlockHeaderHash
) -> Result<u32, StorageError>
Get the block number given a block hash.
pub fn get_block_transactions(
&self,
block_hash: &BlockHeaderHash
) -> Result<DPCTransactions<T>, StorageError>
[src]
&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>
[src]
&self,
parent_header: &BlockHeaderHash
) -> Result<Vec<BlockHeaderHash>, StorageError>
Find the potential child block hashes given a parent block header.
pub fn already_mined(
&self,
block: &Block<T>
) -> Result<Option<u32>, StorageError>
[src]
&self,
block: &Block<T>
) -> Result<Option<u32>, StorageError>
Returns the block number of a conflicting block that has already been mined.
pub fn remove_block(
&self,
block_hash: BlockHeaderHash
) -> Result<(), StorageError>
[src]
&self,
block_hash: BlockHeaderHash
) -> Result<(), StorageError>
Remove a block and it’s related data from the storage.
pub fn decommit_latest_block(&self) -> Result<BlockHeaderHash, StorageError>
[src]
De-commit the latest block and return its header hash.
pub fn remove_latest_block(&self) -> Result<(), StorageError>
[src]
Remove the latest block.
pub fn remove_latest_blocks(&self, num_blocks: u32) -> Result<(), StorageError>
[src]
Remove the latest num_blocks
blocks.
impl<T: Transaction, P: LoadableMerkleParameters, S: Storage> Ledger<T, P, S>
[src]
pub fn block_hash_exists(&self, block_hash: &BlockHeaderHash) -> bool
[src]
Returns true if the block for the given block header hash exists.
pub fn get_block_header(
&self,
block_hash: &BlockHeaderHash
) -> Result<BlockHeader, StorageError>
[src]
&self,
block_hash: &BlockHeaderHash
) -> Result<BlockHeader, StorageError>
Get a block header given the block hash.
pub fn previous_block_hash_exists(&self, block: &Block<T>) -> bool
[src]
Returns true if the block corresponding to this block’s previous_block_hash exists.
pub fn get_latest_shared_hash(
&self,
block_locator_hashes: Vec<BlockHeaderHash>
) -> Result<BlockHeaderHash, StorageError>
[src]
&self,
block_locator_hashes: Vec<BlockHeaderHash>
) -> Result<BlockHeaderHash, StorageError>
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.
pub fn get_block_locator_hashes(
&self
) -> Result<Vec<BlockHeaderHash>, StorageError>
[src]
&self
) -> Result<Vec<BlockHeaderHash>, StorageError>
Returns a list of block locator hashes. The purpose of this method is to detect wrong branches in the caller’s canon chain.
impl<T: Transaction, P: LoadableMerkleParameters, S: Storage> Ledger<T, P, S>
[src]
pub fn get_block_path(
&self,
block_header: &BlockHeader
) -> Result<BlockPath, StorageError>
[src]
&self,
block_header: &BlockHeader
) -> Result<BlockPath, StorageError>
Get the block’s path/origin.
pub fn longest_child_path(
&self,
block_hash: BlockHeaderHash
) -> Result<(usize, Vec<BlockHeaderHash>), StorageError>
[src]
&self,
block_hash: BlockHeaderHash
) -> Result<(usize, Vec<BlockHeaderHash>), StorageError>
Returns the path length and the longest path of children from the given block header
impl<T: Transaction, P: LoadableMerkleParameters, S: Storage> Ledger<T, P, S>
[src]
pub fn current_cm_index(&self) -> Result<usize, StorageError>
[src]
Get the current commitment index
pub fn current_sn_index(&self) -> Result<usize, StorageError>
[src]
Get the current serial number index
pub fn current_memo_index(&self) -> Result<usize, StorageError>
[src]
Get the current memo index
pub fn current_digest(&self) -> Result<Vec<u8>, StorageError>
[src]
Get the current ledger digest
pub fn past_digests(&self) -> Result<HashSet<Box<[u8]>>, StorageError>
[src]
Get the set of past ledger digests
pub fn get_sn_index(
&self,
sn_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
[src]
&self,
sn_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
Get serial number index.
pub fn get_cm_index(
&self,
cm_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
[src]
&self,
cm_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
Get commitment index
pub fn get_memo_index(
&self,
memo_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
[src]
&self,
memo_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
Get memo index
pub fn rebuild_merkle_tree(
&self,
additional_cms: Vec<(T::Commitment, usize)>
) -> Result<(), StorageError>
[src]
&self,
additional_cms: Vec<(T::Commitment, usize)>
) -> Result<(), StorageError>
Build a new commitment merkle tree from the stored commitments
pub fn update_merkle_tree(&self) -> Result<(), StorageError>
[src]
Rebuild the stored merkle tree with the current stored commitments
impl<T: Transaction, P: LoadableMerkleParameters, S: Storage> Ledger<T, P, S>
[src]
pub fn insert_only(&self, block: &Block<T>) -> Result<(), StorageError>
[src]
Insert a block into storage without canonizing/committing it.
pub fn commit(&self, block: &Block<T>) -> Result<(), StorageError>
[src]
Commit/canonize a particular block.
pub fn insert_and_commit(&self, block: &Block<T>) -> Result<(), StorageError>
[src]
Insert a block into the storage and commit as part of the longest chain.
pub fn is_canon(&self, block_hash: &BlockHeaderHash) -> bool
[src]
Returns true if the block exists in the canon chain.
pub fn is_previous_block_canon(&self, block_header: &BlockHeader) -> bool
[src]
Returns true if the block corresponding to this block’s previous_block_hash is in the canon chain.
pub fn revert_for_fork(
&self,
side_chain_path: &SideChainPath
) -> Result<(), StorageError>
[src]
&self,
side_chain_path: &SideChainPath
) -> Result<(), StorageError>
Revert the chain to the state before the fork.
impl<T: Transaction, P: LoadableMerkleParameters, S: Storage> Ledger<T, P, S>
[src]
pub fn get_memory_pool(&self) -> Result<Option<Vec<u8>>, StorageError>
[src]
Get the stored memory pool transactions.
pub fn store_to_memory_pool(
&self,
transactions_serialized: Vec<u8>
) -> Result<(), StorageError>
[src]
&self,
transactions_serialized: Vec<u8>
) -> Result<(), StorageError>
Store the memory pool transactions.
impl<T: Transaction, P: LoadableMerkleParameters, S: Storage> Ledger<T, P, S>
[src]
pub fn get_record_commitments(
&self,
limit: Option<usize>
) -> Result<Vec<Vec<u8>>, StorageError>
[src]
&self,
limit: Option<usize>
) -> Result<Vec<Vec<u8>>, StorageError>
Get all stored record commitments of the node
pub fn get_record<R: Record>(
&self,
record_commitment: &[u8]
) -> Result<Option<R>, StorageError>
[src]
&self,
record_commitment: &[u8]
) -> Result<Option<R>, StorageError>
Get a transaction bytes given the transaction id.
pub fn store_record<R: Record>(&self, record: &R) -> Result<(), StorageError>
[src]
Get a transaction bytes given the transaction id.
pub fn store_records<R: Record>(
&self,
records: &[R]
) -> Result<(), StorageError>
[src]
&self,
records: &[R]
) -> Result<(), StorageError>
Get a transaction bytes given the transaction id.
pub fn delete_record<R: Record>(&self, record: R) -> Result<(), StorageError>
[src]
Removes a record from storage.
impl<T: Transaction, P: LoadableMerkleParameters, S: Storage> Ledger<T, P, S>
[src]
pub fn get_transaction_location(
&self,
transaction_id: &[u8]
) -> Result<Option<TransactionLocation>, StorageError>
[src]
&self,
transaction_id: &[u8]
) -> Result<Option<TransactionLocation>, StorageError>
Returns a transaction location given the transaction ID if it exists. Returns None
otherwise.
pub fn get_transaction(
&self,
transaction_id: &[u8]
) -> Result<Option<T>, StorageError>
[src]
&self,
transaction_id: &[u8]
) -> Result<Option<T>, StorageError>
Returns a transaction given the transaction ID if it exists. Returns None
otherwise.
pub fn get_transaction_bytes(
&self,
transaction_id: &[u8]
) -> Result<Vec<u8>, StorageError>
[src]
&self,
transaction_id: &[u8]
) -> Result<Vec<u8>, StorageError>
Returns a transaction in bytes given a transaction ID.
pub fn transaction_conflicts(&self, transaction: &T) -> bool
[src]
Returns true if the transaction has internal parameters that already exist in the ledger.
Trait Implementations
impl<T: Transaction, P: LoadableMerkleParameters, S: Storage> LedgerScheme for Ledger<T, P, S>
[src]
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
fn new(
path: Option<&Path>,
parameters: Self::MerkleParameters,
genesis_block: Self::Block
) -> Result<Self>
[src]
path: Option<&Path>,
parameters: Self::MerkleParameters,
genesis_block: Self::Block
) -> Result<Self>
Instantiates a new ledger with a genesis block.
fn len(&self) -> usize
[src]
Returns the number of blocks including the genesis block
fn parameters(&self) -> &Self::MerkleParameters
[src]
Return the parameters used to construct the ledger Merkle tree.
fn digest(&self) -> Option<Self::MerkleTreeDigest>
[src]
Return a digest of the latest ledger Merkle tree.
fn validate_digest(&self, digest: &Self::MerkleTreeDigest) -> bool
[src]
Check that st_{ts} is a valid digest for some (past) ledger state.
fn contains_cm(&self, cm: &Self::Commitment) -> bool
[src]
Returns true if the given commitment exists in the ledger.
fn contains_sn(&self, sn: &Self::SerialNumber) -> bool
[src]
Returns true if the given serial number exists in the ledger.
fn contains_memo(
&self,
memo: &<Self::Transaction as Transaction>::Memorandum
) -> bool
[src]
&self,
memo: &<Self::Transaction as Transaction>::Memorandum
) -> bool
Returns true if the given memo exists in the ledger.
fn prove_cm(&self, cm: &Self::Commitment) -> Result<Self::MerklePath>
[src]
Returns the Merkle path to the latest ledger digest for a given commitment, if it exists in the ledger.
fn verify_cm(
_parameters: &Self::MerkleParameters,
digest: &Self::MerkleTreeDigest,
cm: &Self::Commitment,
witness: &Self::MerklePath
) -> bool
[src]
_parameters: &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.
Auto Trait Implementations
impl<T, P, S> !RefUnwindSafe for Ledger<T, P, S>
impl<T, P, S> Send for Ledger<T, P, S> where
P: Send,
S: Send,
T: Send,
<<P as MerkleParameters>::H as CRH>::Output: Send,
P: Send,
S: Send,
T: Send,
<<P as MerkleParameters>::H as CRH>::Output: Send,
impl<T, P, S> Sync for Ledger<T, P, S> where
P: Send + Sync,
S: Sync,
T: Sync,
<<P as MerkleParameters>::H as CRH>::Output: Send + Sync,
P: Send + Sync,
S: Sync,
T: Sync,
<<P as MerkleParameters>::H as CRH>::Output: Send + Sync,
impl<T, P, S> Unpin for Ledger<T, P, S> where
P: Unpin,
S: Unpin,
T: Unpin,
<<P as MerkleParameters>::H as CRH>::Output: Unpin,
P: Unpin,
S: Unpin,
T: Unpin,
<<P as MerkleParameters>::H as CRH>::Output: Unpin,
impl<T, P, S> UnwindSafe for Ledger<T, P, S> where
P: UnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
<<P as MerkleParameters>::H as CRH>::Output: UnwindSafe,
P: UnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
<<P as MerkleParameters>::H as CRH>::Output: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,