Class RoundRobinEngine
java.lang.Object
com.privatechain.consensus.roundrobin.RoundRobinEngine
- All Implemented Interfaces:
ConsensusEngine
Slot-based consensus engine.
This implementation rotates block production through a fixed, ordered peer list. The miner for a given block is selected deterministically by applying the block index modulo the configured peer count, which makes the engine predictable and especially useful for tests, demos, and scripted integration scenarios.
- Since:
- 1.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionRoundRobinEngine(List<String> peers) Creates a round-robin engine with the supplied peer order. -
Method Summary
Modifier and TypeMethodDescriptionReturns the stable name used to identify this engine in logs and status output.getPeers()Returns the configured peer order.mineBlock(List<Transaction> transactions, Block previousBlock) Produces a new block for the next round-robin slot.booleanvalidateBlock(Block block, Blockchain chain) Validates whether the candidate block was produced by the peer assigned to the current slot.
-
Constructor Details
-
RoundRobinEngine
Creates a round-robin engine with the supplied peer order.- Parameters:
peers- ordered peer list used for slot rotation- Throws:
NullPointerException- ifpeersis nullIllegalArgumentException- if the collection contains blank entries
-
-
Method Details
-
getPeers
Returns the configured peer order.- Returns:
- immutable ordered peer list
-
validateBlock
Validates whether the candidate block was produced by the peer assigned to the current slot.- 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 peer list is empty
-
mineBlock
Produces a new block for the next round-robin slot.- 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 peer list is empty
-
engineName
Returns the stable name used to identify this engine in logs and status output.- Specified by:
engineNamein interfaceConsensusEngine- Returns:
- the engine name
-