Package com.privatechain.consensus.poa
Class ProofOfAuthorityEngine
java.lang.Object
com.privatechain.consensus.poa.ProofOfAuthorityEngine
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionProofOfAuthorityEngine(Collection<String> authorizedAddresses) Creates a proof-of-authority engine with the supplied authorized addresses. -
Method Summary
Modifier and TypeMethodDescriptionReturns the stable name used to identify this engine in logs and status output.Returns the configured authorized addresses in deterministic order.mineBlock(List<Transaction> transactions, Block previousBlock) Builds a new authority-signed block using the first authorized miner address.booleanvalidateBlock(Block block, Blockchain chain) Validates whether the candidate block was produced by an authorized miner.
-
Constructor Details
-
ProofOfAuthorityEngine
Creates a proof-of-authority engine with the supplied authorized addresses.- Parameters:
authorizedAddresses- collection of node addresses permitted to produce blocks- Throws:
NullPointerException- ifauthorizedAddressesis nullIllegalArgumentException- if the collection contains blank entries
-
-
Method Details
-
getAuthorizedAddresses
Returns the configured authorized addresses in deterministic order.- Returns:
- immutable list of authorized miner addresses
-
validateBlock
Validates whether the candidate block was produced by an authorized miner.- 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 null
-
mineBlock
Builds a new authority-signed block using the first authorized miner address.- 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 no authorized addresses are configured
-
engineName
Returns the stable name used to identify this engine in logs and status output.- Specified by:
engineNamein interfaceConsensusEngine- Returns:
- the engine name
-