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