[][src]Struct grin_chain::Chain

pub struct Chain { /* fields omitted */ }

Facade to the blockchain block processing pipeline and storage. Provides the current view of the TxHashSet according to the chain state. Also maintains locking for the pipeline to avoid conflicting processing.

Methods

impl Chain[src]

pub fn init(
    db_root: String,
    adapter: Arc<dyn ChainAdapter + Send + Sync>,
    genesis: Block,
    pow_verifier: fn(_: &BlockHeader) -> Result<(), Error>,
    verifier_cache: Arc<RwLock<dyn VerifierCache>>,
    archive_mode: bool,
    stop_state: Arc<Mutex<StopState>>
) -> Result<Chain, Error>
[src]

Initializes the blockchain and returns a new Chain instance. Does a check on the current chain head to make sure it exists and creates one based on the genesis block if necessary.

pub fn txhashset(&self) -> Arc<RwLock<TxHashSet>>[src]

Return our shared txhashset instance.

pub fn store(&self) -> Arc<ChainStore>[src]

Shared store instance.

pub fn reset_sync_head(&self) -> Result<Tip, Error>[src]

Reset sync_head to current header_head. We do this when we first transition to header_sync to ensure we extend the "sync" header MMR from a known consistent state and to ensure we track the header chain correctly at the fork point.

pub fn process_block(
    &self,
    b: Block,
    opts: Options
) -> Result<Option<Tip>, Error>
[src]

Processes a single block, then checks for orphans, processing those as well if they're found

pub fn process_block_header(
    &self,
    bh: &BlockHeader,
    opts: Options
) -> Result<(), Error>
[src]

Process a block header received during "header first" propagation.

pub fn sync_block_headers(
    &self,
    headers: &[BlockHeader],
    opts: Options
) -> Result<(), Error>
[src]

Attempt to add new headers to the header chain (or fork). This is only ever used during sync and is based on sync_head. We update header_head here if our total work increases.

pub fn is_orphan(&self, hash: &Hash) -> bool[src]

Check if hash is for a known orphan.

pub fn orphans_evicted_len(&self) -> usize[src]

Get the OrphanBlockPool accumulated evicted number of blocks

pub fn check_orphans(&self, height: u64)[src]

Check for orphans, once a block is successfully added

pub fn is_unspent(&self, output_ref: &OutputIdentifier) -> Result<Hash, Error>[src]

TODO - where do we call this from? And do we need a rewind first? For the given commitment find the unspent output and return the associated Return an error if the output does not exist or has been spent. This querying is done in a way that is consistent with the current chain state, specifically the current winning (valid, most work) fork.

pub fn validate_tx(&self, tx: &Transaction) -> Result<(), Error>[src]

Validate the tx against the current UTXO set.

pub fn verify_coinbase_maturity(&self, tx: &Transaction) -> Result<(), Error>[src]

Verify we are not attempting to spend a coinbase output that has not yet sufficiently matured.

pub fn verify_tx_lock_height(&self, tx: &Transaction) -> Result<(), Error>[src]

Verify that the tx has a lock_height that is less than or equal to the height of the next block.

pub fn validate(&self, fast_validation: bool) -> Result<(), Error>[src]

Validate the current chain state.

pub fn set_txhashset_roots_forked(
    &self,
    b: &mut Block,
    prev: &BlockHeader
) -> Result<(), Error>
[src]

*** Only used in tests. *** Convenience for setting roots on a block header when creating a chain fork during tests.

pub fn set_txhashset_roots(&self, b: &mut Block) -> Result<(), Error>[src]

Sets the txhashset roots on a brand new block by applying the block on the current txhashset state.

pub fn get_merkle_proof(
    &self,
    output: &OutputIdentifier,
    block_header: &BlockHeader
) -> Result<MerkleProof, Error>
[src]

Return a Merkle proof for the given commitment from the store.

pub fn get_merkle_proof_for_pos(
    &self,
    commit: Commitment
) -> Result<MerkleProof, Error>
[src]

Return a merkle proof valid for the current output pmmr state at the given pos

pub fn get_txhashset_roots(&self) -> TxHashSetRoots[src]

Returns current txhashset roots.

pub fn txhashset_read(&self, h: Hash) -> Result<(u64, u64, File), Error>[src]

Provides a reading view into the current txhashset state as well as the required indexes for a consumer to rewind to a consistent state at the provided block hash.

pub fn rebuild_sync_mmr(&self, head: &Tip) -> Result<(), Error>[src]

Rebuild the sync MMR based on current header_head. We rebuild the sync MMR when first entering sync mode so ensure we have an MMR we can safely rewind based on the headers received from a peer. TODO - think about how to optimize this.

pub fn check_txhashset_needed(
    &self,
    caller: String,
    hashes: &mut Option<Vec<Hash>>
) -> Result<bool, Error>
[src]

Check chain status whether a txhashset downloading is needed

pub fn clean_txhashset_sandbox(&self)[src]

Clean the temporary sandbox folder

pub fn txhashset_write(
    &self,
    h: Hash,
    txhashset_data: File,
    status: &dyn TxHashsetWriteStatus
) -> Result<(), Error>
[src]

Writes a reading view on a txhashset state that's been provided to us. If we're willing to accept that new state, the data stream will be read as a zip file, unzipped and the resulting state files should be rewound to the provided indexes.

pub fn compact(&self) -> Result<(), Error>[src]

Triggers chain compaction.

  • compacts the txhashset based on current prune_list
  • removes historical blocks and associated data from the db (unless archive mode)

pub fn get_last_n_output(&self, distance: u64) -> Vec<(Hash, OutputIdentifier)>[src]

returns the last n nodes inserted into the output sum tree

pub fn get_last_n_rangeproof(&self, distance: u64) -> Vec<(Hash, RangeProof)>[src]

as above, for rangeproofs

pub fn get_last_n_kernel(&self, distance: u64) -> Vec<(Hash, TxKernelEntry)>[src]

as above, for kernels

pub fn get_output_pos(&self, commit: &Commitment) -> Result<u64, Error>[src]

as above, for kernels

pub fn unspent_outputs_by_insertion_index(
    &self,
    start_index: u64,
    max: u64
) -> Result<(u64, u64, Vec<Output>), Error>
[src]

outputs by insertion index

pub fn orphans_len(&self) -> usize[src]

Orphans pool size

pub fn head(&self) -> Result<Tip, Error>[src]

Tip (head) of the block chain.

pub fn tail(&self) -> Result<Tip, Error>[src]

Tail of the block chain in this node after compact (cross-block cut-through)

pub fn header_head(&self) -> Result<Tip, Error>[src]

Tip (head) of the header chain.

pub fn head_header(&self) -> Result<BlockHeader, Error>[src]

Block header for the chain head

pub fn get_block(&self, h: &Hash) -> Result<Block, Error>[src]

Gets a block header by hash

pub fn get_block_header(&self, h: &Hash) -> Result<BlockHeader, Error>[src]

Gets a block header by hash

pub fn get_previous_header(
    &self,
    header: &BlockHeader
) -> Result<BlockHeader, Error>
[src]

Get previous block header.

pub fn get_block_sums(&self, h: &Hash) -> Result<BlockSums, Error>[src]

Get block_sums by header hash.

pub fn get_header_by_height(&self, height: u64) -> Result<BlockHeader, Error>[src]

Gets the block header at the provided height. Note: Takes a read lock on the txhashset. Take care not to call this repeatedly in a tight loop.

pub fn get_header_for_output(
    &self,
    output_ref: &OutputIdentifier
) -> Result<BlockHeader, Error>
[src]

Gets the block header in which a given output appears in the txhashset.

pub fn is_on_current_chain(&self, header: &BlockHeader) -> Result<(), Error>[src]

Verifies the given block header is actually on the current chain. Checks the header_by_height index to verify the header is where we say it is

pub fn get_sync_head(&self) -> Result<Tip, Error>[src]

Get the tip of the current "sync" header chain. This may be significantly different to current header chain.

pub fn difficulty_iter(&self) -> Result<DifficultyIter, Error>[src]

Builds an iterator on blocks starting from the current chain head and running backward. Specialized to return information pertaining to block difficulty calculation (timestamp and previous difficulties).

pub fn block_exists(&self, h: Hash) -> Result<bool, Error>[src]

Check whether we have a block without reading it

Auto Trait Implementations

impl Send for Chain

impl Sync for Chain

Blanket Implementations

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

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

impl<T, U> TryInto 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<T> UnsafeAny for T where
    T: Any

impl<T> Erased for T

impl<T> Same for T

type Output = T

Should always be Self

impl<T> SafeBorrow for T where
    T: ?Sized