Skip to content

Implement Incremental Graph Update Mechanism for Real-Time Node and Edge Additions to Wallet Graph #203

Description

@Inkman007

Description

The wallet graph in detection/wallet_graph.py is currently rebuilt from scratch on each scoring cycle. For large graphs (10,000+ wallets), a full rebuild takes several seconds and creates a gap in real-time detection. An incremental update mechanism would add new wallet nodes and trade edges to the existing graph without a full rebuild, enabling continuous real-time graph maintenance.

What needs to be built

  • Add add_trade_edge(src_wallet, dst_wallet, trade) and remove_stale_edges(max_age_hours) methods to the graph builder in detection/wallet_graph.py.
  • Implement an in-memory graph cache (detection/feature_cache.py already exists — extend it) that holds the current graph state and is updated incrementally.
  • For GNN inference, implement a 2-hop subgraph extraction (get_ego_subgraph(wallet_id, hops=2)) that returns only the neighbourhood needed for a single wallet's embedding, avoiding full-graph reprocessing.
  • Expose graph size metrics (nodes, edges, stale edge count) as Prometheus gauges.

Requirements

Functional

  • Edge additions must be O(1) amortised per edge.
  • Stale edge removal must run as a background scheduled task (GRAPH_STALE_EDGE_MAX_AGE_HOURS, default 168).
  • Ego subgraph extraction must complete in < 10ms for wallets with up to 500 direct neighbours.

Testing

  • Unit test: add 1000 edges incrementally; confirm graph is identical to one built from scratch with the same edges.
  • Test: remove stale edges older than 1 hour; confirm the correct edges are removed.
  • Performance test: ego subgraph extraction for a high-degree wallet (500 neighbours) completes in < 10ms.

Security

  • Wallet IDs used as graph node keys must be normalised to lowercase Stellar address format to prevent duplicate nodes from capitalisation variants.

Documentation

  • Add a section to docs/gnn_architecture.md explaining the incremental update strategy and the staleness policy.

Contributor guidance

Area of specialty: Graph data structures, Python (NetworkX or PyTorch Geometric), real-time systems.

How to contribute:

  1. Comment describing your experience with incremental graph maintenance or dynamic graph algorithms.
  2. Propose how to handle a trade that links two previously disconnected graph components.
  3. PR must include the equivalence test (incremental == batch-built) and the ego subgraph performance test.

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions