mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 23:54:22 +01:00
invoice: don't allow payments in expired invoices.
Fixes: #363 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
e302d6193c
commit
35a6ab8151
@@ -15,6 +15,7 @@ struct invoice_waiter {
|
|||||||
struct command *cmd;
|
struct command *cmd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* FIXME: remove this, just use database ops. */
|
||||||
struct invoices {
|
struct invoices {
|
||||||
/* Payments for r values we know about. */
|
/* Payments for r values we know about. */
|
||||||
struct list_head invlist;
|
struct list_head invlist;
|
||||||
@@ -27,9 +28,12 @@ struct invoice *find_unpaid(struct invoices *invs, const struct sha256 *rhash)
|
|||||||
struct invoice *i;
|
struct invoice *i;
|
||||||
|
|
||||||
list_for_each(&invs->invlist, i, list) {
|
list_for_each(&invs->invlist, i, list) {
|
||||||
if (structeq(rhash, &i->rhash) && i->state == UNPAID)
|
if (structeq(rhash, &i->rhash) && i->state == UNPAID) {
|
||||||
|
if (time_now().ts.tv_sec > i->expiry_time)
|
||||||
|
break;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -314,6 +314,24 @@ class LightningDTests(BaseLightningDTests):
|
|||||||
assert b11['expiry'] == 3600
|
assert b11['expiry'] == 3600
|
||||||
assert b11['payee'] == l1.info['id']
|
assert b11['payee'] == l1.info['id']
|
||||||
|
|
||||||
|
def test_invoice_expiry(self):
|
||||||
|
l1,l2 = self.connect()
|
||||||
|
|
||||||
|
chanid = self.fund_channel(l1, l2, 10**6)
|
||||||
|
|
||||||
|
# Wait for route propagation.
|
||||||
|
bitcoind.rpc.generate(5)
|
||||||
|
l1.daemon.wait_for_logs(['Received channel_update for channel {}\(0\)'
|
||||||
|
.format(chanid),
|
||||||
|
'Received channel_update for channel {}\(1\)'
|
||||||
|
.format(chanid)])
|
||||||
|
|
||||||
|
inv = l2.rpc.invoice(123000, 'test_pay', 'description', 1)['bolt11']
|
||||||
|
time.sleep(2)
|
||||||
|
self.assertRaises(ValueError, l1.rpc.pay, inv)
|
||||||
|
assert l2.rpc.listinvoice('test_pay')[0]['complete'] == False
|
||||||
|
assert l2.rpc.listinvoice('test_pay')[0]['expiry_time'] < time.time()
|
||||||
|
|
||||||
def test_connect(self):
|
def test_connect(self):
|
||||||
l1,l2 = self.connect()
|
l1,l2 = self.connect()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user