Browse Source

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>
ppa-0.6.1
Christian Decker 8 years ago
committed by Rusty Russell
parent
commit
4b64b7f2aa
  1. 14
      lightningd/peer_htlcs.c
  2. 18
      tests/test_lightningd.py
  3. 2
      tests/utils.py

14
lightningd/peer_htlcs.c

@ -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;
}

18
tests/test_lightningd.py

@ -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):

2
tests/utils.py

@ -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…
Cancel
Save