Skip to content

Commit

Permalink
lightningd: handle old Tor version 2 addresses in db without crashing.
Browse files Browse the repository at this point in the history
In non-developer mode, this results in:

   "Could not load channels from the database"

Fixes: #5238
Signed-off-by: Rusty Russell <[email protected]>
Changelog-Fixed: lightningd: fix failed startup "Could not load channels from the database" if old TORv2 addresses were present.
  • Loading branch information
rustyrussell committed Jun 21, 2022
1 parent eead41a commit 04c8915
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@
"ListPeers.peers[].features": 6,
"ListPeers.peers[].id": 1,
"ListPeers.peers[].log[]": 3,
"ListPeers.peers[].netaddr[]": 5
"ListPeers.peers[].netaddr[]": 5,
"ListPeers.peers[].remote_addr": 7
},
"ListpeersPeersChannels": {
"ListPeers.peers[].channels[].channel_id": 6,
Expand Down
1 change: 1 addition & 0 deletions cln-grpc/proto/node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ message ListpeersPeers {
repeated ListpeersPeersLog log = 3;
repeated ListpeersPeersChannels channels = 4;
repeated string netaddr = 5;
optional string remote_addr = 7;
optional bytes features = 6;
}

Expand Down
1 change: 1 addition & 0 deletions cln-grpc/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ impl From<&responses::ListpeersPeers> for pb::ListpeersPeers {
log: c.log.as_ref().map(|arr| arr.iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
channels: c.channels.iter().map(|i| i.into()).collect(), // Rule #3 for type ListpeersPeersChannels
netaddr: c.netaddr.as_ref().map(|arr| arr.iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
remote_addr: c.remote_addr.clone(), // Rule #2 for type string?
features: c.features.as_ref().map(|v| hex::decode(&v).unwrap()), // Rule #2 for type hex?
}
}
Expand Down
2 changes: 2 additions & 0 deletions cln-rpc/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,8 @@ pub mod responses {
pub channels: Vec<ListpeersPeersChannels>,
#[serde(alias = "netaddr", skip_serializing_if = "Option::is_none")]
pub netaddr: Option<Vec<String>>,
#[serde(alias = "remote_addr", skip_serializing_if = "Option::is_none")]
pub remote_addr: Option<String>,
#[serde(alias = "features", skip_serializing_if = "Option::is_none")]
pub features: Option<String>,
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2607,7 +2607,6 @@ def test_datastore_keylist(node_factory):
'hex': b'ab2val2'.hex()}]}


@pytest.mark.xfail(strict=True)
def test_torv2_in_db(node_factory):
l1, l2 = node_factory.line_graph(2, wait_for_announce=True)

Expand Down
9 changes: 7 additions & 2 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,15 @@ static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid)

db_col_node_id(stmt, "node_id", &id);

/* This can happen for peers last seen on Torv2! */
addrstr = db_col_strdup(tmpctx, stmt, "address");
if (!parse_wireaddr_internal(addrstr, &addr, DEFAULT_PORT,
false, false, true, true, NULL))
goto done;
false, false, true, true, NULL)) {
log_unusual(w->log, "Unparsable peer address %s: replacing",
addrstr);
parse_wireaddr_internal("127.0.0.1:1", &addr, DEFAULT_PORT,
false, false, true, true, NULL);
}

/* FIXME: save incoming in db! */
peer = new_peer(w->ld, db_col_u64(stmt, "id"), &id, &addr, false);
Expand Down

0 comments on commit 04c8915

Please sign in to comment.