wallet: correct CSV check in deep_enough

Return false if the timelock didn't mature yet, not the other way
around.

Also, the check shouldn't be strict: if the CSV is 1 it is valid
at utxo->blockheight + 1.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This commit is contained in:
Antoine Poinsot 2021-08-09 08:52:23 +02:00 committed by neil saitug
parent f719343b4e
commit 8157e378f4
4 changed files with 4 additions and 4 deletions

View file

@ -2026,4 +2026,4 @@ struct db_query db_postgres_queries[] = {
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
// SHA256STAMP:6353b67b3e4f539da2d1f0c2564c4a8243f07d59cd0b73bc83d5552600bd67f7
// SHA256STAMP:27a166e040e517422e91cf7ffbd12426b34337b8d75f82d7aa4c448beae5e821

View file

@ -2026,4 +2026,4 @@ struct db_query db_sqlite3_queries[] = {
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
// SHA256STAMP:6353b67b3e4f539da2d1f0c2564c4a8243f07d59cd0b73bc83d5552600bd67f7
// SHA256STAMP:27a166e040e517422e91cf7ffbd12426b34337b8d75f82d7aa4c448beae5e821

View file

@ -1337,4 +1337,4 @@ msgstr ""
#: wallet/test/run-wallet.c:1696
msgid "INSERT INTO channels (id) VALUES (1);"
msgstr ""
# SHA256STAMP:e203d19d9f4192ad6b3aa1a6f257d4f7b267df56c5de9810b573f0affa0122fd
# SHA256STAMP:3652b5850f08383c0f0c01a7f11c1a22ec2b4ac16018152d2770a73674fb05ec

View file

@ -530,7 +530,7 @@ static bool deep_enough(u32 maxheight, const struct utxo *utxo,
if (utxo->close_info) {
u32 csv_free = *utxo->blockheight + utxo->close_info->csv;
assert(csv_free > *utxo->blockheight);
if (csv_free < current_blockheight)
if (current_blockheight < csv_free)
return false;
}
return *utxo->blockheight <= maxheight;