Skip to content

Commit 7f3e62b

Browse files
authored
Fix remote-hsmd CI (#12)
* adding g++, protobuf, grpc++ * add libgrpc++-dev to .travis.yml * wget remotesigner.proto * added libprotobuf-dev * fixed compilation warnings/errors * use Get instead of [] in protobuf seq * fixed include sort order * added protobuf generated files to skip nogen checks * fixed gensrc pattern * added libstdc++6 * fixed python spacing * added specified inclusion guards * renamed c++ header extensions to hpp to avoid c checks * guard satoshi amount calculations * libstdc++-6-dev * added `ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/x86_64-linux-gnu/libstdc++.so`
1 parent eb05907 commit 7f3e62b

File tree

12 files changed

+59
-48
lines changed

12 files changed

+59
-48
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ notifications:
55
email: false
66

77
before_install:
8-
sudo apt-get install -y libsqlite3-dev cppcheck valgrind gcc-4.8 gettext libc6-dev-armhf-cross libc6-dev-arm64-cross gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf qemu-user-static binfmt-support libsecp256k1-dev
8+
- sudo apt-get install -y libsqlite3-dev cppcheck valgrind gcc-4.8 gettext libc6-dev-armhf-cross libc6-dev-arm64-cross gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf qemu-user-static binfmt-support libsecp256k1-dev g++ protobuf-compiler protobuf-c-compiler libprotobuf-dev protobuf-compiler-grpc libgrpc++-dev libstdc++-6-dev
9+
- sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/x86_64-linux-gnu/libstdc++.so
910

1011
env:
1112
- ARCH=64 SOURCE_CHECK_ONLY=true COPTFLAGS="-O3"

.travis/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ pip3 install --user -U --quiet --progress-bar off \
4040
-r contrib/pyln-proto/requirements.txt \
4141
-r contrib/pyln-testing/requirements.txt
4242

43+
wget -q --directory-prefix=contrib/remote_hsmd https://gitlab.com/lightning-signer/rust-lightning-signer/-/raw/master/src/server/remotesigner.proto
44+
4345
echo "Configuration which is going to be built:"
4446
echo -en 'travis_fold:start:script.1\\r'
4547
./configure CC="$CC"

contrib/pyln-testing/pyln/testing/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def env(name, default=None):
7373
TIMEOUT = int(env("TIMEOUT", 180 if SLOW_MACHINE else 60))
7474
SUBDAEMON = env("SUBDAEMON", "")
7575

76+
7677
def wait_for(success, timeout=TIMEOUT):
7778
start_time = time.time()
7879
interval = 0.25

contrib/remote_hsmd/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ RMTHSMD_COMMON_OBJS := \
6060
common/withdraw_tx.o
6161

6262
# For checking
63-
LIGHTNINGD_RMTHSM_ALLSRC_NOGEN := $(filter-out contrib/remote_hsmd/gen_%, $(LIGHTNINGD_RMTHSM_SRC) $(LIGHTNINGD_RMTHSM_SRC))
64-
LIGHTNINGD_RMTHSM_ALLHEADERS_NOGEN := $(filter-out contrib/remote_hsmd/gen_%, $(LIGHTNINGD_RMTHSM_HEADERS))
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))
6565

6666
$(LIGHTNINGD_RMTHSM_OBJS): $(LIGHTNINGD_HEADERS)
6767

contrib/remote_hsmd/NOTES.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ rust-lightning-signer
8383

8484
cargo run --bin server |& tee log3
8585

86-
8786
Signing Formats
8887
```
8988
rust-lightning c-lightning rust-lightning-signer
@@ -94,13 +93,3 @@ p2shwpkh p2sh-p2wpkh P2SH_P2WPKH
9493
p2wsh
9594
p2shwsh
9695
```
97-
98-
99-
Failing tests after removing seed from hsmd:
100-
```
101-
export THETEST=tests/test_misc.py::test_blockchaintrack
102-
export THETEST=tests/test_misc.py::test_new_node_is_mainnet
103-
export THETEST=tests/test_misc.py::test_getsharedsecret
104-
export THETEST=tests/test_wallet.py::test_hsm_secret_encryption
105-
export THETEST=tests/test_wallet.py::test_hsmtool_secret_decryption
106-
```

contrib/remote_hsmd/capabilities.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef LIGHTNING_HSMD_CAPABILITIES_H
2-
#define LIGHTNING_HSMD_CAPABILITIES_H
1+
#ifndef LIGHTNING_CONTRIB_REMOTE_HSMD_CAPABILITIES_H
2+
#define LIGHTNING_CONTRIB_REMOTE_HSMD_CAPABILITIES_H
33

44
#define HSM_CAP_ECDH 1
55
#define HSM_CAP_SIGN_GOSSIP 2
@@ -9,4 +9,4 @@
99
#define HSM_CAP_SIGN_CLOSING_TX 32
1010

1111
#define HSM_CAP_MASTER 1024
12-
#endif /* LIGHTNING_HSMD_CAPABILITIES_H */
12+
#endif /* LIGHTNING_CONTRIB_REMOTE_HSMD_CAPABILITIES_H */

contrib/remote_hsmd/dump.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#include <iostream>
2-
#include <sstream>
1+
#include "contrib/remote_hsmd/dump.hpp"
32

43
extern "C" {
54
#include <bitcoin/chainparams.h>
@@ -11,11 +10,13 @@ extern "C" {
1110
#include <common/status.h>
1211
#include <common/utils.h>
1312
#include <common/utxo.h>
14-
#include <secp256k1_recovery.h>
13+
}
14+
#include <iostream>
15+
#include <sstream>
16+
extern "C" {
1517
#include <wally_bip32.h>
1618
}
1719

18-
#include "contrib/remote_hsmd/dump.h"
1920

2021
using std::ostringstream;
2122
using std::string;

contrib/remote_hsmd/dump.h renamed to contrib/remote_hsmd/dump.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
#ifndef LIGHTNING_CONTRIB_REMOTE_HSMD_DUMP_H
2+
#define LIGHTNING_CONTRIB_REMOTE_HSMD_DUMP_H
3+
4+
extern "C" {
5+
#include <ccan/short_types/short_types.h>
6+
#include <secp256k1_recovery.h>
7+
}
18
#include <string>
29

310
std::string dump_hex(const void *vptr, size_t sz);
@@ -26,3 +33,5 @@ std::string dump_wally_tx_outputs(const struct wally_tx_output *outputs,
2633
std::string dump_wally_tx(const struct wally_tx *wtx);
2734
std::string dump_wally_psbt(const struct wally_psbt *psbt);
2835
std::string dump_tx(const struct bitcoin_tx *tx);
36+
37+
#endif /* LIGHTNING_CONTRIB_REMOTE_HSMD_DUMP_H */

contrib/remote_hsmd/hsmd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
#include <common/utils.h>
3939
#include <common/version.h>
4040
#include <common/withdraw_tx.h>
41+
/*~ All gen_ files are autogenerated; in this case by tools/generate-wire.py */
42+
#include <contrib/remote_hsmd/gen_hsm_wire.h>
43+
#include <contrib/remote_hsmd/proxy.hpp>
4144
#include <errno.h>
4245
#include <fcntl.h>
4346
#include <hsmd/capabilities.h>
44-
/*~ All gen_ files are autogenerated; in this case by tools/generate-wire.py */
45-
#include <contrib/remote_hsmd/gen_hsm_wire.h>
46-
#include <contrib/remote_hsmd/proxy.h>
4747
#include <inttypes.h>
4848
#include <secp256k1_ecdh.h>
4949
#include <sodium.h>

contrib/remote_hsmd/proxy.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
/* This needs to be first */
22
#define __STDC_FORMAT_MACROS
3-
#include <inttypes.h>
4-
5-
#include <sys/types.h> /* These two only needed for sleep() and getpid() */
6-
#include <unistd.h>
7-
8-
#include <iostream>
9-
#include <sstream>
10-
11-
#include <grpc++/grpc++.h>
123

4+
#include "contrib/remote_hsmd/dump.hpp"
5+
#include "contrib/remote_hsmd/proxy.hpp"
6+
#include "contrib/remote_hsmd/remotesigner.grpc.pb.h"
7+
#include "contrib/remote_hsmd/remotesigner.pb.h"
138
extern "C" {
149
#include <bitcoin/chainparams.h>
15-
#include <bitcoin/psbt.h>
1610
#include <bitcoin/privkey.h>
11+
#include <bitcoin/psbt.h>
1712
#include <bitcoin/short_channel_id.h>
1813
#include <bitcoin/tx.h>
1914
#include <common/derive_basepoints.h>
@@ -22,15 +17,20 @@ extern "C" {
2217
#include <common/status.h>
2318
#include <common/utils.h>
2419
#include <common/utxo.h>
20+
}
21+
#include <grpc++/grpc++.h>
22+
#include <inttypes.h>
23+
#include <iostream>
24+
extern "C" {
2525
#include <secp256k1_recovery.h>
26+
}
27+
#include <sstream>
28+
#include <sys/types.h> /* These two only needed for sleep() and getpid() */
29+
#include <unistd.h>
30+
extern "C" {
2631
#include <wally_bip32.h>
2732
}
2833

29-
#include "contrib/remote_hsmd/remotesigner.pb.h"
30-
#include "contrib/remote_hsmd/remotesigner.grpc.pb.h"
31-
32-
#include "contrib/remote_hsmd/dump.h"
33-
#include "contrib/remote_hsmd/proxy.h"
3434

3535
using std::cerr;
3636
using std::endl;
@@ -269,7 +269,7 @@ void unmarshal_witnesses(RepeatedPtrField<Witness> const &wits, u8 ****o_wits)
269269
owits = tal_arrz(tmpctx, u8**, nwits);
270270
for (size_t ii = 0; ii < nwits; ++ii) {
271271
owits[ii] = tal_arrz(owits, u8*, 2);
272-
Witness const &wit = wits[ii];
272+
Witness const &wit = wits.Get(ii);
273273
const string &sig = wit.signature().data();
274274
const string &pubkey = wit.pubkey().data();
275275
owits[ii][0] = tal_arr(owits[ii], u8, sig.size());
@@ -915,7 +915,7 @@ proxy_stat proxy_handle_get_channel_basepoints(
915915
unmarshal_pubkey(bps.delayed_payment(),
916916
&o_basepoints->delayed_payment);
917917
unmarshal_pubkey(bps.funding_pubkey(), o_funding_pubkey);
918-
status_debug("%s:%d %s self_id=%s",
918+
status_debug("%s:%d %s self_id=%s basepoints=%s pubkey=%s",
919919
__FILE__, __LINE__, __FUNCTION__,
920920
dump_node_id(&self_id).c_str(),
921921
dump_basepoints(o_basepoints).c_str(),

contrib/remote_hsmd/proxy.h renamed to contrib/remote_hsmd/proxy.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
#ifndef LIGHTNING_CONTRIB_REMOTE_HSMD_PROXY_H
2+
#define LIGHTNING_CONTRIB_REMOTE_HSMD_PROXY_H
3+
14
#ifdef __cplusplus
25
extern "C" {
36
#endif
47

58
#include <ccan/short_types/short_types.h>
9+
#include <common/hash_u5.h>
610

711
enum proxy_status {
812
/* SUCCESS */
@@ -187,3 +191,5 @@ void print_tx(char const *tag, struct bitcoin_tx const *tx);
187191
#ifdef __cplusplus
188192
} /* extern C */
189193
#endif
194+
195+
#endif /* LIGHTNING_CONTRIB_REMOTE_HSMD_PROXY_H */

hsmd/hsmd.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,11 +1473,11 @@ static struct io_plan *handle_new_channel(struct io_conn *conn,
14731473

14741474
static bool mem_is_zero(const void *mem, size_t len)
14751475
{
1476-
size_t i;
1477-
for (i = 0; i < len; ++i)
1478-
if (((const unsigned char *)mem)[i])
1479-
return false;
1480-
return true;
1476+
size_t i;
1477+
for (i = 0; i < len; ++i)
1478+
if (((const unsigned char *)mem)[i])
1479+
return false;
1480+
return true;
14811481
}
14821482

14831483
/*~ This is used to provide all unchanging public channel parameters. */
@@ -1497,6 +1497,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
14971497
u16 remote_to_self_delay;
14981498
u8 *remote_shutdown_script;
14991499
bool option_static_remotekey;
1500+
struct amount_msat value_msat;
15001501

15011502
if (!fromwire_hsm_ready_channel(tmpctx, msg_in, &is_outbound,
15021503
&channel_value, &push_value, &funding_txid,
@@ -1510,8 +1511,9 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
15101511
return bad_req(conn, c, msg_in);
15111512

15121513
/* Fail fast if any values are obviously uninitialized. */
1513-
assert(channel_value.satoshis > 0);
1514-
assert(push_value.millisatoshis / 1000 <= channel_value.satoshis);
1514+
assert(amount_sat_greater(channel_value, AMOUNT_SAT(0)));
1515+
assert(amount_sat_to_msat(&value_msat, channel_value));
1516+
assert(amount_msat_less_eq(push_value, value_msat));
15151517
assert(!mem_is_zero(&funding_txid, sizeof(funding_txid)));
15161518
assert(local_to_self_delay > 0);
15171519
assert(!mem_is_zero(&remote_basepoints, sizeof(remote_basepoints)));

0 commit comments

Comments
 (0)