diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index b956508c6..4b659589d 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -1134,6 +1134,28 @@ u32 feerate_max(struct lightningd *ld, bool *unknown) return max * topo->ld->config.max_fee_multiplier; } +u32 default_locktime(const struct chain_topology *topo) +{ + u32 locktime, current_height = get_block_height(topo); + + /* Setting the locktime to the next block to be mined has multiple + * benefits: + * - anti fee-snipping (even if not yet likely) + * - less distinguishable transactions (with this we create + * general-purpose transactions which looks like bitcoind: + * native segwit, nlocktime set to tip, and sequence set to + * 0xFFFFFFFD by default. Other wallets are likely to implement + * this too). + */ + locktime = current_height; + + /* Eventually fuzz it too. */ + if (locktime > 100 && pseudorand(10) == 0) + locktime -= pseudorand(100); + + return locktime; +} + /* On shutdown, channels get deleted last. That frees from our list, so * do it now instead. */ static void destroy_chain_topology(struct chain_topology *topo) diff --git a/lightningd/chaintopology.h b/lightningd/chaintopology.h index 4c7ce628a..e79c237f2 100644 --- a/lightningd/chaintopology.h +++ b/lightningd/chaintopology.h @@ -196,6 +196,9 @@ u32 delayed_to_us_feerate(struct chain_topology *topo); u32 htlc_resolution_feerate(struct chain_topology *topo); u32 penalty_feerate(struct chain_topology *topo); +/* Usually we set nLocktime to tip (or recent) like bitcoind does */ +u32 default_locktime(const struct chain_topology *topo); + /** * broadcast_tx - Broadcast a single tx, and rebroadcast as reqd (copies tx). * @topo: topology diff --git a/wallet/reservation.c b/wallet/reservation.c index d131aa375..f7e458c66 100644 --- a/wallet/reservation.c +++ b/wallet/reservation.c @@ -351,22 +351,9 @@ static struct command_result *finish_psbt(struct command *cmd, size_t change_outnum COMPILER_WANTS_INIT("gcc 9.4.0 -Og"); u32 current_height = get_block_height(cmd->ld->topology); - /* Setting the locktime to the next block to be mined has multiple - * benefits: - * - anti fee-snipping (even if not yet likely) - * - less distinguishable transactions (with this we create - * general-purpose transactions which looks like bitcoind: - * native segwit, nlocktime set to tip, and sequence set to - * 0xFFFFFFFD by default. Other wallets are likely to implement - * this too). - */ if (!locktime) { locktime = tal(cmd, u32); - *locktime = current_height; - - /* Eventually fuzz it too. */ - if (*locktime > 100 && pseudorand(10) == 0) - *locktime -= pseudorand(100); + *locktime = default_locktime(cmd->ld->topology); } psbt = psbt_using_utxos(cmd, cmd->ld->wallet, utxos,