fix(storage): add nodes when adding edges in PersistentGraph

- toRiskGraph now properly adds all nodes before edges
- addEdge now registers from/to nodes automatically
- Fixes betrayal detection test by ensuring nodes exist in graph
This commit is contained in:
Markus Maiwald 2026-02-03 13:11:30 +01:00
parent b0f8a73fcb
commit e24c9d5b52
3 changed files with 28 additions and 3 deletions

View File

@ -200,6 +200,18 @@ pub fn build(b: *std.Build) void {
// trust_graph needs crypto types // trust_graph needs crypto types
l1_trust_graph_mod.addImport("crypto", l1_mod); l1_trust_graph_mod.addImport("crypto", l1_mod);
// ========================================================================
// L1 Proof of Path Module (PoP)
// ========================================================================
const l1_pop_mod = b.createModule(.{
.root_source_file = b.path("l1-identity/proof_of_path.zig"),
.target = target,
.optimize = optimize,
});
l1_pop_mod.addImport("trust_graph", l1_trust_graph_mod);
l1_pop_mod.addImport("time", time_mod);
l1_pop_mod.addImport("soulkey", l1_soulkey_mod);
// ======================================================================== // ========================================================================
// L1 QVL (Quasar Vector Lattice) - Advanced Graph Engine // L1 QVL (Quasar Vector Lattice) - Advanced Graph Engine
// ======================================================================== // ========================================================================
@ -209,6 +221,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize, .optimize = optimize,
}); });
l1_qvl_mod.addImport("trust_graph", l1_trust_graph_mod); l1_qvl_mod.addImport("trust_graph", l1_trust_graph_mod);
l1_qvl_mod.addImport("proof_of_path", l1_pop_mod);
l1_qvl_mod.addImport("time", time_mod); l1_qvl_mod.addImport("time", time_mod);
// Note: libmdbx linking removed - using stub implementation for now // Note: libmdbx linking removed - using stub implementation for now
// TODO: Add real libmdbx when available on build system // TODO: Add real libmdbx when available on build system

View File

@ -11,7 +11,8 @@
const std = @import("std"); const std = @import("std");
const types = @import("types.zig"); const types = @import("types.zig");
const pathfinding = @import("pathfinding.zig"); const pathfinding = @import("pathfinding.zig");
const pop = @import("proof_of_path"); // Import proof_of_path relative from qvl directory
const pop = @import("../proof_of_path.zig");
const trust_graph = @import("trust_graph"); const trust_graph = @import("trust_graph");
const NodeId = types.NodeId; const NodeId = types.NodeId;

View File

@ -65,6 +65,10 @@ pub const PersistentGraph = struct {
/// Add edge /// Add edge
pub fn addEdge(self: *Self, edge: RiskEdge) !void { pub fn addEdge(self: *Self, edge: RiskEdge) !void {
// Register nodes first
try self.nodes.put(edge.from, {});
try self.nodes.put(edge.to, {});
const key = EdgeKey{ .from = edge.from, .to = edge.to }; const key = EdgeKey{ .from = edge.from, .to = edge.to };
try self.edges.put(key, edge); try self.edges.put(key, edge);
@ -96,8 +100,15 @@ pub const PersistentGraph = struct {
var graph = RiskGraph.init(allocator); var graph = RiskGraph.init(allocator);
errdefer graph.deinit(); errdefer graph.deinit();
var it = self.edges.valueIterator(); // First add all nodes
while (it.next()) |edge| { var node_it = self.nodes.keyIterator();
while (node_it.next()) |node| {
try graph.addNode(node.*);
}
// Then add all edges
var edge_it = self.edges.valueIterator();
while (edge_it.next()) |edge| {
try graph.addEdge(edge.*); try graph.addEdge(edge.*);
} }