Browse Source

bitcoin: create new wrapper type bitcoin_blkid, log backward endianness.

It's just a sha256_double, but importantly when we convert it to a
string (in type_to_string, which is used in logging) we use
bitcoin_blkid_to_hex() so it's reversed as people expect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
810abb6b21
  1. 10
      bitcoin/block.c
  2. 10
      bitcoin/block.h
  3. 8
      bitcoin/chainparams.c
  4. 4
      bitcoin/chainparams.h
  5. 3
      bitcoin/shadouble.c
  6. 2
      channeld/channel.c
  7. 2
      channeld/channel_wire.csv
  8. 2
      common/type_to_string.h
  9. 7
      gossipd/gossip.c
  10. 6
      gossipd/gossip_wire.csv
  11. 10
      gossipd/routing.c
  12. 4
      gossipd/routing.h
  13. 6
      gossipd/test/run-bench-find_route.c
  14. 6
      gossipd/test/run-find_route-specific.c
  15. 6
      gossipd/test/run-find_route.c
  16. 2
      hsmd/hsm.c
  17. 14
      lightningd/bitcoind.c
  18. 12
      lightningd/bitcoind.h
  19. 8
      lightningd/chaintopology.c
  20. 9
      lightningd/chaintopology.h
  21. 4
      lightningd/peer_control.c
  22. 4
      openingd/opening.c
  23. 4
      tools/generate-wire.py
  24. 6
      wire/fromwire.c
  25. 6
      wire/test/run-peer-wire.c
  26. 5
      wire/towire.c
  27. 5
      wire/wire.h

10
bitcoin/block.c

@ -2,6 +2,7 @@
#include "bitcoin/pullpush.h"
#include "bitcoin/tx.h"
#include <ccan/str/hex/hex.h>
#include <common/type_to_string.h>
/* Encoding is <blockhdr> <varint-num-txs> <tx>... */
struct bitcoin_block *bitcoin_block_from_hex(const tal_t *ctx,
@ -38,20 +39,21 @@ struct bitcoin_block *bitcoin_block_from_hex(const tal_t *ctx,
return b;
}
/* We do the same hex-reversing crud as txids. */
bool bitcoin_blkid_from_hex(const char *hexstr, size_t hexstr_len,
struct sha256_double *blockid)
struct bitcoin_blkid *blockid)
{
struct bitcoin_txid fake_txid;
if (!bitcoin_txid_from_hex(hexstr, hexstr_len, &fake_txid))
return false;
*blockid = fake_txid.shad;
blockid->shad = fake_txid.shad;
return true;
}
bool bitcoin_blkid_to_hex(const struct sha256_double *blockid,
bool bitcoin_blkid_to_hex(const struct bitcoin_blkid *blockid,
char *hexstr, size_t hexstr_len)
{
struct bitcoin_txid fake_txid;
fake_txid.shad = *blockid;
fake_txid.shad = blockid->shad;
return bitcoin_txid_to_hex(&fake_txid, hexstr, hexstr_len);
}

10
bitcoin/block.h

@ -7,9 +7,13 @@
#include <ccan/tal/tal.h>
#include <stdbool.h>
struct bitcoin_blkid {
struct sha256_double shad;
};
struct bitcoin_block_hdr {
le32 version;
struct sha256_double prev_hash;
struct bitcoin_blkid prev_hash;
struct sha256_double merkle_hash;
le32 timestamp;
le32 target;
@ -27,9 +31,9 @@ struct bitcoin_block *bitcoin_block_from_hex(const tal_t *ctx,
/* Parse hex string to get blockid (reversed, a-la bitcoind). */
bool bitcoin_blkid_from_hex(const char *hexstr, size_t hexstr_len,
struct sha256_double *blockid);
struct bitcoin_blkid *blockid);
/* Get hex string of blockid (reversed, a-la bitcoind). */
bool bitcoin_blkid_to_hex(const struct sha256_double *blockid,
bool bitcoin_blkid_to_hex(const struct bitcoin_blkid *blockid,
char *hexstr, size_t hexstr_len);
#endif /* LIGHTNING_BITCOIN_BLOCK_H */

8
bitcoin/chainparams.c

@ -7,7 +7,7 @@ const struct chainparams networks[] = {
{.index = 0,
.network_name = "bitcoin",
.bip173_name = "bc",
.genesis_blockhash = {{.u.u8 = {0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, 0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f, 0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c, 0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00}}},
.genesis_blockhash = {{{.u.u8 = {0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, 0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f, 0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c, 0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00}}}},
.rpc_port = 8332,
.cli = "bitcoin-cli",
.cli_args = NULL,
@ -16,7 +16,7 @@ const struct chainparams networks[] = {
{.index = 1,
.network_name = "regtest",
.bip173_name = "tb",
.genesis_blockhash = {{.u.u8 = {0x06, 0x22, 0x6e, 0x46, 0x11, 0x1a, 0x0b, 0x59, 0xca, 0xaf, 0x12, 0x60, 0x43, 0xeb, 0x5b, 0xbf, 0x28, 0xc3, 0x4f, 0x3a, 0x5e, 0x33, 0x2a, 0x1f, 0xc7, 0xb2, 0xb7, 0x3c, 0xf1, 0x88, 0x91, 0x0f}}},
.genesis_blockhash = {{{.u.u8 = {0x06, 0x22, 0x6e, 0x46, 0x11, 0x1a, 0x0b, 0x59, 0xca, 0xaf, 0x12, 0x60, 0x43, 0xeb, 0x5b, 0xbf, 0x28, 0xc3, 0x4f, 0x3a, 0x5e, 0x33, 0x2a, 0x1f, 0xc7, 0xb2, 0xb7, 0x3c, 0xf1, 0x88, 0x91, 0x0f}}}},
.rpc_port = 18332,
.cli = "bitcoin-cli",
.cli_args = "-regtest",
@ -25,7 +25,7 @@ const struct chainparams networks[] = {
{.index = 2,
.network_name = "testnet",
.bip173_name = "tb",
.genesis_blockhash = {{.u.u8 = {0x43, 0x49, 0x7f, 0xd7, 0xf8, 0x26, 0x95, 0x71, 0x08, 0xf4, 0xa3, 0x0f, 0xd9, 0xce, 0xc3, 0xae, 0xba, 0x79, 0x97, 0x20, 0x84, 0xe9, 0x0e, 0xad, 0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00}}},
.genesis_blockhash = {{{.u.u8 = {0x43, 0x49, 0x7f, 0xd7, 0xf8, 0x26, 0x95, 0x71, 0x08, 0xf4, 0xa3, 0x0f, 0xd9, 0xce, 0xc3, 0xae, 0xba, 0x79, 0x97, 0x20, 0x84, 0xe9, 0x0e, 0xad, 0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00}}}},
.rpc_port = 18332,
.cli = "bitcoin-cli",
.cli_args = "-testnet",
@ -34,7 +34,7 @@ const struct chainparams networks[] = {
{.index = 3,
.network_name = "litecoin",
.bip173_name = "ltc",
.genesis_blockhash = {{.u.u8 = {0xe2, 0xbf, 0x04, 0x7e, 0x7e, 0x5a, 0x19, 0x1a, 0xa4, 0xef, 0x34, 0xd3, 0x14, 0x97, 0x9d, 0xc9, 0x98, 0x6e, 0x0f, 0x19, 0x25, 0x1e, 0xda, 0xba, 0x59, 0x40, 0xfd, 0x1f, 0xe3, 0x65, 0xa7, 0x12 }}},
.genesis_blockhash = {{{.u.u8 = {0xe2, 0xbf, 0x04, 0x7e, 0x7e, 0x5a, 0x19, 0x1a, 0xa4, 0xef, 0x34, 0xd3, 0x14, 0x97, 0x9d, 0xc9, 0x98, 0x6e, 0x0f, 0x19, 0x25, 0x1e, 0xda, 0xba, 0x59, 0x40, 0xfd, 0x1f, 0xe3, 0x65, 0xa7, 0x12 }}}},
.rpc_port = 18332,
.cli = "litecoin-cli",
.cli_args = "",

4
bitcoin/chainparams.h

@ -2,7 +2,7 @@
#define LIGHTNING_BITCOIN_CHAINPARAMS_H
#include "config.h"
#include <bitcoin/shadouble.h>
#include <bitcoin/block.h>
#include <ccan/short_types/short_types.h>
#include <stdbool.h>
@ -10,7 +10,7 @@ struct chainparams {
const int index;
const char *network_name;
const char *bip173_name;
const struct sha256_double genesis_blockhash;
const struct bitcoin_blkid genesis_blockhash;
const int rpc_port;
const char *cli;
const char *cli_args;

3
bitcoin/shadouble.c

@ -1,6 +1,5 @@
#include "shadouble.h"
#include <ccan/mem/mem.h>
#include <common/type_to_string.h>
void sha256_double(struct sha256_double *shadouble, const void *p, size_t len)
{
@ -13,5 +12,3 @@ void sha256_double_done(struct sha256_ctx *shactx, struct sha256_double *res)
sha256_done(shactx, &res->sha);
sha256(&res->sha, &res->sha, sizeof(res->sha));
}
REGISTER_TYPE_TO_HEXSTR(sha256_double);

2
channeld/channel.c

@ -101,7 +101,7 @@ struct peer {
*/
u64 htlc_id;
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
struct channel_id channel_id;
struct channel *channel;

2
channeld/channel_wire.csv

@ -6,7 +6,7 @@ channel_normal_operation,11001
# Begin! (passes gossipd-client fd)
channel_init,1000
channel_init,,chain_hash,struct sha256_double
channel_init,,chain_hash,struct bitcoin_blkid
channel_init,,funding_txid,struct bitcoin_txid
channel_init,,funding_txout,u16
channel_init,,funding_satoshi,u64

Can't render this file because it has a wrong number of fields in line 2.

2
common/type_to_string.h

@ -8,8 +8,8 @@
/* This must match the type_to_string_ cases. */
union printable_types {
const struct pubkey *pubkey;
const struct sha256_double *sha256_double;
const struct bitcoin_txid *bitcoin_txid;
const struct bitcoin_blkid *bitcoin_blkid;
const struct sha256 *sha256;
const struct ripemd160 *ripemd160;
const struct rel_locktime *rel_locktime;

7
gossipd/gossip.c

@ -742,7 +742,7 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg)
{
struct routing_state *rstate = peer->daemon->rstate;
struct short_channel_id scid;
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
struct pubkey remote_node_id;
u16 flags, cltv_expiry_delta, direction;
u32 fee_base_msat, fee_proportional_millionths;
@ -759,7 +759,8 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg)
if (!structeq(&chain_hash, &rstate->chain_hash)) {
status_trace("Received channel_announcement for unknown chain %s",
type_to_string(msg, struct sha256_double,&chain_hash));
type_to_string(msg, struct bitcoin_blkid,
&chain_hash));
return;
}
@ -1288,7 +1289,7 @@ static struct io_plan *gossip_init(struct daemon_conn *master,
struct daemon *daemon,
const u8 *msg)
{
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
u16 port;
if (!fromwire_gossipctl_init(daemon, msg, NULL,

6
gossipd/gossip_wire.csv

@ -4,7 +4,7 @@
# Initialize the gossip daemon.
gossipctl_init,3000
gossipctl_init,,broadcast_interval,u32
gossipctl_init,,chain_hash,struct sha256_double
gossipctl_init,,chain_hash,struct bitcoin_blkid
gossipctl_init,,id,struct pubkey
# If non-zero, port to listen on.
gossipctl_init,,port,u16
@ -150,10 +150,10 @@ gossip_send_gossip,,gossip,len*u8
# we can use it already.
gossip_local_add_channel,3017
gossip_local_add_channel,,short_channel_id,struct short_channel_id
gossip_local_add_channel,,chain_hash,struct sha256_double
gossip_local_add_channel,,chain_hash,struct bitcoin_blkid
gossip_local_add_channel,,remote_node_id,struct pubkey
gossip_local_add_channel,,flags,u16
gossip_local_add_channel,,cltv_expiry_delta,u16
gossip_local_add_channel,,htlc_minimum_msat,u64
gossip_local_add_channel,,fee_base_msat,u32
gossip_local_add_channel,,fee_proportional_millionths,u32
gossip_local_add_channel,,fee_proportional_millionths,u32

Can't render this file because it has a wrong number of fields in line 5.

10
gossipd/routing.c

@ -35,7 +35,7 @@ static struct node_map *empty_node_map(const tal_t *ctx)
}
struct routing_state *new_routing_state(const tal_t *ctx,
const struct sha256_double *chain_hash,
const struct bitcoin_blkid *chain_hash,
const struct pubkey *local_id)
{
struct routing_state *rstate = tal(ctx, struct routing_state);
@ -503,7 +503,7 @@ bool handle_channel_announcement(
struct pubkey node_id_2;
struct pubkey bitcoin_key_1;
struct pubkey bitcoin_key_2;
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
struct node_connection *c0, *c1;
const tal_t *tmpctx = tal_tmpctx(rstate);
u8 *features;
@ -531,7 +531,7 @@ bool handle_channel_announcement(
if (!structeq(&chain_hash, &rstate->chain_hash)) {
status_trace("Received channel_announcement for unknown chain"
" %s",
type_to_string(tmpctx, struct sha256_double,
type_to_string(tmpctx, struct bitcoin_blkid,
&chain_hash));
tal_free(tmpctx);
return false;
@ -603,7 +603,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
u32 fee_base_msat;
u32 fee_proportional_millionths;
const tal_t *tmpctx = tal_tmpctx(rstate);
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
size_t len = tal_len(update);
serialized = tal_dup_arr(tmpctx, u8, update, len, 0);
@ -623,7 +623,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
* specified chain. */
if (!structeq(&chain_hash, &rstate->chain_hash)) {
status_trace("Received channel_update for unknown chain %s",
type_to_string(tmpctx, struct sha256_double,
type_to_string(tmpctx, struct bitcoin_blkid,
&chain_hash));
tal_free(tmpctx);
return;

4
gossipd/routing.h

@ -82,7 +82,7 @@ struct routing_state {
struct broadcast_state *broadcasts;
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
/* Our own ID so we can identify local channels */
struct pubkey local_id;
@ -96,7 +96,7 @@ struct route_hop {
};
struct routing_state *new_routing_state(const tal_t *ctx,
const struct sha256_double *chain_hash,
const struct bitcoin_blkid *chain_hash,
const struct pubkey *local_id);
/* Add a connection to the routing table, but do not mark it as usable

6
gossipd/test/run-bench-find_route.c

@ -49,10 +49,10 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx UNNEEDED)
/* AUTOGENERATED MOCKS START */
/* Generated stub for fromwire_channel_announcement */
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct sha256_double *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
{ fprintf(stderr, "fromwire_channel_announcement called!\n"); abort(); }
/* Generated stub for fromwire_channel_update */
bool fromwire_channel_update(const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct sha256_double *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED)
bool fromwire_channel_update(const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED)
{ fprintf(stderr, "fromwire_channel_update called!\n"); abort(); }
/* Generated stub for fromwire_node_announcement */
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
@ -151,7 +151,7 @@ static void run(const char *name)
int main(int argc, char *argv[])
{
static const struct sha256_double zerohash;
static const struct bitcoin_blkid zerohash;
const tal_t *ctx = trc = tal_tmpctx(NULL);
struct routing_state *rstate;
size_t num_nodes = 100, num_runs = 1;

6
gossipd/test/run-find_route-specific.c

@ -20,10 +20,10 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx UNNEEDED)
/* AUTOGENERATED MOCKS START */
/* Generated stub for fromwire_channel_announcement */
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct sha256_double *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
{ fprintf(stderr, "fromwire_channel_announcement called!\n"); abort(); }
/* Generated stub for fromwire_channel_update */
bool fromwire_channel_update(const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct sha256_double *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED)
bool fromwire_channel_update(const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED)
{ fprintf(stderr, "fromwire_channel_update called!\n"); abort(); }
/* Generated stub for fromwire_node_announcement */
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
@ -57,7 +57,7 @@ const void *trc;
int main(void)
{
static const struct sha256_double zerohash;
static const struct bitcoin_blkid zerohash;
const tal_t *ctx = trc = tal_tmpctx(NULL);
struct node_connection *nc;
struct routing_state *rstate;

6
gossipd/test/run-find_route.c

@ -13,10 +13,10 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx UNNEEDED)
/* AUTOGENERATED MOCKS START */
/* Generated stub for fromwire_channel_announcement */
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct sha256_double *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
{ fprintf(stderr, "fromwire_channel_announcement called!\n"); abort(); }
/* Generated stub for fromwire_channel_update */
bool fromwire_channel_update(const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct sha256_double *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED)
bool fromwire_channel_update(const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED)
{ fprintf(stderr, "fromwire_channel_update called!\n"); abort(); }
/* Generated stub for fromwire_node_announcement */
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
@ -67,7 +67,7 @@ static struct node_connection *add_connection(struct routing_state *rstate,
int main(void)
{
static const struct sha256_double zerohash;
static const struct bitcoin_blkid zerohash;
const tal_t *ctx = trc = tal_tmpctx(NULL);
struct node_connection *nc;
struct routing_state *rstate;

2
hsmd/hsm.c

@ -196,7 +196,7 @@ static struct io_plan *handle_channel_update_sig(struct io_conn *conn,
u32 timestamp, fee_base_msat, fee_proportional_mill;
u64 htlc_minimum_msat;
u16 flags, cltv_expiry_delta;
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
u8 *cu;
if (!fromwire_hsm_cupdate_sig_req(tmpctx, dc->msg_in, NULL, &cu)) {

14
lightningd/bitcoind.c

@ -360,9 +360,9 @@ static void process_chaintips(struct bitcoin_cli *bcli)
const jsmntok_t *tokens, *t, *end;
bool valid;
size_t i;
struct sha256_double tip;
struct bitcoin_blkid tip;
void (*cb)(struct bitcoind *bitcoind,
struct sha256_double *tipid,
struct bitcoin_blkid *tipid,
void *arg) = bcli->cb;
tokens = json_parse_input(bcli->output, bcli->output_bytes, &valid);
@ -418,7 +418,7 @@ static void process_chaintips(struct bitcoin_cli *bcli)
void bitcoind_get_chaintip_(struct bitcoind *bitcoind,
void (*cb)(struct bitcoind *bitcoind,
const struct sha256_double *tipid,
const struct bitcoin_blkid *tipid,
void *arg),
void *arg)
{
@ -444,7 +444,7 @@ static void process_rawblock(struct bitcoin_cli *bcli)
}
void bitcoind_getrawblock_(struct bitcoind *bitcoind,
const struct sha256_double *blockid,
const struct bitcoin_blkid *blockid,
void (*cb)(struct bitcoind *bitcoind,
struct bitcoin_block *blk,
void *arg),
@ -486,9 +486,9 @@ void bitcoind_getblockcount_(struct bitcoind *bitcoind,
static void process_getblockhash(struct bitcoin_cli *bcli)
{
struct sha256_double blkid;
struct bitcoin_blkid blkid;
void (*cb)(struct bitcoind *bitcoind,
const struct sha256_double *blkid,
const struct bitcoin_blkid *blkid,
void *arg) = bcli->cb;
if (bcli->output_bytes == 0
@ -504,7 +504,7 @@ static void process_getblockhash(struct bitcoin_cli *bcli)
void bitcoind_getblockhash_(struct bitcoind *bitcoind,
u32 height,
void (*cb)(struct bitcoind *bitcoind,
const struct sha256_double *blkid,
const struct bitcoin_blkid *blkid,
void *arg),
void *arg)
{

12
lightningd/bitcoind.h

@ -9,7 +9,7 @@
#include <ccan/typesafe_cb/typesafe_cb.h>
#include <stdbool.h>
struct sha256_double;
struct bitcoin_blkid;
struct lightningd;
struct ripemd160;
struct bitcoin_tx;
@ -86,7 +86,7 @@ void bitcoind_sendrawtx_(struct bitcoind *bitcoind,
void bitcoind_get_chaintip_(struct bitcoind *bitcoind,
void (*cb)(struct bitcoind *bitcoind,
const struct sha256_double *tipid,
const struct bitcoin_blkid *tipid,
void *arg),
void *arg);
@ -95,7 +95,7 @@ void bitcoind_get_chaintip_(struct bitcoind *bitcoind,
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct bitcoind *, \
const struct sha256_double *), \
const struct bitcoin_blkid *), \
(arg))
void bitcoind_getblockcount_(struct bitcoind *bitcoind,
@ -115,7 +115,7 @@ void bitcoind_getblockcount_(struct bitcoind *bitcoind,
void bitcoind_getblockhash_(struct bitcoind *bitcoind,
u32 height,
void (*cb)(struct bitcoind *bitcoind,
const struct sha256_double *blkid,
const struct bitcoin_blkid *blkid,
void *arg),
void *arg);
#define bitcoind_getblockhash(bitcoind_, height, cb, arg) \
@ -124,11 +124,11 @@ void bitcoind_getblockhash_(struct bitcoind *bitcoind,
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct bitcoind *, \
const struct sha256_double *), \
const struct bitcoin_blkid *), \
(arg))
void bitcoind_getrawblock_(struct bitcoind *bitcoind,
const struct sha256_double *blockid,
const struct bitcoin_blkid *blockid,
void (*cb)(struct bitcoind *bitcoind,
struct bitcoin_block *blk,
void *arg),

8
lightningd/chaintopology.c

@ -381,9 +381,9 @@ static struct block *new_block(struct chain_topology *topo,
{
struct block *b = tal(topo, struct block);
sha256_double(&b->blkid, &blk->hdr, sizeof(blk->hdr));
sha256_double(&b->blkid.shad, &blk->hdr, sizeof(blk->hdr));
log_debug(topo->log, "Adding block %s",
type_to_string(ltmp, struct sha256_double, &b->blkid));
type_to_string(ltmp, struct bitcoin_blkid, &b->blkid));
assert(!block_map_get(&topo->block_map, &b->blkid));
b->next = next;
b->topo = topo;
@ -443,7 +443,7 @@ static void rawblock_tip(struct bitcoind *bitcoind,
}
static void check_chaintip(struct bitcoind *bitcoind,
const struct sha256_double *tipid,
const struct bitcoin_blkid *tipid,
struct chain_topology *topo)
{
/* 0 is the main tip. */
@ -478,7 +478,7 @@ static void init_topo(struct bitcoind *bitcoind,
}
static void get_init_block(struct bitcoind *bitcoind,
const struct sha256_double *blkid,
const struct bitcoin_blkid *blkid,
struct chain_topology *topo)
{
bitcoind_getrawblock(bitcoind, blkid, init_topo, topo);

9
lightningd/chaintopology.h

@ -16,7 +16,6 @@ struct bitcoind;
struct command;
struct lightningd;
struct peer;
struct sha256_double;
struct txwatch;
enum feerate {
@ -50,7 +49,7 @@ struct block {
struct block *next;
/* Key for hash table */
struct sha256_double blkid;
struct bitcoin_blkid blkid;
/* Transactions in this block we care about */
const struct bitcoin_tx **txs;
@ -66,12 +65,12 @@ struct block {
};
/* Hash blocks by sha */
static inline const struct sha256_double *keyof_block_map(const struct block *b)
static inline const struct bitcoin_blkid *keyof_block_map(const struct block *b)
{
return &b->blkid;
}
static inline size_t hash_sha(const struct sha256_double *key)
static inline size_t hash_sha(const struct bitcoin_blkid *key)
{
size_t ret;
@ -79,7 +78,7 @@ static inline size_t hash_sha(const struct sha256_double *key)
return ret;
}
static inline bool block_eq(const struct block *b, const struct sha256_double *key)
static inline bool block_eq(const struct block *b, const struct bitcoin_blkid *key)
{
return structeq(&b->blkid, key);
}

4
lightningd/peer_control.c

@ -461,12 +461,12 @@ static bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
u16 ignored_u16;
u8 ignored_u8;
struct pubkey ignored_pubkey;
struct sha256_double ignored_shadouble;
struct bitcoin_blkid ignored_chainhash;
if (fromwire_channel_reestablish(in_pkt, NULL, channel_id,
&ignored_u64, &ignored_u64))
return true;
if (fromwire_open_channel(in_pkt, NULL, &ignored_shadouble,
if (fromwire_open_channel(in_pkt, NULL, &ignored_chainhash,
channel_id, &ignored_u64,
&ignored_u64, &ignored_u64,
&ignored_u64, &ignored_u64,

4
openingd/opening.c

@ -529,7 +529,7 @@ static u8 *fundee_channel(struct state *state,
struct pubkey their_funding_pubkey;
secp256k1_ecdsa_signature theirsig, sig;
struct bitcoin_tx *their_commit, *our_commit;
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
u8 *msg;
const u8 *wscript;
u8 channel_flags;
@ -574,7 +574,7 @@ static u8 *fundee_channel(struct state *state,
negotiation_failed(state, true,
"Unknown chain-hash %s",
type_to_string(peer_msg,
struct sha256_double,
struct bitcoin_blkid,
&chain_hash));
}

4
tools/generate-wire.py

@ -18,7 +18,7 @@ type2size = {
'struct preimage': 32,
'struct pubkey': 33,
'struct sha256': 32,
'struct sha256_double': 32,
'struct bitcoin_blkid': 32,
'struct bitcoin_txid': 32,
'u64': 8,
'u32': 4,
@ -78,7 +78,7 @@ partialtypemap = {
'signature': FieldType('secp256k1_ecdsa_signature'),
'features': FieldType('u8'),
'channel_id': FieldType('struct channel_id'),
'chain_hash': FieldType('struct sha256_double'),
'chain_hash': FieldType('struct bitcoin_blkid'),
'funding_txid': FieldType('struct bitcoin_txid'),
'pad': FieldType('pad'),
}

6
wire/fromwire.c

@ -183,6 +183,12 @@ void fromwire_bitcoin_txid(const u8 **cursor, size_t *max,
fromwire_sha256_double(cursor, max, &txid->shad);
}
void fromwire_bitcoin_blkid(const u8 **cursor, size_t *max,
struct bitcoin_blkid *blkid)
{
fromwire_sha256_double(cursor, max, &blkid->shad);
}
void fromwire_preimage(const u8 **cursor, size_t *max, struct preimage *preimage)
{
fromwire(cursor, max, preimage, sizeof(*preimage));

6
wire/test/run-peer-wire.c

@ -128,7 +128,7 @@ struct msg_channel_update {
u64 htlc_minimum_msat;
u32 fee_base_msat;
u32 fee_proportional_millionths;
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
struct short_channel_id short_channel_id;
};
struct msg_funding_locked {
@ -156,7 +156,7 @@ struct msg_node_announcement {
u8 *addresses;
};
struct msg_open_channel {
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
struct channel_id temporary_channel_id;
u64 funding_satoshis;
u64 push_msat;
@ -186,7 +186,7 @@ struct msg_channel_announcement {
secp256k1_ecdsa_signature bitcoin_signature_1;
secp256k1_ecdsa_signature bitcoin_signature_2;
u8 *features;
struct sha256_double chain_hash;
struct bitcoin_blkid chain_hash;
struct short_channel_id short_channel_id;
struct pubkey node_id_1;
struct pubkey node_id_2;

5
wire/towire.c

@ -125,6 +125,11 @@ void towire_bitcoin_txid(u8 **pptr, const struct bitcoin_txid *txid)
towire_sha256_double(pptr, &txid->shad);
}
void towire_bitcoin_blkid(u8 **pptr, const struct bitcoin_blkid *blkid)
{
towire_sha256_double(pptr, &blkid->shad);
}
void towire_preimage(u8 **pptr, const struct preimage *preimage)
{
towire(pptr, preimage, sizeof(*preimage));

5
wire/wire.h

@ -1,6 +1,7 @@
#ifndef LIGHTNING_WIRE_WIRE_H
#define LIGHTNING_WIRE_WIRE_H
#include "config.h"
#include <bitcoin/block.h>
#include <bitcoin/privkey.h>
#include <bitcoin/pubkey.h>
#include <bitcoin/shadouble.h>
@ -15,6 +16,7 @@ struct channel_id {
u8 id[32];
};
struct bitcoin_blkid;
struct bitcoin_txid;
struct preimage;
struct ripemd160;
@ -40,6 +42,7 @@ void towire_short_channel_id(u8 **pptr,
void towire_sha256(u8 **pptr, const struct sha256 *sha256);
void towire_sha256_double(u8 **pptr, const struct sha256_double *sha256d);
void towire_bitcoin_txid(u8 **pptr, const struct bitcoin_txid *txid);
void towire_bitcoin_blkid(u8 **pptr, const struct bitcoin_blkid *blkid);
void towire_preimage(u8 **pptr, const struct preimage *preimage);
void towire_ripemd160(u8 **pptr, const struct ripemd160 *ripemd);
void towire_u8(u8 **pptr, u8 v);
@ -74,6 +77,8 @@ void fromwire_sha256_double(const u8 **cursor, size_t *max,
struct sha256_double *sha256d);
void fromwire_bitcoin_txid(const u8 **cursor, size_t *max,
struct bitcoin_txid *txid);
void fromwire_bitcoin_blkid(const u8 **cursor, size_t *max,
struct bitcoin_blkid *blkid);
void fromwire_preimage(const u8 **cursor, size_t *max, struct preimage *preimage);
void fromwire_ripemd160(const u8 **cursor, size_t *max, struct ripemd160 *ripemd);
void fromwire_pad(const u8 **cursor, size_t *max, size_t num);

Loading…
Cancel
Save