From 4151537b7169b0c56032a62c2369fec5ac3f1737 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 8 Nov 2016 21:59:55 +1030 Subject: [PATCH] peer: commit outstanding changes before sending PKT_CLOSE. Pierre points out that we don't handle this, and it can happen due to race; the spec says we are not supposed to send PKT_CLOSE with uncommitted changes. Closes: #29 Reported-by: Pierre-Marie Padiou Signed-off-by: Rusty Russell --- daemon/peer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/daemon/peer.c b/daemon/peer.c index 7084a3139..9d240444e 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -1529,6 +1529,10 @@ static bool peer_start_shutdown(struct peer *peer) enum state newstate; u8 *redeemscript; + /* We might have uncommited changes; if so, commit them now. */ + if (!do_commit(peer, NULL)) + return false; + db_start_transaction(peer); db_begin_shutdown(peer);