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§
sourcetype StateCommitment: Copy + Debug + PartialEq + Serialize + DeserializeOwned + Send + Sync
type StateCommitment: Copy + Debug + PartialEq + Serialize + DeserializeOwned + Send + Sync
A commitment to the state of the validator.
Required Methods§
sourcefn block_height(&self) -> u64
fn block_height(&self) -> u64
The number of blocks this validator has applied.
sourcefn commit(&self) -> Self::StateCommitment
fn commit(&self) -> Self::StateCommitment
The commitment to the current state of the validator.
sourcefn next_block(&self) -> Self::Block
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.
sourcefn validate_and_apply(
&mut self,
block: Self::Block,
proof: Self::Proof
) -> Result<(Vec<u64>, MerkleTree), <Self::Block as Block>::Error>
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.