Browse Source

tools/generate_wire.py: make bitcoin_tx a varlen structs

Now it allocates naturally.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
674a2c7554
  1. 20
      lightningd/peer_control.c
  2. 4
      lightningd/peer_htlcs.c
  3. 7
      onchaind/onchain.c
  4. 1
      tools/generate-wire.py
  5. 4
      wallet/walletrpc.c
  6. 6
      wire/fromwire.c
  7. 3
      wire/wire.h

20
lightningd/peer_control.c

@ -1150,8 +1150,7 @@ static void handle_onchain_broadcast_tx(struct peer *peer, const u8 *msg)
{ {
struct bitcoin_tx *tx; struct bitcoin_tx *tx;
tx = tal(msg, struct bitcoin_tx); if (!fromwire_onchain_broadcast_tx(msg, msg, NULL, &tx)) {
if (!fromwire_onchain_broadcast_tx(msg, NULL, tx)) {
peer_internal_error(peer, "Invalid onchain_broadcast_tx"); peer_internal_error(peer, "Invalid onchain_broadcast_tx");
return; return;
} }
@ -1581,12 +1580,12 @@ static void opening_got_hsm_funding_sig(struct funding_channel *fc,
const struct crypto_state *cs, const struct crypto_state *cs,
u64 gossip_index) u64 gossip_index)
{ {
struct bitcoin_tx *tx = tal(fc, struct bitcoin_tx); struct bitcoin_tx *tx;
u8 *linear; u8 *linear;
u64 change_satoshi; u64 change_satoshi;
struct json_result *response = new_json_result(fc->cmd); struct json_result *response = new_json_result(fc->cmd);
if (!fromwire_hsm_sign_funding_reply(resp, NULL, tx)) if (!fromwire_hsm_sign_funding_reply(fc, resp, NULL, &tx))
fatal("HSM gave bad sign_funding_reply %s", fatal("HSM gave bad sign_funding_reply %s",
tal_hex(fc, resp)); tal_hex(fc, resp));
@ -1788,9 +1787,9 @@ static bool better_closing_fee(struct peer *peer, const struct bitcoin_tx *tx)
static void peer_received_closing_signature(struct peer *peer, const u8 *msg) static void peer_received_closing_signature(struct peer *peer, const u8 *msg)
{ {
secp256k1_ecdsa_signature sig; secp256k1_ecdsa_signature sig;
struct bitcoin_tx *tx = tal(msg, struct bitcoin_tx); struct bitcoin_tx *tx;
if (!fromwire_closing_received_signature(msg, NULL, &sig, tx)) { if (!fromwire_closing_received_signature(msg, msg, NULL, &sig, &tx)) {
peer_internal_error(peer, "Bad closing_received_signature %s", peer_internal_error(peer, "Bad closing_received_signature %s",
tal_hex(peer, msg)); tal_hex(peer, msg));
return; return;
@ -2220,14 +2219,13 @@ static void opening_funder_finished(struct subd *opening, const u8 *resp,
/* At this point, we care about peer */ /* At this point, we care about peer */
fc->peer->channel_info = channel_info fc->peer->channel_info = channel_info
= tal(fc->peer, struct channel_info); = tal(fc->peer, struct channel_info);
remote_commit = tal(resp, struct bitcoin_tx);
/* This is a new channel_info->their_config so set its ID to 0 */ /* This is a new channel_info->their_config so set its ID to 0 */
fc->peer->channel_info->their_config.id = 0; fc->peer->channel_info->their_config.id = 0;
if (!fromwire_opening_funder_reply(resp, NULL, if (!fromwire_opening_funder_reply(resp, resp, NULL,
&channel_info->their_config, &channel_info->their_config,
remote_commit, &remote_commit,
&remote_commit_sig, &remote_commit_sig,
&cs, &cs,
&gossip_index, &gossip_index,
@ -2340,8 +2338,6 @@ static void opening_fundee_finished(struct subd *opening,
log_debug(peer->log, "Got opening_fundee_finish_response"); log_debug(peer->log, "Got opening_fundee_finish_response");
assert(tal_count(fds) == 2); assert(tal_count(fds) == 2);
remote_commit = tal(reply, struct bitcoin_tx);
/* At this point, we care about peer */ /* At this point, we care about peer */
peer->channel_info = channel_info = tal(peer, struct channel_info); peer->channel_info = channel_info = tal(peer, struct channel_info);
/* This is a new channel_info->their_config, set its ID to 0 */ /* This is a new channel_info->their_config, set its ID to 0 */
@ -2350,7 +2346,7 @@ static void opening_fundee_finished(struct subd *opening,
peer->funding_txid = tal(peer, struct bitcoin_txid); peer->funding_txid = tal(peer, struct bitcoin_txid);
if (!fromwire_opening_fundee_reply(tmpctx, reply, NULL, if (!fromwire_opening_fundee_reply(tmpctx, reply, NULL,
&channel_info->their_config, &channel_info->their_config,
remote_commit, &remote_commit,
&remote_commit_sig, &remote_commit_sig,
&cs, &cs,
&gossip_index, &gossip_index,

4
lightningd/peer_htlcs.c

@ -1081,7 +1081,7 @@ void peer_got_commitsig(struct peer *peer, const u8 *msg)
struct fulfilled_htlc *fulfilled; struct fulfilled_htlc *fulfilled;
struct failed_htlc **failed; struct failed_htlc **failed;
struct changed_htlc *changed; struct changed_htlc *changed;
struct bitcoin_tx *tx = tal(msg, struct bitcoin_tx); struct bitcoin_tx *tx;
size_t i; size_t i;
if (!fromwire_channel_got_commitsig(msg, msg, NULL, if (!fromwire_channel_got_commitsig(msg, msg, NULL,
@ -1094,7 +1094,7 @@ void peer_got_commitsig(struct peer *peer, const u8 *msg)
&fulfilled, &fulfilled,
&failed, &failed,
&changed, &changed,
tx)) { &tx)) {
peer_internal_error(peer, peer_internal_error(peer,
"bad fromwire_channel_got_commitsig %s", "bad fromwire_channel_got_commitsig %s",
tal_hex(peer, msg)); tal_hex(peer, msg));

7
onchaind/onchain.c

@ -943,7 +943,7 @@ static void wait_for_resolved(struct tracked_output **outs)
while (!all_irrevocably_resolved(outs)) { while (!all_irrevocably_resolved(outs)) {
u8 *msg = wire_sync_read(outs, REQ_FD); u8 *msg = wire_sync_read(outs, REQ_FD);
struct bitcoin_txid txid; struct bitcoin_txid txid;
struct bitcoin_tx *tx = tal(msg, struct bitcoin_tx); struct bitcoin_tx *tx;
u32 input_num, depth, tx_blockheight; u32 input_num, depth, tx_blockheight;
struct preimage preimage; struct preimage preimage;
@ -952,7 +952,7 @@ static void wait_for_resolved(struct tracked_output **outs)
if (fromwire_onchain_depth(msg, NULL, &txid, &depth)) if (fromwire_onchain_depth(msg, NULL, &txid, &depth))
tx_new_depth(outs, &txid, depth); tx_new_depth(outs, &txid, depth);
else if (fromwire_onchain_spent(msg, NULL, tx, &input_num, else if (fromwire_onchain_spent(msg, msg, NULL, &tx, &input_num,
&tx_blockheight)) &tx_blockheight))
output_spent(&outs, tx, input_num, tx_blockheight); output_spent(&outs, tx, input_num, tx_blockheight);
else if (fromwire_onchain_known_preimage(msg, NULL, &preimage)) else if (fromwire_onchain_known_preimage(msg, NULL, &preimage))
@ -1982,7 +1982,6 @@ int main(int argc, char *argv[])
missing_htlc_msgs = tal_arr(ctx, u8 *, 0); missing_htlc_msgs = tal_arr(ctx, u8 *, 0);
msg = wire_sync_read(ctx, REQ_FD); msg = wire_sync_read(ctx, REQ_FD);
tx = tal(ctx, struct bitcoin_tx);
if (!fromwire_onchain_init(ctx, msg, NULL, if (!fromwire_onchain_init(ctx, msg, NULL,
&seed, &shachain, &seed, &shachain,
&funding_amount_satoshi, &funding_amount_satoshi,
@ -2001,7 +2000,7 @@ int main(int argc, char *argv[])
&remote_payment_basepoint, &remote_payment_basepoint,
&remote_htlc_basepoint, &remote_htlc_basepoint,
&remote_delayed_payment_basepoint, &remote_delayed_payment_basepoint,
tx, &tx,
&tx_blockheight, &tx_blockheight,
&reasonable_depth, &reasonable_depth,
&remote_htlc_sigs, &remote_htlc_sigs,

1
tools/generate-wire.py

@ -32,6 +32,7 @@ varlen_structs = [
'gossip_getnodes_entry', 'gossip_getnodes_entry',
'failed_htlc', 'failed_htlc',
'utxo', 'utxo',
'bitcoin_tx',
] ]
class FieldType(object): class FieldType(object):

4
wallet/walletrpc.c

@ -289,9 +289,7 @@ static void json_withdraw(struct command *cmd,
msg = hsm_sync_read(cmd, cmd->ld); msg = hsm_sync_read(cmd, cmd->ld);
tx = tal(withdraw, struct bitcoin_tx); if (!fromwire_hsm_sign_withdrawal_reply(msg, msg, NULL, &tx))
if (!fromwire_hsm_sign_withdrawal_reply(msg, NULL, tx))
fatal("HSM gave bad sign_withdrawal_reply %s", fatal("HSM gave bad sign_withdrawal_reply %s",
tal_hex(withdraw, msg)); tal_hex(withdraw, msg));

6
wire/fromwire.c

@ -225,7 +225,9 @@ void derive_channel_id(struct channel_id *channel_id,
channel_id->id[sizeof(*channel_id)-1] ^= txout; channel_id->id[sizeof(*channel_id)-1] ^= txout;
} }
void fromwire_bitcoin_tx(const u8 **cursor, size_t *max, struct bitcoin_tx *tx) /* FIXME: Simply rename pull_bitcoin_tx, remove pull_bitcoin_tx_onto */
struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
const u8 **cursor, size_t *max)
{ {
pull_bitcoin_tx_onto(tx, cursor, max, tx); return pull_bitcoin_tx(ctx, cursor, max);
} }

3
wire/wire.h

@ -87,5 +87,6 @@ void fromwire_pad(const u8 **cursor, size_t *max, size_t num);
void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num); void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num);
void fromwire_bitcoin_tx(const u8 **cursor, size_t *max, struct bitcoin_tx *tx); struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
const u8 **cursor, size_t *max);
#endif /* LIGHTNING_WIRE_WIRE_H */ #endif /* LIGHTNING_WIRE_WIRE_H */

Loading…
Cancel
Save