mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
wallet: Moving wallet_channel->peer_id into the peer struct
This was supposed to be a temporary solution anyway, and I had a rather annoying mixup between peer_id and unique_id, the latter of which is actually a connection identifier.
This commit is contained in:
parent
29785d4990
commit
4bc0750882
5 changed files with 12 additions and 11 deletions
|
@ -541,7 +541,6 @@ static struct wallet_channel *peer_channel_new(struct wallet *w,
|
||||||
wc->peer = peer;
|
wc->peer = peer;
|
||||||
|
|
||||||
/* TODO(cdecker) See if we already stored this peer in the DB and load if yes */
|
/* TODO(cdecker) See if we already stored this peer in the DB and load if yes */
|
||||||
wc->peer_id = 0;
|
|
||||||
wc->id = 0;
|
wc->id = 0;
|
||||||
|
|
||||||
if (!wallet_channel_save(w, wc)) {
|
if (!wallet_channel_save(w, wc)) {
|
||||||
|
|
|
@ -20,6 +20,9 @@ struct crypto_state;
|
||||||
struct peer {
|
struct peer {
|
||||||
struct lightningd *ld;
|
struct lightningd *ld;
|
||||||
|
|
||||||
|
/* Database ID of the peer */
|
||||||
|
u64 dbid;
|
||||||
|
|
||||||
/* Unique ID of connection (works even if we have multiple to same id) */
|
/* Unique ID of connection (works even if we have multiple to same id) */
|
||||||
u64 unique_id;
|
u64 unique_id;
|
||||||
|
|
||||||
|
|
|
@ -395,7 +395,7 @@ static bool wallet_peer_load(struct wallet *w, const u64 id, struct peer *peer)
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
peer->unique_id = sqlite3_column_int64(stmt, 0);
|
peer->dbid = sqlite3_column_int64(stmt, 0);
|
||||||
ok &= sqlite3_column_pubkey(stmt, 1, &peer->id);
|
ok &= sqlite3_column_pubkey(stmt, 1, &peer->id);
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
return ok;
|
return ok;
|
||||||
|
@ -420,8 +420,8 @@ static bool wallet_stmt2channel(struct wallet *w, sqlite3_stmt *stmt,
|
||||||
chan->peer = talz(chan, struct peer);
|
chan->peer = talz(chan, struct peer);
|
||||||
}
|
}
|
||||||
chan->peer->unique_id = sqlite3_column_int64(stmt, col++);
|
chan->peer->unique_id = sqlite3_column_int64(stmt, col++);
|
||||||
chan->peer_id = sqlite3_column_int64(stmt, col++);
|
chan->peer->dbid = sqlite3_column_int64(stmt, col++);
|
||||||
wallet_peer_load(w, chan->peer_id, chan->peer);
|
wallet_peer_load(w, chan->peer->dbid, chan->peer);
|
||||||
|
|
||||||
if (sqlite3_column_short_channel_id(stmt, col++, &scid)) {
|
if (sqlite3_column_short_channel_id(stmt, col++, &scid)) {
|
||||||
chan->peer->scid = tal(chan->peer, struct short_channel_id);
|
chan->peer->scid = tal(chan->peer, struct short_channel_id);
|
||||||
|
@ -649,19 +649,19 @@ bool wallet_channel_save(struct wallet *w, struct wallet_channel *chan){
|
||||||
struct peer *p = chan->peer;
|
struct peer *p = chan->peer;
|
||||||
tal_t *tmpctx = tal_tmpctx(w);
|
tal_t *tmpctx = tal_tmpctx(w);
|
||||||
|
|
||||||
if (chan->peer_id == 0) {
|
if (p->dbid == 0) {
|
||||||
/* Need to store the peer first */
|
/* Need to store the peer first */
|
||||||
ok &= db_exec(__func__, w->db,
|
ok &= db_exec(__func__, w->db,
|
||||||
"INSERT INTO peers (node_id) VALUES ('%s');",
|
"INSERT INTO peers (node_id) VALUES ('%s');",
|
||||||
db_serialize_pubkey(tmpctx, &chan->peer->id));
|
db_serialize_pubkey(tmpctx, &chan->peer->id));
|
||||||
chan->peer_id = sqlite3_last_insert_rowid(w->db->sql);
|
p->dbid = sqlite3_last_insert_rowid(w->db->sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
db_begin_transaction(w->db);
|
db_begin_transaction(w->db);
|
||||||
|
|
||||||
/* Insert a stub, that we can update, unifies INSERT and UPDATE paths */
|
/* Insert a stub, that we can update, unifies INSERT and UPDATE paths */
|
||||||
if (chan->id == 0) {
|
if (chan->id == 0) {
|
||||||
ok &= db_exec(__func__, w->db, "INSERT INTO channels (peer_id) VALUES (%"PRIu64");", chan->peer_id);
|
ok &= db_exec(__func__, w->db, "INSERT INTO channels (peer_id) VALUES (%"PRIu64");", p->dbid);
|
||||||
chan->id = sqlite3_last_insert_rowid(w->db->sql);
|
chan->id = sqlite3_last_insert_rowid(w->db->sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@ struct wallet_shachain {
|
||||||
/* TODO(cdecker) Separate peer from channel */
|
/* TODO(cdecker) Separate peer from channel */
|
||||||
struct wallet_channel {
|
struct wallet_channel {
|
||||||
u64 id;
|
u64 id;
|
||||||
u64 peer_id;
|
|
||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ static bool channelseq(struct wallet_channel *c1, struct wallet_channel *c2)
|
||||||
struct channel_info *ci1 = p1->channel_info, *ci2 = p2->channel_info;
|
struct channel_info *ci1 = p1->channel_info, *ci2 = p2->channel_info;
|
||||||
struct changed_htlc *lc1 = p1->last_sent_commit, *lc2 = p2->last_sent_commit;
|
struct changed_htlc *lc1 = p1->last_sent_commit, *lc2 = p2->last_sent_commit;
|
||||||
CHECK(c1->id == c2->id);
|
CHECK(c1->id == c2->id);
|
||||||
CHECK(c1->peer_id == c2->peer_id);
|
CHECK(c1->peer->dbid == c2->peer->dbid);
|
||||||
CHECK(p1->their_shachain.id == p2->their_shachain.id);
|
CHECK(p1->their_shachain.id == p2->their_shachain.id);
|
||||||
CHECK_MSG(pubkey_eq(&p1->id, &p2->id), "NodeIDs do not match");
|
CHECK_MSG(pubkey_eq(&p1->id, &p2->id), "NodeIDs do not match");
|
||||||
CHECK((p1->scid == NULL && p2->scid == NULL) || short_channel_id_eq(p1->scid, p2->scid));
|
CHECK((p1->scid == NULL && p2->scid == NULL) || short_channel_id_eq(p1->scid, p2->scid));
|
||||||
|
@ -221,7 +221,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||||
|
|
||||||
/* We just inserted them into an empty DB so this must be 1 */
|
/* We just inserted them into an empty DB so this must be 1 */
|
||||||
CHECK(c1.id == 1);
|
CHECK(c1.id == 1);
|
||||||
CHECK(c1.peer_id == 1);
|
CHECK(c1.peer->dbid == 1);
|
||||||
CHECK(c1.peer->their_shachain.id == 1);
|
CHECK(c1.peer->their_shachain.id == 1);
|
||||||
|
|
||||||
/* Variant 2: update with scid set */
|
/* Variant 2: update with scid set */
|
||||||
|
@ -232,7 +232,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||||
|
|
||||||
/* Updates should not result in new ids */
|
/* Updates should not result in new ids */
|
||||||
CHECK(c1.id == 1);
|
CHECK(c1.id == 1);
|
||||||
CHECK(c1.peer_id == 1);
|
CHECK(c1.peer->dbid == 1);
|
||||||
CHECK(c1.peer->their_shachain.id == 1);
|
CHECK(c1.peer->their_shachain.id == 1);
|
||||||
|
|
||||||
/* Variant 3: update with our_satoshi set */
|
/* Variant 3: update with our_satoshi set */
|
||||||
|
|
Loading…
Add table
Reference in a new issue