[][src]Trait sawtooth_sdk::consensus::engine::Engine

pub trait Engine {
    fn start(
        &mut self,
        updates: Receiver<Update>,
        service: Box<dyn Service>,
        startup_state: StartupState
    ) -> Result<(), Error>;
fn version(&self) -> String;
fn name(&self) -> String;
fn additional_protocols(&self) -> Vec<(String, String)>; }

Engine is the only trait that needs to be implemented when adding a new consensus engine.

The consensus engine should listen for notifications from the validator about the status of blocks and messages from peers. It must also determine internally when to build and publish blocks based on its view of the network and the consensus algorithm it implements. Often this will be some sort of timer-based interrupt.

Based on the updates the engine receives through the Receiver<Update> and the specifics of the algorithm being implemented, the engine utilizes the provided Service to create new blocks, communicate with its peers, request that certain blocks be committed, and fail or ignore blocks that should not be committed.

While the validator may take actions beyond what the engine instructs it to do for performance optimization reasons, it is the consensus engine's responsibility to drive the progress of the validator and ensure liveness.

It is not the engine's responsibility to manage blocks or memory, other than to ensure it responds to every new block with a commit, fail, or ignore within a "reasonable amount of time". The validator is responsible for guaranteeing the integrity of all blocks sent to the engine until the engine responds. After the engine responds, the validator does not guarantee that the block and its predecessors continue to be available unless the block was committed.

Finally, as an optimization, the consensus engine can send prioritized lists of blocks to the chain controller for checking instead of sending them one at a time, which allows the chain controller to intelligently work ahead while the consensus engine makes its decisions.

Required methods

fn start(
    &mut self,
    updates: Receiver<Update>,
    service: Box<dyn Service>,
    startup_state: StartupState
) -> Result<(), Error>

Called after the engine is initialized, when a connection to the validator has been established. Notifications from the validator are sent along updates. service is used to send requests to the validator.

fn version(&self) -> String

Get the version of this engine

fn name(&self) -> String

Get the name of the engine, typically the algorithm being implemented

fn additional_protocols(&self) -> Vec<(String, String)>

Any additional name/version pairs this engine supports

Loading content...

Implementors

Loading content...