1
1
/**
2
- * Byzantine Fault-Tolerant Consensus System for Agent-to-Agent Communication
2
+ * Consensus Protocols for Agent-to-Agent Communication
3
3
*
4
- * This module provides a comprehensive Byzantine consensus system that can handle
5
- * up to 33% malicious agents while maintaining correctness and security.
4
+ * This module provides comprehensive consensus protocols for distributed systems:
6
5
*
7
6
* Features:
8
7
* - PBFT (Practical Byzantine Fault Tolerance) consensus algorithm
8
+ * - Raft consensus protocol for leader-based consensus
9
9
* - Advanced voting mechanisms (weighted, quadratic, liquid democracy)
10
10
* - Sophisticated malicious agent detection and isolation
11
11
* - State machine replication with conflict resolution
14
14
* - Integration with A2A security framework
15
15
* - Comprehensive fault injection testing
16
16
*
17
+ * Quorum Requirements:
18
+ * - Byzantine: Math.floor(2*n/3) + 1 (handles up to 33% malicious nodes)
19
+ * - Raft: Math.floor(n/2) + 1 (majority consensus)
20
+ * - Gossip: Configurable threshold (default 51%)
21
+ * - CRDT: No quorum needed (eventual consistency)
22
+ *
17
23
* @author AI Assistant
18
24
* @version 1.0.0
19
25
*/
@@ -28,6 +34,15 @@ export {
28
34
default as ByzantineConsensusDefault
29
35
} from './byzantine-consensus' ;
30
36
37
+ export {
38
+ RaftConsensus ,
39
+ RaftNode ,
40
+ LogEntry ,
41
+ RaftMessage ,
42
+ RaftState ,
43
+ default as RaftConsensusDefault
44
+ } from './raft-consensus' ;
45
+
31
46
export {
32
47
VotingMechanisms ,
33
48
Vote ,
@@ -92,6 +107,44 @@ export {
92
107
} from './consensus-security-integration' ;
93
108
94
109
// Utility types and constants
110
+ export const QUORUM_CALCULATIONS = {
111
+ /**
112
+ * Calculate Byzantine consensus quorum (2f + 1)
113
+ * @param totalAgents Total number of agents in the system
114
+ * @returns Minimum quorum size for Byzantine consensus
115
+ */
116
+ calculateByzantineQuorum : ( totalAgents : number ) : number => {
117
+ return Math . floor ( ( 2 * totalAgents ) / 3 ) + 1 ;
118
+ } ,
119
+
120
+ /**
121
+ * Calculate Raft consensus quorum (majority)
122
+ * @param totalAgents Total number of agents in the system
123
+ * @returns Minimum quorum size for Raft consensus
124
+ */
125
+ calculateRaftQuorum : ( totalAgents : number ) : number => {
126
+ return Math . floor ( totalAgents / 2 ) + 1 ;
127
+ } ,
128
+
129
+ /**
130
+ * Calculate gossip quorum based on threshold
131
+ * @param totalAgents Total number of agents in the system
132
+ * @param threshold Percentage threshold (0-1, default 0.51)
133
+ * @returns Minimum quorum size for gossip consensus
134
+ */
135
+ calculateGossipQuorum : ( totalAgents : number , threshold : number = 0.51 ) : number => {
136
+ return Math . ceil ( totalAgents * threshold ) ;
137
+ } ,
138
+
139
+ /**
140
+ * CRDT doesn't require quorum (eventual consistency)
141
+ * @returns Always 1 (any single node can make progress)
142
+ */
143
+ calculateCRDTQuorum : ( ) : number => {
144
+ return 1 ;
145
+ }
146
+ } ;
147
+
95
148
export const BYZANTINE_FAULT_TOLERANCE = {
96
149
/**
97
150
* Calculate the maximum number of faulty agents that can be tolerated
@@ -160,6 +213,28 @@ export const VOTING_TYPES = {
160
213
STAKE_WEIGHTED : 'stake-weighted' as const
161
214
} ;
162
215
216
+ /**
217
+ * Factory function to create a Raft consensus system
218
+ */
219
+ export function createRaftConsensusSystem (
220
+ nodeId : string ,
221
+ totalNodes : number = 3
222
+ ) : {
223
+ consensus : RaftConsensus ;
224
+ quorumSize : number ;
225
+ hasQuorum : boolean ;
226
+ } {
227
+ const consensus = new RaftConsensus ( nodeId , totalNodes ) ;
228
+ const quorumSize = QUORUM_CALCULATIONS . calculateRaftQuorum ( totalNodes ) ;
229
+ const hasQuorum = consensus . hasQuorum ( ) ;
230
+
231
+ return {
232
+ consensus,
233
+ quorumSize,
234
+ hasQuorum
235
+ } ;
236
+ }
237
+
163
238
/**
164
239
* Factory function to create a complete Byzantine consensus system
165
240
* with all components properly integrated
0 commit comments