Skip to content

Commit 1464a63

Browse files
committed
Persist feature bits across restarts
1 parent 1e457bd commit 1464a63

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

lightningd/opening_control.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,7 @@ static struct channel *stub_chan(struct command *cmd,
13511351
0,
13521352
&nodeid,
13531353
&wint,
1354+
NULL,
13541355
false);
13551356
}
13561357

lightningd/peer_control.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ void peer_set_dbid(struct peer *peer, u64 dbid)
9494
struct peer *new_peer(struct lightningd *ld, u64 dbid,
9595
const struct node_id *id,
9696
const struct wireaddr_internal *addr,
97+
const u8 *their_features,
9798
bool connected_incoming)
9899
{
99100
/* We are owned by our channels, and freed manually by destroy_channel */
@@ -112,6 +113,9 @@ struct peer *new_peer(struct lightningd *ld, u64 dbid,
112113
peer->connected = PEER_DISCONNECTED;
113114
peer->last_connect_attempt.ts.tv_sec
114115
= peer->last_connect_attempt.ts.tv_nsec = 0;
116+
if (their_features)
117+
peer_update_features(peer, their_features);
118+
115119
#if DEVELOPER
116120
peer->ignore_htlcs = false;
117121
#endif
@@ -1403,7 +1407,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg)
14031407
peer = peer_by_id(ld, &id);
14041408
if (!peer)
14051409
peer = new_peer(ld, 0, &id, &hook_payload->addr,
1406-
hook_payload->incoming);
1410+
NULL, hook_payload->incoming);
14071411

14081412
/* We track this, because messages can race between connectd and us.
14091413
* For example, we could tell it to attach a subd, but it's actually

lightningd/peer_control.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct peer *find_peer_by_dbid(struct lightningd *ld, u64 dbid);
7373
struct peer *new_peer(struct lightningd *ld, u64 dbid,
7474
const struct node_id *id,
7575
const struct wireaddr_internal *addr,
76+
const u8 *their_features,
7677
bool connected_incoming);
7778

7879
/* Last one out deletes peer. Also removes from db. */

wallet/db.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ static struct migration dbmigrations[] = {
949949
{NULL, migrate_invalid_last_tx_psbts},
950950
{SQL("ALTER TABLE channels ADD channel_type BLOB DEFAULT NULL;"), NULL},
951951
{NULL, migrate_fill_in_channel_type},
952+
{SQL("ALTER TABLE peers ADD feature_bits BLOB DEFAULT NULL;"), NULL},
952953
};
953954

954955
/**

wallet/test/run-wallet.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
11721172

11731173
/* Add another utxo that's CSV-locked for 5 blocks */
11741174
assert(parse_wireaddr_internal(tmpctx, "localhost:1234", 0, false, &addr) == NULL);
1175-
channel.peer = new_peer(ld, 0, &id, &addr, false);
1175+
channel.peer = new_peer(ld, 0, &id, &addr, NULL, false);
11761176
channel.dbid = 1;
11771177
channel.type = channel_type_anchor_outputs(tmpctx);
11781178
memset(&u.outpoint, 3, sizeof(u.outpoint));
@@ -1502,7 +1502,7 @@ static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx)
15021502
c1.first_blocknum = 1;
15031503
assert(parse_wireaddr_internal(tmpctx, "localhost:1234", 0, false, &addr) == NULL);
15041504
c1.final_key_idx = 1337;
1505-
p = new_peer(ld, 0, &id, &addr, false);
1505+
p = new_peer(ld, 0, &id, &addr, NULL, false);
15061506
c1.peer = p;
15071507
c1.dbid = wallet_get_channel_dbid(w);
15081508
c1.state = CHANNELD_NORMAL;
@@ -1665,7 +1665,7 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
16651665
assert(parse_wireaddr_internal(tmpctx, "localhost:1234", 0, false, &addr) == NULL);
16661666

16671667
/* new channel! */
1668-
p = new_peer(ld, 0, &id, &addr, false);
1668+
p = new_peer(ld, 0, &id, &addr, NULL, false);
16691669

16701670
funding_sats = AMOUNT_SAT(4444444);
16711671
our_sats = AMOUNT_SAT(3333333);

wallet/wallet.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid)
859859
struct db_stmt *stmt;
860860

861861
stmt = db_prepare_v2(
862-
w->db, SQL("SELECT id, node_id, address FROM peers WHERE id=?;"));
862+
w->db, SQL("SELECT id, node_id, address, feature_bits FROM peers WHERE id=?;"));
863863
db_bind_u64(stmt, 0, dbid);
864864
db_query_prepared(stmt);
865865

@@ -869,6 +869,7 @@ static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid)
869869
if (db_col_is_null(stmt, "node_id")) {
870870
db_col_ignore(stmt, "address");
871871
db_col_ignore(stmt, "id");
872+
db_col_ignore(stmt, "feature_bits");
872873
goto done;
873874
}
874875

@@ -886,7 +887,7 @@ static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid)
886887
}
887888

888889
/* FIXME: save incoming in db! */
889-
peer = new_peer(w->ld, db_col_u64(stmt, "id"), &id, &addr, false);
890+
peer = new_peer(w->ld, db_col_u64(stmt, "id"), &id, &addr, db_col_arr(stmt, stmt, "feature_bits", u8), false);
890891

891892
done:
892893
tal_free(stmt);
@@ -2271,21 +2272,23 @@ static void wallet_peer_save(struct wallet *w, struct peer *peer)
22712272
peer_set_dbid(peer, db_col_u64(stmt, "id"));
22722273
tal_free(stmt);
22732274

2274-
/* Since we're at it update the wireaddr */
2275+
/* Since we're at it update the wireaddr, feature bits */
22752276
stmt = db_prepare_v2(
2276-
w->db, SQL("UPDATE peers SET address = ? WHERE id = ?"));
2277+
w->db, SQL("UPDATE peers SET address = ?, feature_bits = ? WHERE id = ?"));
22772278
db_bind_text(stmt, 0, addr);
22782279
db_bind_u64(stmt, 1, peer->dbid);
2280+
db_bind_talarr(stmt, 2, peer->their_features);
22792281
db_exec_prepared_v2(take(stmt));
22802282

22812283
} else {
22822284
/* Unknown peer, create it from scratch */
22832285
tal_free(stmt);
22842286
stmt = db_prepare_v2(w->db,
2285-
SQL("INSERT INTO peers (node_id, address) VALUES (?, ?);")
2287+
SQL("INSERT INTO peers (node_id, address, feature_bits) VALUES (?, ?, ?);")
22862288
);
22872289
db_bind_node_id(stmt, 0, &peer->id);
22882290
db_bind_text(stmt, 1,addr);
2291+
db_bind_talarr(stmt, 2, peer->their_features);
22892292
db_exec_prepared_v2(stmt);
22902293
peer_set_dbid(peer, db_last_insert_id_v2(take(stmt)));
22912294
}

0 commit comments

Comments
 (0)