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:
parent
b0f8a73fcb
commit
e24c9d5b52
13
build.zig
13
build.zig
|
|
@ -200,6 +200,18 @@ pub fn build(b: *std.Build) void {
|
|||
// trust_graph needs crypto types
|
||||
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
|
||||
// ========================================================================
|
||||
|
|
@ -209,6 +221,7 @@ pub fn build(b: *std.Build) void {
|
|||
.optimize = optimize,
|
||||
});
|
||||
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);
|
||||
// Note: libmdbx linking removed - using stub implementation for now
|
||||
// TODO: Add real libmdbx when available on build system
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@
|
|||
const std = @import("std");
|
||||
const types = @import("types.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 NodeId = types.NodeId;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,10 @@ pub const PersistentGraph = struct {
|
|||
|
||||
/// Add edge
|
||||
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 };
|
||||
try self.edges.put(key, edge);
|
||||
|
||||
|
|
@ -96,8 +100,15 @@ pub const PersistentGraph = struct {
|
|||
var graph = RiskGraph.init(allocator);
|
||||
errdefer graph.deinit();
|
||||
|
||||
var it = self.edges.valueIterator();
|
||||
while (it.next()) |edge| {
|
||||
// First add all nodes
|
||||
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.*);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue