| 68 | |
| 69 | impl SelfHealingDatabase { |
| 70 | fn new(num_nodes: usize) -> Self { |
| 71 | let quorum_size = (num_nodes / 2) + 1; |
| 72 | |
| 73 | let mut nodes = Vec::new(); |
| 74 | for i in 0..num_nodes { |
| 75 | nodes.push(DatabaseNode { |
| 76 | id: AgentId::from_u64(i as u64), |
| 77 | arena: Arena::new(), |
| 78 | data: HashMap::new(), |
| 79 | health: NodeHealth::Healthy, |
| 80 | recovery_strategy: RecoveryStrategy { |
| 81 | consistency_proof: None, |
| 82 | steps: vec![], |
| 83 | }, |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | Self { |
| 88 | nodes, |
| 89 | arena: Arena::new(), |
| 90 | symbols: SymbolTable::new(), |
| 91 | env: Environment::new(), |
| 92 | quorum_size, |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /// Write with Byzantine fault tolerance and consistency proof |
| 97 | fn verified_write(&mut self, key: String, value: String) -> Result<ConsistencyProof, String> { |