Skip to content

Commit 855ad92

Browse files
committed
df: wire up using adaptive locktime for dual-funding
1 parent 1ce1051 commit 855ad92

File tree

9 files changed

+28
-5
lines changed

9 files changed

+28
-5
lines changed

common/funding_tx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ static void add_outputs(struct bitcoin_tx *tx, struct output_info **outputs,
222222

223223
struct bitcoin_tx *dual_funding_funding_tx(const tal_t *ctx,
224224
const struct chainparams *chainparams,
225+
u32 tx_locktime,
225226
u16 *outnum,
226227
u32 feerate_kw_funding,
227228
struct amount_sat *opener_funding,
@@ -362,7 +363,7 @@ struct bitcoin_tx *dual_funding_funding_tx(const tal_t *ctx,
362363
assert(output_count > 0);
363364
}
364365

365-
tx = bitcoin_tx(ctx, chainparams, input_count, output_count, 0);
366+
tx = bitcoin_tx(ctx, chainparams, input_count, output_count, tx_locktime);
366367

367368
/* Add the funding output */
368369
wscript = bitcoin_redeem_2of2(tx, local_fundingkey, remote_fundingkey);

common/funding_tx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx,
7272
* funding_tx: create a P2WSH funding transaction for a channel.
7373
* @ctx: context to tal from.
7474
* @chainparams: (in) the params for the resulting transaction.
75+
* @locktime: (in) blockheight to use for the tx locktime
7576
* @outnum: (out) txout which is the funding output.
7677
* @feerate_kw_funding: (in) feerate for the funding transaction
7778
* @opener_funding: (in/out) funding amount contributed by opener
@@ -88,6 +89,7 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx,
8889
*/
8990
struct bitcoin_tx *dual_funding_funding_tx(const tal_t *ctx,
9091
const struct chainparams *chainparams,
92+
u32 tx_locktime,
9193
u16 *outnum,
9294
u32 feerate_kw_funding,
9395
struct amount_sat *opener_funding,

common/test/run-funding_tx_dual.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ int main(void)
818818

819819
/* Note that dust_limit is set to 546, via chainparams */
820820
funding = dual_funding_funding_tx(tmpctx, chainparams,
821+
0, /* examples all have locktime at 0 */
821822
&outnum, test.feerate,
822823
&test.opener_funding,
823824
test.accepter_funding,

hsmd/hsm_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ msgtype,hsm_dual_funding_sigs,40
6767
msgdata,hsm_dual_funding_sigs,num_utxos,u16,
6868
msgdata,hsm_dual_funding_sigs,our_utxos,utxo,num_utxos
6969
msgdata,hsm_dual_funding_sigs,feerate_kw_funding,u32,
70+
msgdata,hsm_dual_funding_sigs,tx_locktime,u32,
7071
msgdata,hsm_dual_funding_sigs,opener_funding,amount_sat,
7172
msgdata,hsm_dual_funding_sigs,accepter_funding,amount_sat,
7273
msgdata,hsm_dual_funding_sigs,num_opener_inputs,u16,

hsmd/hsmd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ static struct io_plan *handle_sign_dual_funding_tx(struct io_conn *conn,
16481648
{
16491649
size_t i = 0, j;
16501650
struct bitcoin_tx *tx;
1651-
u32 feerate_kw_funding, offset;
1651+
u32 feerate_kw_funding, offset, tx_locktime;
16521652
struct pubkey local_pubkey, remote_pubkey;
16531653
struct amount_sat opener_funding, accepter_funding;
16541654
struct input_info **opener_inputs, **accepter_inputs;
@@ -1662,6 +1662,7 @@ static struct io_plan *handle_sign_dual_funding_tx(struct io_conn *conn,
16621662
msg_in,
16631663
&our_utxos,
16641664
&feerate_kw_funding,
1665+
&tx_locktime,
16651666
&opener_funding,
16661667
&accepter_funding,
16671668
&opener_inputs,
@@ -1683,6 +1684,7 @@ static struct io_plan *handle_sign_dual_funding_tx(struct io_conn *conn,
16831684

16841685
tx = dual_funding_funding_tx(tmpctx,
16851686
c->chainparams,
1687+
tx_locktime,
16861688
NULL,
16871689
feerate_kw_funding,
16881690
&opener_funding,

lightningd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ LIGHTNINGD_SRC := \
102102
lightningd/plugin.c \
103103
lightningd/plugin_control.c \
104104
lightningd/plugin_hook.c \
105+
lightningd/tx_locktime.c \
105106
lightningd/subd.c \
106107
lightningd/watch.c
107108

lightningd/opening_control.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <lightningd/options.h>
3636
#include <lightningd/plugin_hook.h>
3737
#include <lightningd/subd.h>
38+
#include <lightningd/tx_locktime.h>
3839
#include <openingd/channel_establishment.h>
3940
#include <openingd/gen_opening_wire.h>
4041
#include <wire/gen_common_wire.h>
@@ -1887,6 +1888,7 @@ static struct command_result *json_fund_channel_start(struct command *cmd,
18871888
struct channel *channel;
18881889
bool *announce_channel;
18891890
u32 *feerate_per_kw;
1891+
u32 locktime;
18901892

18911893
u8 *msg = NULL;
18921894
struct amount_sat *amount;
@@ -1976,6 +1978,11 @@ static struct command_result *json_fund_channel_start(struct command *cmd,
19761978
type_to_string(fc, struct node_id, id));
19771979
}
19781980

1981+
/* BOLT-b746cacbde53ea6170ec43ee3eff46fbb4139bfd #2
1982+
* `locktime` is the locktime for the funding transaction.
1983+
*/
1984+
locktime = locktime_for_new_tx(cmd->ld->topology);
1985+
19791986
peer->uncommitted_channel->fc = tal_steal(peer->uncommitted_channel, fc);
19801987
fc->uc = peer->uncommitted_channel;
19811988

@@ -1992,6 +1999,7 @@ static struct command_result *json_fund_channel_start(struct command *cmd,
19921999

19932000
msg = towire_opening_funder_start(NULL,
19942001
*amount,
2002+
locktime,
19952003
fc->push,
19962004
fc->our_upfront_shutdown_script,
19972005
*feerate_per_kw,

openingd/opening_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ msgdata,opening_funder_reply,shutdown_scriptpubkey,u8,shutdown_len
8787
# master->openingd: start channel establishment for a funding tx
8888
msgtype,opening_funder_start,6002
8989
msgdata,opening_funder_start,funding_satoshis,amount_sat,
90+
msgdata,opening_funder_start,tx_locktime,u32,
9091
msgdata,opening_funder_start,push_msat,amount_msat,
9192
msgdata,opening_funder_start,len_upfront,u16,
9293
msgdata,opening_funder_start,upfront_shutdown_script,u8,len_upfront

openingd/openingd.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ struct state {
127127
struct amount_sat accepter_funding;
128128
u32 feerate_per_kw_funding;
129129

130+
/* Locktime for funding transaction */
131+
u32 locktime;
132+
130133
/* List of queued add input/output/completes.
131134
* These get queued up while we're in transition
132135
* between fundchannel_start and fundchannel_complete
@@ -636,7 +639,7 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
636639
state->feerate_per_kw_funding = state->feerate_per_kw;
637640
msg = towire_open_channel2(NULL,
638641
&chainparams->genesis_blockhash,
639-
0, /* FIXME: use real locktime */
642+
state->locktime,
640643
NULL, /* FIXME: use real podleh2 */
641644
state->feerate_per_kw_funding,
642645
state->opener_funding,
@@ -1477,6 +1480,7 @@ static u8 *funder_finalize_channel_setup2(struct state *state,
14771480

14781481
/* Build the funding transaction */
14791482
funding_tx = dual_funding_funding_tx(state, chainparams,
1483+
state->locktime,
14801484
&state->funding_txout,
14811485
state->feerate_per_kw_funding,
14821486
&state->opener_funding,
@@ -2125,13 +2129,12 @@ static u8 *fundee_channel2(struct state *state, const u8 *open_channel2_msg)
21252129
const u8 *wscript;
21262130
u8 channel_flags;
21272131
u8 *msg;
2128-
u32 locktime;
21292132
struct sha256 podle_h2;
21302133

21312134
struct tlv_opening_tlvs *tlv = tlv_opening_tlvs_new(tmpctx);
21322135
if (!fromwire_open_channel2(open_channel2_msg,
21332136
&chain_hash,
2134-
&locktime,
2137+
&state->locktime,
21352138
&podle_h2,
21362139
&state->feerate_per_kw_funding,
21372140
&state->opener_funding,
@@ -2275,6 +2278,7 @@ static u8 *fundee_channel2(struct state *state, const u8 *open_channel2_msg)
22752278

22762279
/* Build the funding tx */
22772280
funding_tx = dual_funding_funding_tx(state, chainparams,
2281+
state->locktime,
22782282
&state->funding_txout,
22792283
state->feerate_per_kw_funding,
22802284
&state->opener_funding,
@@ -2418,6 +2422,7 @@ static u8 *fundee_channel2(struct state *state, const u8 *open_channel2_msg)
24182422
msg = towire_hsm_dual_funding_sigs(tmpctx,
24192423
cast_const2(const struct utxo **, utxos),
24202424
state->feerate_per_kw_funding,
2425+
state->locktime,
24212426
state->opener_funding,
24222427
state->accepter_funding,
24232428
cast_const2(const struct input_info **, their_inputs),
@@ -2975,6 +2980,7 @@ static u8 *handle_master_in(struct state *state)
29752980
case WIRE_OPENING_FUNDER_START:
29762981
if (!fromwire_opening_funder_start(tmpctx, msg,
29772982
&state->opener_funding,
2983+
&state->locktime,
29782984
&state->push_msat,
29792985
&state->upfront_shutdown_script[LOCAL],
29802986
&state->feerate_per_kw,

0 commit comments

Comments
 (0)