<p>if you invest some programming time you can use the <code>listchannels</code> command to retrieve all channels of the lightning network from the gossip store. No you could store them in the <code>networkx</code> lib</p>

<pre><code>import networkx as nx
network = ln.listchannels()
nx.Graph()                                                                                                                 
for channel in network:                                                                                                        
    G.add_edge(channel["source"],                                                                                              
               channel["destination"],                                                                                         
               **channel)
</code></pre>

<p>and then you could use <a href="https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.algorithms.simple_paths.all_simple_paths.html#networkx.algorithms.simple_paths.all_simple_paths" rel="nofollow noreferrer">this algorithm</a> from the networkx library to get a generator for all paths between a source and a destination rout. Since the lightning network will most likely have cycles you need to define a cutoff. While 20 is to long from a computational point of view it is also the <a href="https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md#conventions" rel="nofollow noreferrer">the maximum path length an onion packet supports according to BOLT 04</a>.</p>

<blockquote>
  <p>Length: the maximum route length is limited to 20 hops.</p>
</blockquote>

CC BY-SA 4.0
2019-03-03T14:35:09.843Z
2019-03-03T14:35:09.843Z
Rene Pickhardt
<p>I'm trying to write some services on top of c-lightning and I need to check if certain payments hit certain nodes. </p>

<blockquote>
  <p>lightning-cli getroute nodeid amount riskfactor</p>
</blockquote>

<p>This gives me a randomly selected single route out of potential two routes.</p>

<p>Is it possible for me to get all potential routes and decide for myself?</p>

<lightning-network><lightning-routing><core-lightning>
How to get all potential routes in c-lightning?
pseudozach
# How to get all potential routes in c-lightning?

(Asked by: username_0 on 2019-03-03)

I'm trying to write some services on top of c-lightning and I need to check if certain payments hit certain nodes.

> lightning-cli getroute nodeid amount riskfactor

This gives me a randomly selected single route out of potential two routes.

Is it possible for me to get all potential routes and decide for myself?

**Tags:** lightning-network, lightning-routing, core-lightning


---

## 1 answers

### Answer by username_1 on 2019-03-03. Score: 1 | Accepted answer

if you invest some programming time you can use the `listchannels` command to retrieve all channels of the lightning network from the gossip store. No you could store them in the `networkx` lib

```
import networkx as nx
network = ln.listchannels()
nx.Graph()                                                                                                                 
for channel in network:                                                                                                        
    G.add_edge(channel["source"],                                                                                              
               channel["destination"],                                                                                         
               **channel)

```

and then you could use [this algorithm](https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.algorithms.simple_paths.all_simple_paths.html#networkx.algorithms.simple_paths.all_simple_paths) from the networkx library to get a generator for all paths between a source and a destination rout. Since the lightning network will most likely have cycles you need to define a cutoff. While 20 is to long from a computational point of view it is also the [the maximum path length an onion packet supports according to BOLT 04](https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md#conventions).

> Length: the maximum route length is limited to 20 hops.


---

