Enum class ConsensusAlgorithm

Package: keychain.constants

Description

Consensus algorithm used in ledger consensus protocols.

This enum defines the various consensus algorithms that can be used in distributed ledger systems to achieve agreement among network participants on the state of the ledger.

Since: v2.0

Enum Class Summary

Enum Constant Value Description

UNINITIALIZED

0

No consensus algorithm specified

ONE_PHASE_COMMIT

1

One-phase commit (Commit)

TWO_PHASE_COMMIT

2

Two-phase commit (Propose/Commit)

THREE_PHASE_COMMIT

3

Three-phases commit (Propose/PreCommit/Commit)

Enum Class Detail

UNINITIALIZED

Value: 0

No consensus algorithm specified. This is the default uninitialized state.

ONE_PHASE_COMMIT

Value: 1

One-phase commit (Commit). This is the simplest consensus protocol where participants directly commit to a transaction without preliminary phases.

TWO_PHASE_COMMIT

Value: 2

Two-phase commit (Propose/Commit). This protocol involves a propose phase followed by a commit phase, providing basic fault tolerance.

THREE_PHASE_COMMIT

Value: 3

Three-phases commit (Propose/PreCommit/Commit). This is the most robust consensus protocol with three phases: propose, pre-commit, and commit, providing the highest level of fault tolerance.

Usage Example

from keychain.constants import ConsensusAlgorithm

# Use two-phase commit for moderate fault tolerance
algorithm = ConsensusAlgorithm.TWO_PHASE_COMMIT
print(f"Using consensus algorithm: {algorithm}")  # Outputs: 2

# Check if algorithm is initialized
if algorithm != ConsensusAlgorithm.UNINITIALIZED:
    print("Consensus algorithm is properly configured")