Reconstruct an accumulator from a serialized graph.
(s: SerializedGraph)
| 185 | |
| 186 | /// Reconstruct an accumulator from a serialized graph. |
| 187 | fn from_serialized(s: SerializedGraph) -> Self { |
| 188 | let session_prefix = make_session_prefix(&s.session_id); |
| 189 | |
| 190 | // Rebuild commitments_since_last_patch by scanning nodes from the |
| 191 | // end backward to find commitment nodes that haven't been followed |
| 192 | // by a patch proposal. |
| 193 | let mut commitments_since_last_patch = Vec::new(); |
| 194 | for node in s.nodes.iter().rev() { |
| 195 | if node.kind == NodeKind::PatchProposal { |
| 196 | break; // Stop at the last patch proposal |
| 197 | } |
| 198 | if node.kind == NodeKind::Commitment { |
| 199 | commitments_since_last_patch.push(node.id.clone()); |
| 200 | } |
| 201 | } |
| 202 | commitments_since_last_patch.reverse(); |
| 203 | |
| 204 | let nodes_saved_count = s.nodes_saved_count.unwrap_or(s.nodes.len()); |
| 205 | let edges_saved_count = s.edges_saved_count.unwrap_or(s.edges.len()); |
| 206 | |
| 207 | Self { |
| 208 | session_id: s.session_id, |
| 209 | session_prefix, |
| 210 | nodes: s.nodes, |
| 211 | edges: s.edges, |
| 212 | stats: s.stats, |
| 213 | counter: s.counter, |
| 214 | current_goal: s.current_goal, |
| 215 | pending_explorations: s.pending_explorations, |
| 216 | last_commitment: s.last_commitment, |
| 217 | last_node: s.last_node, |
| 218 | pending_human_gate: s.pending_human_gate, |
| 219 | commitments_since_last_patch, |
| 220 | last_provenance_hash: s.last_provenance_hash, |
| 221 | nodes_saved_count, |
| 222 | edges_saved_count, |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // ========================================================================= |
| 227 | // Accessors |