Trait reef::traits::Validator

source ·
pub trait Validator: Clone + Debug + PartialEq + Serialize + DeserializeOwned + Send + Sync {
    type StateCommitment: Copy + Debug + PartialEq + Serialize + DeserializeOwned + Send + Sync;
    type Block: Block;
    type Proof: Clone + Debug + Serialize + DeserializeOwned + Send + Sync;

    // Required methods
    fn block_height(&self) -> u64;
    fn commit(&self) -> Self::StateCommitment;
    fn next_block(&self) -> Self::Block;
    fn validate_and_apply(
        &mut self,
        block: Self::Block,
        proof: Self::Proof
    ) -> Result<(Vec<u64>, MerkleTree), <Self::Block as Block>::Error>;
}
Expand description

State required to validate a Block of Transactions.

Technically, this interface does not actually require blocks to be validated. It merely requires that the Validator state is sufficient to produce the outputs of each block, and that each state has a unique commitment. If the network as a whole uses commitments to authenticate ledger states, then Validator::StateCommitment should match that commitment after each block.

Required Associated Types§

source

type StateCommitment: Copy + Debug + PartialEq + Serialize + DeserializeOwned + Send + Sync

A commitment to the state of the validator.

source

type Block: Block

Blocks applied by this validator.

source

type Proof: Clone + Debug + Serialize + DeserializeOwned + Send + Sync

Additional data required to authenticate a committed block, not contained in the block itself.

Required Methods§

source

fn block_height(&self) -> u64

The number of blocks this validator has applied.

source

fn commit(&self) -> Self::StateCommitment

The commitment to the current state of the validator.

source

fn next_block(&self) -> Self::Block

Build a block on top of the current state of this validator.

The block is initially empty. Transactions can be appended using add_transaction.

source

fn validate_and_apply( &mut self, block: Self::Block, proof: Self::Proof ) -> Result<(Vec<u64>, MerkleTree), <Self::Block as Block>::Error>

Apply a new block, updating the state and returning UIDs and Merkle paths for each output.

For each output, the returned UID is the index of that output; that is, the total number of outputs which had been generated before that one. The returned [MerkleTree] should be a sparse [MerkleTree] with the same commitment as the updated Validator, containing paths to each leaf whose index is listed in the UIDs.

Implementors§

source§

impl<const H: u8> Validator for Validator<H>