lightningd: expose default_locktime for wider usage.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-04-10 09:44:56 +09:30
parent 8493ee5e1a
commit 57b2cbcb32
3 changed files with 26 additions and 14 deletions

View File

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

View File

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

View File

@@ -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,