[][src]Struct pbft_engine::node::PbftNode

pub struct PbftNode {
    pub service: Box<dyn Service>,
    pub msg_log: PbftLog,
}

Contains the core logic of the PBFT node

Fields

service: Box<dyn Service>

Used for interactions with the validator

msg_log: PbftLog

Log of messages this node has received and accepted

Implementations

impl PbftNode[src]

pub fn new(
    config: &PbftConfig,
    chain_head: Block,
    connected_peers: Vec<PeerInfo>,
    service: Box<dyn Service>,
    state: &mut PbftState
) -> Self
[src]

Construct a new PBFT node

If the node is the primary on start-up, it initializes a new block on the chain

pub fn on_peer_message(
    &mut self,
    msg: ParsedMessage,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a peer message from another PbftNode

Handle all messages from other nodes. Such messages include PrePrepare, Prepare, Commit, ViewChange, and NewView. Make sure the message is from a PBFT member. If the node is view changing, ignore all messages that aren't ViewChanges or NewViews.

fn handle_pre_prepare(
    &mut self,
    msg: ParsedMessage,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a PrePrepare message

A PrePrepare message is accepted and added to the log if the following are true:

  • The message signature is valid (already verified by validator)
  • The message is from the primary
  • The message's view matches the node's current view
  • A PrePrepare message does not already exist at this view and sequence number with a different block

Once a PrePrepare for the current sequence number is accepted and added to the log, the node will try to switch to the Preparing phase.

fn handle_prepare(
    &mut self,
    msg: ParsedMessage,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a Prepare message

Once a Prepare for the current sequence number is accepted and added to the log, the node will check if it has the required 2f + 1 Prepared messages to move on to the Committing phase

fn handle_commit(
    &mut self,
    msg: ParsedMessage,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a Commit message

Once a Commit for the current sequence number is accepted and added to the log, the node will check if it has the required 2f + 1 Commit messages to actually commit the block

fn handle_view_change(
    &mut self,
    msg: &ParsedMessage,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a ViewChange message

When a ViewChange is received, check that it isn't outdated and add it to the log. If the node isn't already view changing but it now has f + 1 ViewChange messages, start view changing early. If the node is the primary and has 2f view change messages now, broadcast the NewView message to the rest of the nodes to move to the new view.

fn handle_new_view(
    &mut self,
    msg: &ParsedMessage,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a NewView message

When a NewView is received, verify that it is valid; if it is, update the view and the node's state.

fn handle_seal_request(
    &mut self,
    msg: ParsedMessage,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a SealRequest message

A node is requesting a consensus seal for the last block. If the block was the last one committed by this node, build the seal and send it to the requesting node; if the block has not been committed yet but it's the next one to be committed, add the request to the log and the node will build/send the seal when it's done committing. If this is an older block (state.seq_num > msg.seq_num + 1) or this node is behind (state.seq_num < msg.seq_num), the node will not be able to build the requseted seal, so just ignore the message.

fn handle_seal_response(
    &mut self,
    msg: &ParsedMessage,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a Seal message

A node has responded to the seal request by sending a seal for the last block; validate the seal and commit the block.

pub fn on_block_new(
    &mut self,
    block: Block,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a BlockNew update from the Validator

The validator has received a new block; check if it is a block that should be considered, add it to the log as an unvalidated block, and instruct the validator to validate it.

pub fn on_block_valid(
    &mut self,
    block_id: BlockId,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a BlockValid update from the Validator

The block has been verified by the validator, so mark it as validated in the log and attempt to handle the block.

fn try_handling_block(
    &mut self,
    block: Block,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Validate the block's seal and handle the block. If this is the block the node is waiting for and this node is the primary, broadcast a PrePrepare; if the node isn't the primary but it already has the PrePrepare for this block, switch to Preparing. If this is a future block, use it to catch up.

pub fn on_block_invalid(&mut self, block_id: BlockId) -> Result<(), PbftError>[src]

Handle a BlockInvalid update from the Validator

The block is invalid, so drop it from the log and fail it.

fn catchup(
    &mut self,
    state: &mut PbftState,
    seal: &PbftSeal,
    catchup_again: bool
) -> Result<(), PbftError>
[src]

Use the given consensus seal to verify and commit the block this node is working on

pub fn on_block_commit(
    &mut self,
    block_id: BlockId,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a BlockCommit update from the Validator

A block was sucessfully committed; clean up any uncommitted blocks, update state to be ready for the next block, make any necessary view and membership changes, garbage collect the logs, and start a new block if this node is the primary.

fn update_membership(&mut self, block_id: BlockId, state: &mut PbftState)[src]

Check the on-chain list of members; if it has changed, update members list and return true.

Panics

  • If the sawtooth.consensus.pbft.members setting is unset or invalid
  • If the network this node is on does not have enough nodes to be Byzantine fault tolernant

fn try_preparing(
    &mut self,
    block_id: BlockId,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

When the node has a block and a corresponding PrePrepare for its current sequence number, and it is in the PrePreparing phase, it can enter the Preparing phase and broadcast its Prepare

pub fn on_peer_connected(
    &mut self,
    peer_id: PeerId,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Handle a PeerConnected update from the Validator

A peer has just connected to this node. Send a bootstrap commit message if the peer is part of the network and the node isn't at the genesis block.

fn broadcast_bootstrap_commit(
    &mut self,
    peer_id: PeerId,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

When the whole network is starting "fresh" from a non-genesis block, none of the nodes will have the Commit messages necessary to build the consensus seal for the last committed block (the chain head). To bootstrap the network in this scenario, all nodes will send a Commit message for their chain head whenever one of the PBFT members connects; when

2f + 1 nodes have connected and received these Commit messages, the nodes will be able to build a seal using the messages.

fn signed_votes_from_messages(
    msgs: &[&ParsedMessage]
) -> RepeatedField<PbftSignedVote>
[src]

Generate a protobuf::RepeatedField of signed votes from a list of parsed messages

fn build_seal(&self, state: &PbftState) -> Result<PbftSeal, PbftError>[src]

Build a consensus seal that proves the last block committed by this node

fn verify_vote<F>(
    vote: &PbftSignedVote,
    expected_type: PbftMessageType,
    validation_criteria: F
) -> Result<PeerId, PbftError> where
    F: Fn(&PbftMessage) -> Result<(), PbftError>, 
[src]

Verify that a vote matches the expected type, is properly signed, and passes the specified criteria; if it passes verification, return the signer ID to be used for further verification

fn verify_new_view(
    &mut self,
    new_view: &PbftNewView,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Verify that a NewView messsage is valid

fn verify_consensus_seal_from_block(
    &mut self,
    block: &Block,
    state: &mut PbftState
) -> Result<PbftSeal, PbftError>
[src]

Verify the consensus seal from the current block that proves the previous block and return the parsed seal

fn verify_consensus_seal(
    &mut self,
    seal: &PbftSeal,
    previous_id: BlockId,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Verify the given consenus seal

Panics

  • If the sawtooth.consensus.pbft.members setting is unset or invalid

pub fn try_publish(&mut self, state: &mut PbftState) -> Result<(), PbftError>[src]

At a regular interval, try to finalize a block when the primary is ready

pub fn check_idle_timeout_expired(&mut self, state: &mut PbftState) -> bool[src]

Check to see if the idle timeout has expired

pub fn start_idle_timeout(&self, state: &mut PbftState)[src]

Start the idle timeout

pub fn check_commit_timeout_expired(&mut self, state: &mut PbftState) -> bool[src]

Check to see if the commit timeout has expired

pub fn start_commit_timeout(&self, state: &mut PbftState)[src]

Start the commit timeout

pub fn check_view_change_timeout_expired(
    &mut self,
    state: &mut PbftState
) -> bool
[src]

Check to see if the view change timeout has expired

fn broadcast_pbft_message(
    &mut self,
    view: u64,
    seq_num: u64,
    msg_type: PbftMessageType,
    block_id: BlockId,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Construct a PbftMessage message and broadcast it to all peers (including self)

fn broadcast_message(
    &mut self,
    msg: ParsedMessage,
    state: &mut PbftState
) -> Result<(), PbftError>
[src]

Broadcast the specified message to all of the node's peers, including itself

fn send_seal_response(
    &mut self,
    state: &PbftState,
    recipient: &PeerId
) -> Result<(), PbftError>
[src]

Build a consensus seal for the last block this node committed and send it to the node that requested the seal (the recipient)

pub fn start_view_change(
    &mut self,
    state: &mut PbftState,
    view: u64
) -> Result<(), PbftError>
[src]

Start a view change when this node suspects that the primary is faulty

Update state to reflect that the node is now in the process of this view change, start the view change timeout, and broadcast a view change message

Panics

  • If the view change timeout overflows

Auto Trait Implementations

impl !RefUnwindSafe for PbftNode

impl !Send for PbftNode

impl !Sync for PbftNode

impl Unpin for PbftNode

impl !UnwindSafe for PbftNode

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