diff --git a/bitcoin/block.c b/bitcoin/block.c index 7abbd7c88..023961c2e 100644 --- a/bitcoin/block.c +++ b/bitcoin/block.c @@ -2,6 +2,7 @@ #include "bitcoin/pullpush.h" #include "bitcoin/tx.h" #include +#include /* Encoding is ... */ 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); } diff --git a/bitcoin/block.h b/bitcoin/block.h index 44b712b61..b22e07226 100644 --- a/bitcoin/block.h +++ b/bitcoin/block.h @@ -7,9 +7,13 @@ #include #include +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 */ diff --git a/bitcoin/chainparams.c b/bitcoin/chainparams.c index 1e6c8f060..5a6a5b6d3 100644 --- a/bitcoin/chainparams.c +++ b/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 = "", diff --git a/bitcoin/chainparams.h b/bitcoin/chainparams.h index 2982a3aa8..3a5d65489 100644 --- a/bitcoin/chainparams.h +++ b/bitcoin/chainparams.h @@ -2,7 +2,7 @@ #define LIGHTNING_BITCOIN_CHAINPARAMS_H #include "config.h" -#include +#include #include #include @@ -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; diff --git a/bitcoin/shadouble.c b/bitcoin/shadouble.c index 4e819d51b..c229b9744 100644 --- a/bitcoin/shadouble.c +++ b/bitcoin/shadouble.c @@ -1,6 +1,5 @@ #include "shadouble.h" #include -#include 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); diff --git a/channeld/channel.c b/channeld/channel.c index 460b0c645..694777303 100644 --- a/channeld/channel.c +++ b/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; diff --git a/channeld/channel_wire.csv b/channeld/channel_wire.csv index 11d8e8df6..3d48549bd 100644 --- a/channeld/channel_wire.csv +++ b/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 diff --git a/common/type_to_string.h b/common/type_to_string.h index 221ad66c9..357d965b1 100644 --- a/common/type_to_string.h +++ b/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; diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 113159549..798bb15b4 100644 --- a/gossipd/gossip.c +++ b/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, diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 9b4272130..9af6872cf 100644 --- a/gossipd/gossip_wire.csv +++ b/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 \ No newline at end of file +gossip_local_add_channel,,fee_proportional_millionths,u32 diff --git a/gossipd/routing.c b/gossipd/routing.c index f89c5169b..5563ad31b 100644 --- a/gossipd/routing.c +++ b/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; diff --git a/gossipd/routing.h b/gossipd/routing.h index 81ed35900..88fb23aee 100644 --- a/gossipd/routing.h +++ b/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 diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index d89ba3f5c..4c450cc24 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/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; diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 6efabd054..caba4f454 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/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; diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index 929e60a39..75f179cba 100644 --- a/gossipd/test/run-find_route.c +++ b/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; diff --git a/hsmd/hsm.c b/hsmd/hsm.c index 7e68ba6ee..e2170b65e 100644 --- a/hsmd/hsm.c +++ b/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)) { diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index fa8e0c547..c6ce222d2 100644 --- a/lightningd/bitcoind.c +++ b/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) { diff --git a/lightningd/bitcoind.h b/lightningd/bitcoind.h index 553488152..eaf7618a6 100644 --- a/lightningd/bitcoind.h +++ b/lightningd/bitcoind.h @@ -9,7 +9,7 @@ #include #include -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), diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 8ec5d627f..92b9a2ac3 100644 --- a/lightningd/chaintopology.c +++ b/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); diff --git a/lightningd/chaintopology.h b/lightningd/chaintopology.h index 42a189b5c..9bfb79ecb 100644 --- a/lightningd/chaintopology.h +++ b/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); } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 31daaffd8..30929ee4f 100644 --- a/lightningd/peer_control.c +++ b/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, diff --git a/openingd/opening.c b/openingd/opening.c index b60595e1c..3f4b0c3a2 100644 --- a/openingd/opening.c +++ b/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)); } diff --git a/tools/generate-wire.py b/tools/generate-wire.py index 809d858af..f86971ba7 100755 --- a/tools/generate-wire.py +++ b/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'), } diff --git a/wire/fromwire.c b/wire/fromwire.c index 39300e814..dace8bd04 100644 --- a/wire/fromwire.c +++ b/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)); diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index 280c7bf2b..db96ddf8b 100644 --- a/wire/test/run-peer-wire.c +++ b/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; diff --git a/wire/towire.c b/wire/towire.c index c377ec147..2e0c0eb04 100644 --- a/wire/towire.c +++ b/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)); diff --git a/wire/wire.h b/wire/wire.h index 1b24d55bd..ad0ce699e 100644 --- a/wire/wire.h +++ b/wire/wire.h @@ -1,6 +1,7 @@ #ifndef LIGHTNING_WIRE_WIRE_H #define LIGHTNING_WIRE_WIRE_H #include "config.h" +#include #include #include #include @@ -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);