mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
lightningd: Fix channel-persistence for channels with commits
I was hoping to defer HTLC updates until we actually store HTLCs, but we need to flush to DB whenever balances update as well. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
d3f36ba8ae
commit
4b64b7f2aa
3 changed files with 32 additions and 2 deletions
|
@ -887,6 +887,10 @@ static bool peer_save_commitsig_received(struct peer *peer, u64 commitnum)
|
|||
peer->next_index[LOCAL]++;
|
||||
|
||||
/* FIXME: Save to database, with sig and HTLCs. */
|
||||
if (!wallet_channel_save(peer->ld->wallet, peer->channel)) {
|
||||
fatal("Could not save channel to database: %s",
|
||||
peer->ld->wallet->db->err);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -903,6 +907,11 @@ static bool peer_save_commitsig_sent(struct peer *peer, u64 commitnum)
|
|||
peer->next_index[REMOTE]++;
|
||||
|
||||
/* FIXME: Save to database, with sig and HTLCs. */
|
||||
if (!wallet_channel_save(peer->ld->wallet, peer->channel)) {
|
||||
fatal("Could not save channel to database: %s",
|
||||
peer->ld->wallet->db->err);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1207,6 +1216,11 @@ int peer_got_revoke(struct peer *peer, const u8 *msg)
|
|||
hin = find_htlc_in(&peer->ld->htlcs_in, peer, changed[i].id);
|
||||
local_fail_htlc(hin, failcodes[i]);
|
||||
}
|
||||
if (!wallet_channel_save(peer->ld->wallet, peer->channel)) {
|
||||
fatal("Could not save channel to database: %s",
|
||||
peer->ld->wallet->db->err);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1022,11 +1022,17 @@ class LightningDTests(BaseLightningDTests):
|
|||
for n in (l1, l2):
|
||||
assert(n.db_query('SELECT COUNT(id) as count FROM channels;')[0]['count'] == 1)
|
||||
|
||||
# Perform a payment so we have something to restore
|
||||
self.pay(l1, l2, 10000)
|
||||
time.sleep(1)
|
||||
assert l1.rpc.getpeers()['peers'][0]['msatoshi_to_us'] == 99990000
|
||||
assert l2.rpc.getpeers()['peers'][0]['msatoshi_to_us'] == 10000
|
||||
|
||||
# Stop l2, l1 will reattempt to connect
|
||||
l2.daemon.stop()
|
||||
|
||||
# Let the other side notice, then stop it
|
||||
# Wait for l1 to notice
|
||||
wait_for(lambda: not l1.rpc.getpeers()['peers'][0]['connected'])
|
||||
#l1.daemon.stop()
|
||||
|
||||
# Now restart l1 and it should reload peers/channels from the DB
|
||||
l2.daemon.start()
|
||||
|
@ -1037,6 +1043,14 @@ class LightningDTests(BaseLightningDTests):
|
|||
|
||||
# Now make sure this is really functional by sending a payment
|
||||
self.pay(l1, l2, 10000)
|
||||
time.sleep(1)
|
||||
assert l1.rpc.getpeers()['peers'][0]['msatoshi_to_us'] == 99980000
|
||||
assert l2.rpc.getpeers()['peers'][0]['msatoshi_to_us'] == 20000
|
||||
|
||||
# Finally restart l1, and make sure it remembers
|
||||
l1.daemon.stop()
|
||||
l1.daemon.start()
|
||||
assert l1.rpc.getpeers()['peers'][0]['msatoshi_to_us'] == 99980000
|
||||
|
||||
class LegacyLightningDTests(BaseLightningDTests):
|
||||
|
||||
|
|
|
@ -61,6 +61,8 @@ class TailableProc(object):
|
|||
def stop(self):
|
||||
self.proc.terminate()
|
||||
self.proc.kill()
|
||||
self.proc.wait()
|
||||
self.thread.join()
|
||||
if self.outputDir:
|
||||
logpath = os.path.join(self.outputDir, 'log')
|
||||
with open(logpath, 'w') as f:
|
||||
|
|
Loading…
Add table
Reference in a new issue