consensus_stage Enum
namespace keychain
→ enum class consensus_stage
Overview
The consensus_stage
enumeration tracks the lifecycle stages of transactions within consensus protocols, from initial submission through final confirmation.
Syntax
namespace keychain {
enum class consensus_stage {
PENDING, // Transaction submitted but not yet processed
VALIDATING, // Transaction being validated by consensus
CONFIRMED, // Transaction confirmed by consensus
FINALIZED, // Transaction finalized and immutable
REJECTED // Transaction rejected by consensus
};
}
Members
PENDING
Value: consensus_stage::PENDING
Transaction has been submitted to the consensus system but not yet picked up for processing.
Characteristics: * Initial state for new transactions * Transaction in mempool or queue * No guarantees about inclusion * Can still be canceled or modified * Waiting for consensus participation
VALIDATING
Value: consensus_stage::VALIDATING
Transaction is actively being validated through the consensus mechanism.
Characteristics: * Consensus nodes processing transaction * Validation rules being applied * Signatures and proofs being verified * Transaction can still be rejected * Progress depends on consensus algorithm
CONFIRMED
Value: consensus_stage::CONFIRMED
Transaction has been confirmed by the consensus mechanism and included in a block.
Characteristics: * Transaction included in distributed ledger * Meets consensus requirements * High confidence of permanence * May still be subject to reorganization * Generally safe for business logic
FINALIZED
Value: consensus_stage::FINALIZED
Transaction has reached finality and is considered immutable.
Characteristics: * Transaction permanently settled * Cannot be reversed or reorganized * Maximum security guarantee * Safe for irreversible actions * Finality varies by consensus algorithm
REJECTED
Value: consensus_stage::REJECTED
Transaction has been rejected by the consensus mechanism.
Characteristics: * Failed validation or consensus requirements * Will not be included in ledger * Error information available * Can potentially be resubmitted with fixes * Terminal state for this transaction attempt
Usage
#include <keychain/keychain.h>
// Monitor transaction progress
keychain::transaction tx;
// ... create and submit transaction ...
// Check current stage
auto stage = tx.get_consensus_stage();
switch (stage) {
case keychain::consensus_stage::PENDING:
std::cout << "Transaction pending..." << std::endl;
break;
case keychain::consensus_stage::VALIDATING:
std::cout << "Transaction being validated..." << std::endl;
break;
case keychain::consensus_stage::CONFIRMED:
std::cout << "Transaction confirmed!" << std::endl;
break;
case keychain::consensus_stage::FINALIZED:
std::cout << "Transaction finalized!" << std::endl;
// Safe to proceed with business logic
break;
case keychain::consensus_stage::REJECTED:
std::cout << "Transaction rejected" << std::endl;
// Handle error case
break;
}
// Wait for specific stage
bool wait_for_confirmation(keychain::transaction& tx) {
while (true) {
auto stage = tx.get_consensus_stage();
if (stage == keychain::consensus_stage::CONFIRMED ||
stage == keychain::consensus_stage::FINALIZED) {
return true;
}
if (stage == keychain::consensus_stage::REJECTED) {
return false;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
Stage Transitions
Transaction stages follow a defined progression:
stateDiagram-v2
[*] --> PENDING : Transaction submitted
PENDING --> VALIDATING : Picked up by consensus
PENDING --> REJECTED : Invalid transaction
VALIDATING --> CONFIRMED : Consensus reached
VALIDATING --> REJECTED : Validation failed
CONFIRMED --> FINALIZED : Finality achieved
CONFIRMED --> REJECTED : Reorganization (rare)
REJECTED --> [*]
FINALIZED --> [*]
Finality by Consensus Algorithm
Different consensus algorithms have different finality characteristics:
Consensus Algorithm | Confirmation Time | Finality Time | Reorganization Risk |
---|---|---|---|
Proof of Work |
~10 minutes |
~60 minutes (6 blocks) |
Low but possible |
Proof of Stake |
~12 seconds |
~6 minutes (2 epochs) |
Very low |
Delegated PoS |
~3 seconds |
~3 seconds |
Very low |
Proof of Authority |
~5 seconds |
~5 seconds |
None (immediate) |
pBFT/Tendermint |
~5 seconds |
~5 seconds |
None (immediate) |
Raft |
~100ms |
~100ms |
None (immediate) |
Error Handling
// Handle rejection with error details
if (tx.get_consensus_stage() == keychain::consensus_stage::REJECTED) {
auto result = tx.get_ledger_result();
if (result != keychain::ledger_result::SUCCESS) {
std::cerr << "Transaction rejected: " << to_string(result) << std::endl;
// Get detailed error information
auto error_details = tx.get_error_details();
for (const auto& error : error_details) {
std::cerr << " - " << error << std::endl;
}
}
}
Related Types
-
consensus_algorithm - Consensus mechanisms
-
transaction - Consensus-based transactions
-
ledger_result - Transaction result codes
See Also
-
gateway - Transaction submission
-
{consensus-algorithms}[Consensus Algorithm Comparison]
-
{blockchain-finality}[Understanding Blockchain Finality]