Struct snarkos_storage::ledger::Ledger[][src]

pub struct Ledger<T: Transaction, P: LoadableMerkleParameters, S: Storage> {
    pub current_block_height: AtomicU32,
    pub ledger_parameters: P,
    pub cm_merkle_tree: RwLock<MerkleTree<P>>,
    pub storage: S,
    pub _transaction: PhantomData<T>,
}

Fields

current_block_height: AtomicU32ledger_parameters: Pcm_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]

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]

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]

Store the connected peers.

pub fn catch_up_secondary(
    &self,
    update_merkle_tree: bool
) -> Result<(), StorageError>
[src]

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]

Get a block given the block hash.

pub fn get_block_from_block_number(
    &self,
    block_number: u32
) -> Result<Block<T>, StorageError>
[src]

Get a block given the block number.

pub fn get_block_hash(
    &self,
    block_number: u32
) -> Result<BlockHeaderHash, StorageError>
[src]

Get the block hash given a block number.

pub fn get_block_number(
    &self,
    block_hash: &BlockHeaderHash
) -> Result<u32, StorageError>
[src]

Get the block number given a block hash.

pub fn get_block_transactions(
    &self,
    block_hash: &BlockHeaderHash
) -> Result<DPCTransactions<T>, StorageError>
[src]

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]

Find the potential child block hashes given a parent block header.

pub fn already_mined(
    &self,
    block: &Block<T>
) -> Result<Option<u32>, StorageError>
[src]

Returns the block number of a conflicting block that has already been mined.

pub fn remove_block(
    &self,
    block_hash: BlockHeaderHash
) -> Result<(), StorageError>
[src]

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]

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]

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]

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]

Get the block’s path/origin.

pub fn longest_child_path(
    &self,
    block_hash: BlockHeaderHash
) -> Result<(usize, Vec<BlockHeaderHash>), StorageError>
[src]

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]

Get serial number index.

pub fn get_cm_index(
    &self,
    cm_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
[src]

Get commitment index

pub fn get_memo_index(
    &self,
    memo_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
[src]

Get memo index

pub fn rebuild_merkle_tree(
    &self,
    additional_cms: Vec<(T::Commitment, usize)>
) -> Result<(), StorageError>
[src]

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]

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]

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]

Get all stored record commitments of the node

pub fn get_record<R: Record>(
    &self,
    record_commitment: &[u8]
) -> Result<Option<R>, StorageError>
[src]

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]

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]

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]

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]

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]

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]

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]

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

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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