mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
lightningd/build_utxos: don't lockin the UTXO reservation until confirmed.
Unless the transaction is confirmed, the UTXOs should be released if something happens to the peer. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -188,6 +188,19 @@ static void unreserve_utxo(struct lightningd *ld, const struct utxo *unres)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void destroy_utxos(struct utxo *utxos, struct lightningd *ld)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < tal_count(utxos); i++)
|
||||||
|
unreserve_utxo(ld, &utxos[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void confirm_utxos(struct lightningd *ld, struct utxo *utxos)
|
||||||
|
{
|
||||||
|
tal_del_destructor2(utxos, destroy_utxos, ld);
|
||||||
|
}
|
||||||
|
|
||||||
struct utxo *build_utxos(const tal_t *ctx,
|
struct utxo *build_utxos(const tal_t *ctx,
|
||||||
struct lightningd *ld, u64 satoshi_out,
|
struct lightningd *ld, u64 satoshi_out,
|
||||||
u32 feerate_per_kw, u64 dust_limit,
|
u32 feerate_per_kw, u64 dust_limit,
|
||||||
@@ -199,6 +212,8 @@ struct utxo *build_utxos(const tal_t *ctx,
|
|||||||
/* We assume two outputs for the weight. */
|
/* We assume two outputs for the weight. */
|
||||||
u64 satoshi_in = 0, weight = (4 + (8 + 22) * 2 + 4) * 4;
|
u64 satoshi_in = 0, weight = (4 + (8 + 22) * 2 + 4) * 4;
|
||||||
|
|
||||||
|
tal_add_destructor2(utxos, destroy_utxos, ld);
|
||||||
|
|
||||||
list_for_each(&ld->utxos, utxo, list) {
|
list_for_each(&ld->utxos, utxo, list) {
|
||||||
u64 fee;
|
u64 fee;
|
||||||
|
|
||||||
@@ -230,9 +245,5 @@ struct utxo *build_utxos(const tal_t *ctx,
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Failed, unmark them all. */
|
|
||||||
for (i = 0; i < tal_count(utxos); i++)
|
|
||||||
unreserve_utxo(ld, &utxos[i]);
|
|
||||||
|
|
||||||
return tal_free(utxos);
|
return tal_free(utxos);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ struct utxo *build_utxos(const tal_t *ctx,
|
|||||||
u32 feerate_per_kw, u64 dust_limit,
|
u32 feerate_per_kw, u64 dust_limit,
|
||||||
u64 *change_amount, u32 *change_keyindex);
|
u64 *change_amount, u32 *change_keyindex);
|
||||||
|
|
||||||
|
/* Once we've spent them, mark them confirmed. */
|
||||||
|
void confirm_utxos(struct lightningd *ld, struct utxo *utxos);
|
||||||
#endif /* LIGHTNING_LIGHTNINGD_BUILD_UTXOS_H */
|
#endif /* LIGHTNING_LIGHTNINGD_BUILD_UTXOS_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user