wallet: Add last_was_revoke to channels

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-01-13 14:25:49 +01:00
parent 44f9863192
commit cc77012f63
3 changed files with 11 additions and 3 deletions

View File

@ -156,6 +156,7 @@ char *dbmigrations[] = {
"ALTER TABLE invoices ADD COLUMN msatoshi_received INTEGER;",
/* Normally impossible, so at least we'll know if databases are ancient. */
"UPDATE invoices SET msatoshi_received=0 WHERE state=1;",
"ALTER TABLE channels ADD COLUMN last_was_revoke INTEGER;",
NULL,
};

View File

@ -281,6 +281,8 @@ static bool channelseq(struct wallet_channel *c1, struct wallet_channel *c2)
CHECK(p1->local_shutdown_idx == p2->local_shutdown_idx);
}
CHECK(p1->last_was_revoke == p2->last_was_revoke);
return true;
}
@ -373,6 +375,7 @@ static bool test_channel_crud(const tal_t *ctx)
/* Variant 3: update with our_satoshi set */
c1.peer->our_msatoshi = &msat;
c1.peer->last_was_revoke = !c1.peer->last_was_revoke;
wallet_channel_save(w, &c1, 0);
CHECK_MSG(!wallet_err, tal_fmt(w, "Insert into DB: %s", wallet_err));

View File

@ -571,6 +571,8 @@ static bool wallet_stmt2channel(const tal_t *ctx, struct wallet *w, sqlite3_stmt
chan->peer->last_sig = tal_free(chan->peer->last_sig);
}
chan->peer->last_was_revoke = sqlite3_column_int(stmt, 34) != 0;
chan->peer->channel = chan;
return ok;
@ -591,7 +593,7 @@ static const char *channel_fields =
"old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, "
"shutdown_scriptpubkey_remote, shutdown_keyidx_local, "
"last_sent_commit_state, last_sent_commit_id, "
"last_tx, last_sig";
"last_tx, last_sig, last_was_revoke";
bool wallet_channels_load_active(const tal_t *ctx, struct wallet *w, struct list_head *peers)
{
@ -745,7 +747,8 @@ void wallet_channel_save(struct wallet *w, struct wallet_channel *chan,
" shutdown_scriptpubkey_remote=?,"
" shutdown_keyidx_local=?,"
" channel_config_local=?,"
" last_tx=?, last_sig=?"
" last_tx=?, last_sig=?,"
" last_was_revoke=?"
" WHERE id=?");
sqlite3_bind_int64(stmt, 1, p->their_shachain.id);
if (p->scid)
@ -781,7 +784,8 @@ void wallet_channel_save(struct wallet *w, struct wallet_channel *chan,
sqlite3_bind_tx(stmt, 19, p->last_tx);
if (p->last_sig)
sqlite3_bind_signature(stmt, 20, p->last_sig);
sqlite3_bind_int64(stmt, 21, chan->id);
sqlite3_bind_int(stmt, 21, p->last_was_revoke);
sqlite3_bind_int64(stmt, 22, chan->id);
db_exec_prepared(w->db, stmt);
if (chan->peer->channel_info) {