mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
tx: Add chainparams when deserializing transactions from wire msgs
This is the other origin, besides `bitcoin_tx`, where we create `bitcoin_tx` instances, so add the context as soon as possible. Sadly I can't weave the chainparams into the deserialization code since that'd need to change all the generated wire code as well. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
d14bd286ba
commit
5dff67900e
10 changed files with 33 additions and 7 deletions
|
@ -281,6 +281,7 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx,
|
||||||
varint_t input_count, varint_t output_count)
|
varint_t input_count, varint_t output_count)
|
||||||
{
|
{
|
||||||
struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx);
|
struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx);
|
||||||
|
assert(chainparams);
|
||||||
|
|
||||||
wally_tx_init_alloc(WALLY_TX_VERSION_2, 0, input_count, output_count,
|
wally_tx_init_alloc(WALLY_TX_VERSION_2, 0, input_count, output_count,
|
||||||
&tx->wtx);
|
&tx->wtx);
|
||||||
|
|
11
hsmd/hsmd.c
11
hsmd/hsmd.c
|
@ -825,6 +825,8 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
|
||||||
&funding))
|
&funding))
|
||||||
return bad_req(conn, c, msg_in);
|
return bad_req(conn, c, msg_in);
|
||||||
|
|
||||||
|
tx->chainparams = c->chainparams;
|
||||||
|
|
||||||
/* Basic sanity checks. */
|
/* Basic sanity checks. */
|
||||||
if (tx->wtx->num_inputs != 1)
|
if (tx->wtx->num_inputs != 1)
|
||||||
return bad_req_fmt(conn, c, msg_in, "tx must have 1 input");
|
return bad_req_fmt(conn, c, msg_in, "tx must have 1 input");
|
||||||
|
@ -883,6 +885,7 @@ static struct io_plan *handle_sign_remote_commitment_tx(struct io_conn *conn,
|
||||||
&remote_funding_pubkey,
|
&remote_funding_pubkey,
|
||||||
&funding))
|
&funding))
|
||||||
bad_req(conn, c, msg_in);
|
bad_req(conn, c, msg_in);
|
||||||
|
tx->chainparams = c->chainparams;
|
||||||
|
|
||||||
/* Basic sanity checks. */
|
/* Basic sanity checks. */
|
||||||
if (tx->wtx->num_inputs != 1)
|
if (tx->wtx->num_inputs != 1)
|
||||||
|
@ -929,7 +932,7 @@ static struct io_plan *handle_sign_remote_htlc_tx(struct io_conn *conn,
|
||||||
&tx, &wscript, &amount,
|
&tx, &wscript, &amount,
|
||||||
&remote_per_commit_point))
|
&remote_per_commit_point))
|
||||||
return bad_req(conn, c, msg_in);
|
return bad_req(conn, c, msg_in);
|
||||||
|
tx->chainparams = c->chainparams;
|
||||||
get_channel_seed(&c->id, c->dbid, &channel_seed);
|
get_channel_seed(&c->id, c->dbid, &channel_seed);
|
||||||
derive_basepoints(&channel_seed, NULL, &basepoints, &secrets, NULL);
|
derive_basepoints(&channel_seed, NULL, &basepoints, &secrets, NULL);
|
||||||
|
|
||||||
|
@ -1004,7 +1007,7 @@ static struct io_plan *handle_sign_delayed_payment_to_us(struct io_conn *conn,
|
||||||
&tx, &wscript,
|
&tx, &wscript,
|
||||||
&input_sat))
|
&input_sat))
|
||||||
return bad_req(conn, c, msg_in);
|
return bad_req(conn, c, msg_in);
|
||||||
|
tx->chainparams = c->chainparams;
|
||||||
get_channel_seed(&c->id, c->dbid, &channel_seed);
|
get_channel_seed(&c->id, c->dbid, &channel_seed);
|
||||||
|
|
||||||
/*~ ccan/crypto/shachain how we efficiently derive 2^48 ordered
|
/*~ ccan/crypto/shachain how we efficiently derive 2^48 ordered
|
||||||
|
@ -1059,6 +1062,7 @@ static struct io_plan *handle_sign_remote_htlc_to_us(struct io_conn *conn,
|
||||||
&input_sat))
|
&input_sat))
|
||||||
return bad_req(conn, c, msg_in);
|
return bad_req(conn, c, msg_in);
|
||||||
|
|
||||||
|
tx->chainparams = c->chainparams;
|
||||||
get_channel_seed(&c->id, c->dbid, &channel_seed);
|
get_channel_seed(&c->id, c->dbid, &channel_seed);
|
||||||
|
|
||||||
if (!derive_htlc_basepoint(&channel_seed, &htlc_basepoint,
|
if (!derive_htlc_basepoint(&channel_seed, &htlc_basepoint,
|
||||||
|
@ -1097,6 +1101,7 @@ static struct io_plan *handle_sign_penalty_to_us(struct io_conn *conn,
|
||||||
&tx, &wscript,
|
&tx, &wscript,
|
||||||
&input_sat))
|
&input_sat))
|
||||||
return bad_req(conn, c, msg_in);
|
return bad_req(conn, c, msg_in);
|
||||||
|
tx->chainparams = c->chainparams;
|
||||||
|
|
||||||
if (!pubkey_from_secret(&revocation_secret, &point))
|
if (!pubkey_from_secret(&revocation_secret, &point))
|
||||||
return bad_req_fmt(conn, c, msg_in, "Failed deriving pubkey");
|
return bad_req_fmt(conn, c, msg_in, "Failed deriving pubkey");
|
||||||
|
@ -1143,6 +1148,7 @@ static struct io_plan *handle_sign_local_htlc_tx(struct io_conn *conn,
|
||||||
&input_sat))
|
&input_sat))
|
||||||
return bad_req(conn, c, msg_in);
|
return bad_req(conn, c, msg_in);
|
||||||
|
|
||||||
|
tx->chainparams = c->chainparams;
|
||||||
get_channel_seed(&c->id, c->dbid, &channel_seed);
|
get_channel_seed(&c->id, c->dbid, &channel_seed);
|
||||||
|
|
||||||
if (!derive_shaseed(&channel_seed, &shaseed))
|
if (!derive_shaseed(&channel_seed, &shaseed))
|
||||||
|
@ -1277,6 +1283,7 @@ static struct io_plan *handle_sign_mutual_close_tx(struct io_conn *conn,
|
||||||
&funding))
|
&funding))
|
||||||
return bad_req(conn, c, msg_in);
|
return bad_req(conn, c, msg_in);
|
||||||
|
|
||||||
|
tx->chainparams = c->chainparams;
|
||||||
/* FIXME: We should know dust level, decent fee range and
|
/* FIXME: We should know dust level, decent fee range and
|
||||||
* balances, and final_keyindex, and thus be able to check tx
|
* balances, and final_keyindex, and thus be able to check tx
|
||||||
* outputs! */
|
* outputs! */
|
||||||
|
|
|
@ -703,6 +703,12 @@ static void have_new_block(struct bitcoind *bitcoind UNUSED,
|
||||||
struct bitcoin_block *blk,
|
struct bitcoin_block *blk,
|
||||||
struct chain_topology *topo)
|
struct chain_topology *topo)
|
||||||
{
|
{
|
||||||
|
const struct chainparams *chainparams = get_chainparams(topo->ld);
|
||||||
|
/* Annotate all transactions with the chainparams */
|
||||||
|
for (size_t i=0; i<tal_count(blk->tx); i++)
|
||||||
|
blk->tx[i]->chainparams = chainparams;
|
||||||
|
|
||||||
|
|
||||||
/* Unexpected predecessor? Free predecessor, refetch it. */
|
/* Unexpected predecessor? Free predecessor, refetch it. */
|
||||||
if (!bitcoin_blkid_eq(&topo->tip->blkid, &blk->hdr.prev_hash))
|
if (!bitcoin_blkid_eq(&topo->tip->blkid, &blk->hdr.prev_hash))
|
||||||
remove_tip(topo);
|
remove_tip(topo);
|
||||||
|
|
|
@ -226,6 +226,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||||
channel->msat_to_us_min = msat_to_us_min;
|
channel->msat_to_us_min = msat_to_us_min;
|
||||||
channel->msat_to_us_max = msat_to_us_max;
|
channel->msat_to_us_max = msat_to_us_max;
|
||||||
channel->last_tx = tal_steal(channel, last_tx);
|
channel->last_tx = tal_steal(channel, last_tx);
|
||||||
|
channel->last_tx->chainparams = get_chainparams(peer->ld);
|
||||||
channel->last_tx_type = TX_UNKNOWN;
|
channel->last_tx_type = TX_UNKNOWN;
|
||||||
channel->last_sig = *last_sig;
|
channel->last_sig = *last_sig;
|
||||||
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);
|
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);
|
||||||
|
@ -328,6 +329,7 @@ void channel_set_last_tx(struct channel *channel,
|
||||||
const struct bitcoin_signature *sig,
|
const struct bitcoin_signature *sig,
|
||||||
enum wallet_tx_type txtypes)
|
enum wallet_tx_type txtypes)
|
||||||
{
|
{
|
||||||
|
assert(tx->chainparams);
|
||||||
channel->last_sig = *sig;
|
channel->last_sig = *sig;
|
||||||
tal_free(channel->last_tx);
|
tal_free(channel->last_tx);
|
||||||
channel->last_tx = tal_steal(channel, tx);
|
channel->last_tx = tal_steal(channel, tx);
|
||||||
|
|
|
@ -92,6 +92,7 @@ static void peer_received_closing_signature(struct channel *channel,
|
||||||
tal_hex(msg, msg));
|
tal_hex(msg, msg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
tx->chainparams = get_chainparams(channel->peer->ld);
|
||||||
|
|
||||||
/* FIXME: Make sure signature is correct! */
|
/* FIXME: Make sure signature is correct! */
|
||||||
if (better_closing_fee(ld, channel, tx)) {
|
if (better_closing_fee(ld, channel, tx)) {
|
||||||
|
|
|
@ -187,6 +187,7 @@ static void handle_onchain_broadcast_tx(struct channel *channel, const u8 *msg)
|
||||||
channel_internal_error(channel, "Invalid onchain_broadcast_tx");
|
channel_internal_error(channel, "Invalid onchain_broadcast_tx");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
tx->chainparams = get_chainparams(channel->peer->ld);
|
||||||
|
|
||||||
bitcoin_txid(tx, &txid);
|
bitcoin_txid(tx, &txid);
|
||||||
wallet_transaction_add(w, tx, 0, 0);
|
wallet_transaction_add(w, tx, 0, 0);
|
||||||
|
|
|
@ -522,6 +522,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
||||||
tal_hex(fc->cmd, resp)));
|
tal_hex(fc->cmd, resp)));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
remote_commit->chainparams = get_chainparams(openingd->ld);
|
||||||
per_peer_state_set_fds_arr(pps, fds);
|
per_peer_state_set_fds_arr(pps, fds);
|
||||||
|
|
||||||
log_debug(ld->log,
|
log_debug(ld->log,
|
||||||
|
@ -629,6 +630,8 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||||
uncommitted_channel_disconnect(uc, "bad OPENING_FUNDEE_REPLY");
|
uncommitted_channel_disconnect(uc, "bad OPENING_FUNDEE_REPLY");
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remote_commit->chainparams = get_chainparams(openingd->ld);
|
||||||
per_peer_state_set_fds_arr(pps, fds);
|
per_peer_state_set_fds_arr(pps, fds);
|
||||||
|
|
||||||
/* openingd should never accept them funding channel in this case. */
|
/* openingd should never accept them funding channel in this case. */
|
||||||
|
|
|
@ -1468,6 +1468,7 @@ void peer_got_commitsig(struct channel *channel, const u8 *msg)
|
||||||
tal_hex(channel, msg));
|
tal_hex(channel, msg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
tx->chainparams = get_chainparams(ld);
|
||||||
|
|
||||||
log_debug(channel->log,
|
log_debug(channel->log,
|
||||||
"got commitsig %"PRIu64
|
"got commitsig %"PRIu64
|
||||||
|
|
|
@ -1374,9 +1374,10 @@ static void wait_for_resolved(const struct chainparams *chainparams,
|
||||||
if (fromwire_onchain_depth(msg, &txid, &depth))
|
if (fromwire_onchain_depth(msg, &txid, &depth))
|
||||||
tx_new_depth(outs, &txid, depth);
|
tx_new_depth(outs, &txid, depth);
|
||||||
else if (fromwire_onchain_spent(msg, msg, &tx, &input_num,
|
else if (fromwire_onchain_spent(msg, msg, &tx, &input_num,
|
||||||
&tx_blockheight))
|
&tx_blockheight)) {
|
||||||
|
tx->chainparams = chainparams;
|
||||||
output_spent(chainparams, &outs, tx, input_num, tx_blockheight);
|
output_spent(chainparams, &outs, tx, input_num, tx_blockheight);
|
||||||
else if (fromwire_onchain_known_preimage(msg, &preimage))
|
} else if (fromwire_onchain_known_preimage(msg, &preimage))
|
||||||
handle_preimage(chainparams, outs, &preimage);
|
handle_preimage(chainparams, outs, &preimage);
|
||||||
else if (!handle_dev_memleak(outs, msg))
|
else if (!handle_dev_memleak(outs, msg))
|
||||||
master_badmsg(-1, msg);
|
master_badmsg(-1, msg);
|
||||||
|
|
|
@ -29,6 +29,11 @@ static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, bool ca
|
||||||
|
|
||||||
bool deprecated_apis = true;
|
bool deprecated_apis = true;
|
||||||
|
|
||||||
|
const struct chainparams *get_chainparams(const struct lightningd *ld)
|
||||||
|
{
|
||||||
|
return chainparams_for_network("bitcoin");
|
||||||
|
}
|
||||||
|
|
||||||
/* AUTOGENERATED MOCKS START */
|
/* AUTOGENERATED MOCKS START */
|
||||||
/* Generated stub for bitcoind_gettxout */
|
/* Generated stub for bitcoind_gettxout */
|
||||||
void bitcoind_gettxout(struct bitcoind *bitcoind UNNEEDED,
|
void bitcoind_gettxout(struct bitcoind *bitcoind UNNEEDED,
|
||||||
|
@ -109,9 +114,6 @@ bool fromwire_onchain_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEE
|
||||||
/* Generated stub for get_block_height */
|
/* Generated stub for get_block_height */
|
||||||
u32 get_block_height(const struct chain_topology *topo UNNEEDED)
|
u32 get_block_height(const struct chain_topology *topo UNNEEDED)
|
||||||
{ fprintf(stderr, "get_block_height called!\n"); abort(); }
|
{ fprintf(stderr, "get_block_height called!\n"); abort(); }
|
||||||
/* Generated stub for get_chainparams */
|
|
||||||
const struct chainparams *get_chainparams(const struct lightningd *ld UNNEEDED)
|
|
||||||
{ fprintf(stderr, "get_chainparams called!\n"); abort(); }
|
|
||||||
/* Generated stub for htlc_is_trimmed */
|
/* Generated stub for htlc_is_trimmed */
|
||||||
bool htlc_is_trimmed(enum side htlc_owner UNNEEDED,
|
bool htlc_is_trimmed(enum side htlc_owner UNNEEDED,
|
||||||
struct amount_msat htlc_amount UNNEEDED,
|
struct amount_msat htlc_amount UNNEEDED,
|
||||||
|
@ -980,6 +982,7 @@ static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx)
|
||||||
c1.last_tx = bitcoin_tx_from_hex(w, "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8003a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110ae8f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e040047304402206a2679efa3c7aaffd2a447fd0df7aba8792858b589750f6a1203f9259173198a022008d52a0e77a99ab533c36206cb15ad7aeb2aa72b93d4b571e728cb5ec2f6fe260147304402206d6cb93969d39177a09d5d45b583f34966195b77c7e585cf47ac5cce0c90cefb022031d71ae4e33a4e80df7f981d696fbdee517337806a3c7138b7491e2cbb077a0e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220", strlen("02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8003a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110ae8f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e040047304402206a2679efa3c7aaffd2a447fd0df7aba8792858b589750f6a1203f9259173198a022008d52a0e77a99ab533c36206cb15ad7aeb2aa72b93d4b571e728cb5ec2f6fe260147304402206d6cb93969d39177a09d5d45b583f34966195b77c7e585cf47ac5cce0c90cefb022031d71ae4e33a4e80df7f981d696fbdee517337806a3c7138b7491e2cbb077a0e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220"));
|
c1.last_tx = bitcoin_tx_from_hex(w, "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8003a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110ae8f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e040047304402206a2679efa3c7aaffd2a447fd0df7aba8792858b589750f6a1203f9259173198a022008d52a0e77a99ab533c36206cb15ad7aeb2aa72b93d4b571e728cb5ec2f6fe260147304402206d6cb93969d39177a09d5d45b583f34966195b77c7e585cf47ac5cce0c90cefb022031d71ae4e33a4e80df7f981d696fbdee517337806a3c7138b7491e2cbb077a0e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220", strlen("02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8003a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110ae8f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e040047304402206a2679efa3c7aaffd2a447fd0df7aba8792858b589750f6a1203f9259173198a022008d52a0e77a99ab533c36206cb15ad7aeb2aa72b93d4b571e728cb5ec2f6fe260147304402206d6cb93969d39177a09d5d45b583f34966195b77c7e585cf47ac5cce0c90cefb022031d71ae4e33a4e80df7f981d696fbdee517337806a3c7138b7491e2cbb077a0e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220"));
|
||||||
c1.last_sig.s = *sig;
|
c1.last_sig.s = *sig;
|
||||||
c1.last_sig.sighash_type = SIGHASH_ALL;
|
c1.last_sig.sighash_type = SIGHASH_ALL;
|
||||||
|
c1.last_tx->chainparams = chainparams_for_network("bitcoin");
|
||||||
|
|
||||||
db_begin_transaction(w->db);
|
db_begin_transaction(w->db);
|
||||||
CHECK(!wallet_err);
|
CHECK(!wallet_err);
|
||||||
|
|
Loading…
Add table
Reference in a new issue