Package com.privatechain.consensus.pbft
Class PBFTEngine
java.lang.Object
com.privatechain.consensus.pbft.PBFTEngine
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionPBFTEngine(int quorumSize, Collection<String> validators) Creates a PBFT engine with an explicit quorum size.PBFTEngine(Collection<String> validators) Creates a PBFT engine with an automatically derived quorum size.PBFTEngine(Collection<String> validators, int quorumSize) Creates a PBFT engine with an explicit quorum size. -
Method Summary
Modifier and TypeMethodDescriptionReturns the stable name used to identify this engine in logs and status output.intReturns the configured quorum size.Returns the configured validators.mineBlock(List<Transaction> transactions, Block previousBlock) Produces a new block using the deterministic PBFT leader for the current view.booleanvalidateBlock(Block block, Blockchain chain) Validates whether the candidate block satisfies the PBFT acceptance rules.
-
Constructor Details
-
PBFTEngine
Creates a PBFT engine with an automatically derived quorum size.The quorum follows the common
2f + 1rule for a validator set of sizen, which evaluates tofloor(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- ifvalidatorsis nullIllegalArgumentException- if the collection contains blank entries
-
PBFTEngine
Creates a PBFT engine with an explicit quorum size.- Parameters:
validators- ordered validator addresses participating in consensusquorumSize- number of distinct validator approvals required for commit- Throws:
NullPointerException- ifvalidatorsis nullIllegalArgumentException- if the validator list contains blanks or the quorum is invalid
-
PBFTEngine
Creates a PBFT engine with an explicit quorum size.- Parameters:
quorumSize- number of validator approvals required for commitvalidators- ordered validator addresses participating in consensus- Throws:
NullPointerException- ifvalidatorsis nullIllegalArgumentException- if the validator list contains blanks or the quorum is invalid
-
-
Method Details
-
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
Validates whether the candidate block satisfies the PBFT acceptance rules.- Specified by:
validateBlockin interfaceConsensusEngine- Parameters:
block- the candidate block to validatechain- the current blockchain state- Returns:
trueif the block is valid for this engine- Throws:
NullPointerException- ifblockorchainis nullConsensusException- if the configured quorum cannot be satisfied
-
mineBlock
Produces a new block using the deterministic PBFT leader for the current view.- Specified by:
mineBlockin interfaceConsensusEngine- Parameters:
transactions- ordered transactions to include in the blockpreviousBlock- the current chain tip- Returns:
- a newly produced block
- Throws:
NullPointerException- iftransactionsorpreviousBlockis nullConsensusException- if the configured quorum cannot be satisfied
-
engineName
Returns the stable name used to identify this engine in logs and status output.- Specified by:
engineNamein interfaceConsensusEngine- Returns:
- the engine name
-