Class RoundRobinEngine

java.lang.Object
com.privatechain.consensus.roundrobin.RoundRobinEngine
All Implemented Interfaces:
ConsensusEngine

public final class RoundRobinEngine extends Object implements 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 Details

    • RoundRobinEngine

      public RoundRobinEngine(List<String> peers)
      Creates a round-robin engine with the supplied peer order.
      Parameters:
      peers - ordered peer list used for slot rotation
      Throws:
      NullPointerException - if peers is null
      IllegalArgumentException - if the collection contains blank entries
  • Method Details

    • getPeers

      public List<String> getPeers()
      Returns the configured peer order.
      Returns:
      immutable ordered peer list
    • validateBlock

      public boolean validateBlock(Block block, Blockchain chain)
      Validates whether the candidate block was produced by the peer assigned to the current slot.
      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 peer list is empty
    • mineBlock

      public Block mineBlock(List<Transaction> transactions, Block previousBlock)
      Produces a new block for the next round-robin slot.
      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 peer list is empty
    • 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