Class PBFTEngine

java.lang.Object
com.privatechain.consensus.pbft.PBFTEngine
All Implemented Interfaces:
ConsensusEngine

public final class PBFTEngine extends Object implements ConsensusEngine
Practical Byzantine Fault Tolerance consensus engine.

This implementation keeps the PBFT contract lightweight and deterministic while still exposing the same public API shape that a network-backed implementation would use. The engine requires a configurable quorum and a stable, ordered validator set. It validates that the block was produced by an authorized validator and that the block header carries the configured quorum marker.

Since:
1.0.0
  • Constructor Details

    • PBFTEngine

      public PBFTEngine(Collection<String> validators)
      Creates a PBFT engine with an automatically derived quorum size.

      The quorum follows the common 2f + 1 rule for a validator set of size n, which evaluates to floor(2n/3) + 1. The value is at least 1 so that a single-node test chain remains usable.

      Parameters:
      validators - ordered validator addresses participating in consensus
      Throws:
      NullPointerException - if validators is null
      IllegalArgumentException - if the collection contains blank entries
    • PBFTEngine

      public PBFTEngine(Collection<String> validators, int quorumSize)
      Creates a PBFT engine with an explicit quorum size.
      Parameters:
      validators - ordered validator addresses participating in consensus
      quorumSize - number of distinct validator approvals required for commit
      Throws:
      NullPointerException - if validators is null
      IllegalArgumentException - if the validator list contains blanks or the quorum is invalid
    • PBFTEngine

      public PBFTEngine(int quorumSize, Collection<String> validators)
      Creates a PBFT engine with an explicit quorum size.
      Parameters:
      quorumSize - number of validator approvals required for commit
      validators - ordered validator addresses participating in consensus
      Throws:
      NullPointerException - if validators is null
      IllegalArgumentException - if the validator list contains blanks or the quorum is invalid
  • Method Details

    • getValidators

      public List<String> getValidators()
      Returns the configured validators.
      Returns:
      immutable list of validator addresses
    • getQuorumSize

      public int getQuorumSize()
      Returns the configured quorum size.
      Returns:
      quorum size in validators
    • validateBlock

      public boolean validateBlock(Block block, Blockchain chain)
      Validates whether the candidate block satisfies the PBFT acceptance rules.
      Specified by:
      validateBlock in interface ConsensusEngine
      Parameters:
      block - the candidate block to validate
      chain - the current blockchain state
      Returns:
      true if the block is valid for this engine
      Throws:
      NullPointerException - if block or chain is null
      ConsensusException - if the configured quorum cannot be satisfied
    • mineBlock

      public Block mineBlock(List<Transaction> transactions, Block previousBlock)
      Produces a new block using the deterministic PBFT leader for the current view.
      Specified by:
      mineBlock in interface ConsensusEngine
      Parameters:
      transactions - ordered transactions to include in the block
      previousBlock - the current chain tip
      Returns:
      a newly produced block
      Throws:
      NullPointerException - if transactions or previousBlock is null
      ConsensusException - if the configured quorum cannot be satisfied
    • engineName

      public String engineName()
      Returns the stable name used to identify this engine in logs and status output.
      Specified by:
      engineName in interface ConsensusEngine
      Returns:
      the engine name