Skip to content

Commit b6911c9

Browse files
committed
submodule update libwally-core
adjusted external/libwally-core version first pass of rebase fixes, still need anchors, bolt12, get_output_scriptpubkey skip v2 funding, bolt12, backfill tests add witscripts on commitment to_remote outputs w/ option_anchor_outputs Connect opt_anchor_outputs to ReadyChannel. skipped more unsupported tests
1 parent a306e58 commit b6911c9

26 files changed

+602
-247
lines changed

channeld/commit_tx.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
262262
struct amount_sat amount = amount_msat_to_sat_round_down(other_pay);
263263
u8 *scriptpubkey;
264264
int pos;
265+
u8 *wscript = NULL;
265266

266267
/* BOLT #3:
267268
*
@@ -276,13 +277,13 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
276277
* Otherwise, this output is a simple P2WPKH to `remotepubkey`.
277278
*/
278279
if (option_anchor_outputs) {
279-
scriptpubkey = scriptpubkey_p2wsh(tmpctx,
280-
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key));
280+
wscript = anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key);
281+
scriptpubkey = scriptpubkey_p2wsh(tmpctx, wscript);
281282
} else {
282283
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
283284
&keyset->other_payment_key);
284285
}
285-
pos = bitcoin_tx_add_output(tx, scriptpubkey, NULL, amount);
286+
pos = bitcoin_tx_add_output(tx, scriptpubkey, wscript, amount);
286287
assert(pos == n);
287288
(*htlcmap)[n] = direct_outputs ? dummy_to_remote : NULL;
288289
/* We don't assign cltvs[n]: if we use it, order doesn't matter.

common/initial_commit_tx.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,17 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
238238
*/
239239
u8 *scriptpubkey;
240240
int pos;
241+
u8 *wscript = NULL;
241242

242243
amount = amount_msat_to_sat_round_down(other_pay);
243244
if (option_anchor_outputs) {
244-
scriptpubkey = scriptpubkey_p2wsh(tmpctx,
245-
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key));
245+
wscript = anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key);
246+
scriptpubkey = scriptpubkey_p2wsh(tmpctx, wscript);
246247
} else {
247248
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
248249
&keyset->other_payment_key);
249250
}
250-
pos = bitcoin_tx_add_output(tx, scriptpubkey, NULL, amount);
251+
pos = bitcoin_tx_add_output(tx, scriptpubkey, wscript, amount);
251252
assert(pos == n);
252253
output_order[n] = dummy_remote;
253254
n++;

contrib/remote_hsmd/Makefile

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ rmthsmd-wrongdir:
77
default: rmthsmd-all
88

99
LIGHTNINGD_RMTHSM_SRC := contrib/remote_hsmd/hsmd.c \
10-
contrib/remote_hsmd/gen_hsm_wire.c \
1110
contrib/remote_hsmd/remotesigner.pb.cc \
1211
contrib/remote_hsmd/remotesigner.grpc.pb.cc \
1312
contrib/remote_hsmd/dump.cc \
1413
contrib/remote_hsmd/proxy.cc
15-
LIGHTNINGD_RMTHSM_HEADERS := contrib/remote_hsmd/gen_hsm_wire.h \
16-
contrib/remote_hsmd/remotesigner.pb.h \
14+
LIGHTNINGD_RMTHSM_HEADERS := contrib/remote_hsmd/remotesigner.pb.h \
1715
contrib/remote_hsmd/remotesigner.grpc.pb.h
1816
LIGHTNINGD_RMTHSM_CCOBJS := $(LIGHTNINGD_RMTHSM_SRC:.cc=.o)
1917
LIGHTNINGD_RMTHSM_OBJS := $(LIGHTNINGD_RMTHSM_CCOBJS:.c=.o)
@@ -34,41 +32,40 @@ PROTOS_PATH = contrib/remote_hsmd
3432

3533
# Common source we use.
3634
RMTHSMD_COMMON_OBJS := \
35+
hsmd/hsmd_wiregen.o \
3736
common/amount.o \
3837
common/bigsize.o \
3938
common/bip32.o \
4039
common/channel_id.o \
4140
common/daemon.o \
42-
common/daemon_conn.o \
43-
common/derive_basepoints.o \
44-
common/funding_tx.o \
45-
common/gen_status_wire.o \
41+
common/daemon_conn.o \
42+
common/derive_basepoints.o \
43+
common/status_wiregen.o \
4644
common/hash_u5.o \
4745
common/key_derive.o \
4846
common/memleak.o \
4947
common/msg_queue.o \
5048
common/node_id.o \
5149
common/permute_tx.o \
50+
common/pseudorand.o \
5251
common/setup.o \
5352
common/status.o \
54-
common/status_wire.o \
53+
common/status_wire.o \
5554
common/subdaemon.o \
56-
common/type_to_string.o \
55+
common/type_to_string.o \
5756
common/utils.o \
5857
common/utxo.o \
59-
common/version.o \
60-
common/withdraw_tx.o
58+
common/version.o
6159

6260
# For checking
63-
LIGHTNINGD_RMTHSM_ALLSRC_NOGEN := $(filter-out contrib/remote_hsmd/gen_% contrib/remote_hsmd/remotesigner.%, $(LIGHTNINGD_RMTHSM_SRC) $(LIGHTNINGD_RMTHSM_SRC))
64-
LIGHTNINGD_RMTHSM_ALLHEADERS_NOGEN := $(filter-out contrib/remote_hsmd/gen_% contrib/remote_hsmd/remotesigner.%, $(LIGHTNINGD_RMTHSM_HEADERS))
61+
LIGHTNINGD_RMTHSM_ALLSRC_NOGEN := $(filter-out contrib/remote_hsmd/remotesigner.%, $(LIGHTNINGD_RMTHSM_SRC) $(LIGHTNINGD_RMTHSM_SRC))
62+
LIGHTNINGD_RMTHSM_ALLHEADERS_NOGEN := $(filter-out contrib/remote_hsmd/remotesigner.%, $(LIGHTNINGD_RMTHSM_HEADERS))
6563

6664
$(LIGHTNINGD_RMTHSM_OBJS): $(LIGHTNINGD_HEADERS)
6765

6866
# Make sure these depend on everything.
6967
ALL_OBJS += $(LIGHTNINGD_RMTHSM_OBJS)
7068
ALL_PROGRAMS += lightningd/remote_hsmd
71-
ALL_GEN_HEADERS += contrib/remote_hsmd/gen_hsm_wire.h
7269
ALL_GEN_HEADERS += contrib/remote_hsmd/remotesigner.pb.h contrib/remote_hsmd/remotesigner.grpc.pb.h
7370

7471
rmthsmd-all: lightningd/remote_hsmd
@@ -85,12 +82,6 @@ lightningd/remote_hsmd: LDLIBS += -L/usr/local/lib \
8582
-ldl
8683
lightningd/remote_hsmd: LDLIBS += -lstdc++
8784

88-
contrib/remote_hsmd/gen_hsm_wire.h: $(WIRE_GEN) contrib/remote_hsmd/hsm_wire.csv
89-
$(WIRE_GEN) --page header $@ hsm_wire_type < contrib/remote_hsmd/hsm_wire.csv > $@
90-
91-
contrib/remote_hsmd/gen_hsm_wire.c: $(WIRE_GEN) contrib/remote_hsmd/hsm_wire.csv
92-
$(WIRE_GEN) --page impl ${@:.c=.h} hsm_wire_type < contrib/remote_hsmd/hsm_wire.csv > $@
93-
9485
check-source: $(LIGHTNINGD_RMTHSM_ALLSRC_NOGEN:%=check-src-include-order/%) $(LIGHTNINGD_RMTHSM_ALLHEADERS_NOGEN:%=check-hdr-include-order/%)
9586
check-source-bolt: $(LIGHTNINGD_RMTHSM_SRC:%=bolt-check/%)
9687

@@ -99,7 +90,7 @@ check-whitespace: $(LIGHTNINGD_RMTHSM_ALLSRC_NOGEN:%=check-whitespace/%) $(LIGHT
9990
clean: lightningd/rmthsm-clean
10091

10192
lightningd/rmthsm-clean:
102-
$(RM) $(LIGHTNINGD_RMTHSM_OBJS) contrib/remote_hsmd/gen_*
93+
$(RM) $(LIGHTNINGD_RMTHSM_OBJS)
10394
$(RM) contrib/remote_hsmd/*.pb.cc contrib/remote_hsmd/*.pb.h
10495

10596
.PRECIOUS: %.grpc.pb.cc
@@ -110,4 +101,12 @@ lightningd/rmthsm-clean:
110101
%.pb.cc: %.proto
111102
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=contrib/remote_hsmd $<
112103

104+
.PRECIOUS: %.grpc.pb.h
105+
%.grpc.pb.h: %.proto
106+
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=contrib/remote_hsmd --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
107+
108+
.PRECIOUS: %.pb.h
109+
%.pb.h: %.proto
110+
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=contrib/remote_hsmd $<
111+
113112
-include contrib/remote_hsmd/test/Makefile

contrib/remote_hsmd/NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ c-lightning
44
Setup
55

66
(cd contrib/remote_hsmd && \
7-
ln -s ../../../rust-lightning-signer/src/server/remotesigner.proto)
7+
ln -s ../../../rust-lightning-signer/lightning-signer-server/src/server/remotesigner.proto)
88

99
Building
1010

contrib/remote_hsmd/dump.cc

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ string dump_pubkey(const struct pubkey *kp)
8787
string dump_ext_pubkey(const struct ext_key *xp)
8888
{
8989
char *out;
90+
tal_wally_start();
9091
int rv = bip32_key_to_base58(xp, BIP32_FLAG_KEY_PUBLIC, &out);
92+
tal_wally_end(NULL);
9193
assert(rv == WALLY_OK);
9294
string retval(out);
9395
wally_free_string(out);
@@ -208,29 +210,30 @@ string dump_wally_tx_witness_stack(const struct wally_tx_witness_stack *sp)
208210
return ostrm.str();
209211
}
210212

211-
string dump_wally_keypath_item(const struct wally_keypath_item *ip)
213+
string dump_wally_keypath_item(const struct wally_map_item *ip)
212214
{
215+
size_t npath = (ip->value_len - BIP32_KEY_FINGERPRINT_LEN) / sizeof(uint32_t);
213216
ostringstream ostrm;
214217
ostrm << "{ ";
215-
ostrm << "\"pubkey\":" << dump_hex(
216-
ip->pubkey, pubkey_is_compressed(ip->pubkey) ?
217-
EC_PUBLIC_KEY_LEN : EC_PUBLIC_KEY_UNCOMPRESSED_LEN);
218+
ostrm << "\"pubkey\":" << dump_hex(ip->key, ip->key_len);
218219
ostrm << ", \"origin\":{ ";
219-
ostrm << " \"fingerprint\":" << dump_hex(ip->origin.fingerprint,
220-
sizeof(ip->origin.fingerprint));
220+
ostrm << " \"fingerprint\":"
221+
<< dump_hex(ip->value, BIP32_KEY_FINGERPRINT_LEN);
221222
ostrm << ", \"path\":[ ";
222-
for (size_t ii = 0; ii < ip->origin.path_len; ++ii) {
223+
for (size_t ii = 0; ii < npath; ++ii) {
223224
if (ii != 0)
224225
ostrm << ",";
225-
ostrm << ip->origin.path[ii];
226+
uint32_t pelem = *(uint32_t *)
227+
ip->value + BIP32_KEY_FINGERPRINT_LEN + ii * sizeof(uint32_t);
228+
ostrm << pelem;
226229
}
227230
ostrm << " ]";
228231
ostrm << " }";
229232
ostrm << " }";
230233
return ostrm.str();
231234
}
232235

233-
string dump_wally_keypath_map(const struct wally_keypath_map *mp)
236+
string dump_wally_keypath_map(const struct wally_map *mp)
234237
{
235238
ostringstream ostrm;
236239
ostrm << "[";
@@ -245,34 +248,32 @@ string dump_wally_keypath_map(const struct wally_keypath_map *mp)
245248
return ostrm.str();
246249
}
247250

248-
string dump_wally_partial_sigs_item(const struct wally_partial_sigs_item *ip)
251+
string dump_wally_signatures_item(const struct wally_map_item *ip)
249252
{
250253
ostringstream ostrm;
251254
ostrm << "{ ";
252-
ostrm << "\"pubkey\":" << dump_hex(
253-
ip->pubkey, pubkey_is_compressed(ip->pubkey) ?
254-
EC_PUBLIC_KEY_LEN : EC_PUBLIC_KEY_UNCOMPRESSED_LEN);
255-
ostrm << ", \"sig\":" << dump_hex(ip->sig, ip->sig_len);
255+
ostrm << "\"pubkey\":" << dump_hex(ip->key, ip->key_len);
256+
ostrm << ", \"sig\":" << dump_hex(ip->value, ip->value_len);
256257
ostrm << " }";
257258
return ostrm.str();
258259
}
259260

260-
string dump_wally_partial_sigs_map(const struct wally_partial_sigs_map *mp)
261+
string dump_wally_signatures_map(const struct wally_map *mp)
261262
{
262263
ostringstream ostrm;
263264
ostrm << "[";
264265
if (mp) {
265266
for (size_t ii = 0; ii < mp->num_items; ii++) {
266267
if (ii != 0)
267268
ostrm << ",";
268-
ostrm << dump_wally_partial_sigs_item(&mp->items[ii]);
269+
ostrm << dump_wally_signatures_item(&mp->items[ii]);
269270
}
270271
}
271272
ostrm << "]";
272273
return ostrm.str();
273274
}
274275

275-
string dump_wally_unknowns_item(const struct wally_unknowns_item *ip)
276+
string dump_wally_unknowns_item(const struct wally_map_item *ip)
276277
{
277278
ostringstream ostrm;
278279
ostrm << "{ ";
@@ -282,7 +283,7 @@ string dump_wally_unknowns_item(const struct wally_unknowns_item *ip)
282283
return ostrm.str();
283284
}
284285

285-
string dump_wally_unknowns_map(const struct wally_unknowns_map *mp)
286+
string dump_wally_unknowns_map(const struct wally_map *mp)
286287
{
287288
ostringstream ostrm;
288289
ostrm << "[";
@@ -380,21 +381,21 @@ string dump_wally_psbt_input(const struct wally_psbt_input *in)
380381
{
381382
ostringstream ostrm;
382383
ostrm << "{ ";
383-
ostrm << "\"non_witness_utxo\":" << dump_wally_tx(in->non_witness_utxo);
384+
ostrm << "\"utxo\":" << dump_wally_tx(in->utxo);
384385
ostrm << ", \"witness_utxo\":" << dump_wally_tx_output(in->witness_utxo);
385386
ostrm << ", \"redeem_script\":" << dump_hex(in->redeem_script,
386387
in->redeem_script_len);
387388
ostrm << ", \"witness_script\":" << dump_hex(in->witness_script,
388389
in->witness_script_len);
389-
ostrm << ", \"final_script_sig\":" << dump_hex(in->final_script_sig,
390-
in->final_script_sig_len);
390+
ostrm << ", \"final_scriptsig\":" << dump_hex(in->final_scriptsig,
391+
in->final_scriptsig_len);
391392
ostrm << ", \"final_witness\":"
392393
<< dump_wally_tx_witness_stack(in->final_witness);
393-
ostrm << ", \"keypaths\":" << dump_wally_keypath_map(in->keypaths);
394-
ostrm << ", \"partial_sigs\":"
395-
<< dump_wally_partial_sigs_map(in->partial_sigs);
396-
ostrm << ", \"unknowns\":" << dump_wally_unknowns_map(in->unknowns);
397-
ostrm << ", \"sighash_type\":" << in->sighash_type;
394+
ostrm << ", \"keypaths\":" << dump_wally_keypath_map(&in->keypaths);
395+
ostrm << ", \"signatures\":"
396+
<< dump_wally_signatures_map(&in->signatures);
397+
ostrm << ", \"unknowns\":" << dump_wally_unknowns_map(&in->unknowns);
398+
ostrm << ", \"sighash\":" << in->sighash;
398399
ostrm << " }";
399400
return ostrm.str();
400401
}
@@ -421,8 +422,8 @@ string dump_wally_psbt_output(const struct wally_psbt_output *out)
421422
out->redeem_script_len);
422423
ostrm << ", \"witness_script\":" << dump_hex(out->witness_script,
423424
out->witness_script_len);
424-
ostrm << ", \"keypaths\":" << dump_wally_keypath_map(out->keypaths);
425-
ostrm << ", \"unknowns\":" << dump_wally_unknowns_map(out->unknowns);
425+
ostrm << ", \"keypaths\":" << dump_wally_keypath_map(&out->keypaths);
426+
ostrm << ", \"unknowns\":" << dump_wally_unknowns_map(&out->unknowns);
426427
ostrm << " }";
427428
return ostrm.str();
428429

@@ -452,7 +453,7 @@ string dump_wally_psbt(const struct wally_psbt *psbt)
452453
<< dump_wally_psbt_inputs(psbt->inputs, psbt->num_inputs);
453454
ostrm << ", \"outputs\":"
454455
<< dump_wally_psbt_outputs(psbt->outputs, psbt->num_outputs);
455-
ostrm << ", \"unknowns\":" << dump_wally_unknowns_map(psbt->unknowns);
456+
ostrm << ", \"unknowns\":" << dump_wally_unknowns_map(&psbt->unknowns);
456457
ostrm << ", \"version\":" << psbt->version;
457458
ostrm << " }";
458459
return ostrm.str();

contrib/remote_hsmd/dump.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ std::string dump_utxos(const struct utxo **utxos);
2424
std::string dump_bitcoin_tx_output(const struct bitcoin_tx_output *op);
2525
std::string dump_bitcoin_tx_outputs(const struct bitcoin_tx_output **outputs);
2626
std::string dump_wally_tx_witness_stack(const struct wally_tx_witness_stack *sp);
27-
std::string dump_wally_keypath_map(const struct wally_keypath_map *mp);
28-
std::string dump_wally_partial_sigs_map(const struct wally_partial_sigs_map *mp);
29-
std::string dump_wally_unknowns_map(const struct wally_unknowns_map *mp);
27+
std::string dump_wally_keypath_map(const struct wally_map *mp);
28+
std::string dump_wally_partial_sigs_map(const struct wally_map *mp);
29+
std::string dump_wally_unknowns_map(const struct wally_map *mp);
3030
std::string dump_wally_tx_input(const struct wally_tx_input *in);
3131
std::string dump_wally_tx_inputs(const struct wally_tx_input *inputs,
3232
size_t num_inputs);

contrib/remote_hsmd/hsm_wire.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)