## Overview
Consensus mechanisms overview providing the foundation for blockchain agreement and validation in the Cellframe SDK. This module serves as a navigation hub for different consensus implementations, each offering unique approaches to achieving distributed agreement across the network.
**Key Responsibilities:**
- Provide overview of available consensus mechanisms
- Navigate to specific consensus implementations
- Explain consensus selection criteria
- Document common consensus interfaces
*Based on: `dap_chain_cs.h`, `dap_chain_cs.c`*
## Document Structure
- [[#Overview|Overview]]
- [[#Consensus Mechanisms|Consensus Mechanisms]] - Available consensus implementations
- [[#Consensus Selection|Consensus Selection]] - How to choose appropriate consensus
- [[#Common Interface|Common Interface]] - Shared consensus functionality
---
## Consensus Mechanisms
The Cellframe SDK provides multiple consensus mechanisms to support different use cases and network requirements:
### **[[Module Consensus - DAG PoA|Module Consensus - DAG PoA]]**
**Directed Acyclic Graph Proof of Authority**
- **Use Case:** High-performance networks with trusted validators
- **Characteristics:** Fast finality, low energy consumption, authority-based validation
- **Best For:** Enterprise networks, consortium blockchains, high-throughput applications
- **Performance:** High transaction throughput with immediate finality
### **[[Module Consensus - ESBOCS|Module Consensus - ESBOCS]]**
**Enhanced Scalable Byzantine Consensus**
- **Use Case:** Byzantine fault-tolerant networks requiring high security
- **Characteristics:** Byzantine fault tolerance, scalable consensus, robust security
- **Best For:** Public networks, high-security applications, distributed systems
- **Performance:** Balanced throughput with strong security guarantees
### **[[Module Consensus - CS None|Module Consensus - CS None]]**
**No-Validation Consensus for Development**
- **Use Case:** Development and testing environments
- **Characteristics:** No validation, immediate acceptance, development-friendly
- **Best For:** Testing, development, proof-of-concept applications
- **Performance:** Maximum speed with no validation overhead
---
## Consensus Selection
### **Performance Requirements**
- **High Throughput:** Choose DAG PoA for maximum transaction processing
- **Security Priority:** Choose ESBOCS for Byzantine fault tolerance
- **Development Speed:** Choose CS None for rapid prototyping
### **Network Characteristics**
- **Trusted Environment:** DAG PoA with known validators
- **Public Network:** ESBOCS with Byzantine fault tolerance
- **Testing Environment:** CS None for development and testing
### **Use Case Alignment**
- **Enterprise Applications:** DAG PoA for controlled environments
- **Public Blockchains:** ESBOCS for decentralized security
- **Development Tools:** CS None for rapid iteration
---
## Common Interface
All consensus mechanisms implement the common interface defined in `dap_chain_cs.h`:
### **Initialization**
```c
int dap_chain_cs_init(void);
void dap_chain_cs_deinit(void);
```
### **Consensus Creation**
```c
int dap_chain_cs_create(dap_chain_t *a_chain, dap_config_t *a_chain_cfg);
```
### **Type Registration**
```c
void dap_chain_cs_type_add(const char *a_cs_str,
dap_chain_callback_new_cfg_t a_callback_init,
dap_chain_callback_t a_callback_start);
```
### **Consensus Management**
```c
int dap_chain_cs_type_create(const char *a_type, dap_chain_t *a_chain, dap_config_t *a_chain_cfg);
void dap_chain_cs_type_start(const char *a_type, dap_chain_t *a_chain);
```
---
## Typical Examples
### Consensus Selection Example
```c
#include <dap_chain_cs.h>
#include <dap_common.h>
void consensus_selection_example() {
log_it(L_INFO, "=== Consensus Selection Example ===");
// Step 1: Initialize consensus subsystem
int result = dap_chain_cs_init();
if (result != 0) {
log_it(L_ERROR, "✗ Failed to initialize consensus: %d", result);
return;
}
log_it(L_INFO, "✓ Consensus subsystem initialized");
// Step 2: Choose consensus based on requirements
const char *consensus_type;
const char *network_name = "Backbone";
// Example: Choose DAG PoA for high-performance enterprise network
if (strcmp(network_name, "Backbone") == 0) {
consensus_type = "dag-poa";
log_it(L_INFO, "✓ Selected DAG PoA for high-performance network");
}
// Example: Choose ESBOCS for public network
else if (strcmp(network_name, "Public") == 0) {
consensus_type = "esbocs";
log_it(L_INFO, "✓ Selected ESBOCS for public network");
}
// Example: Choose CS None for development
else {
consensus_type = "cs-none";
log_it(L_INFO, "✓ Selected CS None for development");
}
// Step 3: Create consensus for chain
dap_chain_t *chain = dap_chain_find_by_id(0x01, 0x01);
if (chain) {
dap_config_t *chain_cfg = chain->config;
result = dap_chain_cs_type_create(consensus_type, chain, chain_cfg);
if (result == 0) {
log_it(L_INFO, "✓ Consensus created successfully");
// Step 4: Start consensus
dap_chain_cs_type_start(consensus_type, chain);
log_it(L_INFO, "✓ Consensus started");
} else {
log_it(L_ERROR, "✗ Failed to create consensus: %d", result);
}
}
log_it(L_INFO, "✓ Consensus selection example completed");
}
```
### Consensus Comparison Example
```c
#include <dap_chain_cs.h>
#include <dap_common.h>
void consensus_comparison_example() {
log_it(L_INFO, "=== Consensus Comparison Example ===");
// Compare consensus characteristics
log_it(L_INFO, "Consensus Mechanism Comparison:");
log_it(L_INFO, "");
log_it(L_INFO, "DAG PoA (Directed Acyclic Graph Proof of Authority):");
log_it(L_INFO, " • High transaction throughput");
log_it(L_INFO, " • Immediate finality");
log_it(L_INFO, " • Low energy consumption");
log_it(L_INFO, " • Authority-based validation");
log_it(L_INFO, " • Best for: Enterprise networks, consortium blockchains");
log_it(L_INFO, "");
log_it(L_INFO, "ESBOCS (Enhanced Scalable Byzantine Consensus):");
log_it(L_INFO, " • Byzantine fault tolerance");
log_it(L_INFO, " • Strong security guarantees");
log_it(L_INFO, " • Scalable consensus");
log_it(L_INFO, " • Robust against malicious actors");
log_it(L_INFO, " • Best for: Public networks, high-security applications");
log_it(L_INFO, "");
log_it(L_INFO, "CS None (No-Validation Consensus):");
log_it(L_INFO, " • No validation overhead");
log_it(L_INFO, " • Maximum development speed");
log_it(L_INFO, " • Immediate acceptance");
log_it(L_INFO, " • No security guarantees");
log_it(L_INFO, " • Best for: Development, testing, proof-of-concept");
log_it(L_INFO, "");
log_it(L_INFO, "✓ Consensus comparison completed");
}
```
---
*See also: [[Module Consensus - DAG PoA|Module Consensus - DAG PoA]], [[Module Consensus - ESBOCS|Module Consensus - ESBOCS]], [[Module Consensus - CS None|Module Consensus - CS None]], [[Modules/Module Chain|Module Chain]], [[ETC/Development Guide|Development Guide]]*
---
*Based on: `dap_chain_cs.h`, `dap_chain_cs.c`*