mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
db: make db_set_visible_state called from within transaction.
We want to do this atomically; this is the first step. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
8c5fae2b28
commit
6acb4953b1
3 changed files with 7 additions and 8 deletions
|
@ -1350,13 +1350,13 @@ void db_set_anchor(struct peer *peer)
|
|||
tal_free(ctx);
|
||||
}
|
||||
|
||||
bool db_set_visible_state(struct peer *peer)
|
||||
void db_set_visible_state(struct peer *peer)
|
||||
{
|
||||
const char *errmsg, *ctx = tal_tmpctx(peer);
|
||||
const char *ctx = tal_tmpctx(peer);
|
||||
const char *peerid = pubkey_to_hexstr(ctx, peer->dstate->secpctx, peer->id);
|
||||
|
||||
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
||||
db_start_transaction(peer);
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO their_visible_state VALUES (x'%s', %s, x'%s', x'%s', %u, %u, %"PRIu64", x'%s');",
|
||||
|
@ -1372,10 +1372,7 @@ bool db_set_visible_state(struct peer *peer)
|
|||
tal_hexstr(ctx, &peer->remote.next_revocation_hash,
|
||||
sizeof(peer->remote.next_revocation_hash)));
|
||||
|
||||
errmsg = db_commit_transaction(peer);
|
||||
|
||||
tal_free(ctx);
|
||||
return !errmsg;
|
||||
}
|
||||
|
||||
void db_update_next_revocation_hash(struct peer *peer)
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
void db_init(struct lightningd_state *dstate);
|
||||
|
||||
bool db_create_peer(struct peer *peer);
|
||||
bool db_set_visible_state(struct peer *peer);
|
||||
|
||||
void db_start_transaction(struct peer *peer);
|
||||
void db_abort_transaction(struct peer *peer);
|
||||
|
@ -44,6 +43,7 @@ bool db_remove_invoice(struct lightningd_state *dstate,
|
|||
* which have to be inside transaction anyway. */
|
||||
|
||||
/* Must be inside transaction. */
|
||||
void db_set_visible_state(struct peer *peer);
|
||||
void db_set_anchor(struct peer *peer);
|
||||
void db_new_htlc(struct peer *peer, const struct htlc *htlc);
|
||||
void db_new_feechange(struct peer *peer, const struct feechange *feechange);
|
||||
|
|
4
state.c
4
state.c
|
@ -32,7 +32,9 @@ static Pkt *init_from_pkt_open(struct peer *peer, const Pkt *pkt)
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
if (!db_set_visible_state(peer))
|
||||
db_start_transaction(peer);
|
||||
db_set_visible_state(peer);
|
||||
if (db_commit_transaction(peer) != NULL)
|
||||
return pkt_err(peer, "Database error");
|
||||
|
||||
/* Set up their commit info now: rest gets done in setup_first_commit
|
||||
|
|
Loading…
Add table
Reference in a new issue