mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
openingd: supply initial tx as well as signature.
And store in peer->last_tx/peer->last_sig like all other places, that way we broadcast it if we need to. Note: the removal of tmpctx in funder_channel() is needed because we use txs[0], which was allocated off tmpctx. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
80e28707a3
commit
893335244d
@ -209,7 +209,6 @@ static u8 *funder_channel(struct state *state,
|
|||||||
const struct utxo *utxos,
|
const struct utxo *utxos,
|
||||||
const struct ext_key *bip32_base)
|
const struct ext_key *bip32_base)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(state);
|
|
||||||
struct channel_id channel_id, id_in;
|
struct channel_id channel_id, id_in;
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
struct bitcoin_tx **txs;
|
struct bitcoin_tx **txs;
|
||||||
@ -243,7 +242,7 @@ static u8 *funder_channel(struct state *state,
|
|||||||
"push-msat must be < %"PRIu64,
|
"push-msat must be < %"PRIu64,
|
||||||
1000 * state->funding_satoshis);
|
1000 * state->funding_satoshis);
|
||||||
|
|
||||||
msg = towire_open_channel(tmpctx,
|
msg = towire_open_channel(state,
|
||||||
&state->chainparams->genesis_blockhash.sha,
|
&state->chainparams->genesis_blockhash.sha,
|
||||||
&channel_id,
|
&channel_id,
|
||||||
state->funding_satoshis, state->push_msat,
|
state->funding_satoshis, state->push_msat,
|
||||||
@ -266,7 +265,7 @@ static u8 *funder_channel(struct state *state,
|
|||||||
|
|
||||||
state->remoteconf = tal(state, struct channel_config);
|
state->remoteconf = tal(state, struct channel_config);
|
||||||
|
|
||||||
msg = read_next_peer_msg(state, tmpctx);
|
msg = read_next_peer_msg(state, state);
|
||||||
if (!msg)
|
if (!msg)
|
||||||
peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_READ_FAILED,
|
peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_READ_FAILED,
|
||||||
"Reading accept_channel");
|
"Reading accept_channel");
|
||||||
@ -361,7 +360,7 @@ static u8 *funder_channel(struct state *state,
|
|||||||
* for the initial commitment transactions. After receiving the
|
* for the initial commitment transactions. After receiving the
|
||||||
* peer's signature, it will broadcast the funding transaction.
|
* peer's signature, it will broadcast the funding transaction.
|
||||||
*/
|
*/
|
||||||
txs = channel_txs(tmpctx, NULL, &wscripts, state->channel,
|
txs = channel_txs(state, NULL, &wscripts, state->channel,
|
||||||
&state->next_per_commit[REMOTE], 0, REMOTE);
|
&state->next_per_commit[REMOTE], 0, REMOTE);
|
||||||
|
|
||||||
sign_tx_input(txs[0], 0, NULL, wscripts[0],
|
sign_tx_input(txs[0], 0, NULL, wscripts[0],
|
||||||
@ -372,7 +371,7 @@ static u8 *funder_channel(struct state *state,
|
|||||||
type_to_string(trc, struct bitcoin_tx, txs[0]),
|
type_to_string(trc, struct bitcoin_tx, txs[0]),
|
||||||
type_to_string(trc, struct pubkey, our_funding_pubkey));
|
type_to_string(trc, struct pubkey, our_funding_pubkey));
|
||||||
|
|
||||||
msg = towire_funding_created(tmpctx, &channel_id,
|
msg = towire_funding_created(state, &channel_id,
|
||||||
&state->funding_txid.sha,
|
&state->funding_txid.sha,
|
||||||
state->funding_txout,
|
state->funding_txout,
|
||||||
&sig);
|
&sig);
|
||||||
@ -388,7 +387,7 @@ static u8 *funder_channel(struct state *state,
|
|||||||
* commitment transaction, so they can broadcast it knowing they can
|
* commitment transaction, so they can broadcast it knowing they can
|
||||||
* redeem their funds if they need to.
|
* redeem their funds if they need to.
|
||||||
*/
|
*/
|
||||||
msg = read_next_peer_msg(state, tmpctx);
|
msg = read_next_peer_msg(state, state);
|
||||||
if (!msg)
|
if (!msg)
|
||||||
peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_READ_FAILED,
|
peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_READ_FAILED,
|
||||||
"Reading funding_signed");
|
"Reading funding_signed");
|
||||||
@ -419,7 +418,7 @@ static u8 *funder_channel(struct state *state,
|
|||||||
*
|
*
|
||||||
* The recipient MUST fail the channel if `signature` is incorrect.
|
* The recipient MUST fail the channel if `signature` is incorrect.
|
||||||
*/
|
*/
|
||||||
txs = channel_txs(tmpctx, NULL, &wscripts, state->channel,
|
txs = channel_txs(state, NULL, &wscripts, state->channel,
|
||||||
&state->next_per_commit[LOCAL], 0, LOCAL);
|
&state->next_per_commit[LOCAL], 0, LOCAL);
|
||||||
|
|
||||||
if (!check_tx_sig(txs[0], 0, NULL, wscripts[0], &their_funding_pubkey,
|
if (!check_tx_sig(txs[0], 0, NULL, wscripts[0], &their_funding_pubkey,
|
||||||
@ -433,8 +432,6 @@ static u8 *funder_channel(struct state *state,
|
|||||||
&their_funding_pubkey));
|
&their_funding_pubkey));
|
||||||
}
|
}
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
|
|
||||||
/* BOLT #2:
|
/* BOLT #2:
|
||||||
*
|
*
|
||||||
* Once the channel funder receives the `funding_signed` message, they
|
* Once the channel funder receives the `funding_signed` message, they
|
||||||
@ -442,6 +439,7 @@ static u8 *funder_channel(struct state *state,
|
|||||||
*/
|
*/
|
||||||
return towire_opening_funder_reply(state,
|
return towire_opening_funder_reply(state,
|
||||||
state->remoteconf,
|
state->remoteconf,
|
||||||
|
txs[0],
|
||||||
&sig,
|
&sig,
|
||||||
&state->cs,
|
&state->cs,
|
||||||
&theirs.revocation,
|
&theirs.revocation,
|
||||||
@ -659,6 +657,7 @@ static u8 *fundee_channel(struct state *state,
|
|||||||
|
|
||||||
return towire_opening_fundee_reply(state,
|
return towire_opening_fundee_reply(state,
|
||||||
state->remoteconf,
|
state->remoteconf,
|
||||||
|
txs[0],
|
||||||
&theirsig,
|
&theirsig,
|
||||||
&state->cs,
|
&state->cs,
|
||||||
&theirs.revocation,
|
&theirs.revocation,
|
||||||
|
@ -26,6 +26,7 @@ opening_init,,crypto_state,struct crypto_state
|
|||||||
opening_init,,seed,struct privkey
|
opening_init,,seed,struct privkey
|
||||||
|
|
||||||
#include <lightningd/bip32.h>
|
#include <lightningd/bip32.h>
|
||||||
|
#include <lightningd/htlc_wire.h>
|
||||||
# This means we offer the open.
|
# This means we offer the open.
|
||||||
opening_funder,1
|
opening_funder,1
|
||||||
opening_funder,,funding_satoshis,8
|
opening_funder,,funding_satoshis,8
|
||||||
@ -43,6 +44,7 @@ opening_funder,,bip32,struct ext_key
|
|||||||
# This gives their sig, means we can broadcast tx: we're done.
|
# This gives their sig, means we can broadcast tx: we're done.
|
||||||
opening_funder_reply,101
|
opening_funder_reply,101
|
||||||
opening_funder_reply,,their_config,struct channel_config
|
opening_funder_reply,,their_config,struct channel_config
|
||||||
|
opening_funder_reply,,first_commit,struct bitcoin_tx
|
||||||
opening_funder_reply,,first_commit_sig,secp256k1_ecdsa_signature
|
opening_funder_reply,,first_commit_sig,secp256k1_ecdsa_signature
|
||||||
opening_funder_reply,,crypto_state,struct crypto_state
|
opening_funder_reply,,crypto_state,struct crypto_state
|
||||||
opening_funder_reply,,revocation_basepoint,33
|
opening_funder_reply,,revocation_basepoint,33
|
||||||
@ -65,6 +67,7 @@ opening_fundee,,msg,len*u8
|
|||||||
# This gives their txid and info, means we can send funding_signed: we're done.
|
# This gives their txid and info, means we can send funding_signed: we're done.
|
||||||
opening_fundee_reply,103
|
opening_fundee_reply,103
|
||||||
opening_fundee_reply,,their_config,struct channel_config
|
opening_fundee_reply,,their_config,struct channel_config
|
||||||
|
opening_fundee_reply,,first_commit,struct bitcoin_tx
|
||||||
opening_fundee_reply,,first_commit_sig,secp256k1_ecdsa_signature
|
opening_fundee_reply,,first_commit_sig,secp256k1_ecdsa_signature
|
||||||
opening_fundee_reply,,crypto_state,struct crypto_state
|
opening_fundee_reply,,crypto_state,struct crypto_state
|
||||||
opening_fundee_reply,,revocation_basepoint,33
|
opening_fundee_reply,,revocation_basepoint,33
|
||||||
|
|
@ -1633,7 +1633,7 @@ static bool peer_start_channeld(struct peer *peer,
|
|||||||
&peer->our_config,
|
&peer->our_config,
|
||||||
&peer->channel_info->their_config,
|
&peer->channel_info->their_config,
|
||||||
peer->channel_info->feerate_per_kw,
|
peer->channel_info->feerate_per_kw,
|
||||||
&peer->channel_info->commit_sig,
|
peer->last_sig,
|
||||||
cs,
|
cs,
|
||||||
&peer->channel_info->remote_fundingkey,
|
&peer->channel_info->remote_fundingkey,
|
||||||
&peer->channel_info->theirbase.revocation,
|
&peer->channel_info->theirbase.revocation,
|
||||||
@ -1694,16 +1694,20 @@ static bool opening_funder_finished(struct subd *opening, const u8 *resp,
|
|||||||
struct pubkey changekey;
|
struct pubkey changekey;
|
||||||
struct pubkey local_fundingkey;
|
struct pubkey local_fundingkey;
|
||||||
struct crypto_state cs;
|
struct crypto_state cs;
|
||||||
|
secp256k1_ecdsa_signature remote_commit_sig;
|
||||||
|
struct bitcoin_tx *remote_commit;
|
||||||
|
|
||||||
assert(tal_count(fds) == 2);
|
assert(tal_count(fds) == 2);
|
||||||
|
|
||||||
/* 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);
|
||||||
|
|
||||||
if (!fromwire_opening_funder_reply(resp, NULL,
|
if (!fromwire_opening_funder_reply(resp, NULL,
|
||||||
&channel_info->their_config,
|
&channel_info->their_config,
|
||||||
&channel_info->commit_sig,
|
remote_commit,
|
||||||
|
&remote_commit_sig,
|
||||||
&cs,
|
&cs,
|
||||||
&channel_info->theirbase.revocation,
|
&channel_info->theirbase.revocation,
|
||||||
&channel_info->theirbase.payment,
|
&channel_info->theirbase.payment,
|
||||||
@ -1721,6 +1725,9 @@ static bool opening_funder_finished(struct subd *opening, const u8 *resp,
|
|||||||
/* old_remote_per_commit not valid yet, copy valid one. */
|
/* old_remote_per_commit not valid yet, copy valid one. */
|
||||||
channel_info->old_remote_per_commit = channel_info->remote_per_commit;
|
channel_info->old_remote_per_commit = channel_info->remote_per_commit;
|
||||||
|
|
||||||
|
/* Now, keep the initial commit as our last-tx-to-broadast. */
|
||||||
|
peer_last_tx(fc->peer, remote_commit, &remote_commit_sig);
|
||||||
|
|
||||||
/* Generate the funding tx. */
|
/* Generate the funding tx. */
|
||||||
if (fc->change
|
if (fc->change
|
||||||
&& !bip32_pubkey(fc->peer->ld->bip32_base,
|
&& !bip32_pubkey(fc->peer->ld->bip32_base,
|
||||||
@ -1789,16 +1796,21 @@ static bool opening_fundee_finished(struct subd *opening,
|
|||||||
u8 *funding_signed;
|
u8 *funding_signed;
|
||||||
struct channel_info *channel_info;
|
struct channel_info *channel_info;
|
||||||
struct crypto_state cs;
|
struct crypto_state cs;
|
||||||
|
secp256k1_ecdsa_signature remote_commit_sig;
|
||||||
|
struct bitcoin_tx *remote_commit;
|
||||||
|
|
||||||
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);
|
||||||
peer->funding_txid = tal(peer, struct sha256_double);
|
peer->funding_txid = tal(peer, struct sha256_double);
|
||||||
if (!fromwire_opening_fundee_reply(peer, reply, NULL,
|
if (!fromwire_opening_fundee_reply(peer, reply, NULL,
|
||||||
&channel_info->their_config,
|
&channel_info->their_config,
|
||||||
&channel_info->commit_sig,
|
remote_commit,
|
||||||
|
&remote_commit_sig,
|
||||||
&cs,
|
&cs,
|
||||||
&channel_info->theirbase.revocation,
|
&channel_info->theirbase.revocation,
|
||||||
&channel_info->theirbase.payment,
|
&channel_info->theirbase.payment,
|
||||||
@ -1819,6 +1831,9 @@ static bool opening_fundee_finished(struct subd *opening,
|
|||||||
/* old_remote_per_commit not valid yet, copy valid one. */
|
/* old_remote_per_commit not valid yet, copy valid one. */
|
||||||
channel_info->old_remote_per_commit = channel_info->remote_per_commit;
|
channel_info->old_remote_per_commit = channel_info->remote_per_commit;
|
||||||
|
|
||||||
|
/* Now, keep the initial commit as our last-tx-to-broadast. */
|
||||||
|
peer_last_tx(peer, remote_commit, &remote_commit_sig);
|
||||||
|
|
||||||
if (!peer_commit_initial(peer))
|
if (!peer_commit_initial(peer))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1058,7 +1058,6 @@ int peer_got_commitsig(struct peer *peer, const u8 *msg)
|
|||||||
if (!peer_sending_revocation(peer, added, fulfilled, failed, changed))
|
if (!peer_sending_revocation(peer, added, fulfilled, failed, changed))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
peer->channel_info->commit_sig = commit_sig;
|
|
||||||
if (!peer_save_commitsig_received(peer, commitnum))
|
if (!peer_save_commitsig_received(peer, commitnum))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
/* FIXME: Define serialization primitive for this? */
|
/* FIXME: Define serialization primitive for this? */
|
||||||
struct channel_info {
|
struct channel_info {
|
||||||
secp256k1_ecdsa_signature commit_sig;
|
|
||||||
struct channel_config their_config;
|
struct channel_config their_config;
|
||||||
struct pubkey remote_fundingkey;
|
struct pubkey remote_fundingkey;
|
||||||
struct basepoints theirbase;
|
struct basepoints theirbase;
|
||||||
|
@ -58,7 +58,6 @@ char *dbmigrations[] = {
|
|||||||
" push_msatoshi INTEGER,"
|
" push_msatoshi INTEGER,"
|
||||||
" msatoshi_local INTEGER," /* our_msatoshi */
|
" msatoshi_local INTEGER," /* our_msatoshi */
|
||||||
/* START channel_info */
|
/* START channel_info */
|
||||||
" commit_sig_remote BLOB,"
|
|
||||||
" fundingkey_remote BLOB,"
|
" fundingkey_remote BLOB,"
|
||||||
" revocation_basepoint_remote BLOB,"
|
" revocation_basepoint_remote BLOB,"
|
||||||
" payment_basepoint_remote BLOB,"
|
" payment_basepoint_remote BLOB,"
|
||||||
|
@ -474,7 +474,6 @@ static bool wallet_stmt2channel(struct wallet *w, sqlite3_stmt *stmt,
|
|||||||
channel_info = chan->peer->channel_info;
|
channel_info = chan->peer->channel_info;
|
||||||
|
|
||||||
/* Populate channel_info */
|
/* Populate channel_info */
|
||||||
ok &= sqlite3_column_sig(stmt, col++, &chan->peer->channel_info->commit_sig);
|
|
||||||
ok &= sqlite3_column_pubkey(stmt, col++, &chan->peer->channel_info->remote_fundingkey);
|
ok &= sqlite3_column_pubkey(stmt, col++, &chan->peer->channel_info->remote_fundingkey);
|
||||||
ok &= sqlite3_column_pubkey(stmt, col++, &channel_info->theirbase.revocation);
|
ok &= sqlite3_column_pubkey(stmt, col++, &channel_info->theirbase.revocation);
|
||||||
ok &= sqlite3_column_pubkey(stmt, col++, &channel_info->theirbase.payment);
|
ok &= sqlite3_column_pubkey(stmt, col++, &channel_info->theirbase.payment);
|
||||||
@ -485,7 +484,7 @@ static bool wallet_stmt2channel(struct wallet *w, sqlite3_stmt *stmt,
|
|||||||
wallet_channel_config_load(w, remote_config_id, &chan->peer->channel_info->their_config);
|
wallet_channel_config_load(w, remote_config_id, &chan->peer->channel_info->their_config);
|
||||||
} else {
|
} else {
|
||||||
/* No channel_info, skip positions in the result */
|
/* No channel_info, skip positions in the result */
|
||||||
col += 8;
|
col += 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load shachain */
|
/* Load shachain */
|
||||||
@ -525,7 +524,7 @@ static bool wallet_stmt2channel(struct wallet *w, sqlite3_stmt *stmt,
|
|||||||
col += 2;
|
col += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(col == 34);
|
assert(col == 33);
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@ -543,7 +542,6 @@ bool wallet_channel_load(struct wallet *w, const u64 id,
|
|||||||
"next_index_local, next_index_remote, num_revocations_received, "
|
"next_index_local, next_index_remote, num_revocations_received, "
|
||||||
"next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, "
|
"next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, "
|
||||||
"funding_locked_remote, push_msatoshi, msatoshi_local, "
|
"funding_locked_remote, push_msatoshi, msatoshi_local, "
|
||||||
"commit_sig_remote, "
|
|
||||||
"fundingkey_remote, revocation_basepoint_remote, "
|
"fundingkey_remote, revocation_basepoint_remote, "
|
||||||
"payment_basepoint_remote, "
|
"payment_basepoint_remote, "
|
||||||
"delayed_payment_basepoint_remote, per_commit_remote, "
|
"delayed_payment_basepoint_remote, per_commit_remote, "
|
||||||
@ -722,7 +720,6 @@ bool wallet_channel_save(struct wallet *w, struct wallet_channel *chan){
|
|||||||
ok &= wallet_channel_config_save(w, &p->channel_info->their_config);
|
ok &= wallet_channel_config_save(w, &p->channel_info->their_config);
|
||||||
ok &= db_exec(__func__, w->db,
|
ok &= db_exec(__func__, w->db,
|
||||||
"UPDATE channels SET"
|
"UPDATE channels SET"
|
||||||
" commit_sig_remote=%s,"
|
|
||||||
" fundingkey_remote='%s',"
|
" fundingkey_remote='%s',"
|
||||||
" revocation_basepoint_remote='%s',"
|
" revocation_basepoint_remote='%s',"
|
||||||
" payment_basepoint_remote='%s',"
|
" payment_basepoint_remote='%s',"
|
||||||
@ -732,7 +729,6 @@ bool wallet_channel_save(struct wallet *w, struct wallet_channel *chan){
|
|||||||
" feerate_per_kw=%d,"
|
" feerate_per_kw=%d,"
|
||||||
" channel_config_remote=%"PRIu64
|
" channel_config_remote=%"PRIu64
|
||||||
" WHERE id=%"PRIu64,
|
" WHERE id=%"PRIu64,
|
||||||
db_serialize_signature(tmpctx, &p->channel_info->commit_sig),
|
|
||||||
db_serialize_pubkey(tmpctx, &p->channel_info->remote_fundingkey),
|
db_serialize_pubkey(tmpctx, &p->channel_info->remote_fundingkey),
|
||||||
db_serialize_pubkey(tmpctx, &p->channel_info->theirbase.revocation),
|
db_serialize_pubkey(tmpctx, &p->channel_info->theirbase.revocation),
|
||||||
db_serialize_pubkey(tmpctx, &p->channel_info->theirbase.payment),
|
db_serialize_pubkey(tmpctx, &p->channel_info->theirbase.payment),
|
||||||
|
@ -148,8 +148,6 @@ static bool channelseq(struct wallet_channel *c1, struct wallet_channel *c2)
|
|||||||
sizeof(struct sha256_double)));
|
sizeof(struct sha256_double)));
|
||||||
CHECK((ci1 != NULL) == (ci2 != NULL));
|
CHECK((ci1 != NULL) == (ci2 != NULL));
|
||||||
if(ci1) {
|
if(ci1) {
|
||||||
CHECK(memeq(&ci1->commit_sig, sizeof(secp256k1_ecdsa_signature),
|
|
||||||
&ci2->commit_sig, sizeof(secp256k1_ecdsa_signature)));
|
|
||||||
CHECK(pubkey_eq(&ci1->remote_fundingkey, &ci2->remote_fundingkey));
|
CHECK(pubkey_eq(&ci1->remote_fundingkey, &ci2->remote_fundingkey));
|
||||||
CHECK(pubkey_eq(&ci1->theirbase.revocation, &ci2->theirbase.revocation));
|
CHECK(pubkey_eq(&ci1->theirbase.revocation, &ci2->theirbase.revocation));
|
||||||
CHECK(pubkey_eq(&ci1->theirbase.payment, &ci2->theirbase.payment));
|
CHECK(pubkey_eq(&ci1->theirbase.payment, &ci2->theirbase.payment));
|
||||||
|
Loading…
Reference in New Issue
Block a user