Class ProofOfAuthorityEngine

java.lang.Object
com.privatechain.consensus.poa.ProofOfAuthorityEngine
All Implemented Interfaces:
ConsensusEngine

public final class ProofOfAuthorityEngine extends Object implements ConsensusEngine
Proof-of-authority consensus engine.

This engine models a private-chain authority scheme where block production is restricted to a fixed set of pre-approved miner addresses. The implementation keeps block production deterministic by selecting the lexicographically first configured address when mining a block.

Validation checks that the block hash is internally consistent and that the claimed miner belongs to the configured authorization set.

Since:
1.0.0
  • Constructor Details

    • ProofOfAuthorityEngine

      public ProofOfAuthorityEngine(Collection<String> authorizedAddresses)
      Creates a proof-of-authority engine with the supplied authorized addresses.
      Parameters:
      authorizedAddresses - collection of node addresses permitted to produce blocks
      Throws:
      NullPointerException - if authorizedAddresses is null
      IllegalArgumentException - if the collection contains blank entries
  • Method Details

    • getAuthorizedAddresses

      public List<String> getAuthorizedAddresses()
      Returns the configured authorized addresses in deterministic order.
      Returns:
      immutable list of authorized miner addresses
    • validateBlock

      public boolean validateBlock(Block block, Blockchain chain)
      Validates whether the candidate block was produced by an authorized miner.
      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
    • mineBlock

      public Block mineBlock(List<Transaction> transactions, Block previousBlock)
      Builds a new authority-signed block using the first authorized miner address.
      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 no authorized addresses are configured
    • 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