In Neo4j Graph, How to Propagate Data from One Node to Other Nodes Directly or Indirectly Connected?

I'm working on clustering Bitcoin addresses using the multi-input heuristic, and I need to propagate entity information across connected nodes. Here's the scenario:

  1. I treat each unique Bitcoin address as a node in the graph.

  2. For transactions with multiple input addresses, I have addresses A1, A2, A3, A4, and A5. These addresses are connected with edges as follows:

    1. A1 is connected to A2
    2. A2 is connected to A3
    3. A3 is connected to A4
    4. A4 is connected to A5
      So, these 5 addresses form a connected cluster.
  3. Later, I find out that A2 belongs to Binance. I want to automatically propagate the entity name "Binance" across all connected nodes in this cluster. For instance, querying A5 should return the entity "Binance."

Questions:

  • In Neo4j, how can I propagate the entity label from A2 to all other nodes in the connected cluster (A1, A3, A4, A5) efficiently?
  • Is there a way to automatically assign the entity label to all nodes directly or indirectly connected to A2 without manually traversing the edges every time?
  • What would be the best approach in Neo4j (e.g., Cypher queries, triggers) to handle this for large-scale datasets like Bitcoin address clusters?

Any guidance or suggestions on how to implement this propagation would be greatly appreciated!

1 Like

I have a similar query.

You are going to have to traverse the edges.

This example cypher assumes a Bitcoin only belongs to one entity at a time.
This example has not been tested, but should give you one idea of how to do it.

MATCH (bitcoin:Bitcoin {address: $address})
MATCH (entity:Entity {name: $name})
OPTIONAL MATCH (bitcoin)-[belongsTo:BELONGS_TO]-(oldEntity:Entity) DELETE belongsTo
CREATE (bitcoin)-[:BELONGS_TO]->(entity)
WITH bitcoin, entity
// This MATCH will return each connected bitcoin in the cluster one at a time
// Note there is no direction on the relationship so it will go both ways through the linked list
MATCH (bitcoin)-[:CONNECTED_TO*]-(clusterBitcoin:Bitcoin)
OPTIONAL MATCH (clusterBitcoin)-[belongsTo:BELONGS_TO]-(oldEntity:Entity) DELETE belongsTo
CREATE (clusterBitcoin)-[:BELONGS_TO]->(entity)