Browse Source

gossipd: drain fd instead of passing around gossip index.

(This was sitting in my gossip-enchancement patch queue, but it simplifies
this set too, so I moved it here).

In 94711969f we added an explicit gossip_index so when gossipd gets
peers back from other daemons, it knows what gossip it has sent (since
gossipd can send gossip after the other daemon is already complete).

This solution is insufficient for the more general case where gossipd
wants to send other messages reliably, so replace it with the other
solution: have gossipd drain the "gossip fd" which the daemon returns.

This turns out to be quite simple, and is probably how I should have
done it originally :(

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
ab9d9ef3b8
  1. 62
      channeld/channel.c
  2. 2
      channeld/channel_wire.csv
  3. 53
      closingd/closing.c
  4. 2
      closingd/closing_wire.csv
  5. 8
      common/peer_failed.c
  6. 12
      common/peer_failed.h
  7. 1
      common/peer_status_wire.csv
  8. 5
      common/read_peer_msg.c
  9. 8
      common/read_peer_msg.h
  10. 44
      gossipd/gossip.c
  11. 5
      gossipd/gossip_wire.csv
  12. 9
      lightningd/channel_control.c
  13. 1
      lightningd/channel_control.h
  14. 7
      lightningd/closing_control.c
  15. 1
      lightningd/closing_control.h
  16. 5
      lightningd/gossip_control.c
  17. 1
      lightningd/onchain_control.c
  18. 30
      lightningd/opening_control.c
  19. 2
      lightningd/opening_control.h
  20. 23
      lightningd/peer_control.c
  21. 2
      lightningd/peer_control.h
  22. 9
      lightningd/subd.c
  23. 3
      lightningd/subd.h
  24. 35
      openingd/opening.c
  25. 3
      openingd/opening_wire.csv
  26. 8
      wallet/test/run-wallet.c

62
channeld/channel.c

@ -161,9 +161,6 @@ struct peer {
bool announce_depth_reached;
/* Where we got up to in gossip broadcasts. */
u64 gossip_index;
/* Make sure timestamps move forward. */
u32 last_update_timestamp;
};
@ -304,23 +301,18 @@ static void enqueue_peer_msg(struct peer *peer, const u8 *msg TAKES)
static void gossip_in(struct peer *peer, const u8 *msg)
{
u8 *gossip;
u64 gossip_index;
if (!fromwire_gossip_send_gossip(msg, msg, &gossip_index, &gossip))
if (!fromwire_gossip_send_gossip(msg, msg, &gossip))
status_failed(STATUS_FAIL_GOSSIP_IO,
"Got bad message from gossipd: %s",
tal_hex(msg, msg));
/* Zero is a special index meaning this is unindexed gossip. */
if (gossip_index != 0)
peer->gossip_index = gossip_index;
if (is_msg_for_gossipd(gossip))
enqueue_peer_msg(peer, gossip);
else if (fromwire_peektype(gossip) == WIRE_ERROR) {
struct channel_id channel_id;
char *what = sanitize_error(msg, msg, &channel_id);
peer_failed(&peer->cs, peer->gossip_index, &channel_id,
peer_failed(&peer->cs, &channel_id,
"gossipd said: %s", what);
} else
status_failed(STATUS_FAIL_GOSSIP_IO,
@ -497,12 +489,12 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg)
peer->old_remote_per_commit = peer->remote_per_commit;
if (!fromwire_funding_locked(msg, &chanid,
&peer->remote_per_commit))
peer_failed(&peer->cs, peer->gossip_index,
peer_failed(&peer->cs,
&peer->channel_id,
"Bad funding_locked %s", tal_hex(msg, msg));
if (!structeq(&chanid, &peer->channel_id))
peer_failed(&peer->cs, peer->gossip_index,
peer_failed(&peer->cs,
&peer->channel_id,
"Wrong channel id in %s (expected %s)",
tal_hex(tmpctx, msg),
@ -529,7 +521,7 @@ static void check_short_ids_match(struct peer *peer)
if (!structeq(&peer->short_channel_ids[LOCAL],
&peer->short_channel_ids[REMOTE]))
peer_failed(&peer->cs, peer->gossip_index,
peer_failed(&peer->cs,
&peer->channel_id,
"We disagree on short_channel_ids:"
" I have %s, you say %s",
@ -561,14 +553,14 @@ static void handle_peer_announcement_signatures(struct peer *peer, const u8 *msg
&peer->short_channel_ids[REMOTE],
&peer->announcement_node_sigs[REMOTE],
&peer->announcement_bitcoin_sigs[REMOTE]))
peer_failed(&peer->cs, peer->gossip_index,
peer_failed(&peer->cs,
&peer->channel_id,
"Bad announcement_signatures %s",
tal_hex(msg, msg));
/* Make sure we agree on the channel ids */
if (!structeq(&chanid, &peer->channel_id)) {
peer_failed(&peer->cs, peer->gossip_index,
peer_failed(&peer->cs,
&peer->channel_id,
"Wrong channel_id: expected %s, got %s",
type_to_string(tmpctx, struct channel_id,
@ -627,7 +619,6 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
&payment_hash, &cltv_expiry,
onion_routing_packet))
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad peer_add_htlc %s", tal_hex(msg, msg));
@ -636,7 +627,6 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
onion_routing_packet, &htlc);
if (add_err != CHANNEL_ERR_ADD_OK)
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad peer_add_htlc: %s",
channel_add_err_name(add_err));
@ -654,7 +644,6 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
if (!fromwire_update_fee(msg, &channel_id, &feerate)) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad update_fee %s", tal_hex(msg, msg));
}
@ -666,7 +655,6 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
*/
if (peer->channel->funder != REMOTE)
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"update_fee from non-funder?");
@ -680,7 +668,6 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
*/
if (feerate < peer->feerate_min || feerate > peer->feerate_max)
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"update_fee %u outside range %u-%u",
feerate, peer->feerate_min, peer->feerate_max);
@ -694,7 +681,6 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
*/
if (!channel_update_feerate(peer->channel, feerate))
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"update_fee %u unaffordable",
feerate);
@ -1175,7 +1161,6 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
* does not include any updates.
*/
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"commit_sig with no changes");
}
@ -1189,7 +1174,6 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
if (!fromwire_commitment_signed(tmpctx, msg,
&channel_id, &commit_sig, &htlc_sigs))
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad commit_sig %s", tal_hex(msg, msg));
@ -1221,7 +1205,6 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
&peer->channel->funding_pubkey[REMOTE], &commit_sig)) {
dump_htlcs(peer->channel, "receiving commit_sig");
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad commit_sig signature %"PRIu64" %s for tx %s wscript %s key %s",
peer->next_index[LOCAL],
@ -1242,7 +1225,6 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
*/
if (tal_count(htlc_sigs) != tal_count(txs) - 1)
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Expected %zu htlc sigs, not %zu",
tal_count(txs) - 1, tal_count(htlc_sigs));
@ -1257,7 +1239,6 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
if (!check_tx_sig(txs[1+i], 0, NULL, wscripts[1+i],
&remote_htlckey, &htlc_sigs[i]))
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad commit_sig signature %s for htlc %s wscript %s key %s",
type_to_string(msg, secp256k1_ecdsa_signature, &htlc_sigs[i]),
@ -1316,14 +1297,12 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
if (!fromwire_revoke_and_ack(msg, &channel_id, &old_commit_secret,
&next_per_commit)) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad revoke_and_ack %s", tal_hex(msg, msg));
}
if (peer->revocations_received != peer->next_index[REMOTE] - 2) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Unexpected revoke_and_ack");
}
@ -1337,14 +1316,12 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
memcpy(&privkey, &old_commit_secret, sizeof(privkey));
if (!pubkey_from_privkey(&privkey, &per_commit_point)) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad privkey %s",
type_to_string(msg, struct privkey, &privkey));
}
if (!pubkey_eq(&per_commit_point, &peer->old_remote_per_commit)) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Wrong privkey %s for %"PRIu64" %s",
type_to_string(msg, struct privkey, &privkey),
@ -1389,7 +1366,6 @@ static void handle_peer_fulfill_htlc(struct peer *peer, const u8 *msg)
if (!fromwire_update_fulfill_htlc(msg, &channel_id,
&id, &preimage)) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad update_fulfill_htlc %s", tal_hex(msg, msg));
}
@ -1409,7 +1385,6 @@ static void handle_peer_fulfill_htlc(struct peer *peer, const u8 *msg)
case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE:
case CHANNEL_ERR_BAD_PREIMAGE:
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad update_fulfill_htlc: failed to fulfill %"
PRIu64 " error %s", id, channel_remove_err_name(e));
@ -1428,7 +1403,6 @@ static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg)
if (!fromwire_update_fail_htlc(msg, msg,
&channel_id, &id, &reason)) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad update_fulfill_htlc %s", tal_hex(msg, msg));
}
@ -1447,7 +1421,6 @@ static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg)
case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE:
case CHANNEL_ERR_BAD_PREIMAGE:
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad update_fail_htlc: failed to remove %"
PRIu64 " error %s", id,
@ -1470,7 +1443,6 @@ static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg)
&sha256_of_onion,
&failure_code)) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad update_fail_malformed_htlc %s",
tal_hex(msg, msg));
@ -1483,7 +1455,6 @@ static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg)
*/
if (!(failure_code & BADONION)) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad update_fail_malformed_htlc failure code %u",
failure_code);
@ -1521,7 +1492,6 @@ static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg)
case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE:
case CHANNEL_ERR_BAD_PREIMAGE:
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad update_fail_malformed_htlc: failed to remove %"
PRIu64 " error %s", id, channel_remove_err_name(e));
@ -1534,7 +1504,6 @@ static void handle_pong(struct peer *peer, const u8 *pong)
const char *err = got_pong(pong, &peer->num_pings_outstanding);
if (err)
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"%s", err);
@ -1552,7 +1521,6 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown)
if (!fromwire_shutdown(peer, shutdown, &channel_id, &scriptpubkey))
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Bad shutdown %s", tal_hex(peer, shutdown));
@ -1589,7 +1557,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
&& type != WIRE_PONG
&& type != WIRE_SHUTDOWN) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"%s (%u) before funding locked",
wire_type_name(type), type);
@ -1650,7 +1617,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
}
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Peer sent unknown message %u (%s)",
type, wire_type_name(type));
@ -1692,7 +1658,6 @@ static void send_fail_or_fulfill(struct peer *peer, const struct htlc *h)
h->r);
} else
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"HTLC %"PRIu64" state %s not failed/fulfilled",
h->id, htlc_state_name(h->state));
@ -1725,7 +1690,6 @@ static void resend_commitment(struct peer *peer, const struct changed_htlc *last
* then they asked for a retransmit */
if (!h)
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"Can't find HTLC %"PRIu64" to resend",
last[i].id);
@ -1778,7 +1742,7 @@ static bool channeld_send_reply(struct crypto_state *cs UNUSED,
static u8 *channeld_read_peer_msg(struct peer *peer)
{
return read_peer_msg(peer, &peer->cs, peer->gossip_index,
return read_peer_msg(peer, &peer->cs,
&peer->channel_id,
channeld_send_reply,
channeld_io_error,
@ -1824,7 +1788,6 @@ static void peer_reconnect(struct peer *peer)
&next_local_commitment_number,
&next_remote_revocation_number)) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"bad reestablish msg: %s %s",
wire_type_name(fromwire_peektype(msg)),
@ -1873,7 +1836,6 @@ static void peer_reconnect(struct peer *peer)
/* Don't try to retransmit revocation index -1! */
if (peer->next_index[LOCAL] < 2) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"bad reestablish revocation_number: %"
PRIu64,
@ -1882,7 +1844,6 @@ static void peer_reconnect(struct peer *peer)
retransmit_revoke_and_ack = true;
} else if (next_remote_revocation_number != peer->next_index[LOCAL] - 1) {
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"bad reestablish revocation_number: %"PRIu64
" vs %"PRIu64,
@ -1907,7 +1868,6 @@ static void peer_reconnect(struct peer *peer)
/* We completed opening, we don't re-transmit that one! */
if (next_local_commitment_number == 0)
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"bad reestablish commitment_number: %"
PRIu64,
@ -1923,7 +1883,6 @@ static void peer_reconnect(struct peer *peer)
*/
} else if (next_local_commitment_number != peer->next_index[REMOTE])
peer_failed(&peer->cs,
peer->gossip_index,
&peer->channel_id,
"bad reestablish commitment_number: %"PRIu64
" vs %"PRIu64,
@ -2477,7 +2436,6 @@ static void init_channel(struct peer *peer)
&peer->feerate_min, &peer->feerate_max,
&peer->their_commit_sig,
&peer->cs,
&peer->gossip_index,
&funding_pubkey[REMOTE],
&points[REMOTE].revocation,
&points[REMOTE].payment,
@ -2592,9 +2550,7 @@ static void send_shutdown_complete(struct peer *peer)
/* Now we can tell master shutdown is complete. */
wire_sync_write(MASTER_FD,
take(towire_channel_shutdown_complete(NULL,
&peer->cs,
peer->gossip_index)));
take(towire_channel_shutdown_complete(NULL, &peer->cs)));
fdpass_send(MASTER_FD, PEER_FD);
fdpass_send(MASTER_FD, GOSSIP_FD);
close(MASTER_FD);

2
channeld/channel_wire.csv

@ -15,7 +15,6 @@ channel_init,,feerate_min,u32
channel_init,,feerate_max,u32
channel_init,,first_commit_sig,secp256k1_ecdsa_signature
channel_init,,crypto_state,struct crypto_state
channel_init,,gossip_index,u64
channel_init,,remote_fundingkey,struct pubkey
channel_init,,remote_revocation_basepoint,struct pubkey
channel_init,,remote_payment_basepoint,struct pubkey
@ -173,7 +172,6 @@ channel_got_shutdown,,scriptpubkey,scriptpubkey_len*u8
# Shutdown is complete, ready for closing negotiation. + peer_fd & gossip_fd.
channel_shutdown_complete,1025
channel_shutdown_complete,,crypto_state,struct crypto_state
channel_shutdown_complete,,gossip_index,u64
# Re-enable commit timer.
channel_dev_reenable_commit,1026

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

53
closingd/closing.c

@ -29,7 +29,6 @@
static struct bitcoin_tx *close_tx(const tal_t *ctx,
struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
u8 *scriptpubkey[NUM_SIDES],
const struct bitcoin_txid *funding_txid,
@ -43,7 +42,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
struct bitcoin_tx *tx;
if (satoshi_out[funder] < fee)
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"Funder cannot afford fee %"PRIu64
" (%"PRIu64" and %"PRIu64")",
fee, satoshi_out[LOCAL],
@ -62,7 +61,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
satoshi_out[REMOTE] - (funder == REMOTE ? fee : 0),
dust_limit);
if (!tx)
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"Both outputs below dust limit:"
" funding = %"PRIu64
" fee = %"PRIu64
@ -78,7 +77,6 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
}
static void do_reconnect(struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const u64 next_index[NUM_SIDES],
u64 revocations_received,
@ -111,7 +109,7 @@ static void do_reconnect(struct crypto_state *cs,
/* Wait for them to say something interesting */
channel_reestablish
= read_peer_msg(tmpctx, cs, gossip_index, channel_id,
= read_peer_msg(tmpctx, cs, channel_id,
sync_crypto_write_arg,
status_fail_io,
NULL);
@ -120,7 +118,7 @@ static void do_reconnect(struct crypto_state *cs,
if (!fromwire_channel_reestablish(channel_reestablish, &their_channel_id,
&next_local_commitment_number,
&next_remote_revocation_number)) {
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"bad reestablish msg: %s %s",
wire_type_name(fromwire_peektype(channel_reestablish)),
tal_hex(tmpctx, channel_reestablish));
@ -144,7 +142,6 @@ static void do_reconnect(struct crypto_state *cs,
}
static void send_offer(struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const struct pubkey funding_pubkey[NUM_SIDES],
const u8 *funding_wscript,
@ -168,7 +165,7 @@ static void send_offer(struct crypto_state *cs,
* the close transaction as specified in [BOLT
* #3](03-transactions.md#closing-transaction).
*/
tx = close_tx(tmpctx, cs, gossip_index, channel_id,
tx = close_tx(tmpctx, cs, channel_id,
scriptpubkey,
funding_txid,
funding_txout,
@ -214,7 +211,6 @@ static void tell_master_their_offer(const secp256k1_ecdsa_signature *their_sig,
/* Returns fee they offered. */
static uint64_t receive_offer(struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const struct pubkey funding_pubkey[NUM_SIDES],
const u8 *funding_wscript,
@ -237,7 +233,7 @@ static uint64_t receive_offer(struct crypto_state *cs,
do {
clean_tmpctx();
msg = read_peer_msg(tmpctx, cs, gossip_index, channel_id,
msg = read_peer_msg(tmpctx, cs, channel_id,
sync_crypto_write_arg,
status_fail_io,
NULL);
@ -262,7 +258,7 @@ static uint64_t receive_offer(struct crypto_state *cs,
if (!fromwire_closing_signed(msg, &their_channel_id,
&received_fee, &their_sig))
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"Expected closing_signed: %s",
tal_hex(tmpctx, msg));
@ -273,7 +269,7 @@ static uint64_t receive_offer(struct crypto_state *cs,
* #3](03-transactions.md#closing-transaction), and MUST fail
* the connection if it is not.
*/
tx = close_tx(tmpctx, cs, gossip_index, channel_id,
tx = close_tx(tmpctx, cs, channel_id,
scriptpubkey,
funding_txid,
funding_txout,
@ -299,7 +295,7 @@ static uint64_t receive_offer(struct crypto_state *cs,
* then remove any output below its own `dust_limit_satoshis`,
* and MAY also eliminate its own output.
*/
trimmed = close_tx(tmpctx, cs, gossip_index, channel_id,
trimmed = close_tx(tmpctx, cs, channel_id,
scriptpubkey,
funding_txid,
funding_txout,
@ -309,7 +305,7 @@ static uint64_t receive_offer(struct crypto_state *cs,
if (!trimmed
|| !check_tx_sig(trimmed, 0, NULL, funding_wscript,
&funding_pubkey[REMOTE], &their_sig)) {
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"Bad closing_signed signature for"
" %s (and trimmed version %s)",
type_to_string(tmpctx,
@ -368,14 +364,13 @@ static void init_feerange(struct feerange *feerange,
}
static void adjust_feerange(struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
struct feerange *feerange,
u64 offer, enum side side)
{
if (offer < feerange->min || offer > feerange->max) {
if (!feerange->allow_mistakes || side != REMOTE)
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"%s offer %"PRIu64
" not between %"PRIu64" and %"PRIu64,
side == LOCAL ? "local" : "remote",
@ -402,7 +397,6 @@ static void adjust_feerange(struct crypto_state *cs,
/* Figure out what we should offer now. */
static u64 adjust_offer(struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const struct feerange *feerange,
u64 remote_offer,
@ -414,7 +408,7 @@ static u64 adjust_offer(struct crypto_state *cs,
/* Max is below our minimum acceptable? */
if (feerange->max < min_fee_to_accept)
peer_failed(cs, gossip_index, channel_id,
peer_failed(cs, channel_id,
"Feerange %"PRIu64"-%"PRIu64
" below minimum acceptable %"PRIu64,
feerange->min, feerange->max,
@ -446,7 +440,6 @@ int main(int argc, char *argv[])
struct secrets secrets;
bool reconnected;
u64 next_index[NUM_SIDES], revocations_received;
u64 gossip_index;
enum side whose_turn;
bool deprecated_api;
u8 *channel_reestablish;
@ -457,7 +450,7 @@ int main(int argc, char *argv[])
msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_closing_init(ctx, msg,
&cs, &gossip_index, &seed,
&cs, &seed,
&funding_txid, &funding_txout,
&funding_satoshi,
&funding_pubkey[REMOTE],
@ -490,7 +483,7 @@ int main(int argc, char *argv[])
&funding_pubkey[REMOTE]);
if (reconnected)
do_reconnect(&cs, gossip_index, &channel_id,
do_reconnect(&cs, &channel_id,
next_index, revocations_received,
channel_reestablish);
@ -508,7 +501,7 @@ int main(int argc, char *argv[])
whose_turn = funder;
for (size_t i = 0; i < 2; i++, whose_turn = !whose_turn) {
if (whose_turn == LOCAL) {
send_offer(&cs, gossip_index,
send_offer(&cs,
&channel_id, funding_pubkey,
funding_wscript,
scriptpubkey, &funding_txid, funding_txout,
@ -524,7 +517,7 @@ int main(int argc, char *argv[])
" ours was %"PRIu64" satoshi",
offer[LOCAL]);
offer[REMOTE]
= receive_offer(&cs, gossip_index,
= receive_offer(&cs,
&channel_id, funding_pubkey,
funding_wscript,
scriptpubkey, &funding_txid,
@ -539,8 +532,7 @@ int main(int argc, char *argv[])
init_feerange(&feerange, commitment_fee, offer);
/* Apply (and check) funder offer now. */
adjust_feerange(&cs, gossip_index, &channel_id,
&feerange, offer[funder], funder);
adjust_feerange(&cs, &channel_id, &feerange, offer[funder], funder);
/* Older spec clients would make offers independently, so allow */
feerange.allow_mistakes = deprecated_api;
@ -548,16 +540,16 @@ int main(int argc, char *argv[])
/* Now any extra rounds required. */
while (offer[LOCAL] != offer[REMOTE]) {
/* Still don't agree: adjust feerange based on previous offer */
adjust_feerange(&cs, gossip_index, &channel_id,
adjust_feerange(&cs, &channel_id,
&feerange,
offer[!whose_turn], !whose_turn);
if (whose_turn == LOCAL) {
offer[LOCAL] = adjust_offer(&cs, gossip_index,
offer[LOCAL] = adjust_offer(&cs,
&channel_id,
&feerange, offer[REMOTE],
min_fee_to_accept);
send_offer(&cs, gossip_index, &channel_id,
send_offer(&cs, &channel_id,
funding_pubkey,
funding_wscript,
scriptpubkey, &funding_txid, funding_txout,
@ -570,7 +562,7 @@ int main(int argc, char *argv[])
" theirs was %"PRIu64" satoshi,",
offer[LOCAL], offer[REMOTE]);
offer[REMOTE]
= receive_offer(&cs, gossip_index, &channel_id,
= receive_offer(&cs, &channel_id,
funding_pubkey,
funding_wscript,
scriptpubkey, &funding_txid,
@ -587,8 +579,7 @@ int main(int argc, char *argv[])
offer[LOCAL]);
/* We're done! */
wire_sync_write(REQ_FD,
take(towire_closing_complete(NULL, gossip_index)));
wire_sync_write(REQ_FD, take(towire_closing_complete(NULL)));
tal_free(ctx);
daemon_shutdown();

2
closingd/closing_wire.csv

@ -3,7 +3,6 @@
# Begin! (passes peer fd, gossipd-client fd)
closing_init,2001
closing_init,,crypto_state,struct crypto_state
closing_init,,gossip_index,u64
closing_init,,seed,struct privkey
closing_init,,funding_txid,struct bitcoin_txid
closing_init,,funding_txout,u16
@ -38,4 +37,3 @@ closing_received_signature_reply,2102
# Negotiations complete, we're exiting.
closing_complete,2004
closing_complete,,gossip_index,u64

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

8
common/peer_failed.c

@ -9,7 +9,7 @@
/* We only support one channel per peer anyway */
void peer_failed_(int peer_fd, int gossip_fd,
struct crypto_state *cs, u64 gossip_index,
struct crypto_state *cs,
const struct channel_id *channel_id,
const char *fmt, ...)
{
@ -22,7 +22,7 @@ void peer_failed_(int peer_fd, int gossip_fd,
va_end(ap);
msg = towire_status_peer_error(NULL, channel_id,
desc, cs, gossip_index,
desc, cs,
towire_errorfmt(desc, channel_id,
"%s", desc));
peer_billboard(true, desc);
@ -32,12 +32,12 @@ void peer_failed_(int peer_fd, int gossip_fd,
/* We're failing because peer sent us an error message */
void peer_failed_received_errmsg(int peer_fd, int gossip_fd,
struct crypto_state *cs, u64 gossip_index,
struct crypto_state *cs,
const char *desc,
const struct channel_id *channel_id)
{
u8 *msg = towire_status_peer_error(NULL, channel_id,
desc, cs, gossip_index, NULL);
desc, cs, NULL);
peer_billboard(true, "Received error from peer: %s", desc);
status_send_fatal(take(msg), peer_fd, gossip_fd);
}

12
common/peer_failed.h

@ -9,23 +9,21 @@ struct channel_id;
/**
* peer_failed - Exit with error for peer.
* @cs: the peer's current crypto state.
* @gossip_index: the peer's current gossip_index.
* @channel_id: channel with error, or NULL for all.
* @fmt...: format as per status_failed(STATUS_FAIL_PEER_BAD)
*/
#define peer_failed(cs, gossip_index, channel_id, ...) \
peer_failed_(PEER_FD, GOSSIP_FD, (cs), (gossip_index), (channel_id), \
__VA_ARGS__)
#define peer_failed(cs, channel_id, ...) \
peer_failed_(PEER_FD, GOSSIP_FD, (cs), (channel_id), __VA_ARGS__)
void peer_failed_(int peer_fd, int gossip_fd,
struct crypto_state *cs, u64 gossip_index,
struct crypto_state *cs,
const struct channel_id *channel_id,
const char *fmt, ...)
PRINTF_FMT(6,7) NORETURN;
PRINTF_FMT(5,6) NORETURN;
/* We're failing because peer sent us an error message */
void peer_failed_received_errmsg(int peer_fd, int gossip_fd,
struct crypto_state *cs, u64 gossip_index,
struct crypto_state *cs,
const char *desc,
const struct channel_id *channel_id) NORETURN;

1
common/peer_status_wire.csv

@ -6,6 +6,5 @@ status_peer_error,0xFFF4
status_peer_error,,channel,struct channel_id
status_peer_error,,desc,wirestring
status_peer_error,,crypto_state,struct crypto_state
status_peer_error,,gossip_index,u64
status_peer_error,,len,u16
status_peer_error,,error_for_them,len*u8

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

5
common/read_peer_msg.c

@ -40,7 +40,7 @@ static void handle_ping(const u8 *msg,
u8 *read_peer_msg_(const tal_t *ctx,
int peer_fd, int gossip_fd,
struct crypto_state *cs, u64 gossip_index,
struct crypto_state *cs,
const struct channel_id *channel,
bool (*send_reply)(struct crypto_state *cs, int fd,
const u8 *TAKES, void *arg),
@ -86,8 +86,7 @@ u8 *read_peer_msg_(const tal_t *ctx,
*/
if (structeq(&chanid, channel) || channel_id_is_all(&chanid))
peer_failed_received_errmsg(peer_fd, gossip_fd,
cs, gossip_index,
err, &chanid);
cs, err, &chanid);
return tal_free(msg);
}

8
common/read_peer_msg.h

@ -12,7 +12,6 @@ struct channel_id;
* read_peer_msg - read & decode in a peer message, handling common ones.
* @ctx: context to allocate return packet from.
* @cs: the cryptostate (updated)
* @gossip_index: the gossip_index
* @chanid: the channel id (for identifying errors)
* @send_reply: the way to send a reply packet (eg. sync_crypto_write_arg)
* @io_error: what to do if there's an IO error (eg. status_fail_io)
@ -21,9 +20,8 @@ struct channel_id;
* This returns NULL if it handled the message, so it's normally called in
* a loop.
*/
#define read_peer_msg(ctx, cs, gossip_index, chanid, send_reply, \
io_error, arg) \
read_peer_msg_((ctx), PEER_FD, GOSSIP_FD, (cs), (gossip_index), \
#define read_peer_msg(ctx, cs, chanid, send_reply, io_error, arg) \
read_peer_msg_((ctx), PEER_FD, GOSSIP_FD, (cs), \
(chanid), \
typesafe_cb_preargs(bool, void *, (send_reply), (arg), \
struct crypto_state *, int, \
@ -40,7 +38,7 @@ void status_fail_io(void *unused);
u8 *read_peer_msg_(const tal_t *ctx,
int peer_fd, int gossip_fd,
struct crypto_state *cs, u64 gossip_index,
struct crypto_state *cs,
const struct channel_id *channel,
bool (*send_reply)(struct crypto_state *cs, int fd,
const u8 *TAKES, void *arg),

44
gossipd/gossip.c

@ -330,8 +330,7 @@ static void queue_peer_msg(struct peer *peer, const u8 *msg TAKES)
if (peer->local) {
msg_enqueue(&peer->local->peer_out, msg);
} else {
/* Use gossip_index 0 meaning don't update index */
const u8 *send = towire_gossip_send_gossip(NULL, 0, msg);
const u8 *send = towire_gossip_send_gossip(NULL, msg);
if (taken(msg))
tal_free(msg);
daemon_conn_send(peer->remote, take(send));
@ -406,7 +405,6 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
/* We will not have anything queued, since we're not duplex. */
msg = towire_gossip_peer_connected(peer, &peer->id, &peer->addr,
&peer->local->pcs.cs,
peer->broadcast_index,
peer->gfeatures, peer->lfeatures);
if (!send_peer_with_fds(peer, msg))
return io_close(conn);
@ -599,7 +597,6 @@ static struct io_plan *ready_for_master(struct io_conn *conn, struct peer *peer)
msg = towire_gossip_peer_nongossip(peer, &peer->id,
&peer->addr,
&peer->local->pcs.cs,
peer->broadcast_index,
peer->gfeatures,
peer->lfeatures,
peer->local->nongossip_msg);
@ -607,7 +604,6 @@ static struct io_plan *ready_for_master(struct io_conn *conn, struct peer *peer)
msg = towire_gossipctl_release_peer_reply(peer,
&peer->addr,
&peer->local->pcs.cs,
peer->broadcast_index,
peer->gfeatures,
peer->lfeatures);
@ -925,9 +921,7 @@ static bool nonlocal_dump_gossip(struct io_conn *conn, struct daemon_conn *dc)
peer->gossip_sync = false;
return false;
} else {
u8 *msg = towire_gossip_send_gossip(NULL,
peer->broadcast_index,
next);
u8 *msg = towire_gossip_send_gossip(NULL, next);
daemon_conn_send(peer->remote, take(msg));
return true;
}
@ -953,11 +947,33 @@ struct returning_peer {
struct daemon *daemon;
struct pubkey id;
struct crypto_state cs;
u64 gossip_index;
u8 *inner_msg;
int peer_fd, gossip_fd;
};
static void drain_and_forward_gossip(struct peer *peer, int gossip_fd)
{
u8 *msg;
/* Be careful: what if they handed wrong fd? Make it non-blocking. */
if (!io_fd_block(gossip_fd, false)) {
status_unusual("NONBLOCK failed for gossip_fd from peer %s: %s",
type_to_string(tmpctx, struct pubkey, &peer->id),
strerror(errno));
return;
}
/* It's sync, but not blocking. */
while ((msg = wire_sync_read(tmpctx, gossip_fd)) != NULL) {
u8 *gossip;
if (!fromwire_gossip_send_gossip(NULL, msg, &gossip))
break;
msg_enqueue(&peer->local->peer_out, take(gossip));
}
close(gossip_fd);
}
static struct io_plan *handle_returning_peer(struct io_conn *conn,
struct returning_peer *rpeer)
{
@ -970,15 +986,12 @@ static struct io_plan *handle_returning_peer(struct io_conn *conn,
"hand_back_peer unknown peer: %s",
type_to_string(tmpctx, struct pubkey, &rpeer->id));
/* We don't need the gossip_fd; we know what gossip it got
* from gossip_index */
close(rpeer->gossip_fd);
/* Possible if there's a reconnect: ignore handed back. */
if (peer->local) {
status_trace("hand_back_peer %s: reconnected, dropping handback",
type_to_string(tmpctx, struct pubkey, &rpeer->id));
close(rpeer->gossip_fd);
close(rpeer->peer_fd);
tal_free(rpeer);
return daemon_conn_read_next(conn, &daemon->master);
@ -993,7 +1006,9 @@ static struct io_plan *handle_returning_peer(struct io_conn *conn,
peer->local = new_local_peer_state(peer, &rpeer->cs);
peer->local->fd = rpeer->peer_fd;
peer->broadcast_index = rpeer->gossip_index;
/* Forward any gossip we sent while fd wasn't being read */
drain_and_forward_gossip(peer, rpeer->gossip_fd);
/* If they told us to send a message, queue it now */
if (tal_len(rpeer->inner_msg))
@ -1019,7 +1034,6 @@ static struct io_plan *hand_back_peer(struct io_conn *conn,
rpeer->daemon = daemon;
if (!fromwire_gossipctl_hand_back_peer(msg, msg,
&rpeer->id, &rpeer->cs,
&rpeer->gossip_index,
&rpeer->inner_msg))
master_badmsg(WIRE_GOSSIPCTL_HAND_BACK_PEER, msg);

5
gossipd/gossip_wire.csv

@ -52,7 +52,6 @@ gossip_peer_connected,3002
gossip_peer_connected,,id,struct pubkey
gossip_peer_connected,,addr,struct wireaddr
gossip_peer_connected,,crypto_state,struct crypto_state
gossip_peer_connected,,gossip_index,u64
gossip_peer_connected,,gflen,u16
gossip_peer_connected,,gfeatures,gflen*u8
gossip_peer_connected,,lflen,u16
@ -63,7 +62,6 @@ gossip_peer_nongossip,3003
gossip_peer_nongossip,,id,struct pubkey
gossip_peer_nongossip,,addr,struct wireaddr
gossip_peer_nongossip,,crypto_state,struct crypto_state
gossip_peer_nongossip,,gossip_index,u64
gossip_peer_nongossip,,gflen,u16
gossip_peer_nongossip,,gfeatures,gflen*u8
gossip_peer_nongossip,,lflen,u16
@ -79,7 +77,6 @@ gossipctl_release_peer,,id,struct pubkey
gossipctl_release_peer_reply,3104
gossipctl_release_peer_reply,,addr,struct wireaddr
gossipctl_release_peer_reply,,crypto_state,struct crypto_state
gossipctl_release_peer_reply,,gossip_index,u64
gossipctl_release_peer_reply,,gflen,u16
gossipctl_release_peer_reply,,gfeatures,gflen*u8
gossipctl_release_peer_reply,,lflen,u16
@ -92,7 +89,6 @@ gossipctl_release_peer_replyfail,3204
gossipctl_hand_back_peer,3013
gossipctl_hand_back_peer,,id,struct pubkey
gossipctl_hand_back_peer,,crypto_state,struct crypto_state
gossipctl_hand_back_peer,,gossip_index,u64
gossipctl_hand_back_peer,,len,u16
gossipctl_hand_back_peer,,msg,len*u8
@ -175,7 +171,6 @@ gossip_get_update_reply,,update,len*u8
# Gossipd can tell channeld etc about gossip to fwd.
gossip_send_gossip,3016
gossip_send_gossip,,gossip_index,u64
gossip_send_gossip,,len,u16
gossip_send_gossip,,gossip,len*u8

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

9
lightningd/channel_control.c

@ -102,20 +102,18 @@ static void peer_start_closingd_after_shutdown(struct channel *channel,
const int *fds)
{
struct crypto_state cs;
u64 gossip_index;
/* We expect 2 fds. */
assert(tal_count(fds) == 2);
if (!fromwire_channel_shutdown_complete(msg, &cs, &gossip_index)) {
if (!fromwire_channel_shutdown_complete(msg, &cs)) {
channel_internal_error(channel, "bad shutdown_complete: %s",
tal_hex(msg, msg));
return;
}
/* This sets channel->owner, closes down channeld. */
peer_start_closingd(channel, &cs, gossip_index, fds[0], fds[1],
false, NULL);
peer_start_closingd(channel, &cs, fds[0], fds[1], false, NULL);
channel_set_state(channel, CHANNELD_SHUTTING_DOWN, CLOSINGD_SIGEXCHANGE);
}
@ -172,7 +170,6 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
bool peer_start_channeld(struct channel *channel,
const struct crypto_state *cs,
u64 gossip_index,
int peer_fd, int gossip_fd,
const u8 *funding_signed,
bool reconnected)
@ -248,7 +245,7 @@ bool peer_start_channeld(struct channel *channel,
feerate_min(ld),
feerate_max(ld),
&channel->last_sig,
cs, gossip_index,
cs,
&channel->channel_info.remote_fundingkey,
&channel->channel_info.theirbase.revocation,
&channel->channel_info.theirbase.payment,

1
lightningd/channel_control.h

@ -10,7 +10,6 @@ struct lightningd;
bool peer_start_channeld(struct channel *channel,
const struct crypto_state *cs,
u64 gossip_index,
int peer_fd, int gossip_fd,
const u8 *funding_signed,
bool reconnected);

7
lightningd/closing_control.c

@ -81,10 +81,7 @@ static void peer_received_closing_signature(struct channel *channel,
static void peer_closing_complete(struct channel *channel, const u8 *msg)
{
/* FIXME: We should save this, to return to gossipd */
u64 gossip_index;
if (!fromwire_closing_complete(msg, &gossip_index)) {
if (!fromwire_closing_complete(msg)) {
channel_internal_error(channel, "Bad closing_complete %s",
tal_hex(msg, msg));
return;
@ -132,7 +129,6 @@ static unsigned closing_msg(struct subd *sd, const u8 *msg, const int *fds UNUSE
void peer_start_closingd(struct channel *channel,
const struct crypto_state *cs,
u64 gossip_index,
int peer_fd, int gossip_fd,
bool reconnected,
const u8 *channel_reestablish)
@ -197,7 +193,6 @@ void peer_start_closingd(struct channel *channel,
their_msatoshi = funding_msatoshi - our_msatoshi;
initmsg = towire_closing_init(tmpctx,
cs,
gossip_index,
&channel->seed,
&channel->funding_txid,
channel->funding_outnum,

1
lightningd/closing_control.h

@ -8,7 +8,6 @@ struct crypto_state;
void peer_start_closingd(struct channel *channel,
const struct crypto_state *cs,
u64 gossip_index,
int peer_fd, int gossip_fd,
bool reconnected,
const u8 *channel_reestablish);

5
lightningd/gossip_control.c

@ -37,10 +37,9 @@ static void peer_nongossip(struct subd *gossip, const u8 *msg,
struct crypto_state cs;
struct wireaddr addr;
u8 *gfeatures, *lfeatures, *in_pkt;
u64 gossip_index;
if (!fromwire_gossip_peer_nongossip(msg, msg,
&id, &addr, &cs, &gossip_index,
&id, &addr, &cs,
&gfeatures,
&lfeatures,
&in_pkt))
@ -58,7 +57,7 @@ static void peer_nongossip(struct subd *gossip, const u8 *msg,
return;
}
peer_sent_nongossip(gossip->ld, &id, &addr, &cs, gossip_index,
peer_sent_nongossip(gossip->ld, &id, &addr, &cs,
gfeatures, lfeatures,
peer_fd, gossip_fd, in_pkt);
}

1
lightningd/onchain_control.c

@ -357,7 +357,6 @@ static bool tell_if_missing(const struct channel *channel,
static void onchain_error(struct channel *channel,
int peer_fd UNUSED, int gossip_fd UNUSED,
const struct crypto_state *cs UNUSED,
u64 gossip_index UNUSED,
const struct channel_id *channel_id UNUSED,
const char *desc,
const u8 *err_for_them UNUSED)

30
lightningd/opening_control.c

@ -101,7 +101,6 @@ static void remove_funding_channel_from_list(struct funding_channel *fc)
static void uncommitted_channel_to_gossipd(struct lightningd *ld,
struct uncommitted_channel *uc,
const struct crypto_state *cs,
u64 gossip_index,
int peer_fd, int gossip_fd,
const u8 *errorpkt,
const char *fmt,
@ -121,7 +120,6 @@ static void uncommitted_channel_to_gossipd(struct lightningd *ld,
/* Hand back to gossipd, (maybe) with an error packet to send. */
msg = towire_gossipctl_hand_back_peer(errstr, &uc->peer->id, cs,
gossip_index,
errorpkt);
subd_send_msg(ld->gossip, take(msg));
subd_send_fd(ld->gossip, peer_fd);
@ -286,7 +284,6 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
secp256k1_ecdsa_signature remote_commit_sig;
struct bitcoin_tx *remote_commit;
u16 funding_outnum;
u64 gossip_index;
u32 feerate;
u64 change_satoshi;
struct channel *channel;
@ -304,7 +301,6 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
&remote_commit,
&remote_commit_sig,
&cs,
&gossip_index,
&channel_info.theirbase.revocation,
&channel_info.theirbase.payment,
&channel_info.theirbase.htlc,
@ -430,8 +426,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
tell_gossipd_peer_is_important(ld, channel);
/* Start normal channel daemon. */
peer_start_channeld(channel, &cs, gossip_index,
fds[0], fds[1], NULL, false);
peer_start_channeld(channel, &cs, fds[0], fds[1], NULL, false);
wallet_confirm_utxos(ld->wallet, fc->utxomap);
@ -470,7 +465,6 @@ static void opening_fundee_finished(struct subd *openingd,
u8 *funding_signed;
struct channel_info channel_info;
struct crypto_state cs;
u64 gossip_index;
secp256k1_ecdsa_signature remote_commit_sig;
struct bitcoin_tx *remote_commit;
struct lightningd *ld = openingd->ld;
@ -492,7 +486,6 @@ static void opening_fundee_finished(struct subd *openingd,
&remote_commit,
&remote_commit_sig,
&cs,
&gossip_index,
&channel_info.theirbase.revocation,
&channel_info.theirbase.payment,
&channel_info.theirbase.htlc,
@ -537,7 +530,7 @@ static void opening_fundee_finished(struct subd *openingd,
tell_gossipd_peer_is_important(ld, channel);
/* On to normal operation! */
peer_start_channeld(channel, &cs, gossip_index,
peer_start_channeld(channel, &cs,
fds[0], fds[1], funding_signed, false);
subd_release_channel(openingd, uc);
@ -548,7 +541,6 @@ static void opening_fundee_finished(struct subd *openingd,
static void opening_channel_errmsg(struct uncommitted_channel *uc,
int peer_fd, int gossip_fd,
const struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id UNUSED,
const char *desc,
const u8 *err_for_them)
@ -562,7 +554,7 @@ static void opening_channel_errmsg(struct uncommitted_channel *uc,
const char *errsrc = err_for_them ? "sent" : "received";
uncommitted_channel_to_gossipd(uc->peer->ld, uc,
cs, gossip_index,
cs,
peer_fd, gossip_fd,
err_for_them,
"%s ERROR %s", errsrc, desc);
@ -687,7 +679,6 @@ u8 *peer_accept_channel(const tal_t *ctx,
const struct pubkey *peer_id,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures UNUSED, const u8 *lfeatures UNUSED,
int peer_fd, int gossip_fd,
const struct channel_id *channel_id,
@ -722,7 +713,7 @@ u8 *peer_accept_channel(const tal_t *ctx,
errpkt = towire_errorfmt(uc, channel_id, "%s", errmsg);
uncommitted_channel_to_gossipd(ld, uc,
cs, gossip_index,
cs,
peer_fd, gossip_fd,
errpkt, "%s", errmsg);
tal_free(uc);
@ -745,7 +736,7 @@ u8 *peer_accept_channel(const tal_t *ctx,
&uc->our_config,
max_to_self_delay,
min_effective_htlc_capacity_msat,
cs, gossip_index, &uc->seed);
cs, &uc->seed);
subd_send_msg(uc->openingd, take(msg));
@ -769,7 +760,6 @@ static void peer_offer_channel(struct lightningd *ld,
struct funding_channel *fc,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures UNUSED, const u8 *lfeatures UNUSED,
int peer_fd, int gossip_fd)
{
@ -806,7 +796,6 @@ static void peer_offer_channel(struct lightningd *ld,
/* We don't send them an error packet: for them, nothing
* happened! */
uncommitted_channel_to_gossipd(ld, fc->uc, NULL,
gossip_index,
peer_fd, gossip_fd,
NULL,
"Failed to launch openingd: %s",
@ -824,7 +813,7 @@ static void peer_offer_channel(struct lightningd *ld,
&fc->uc->our_config,
max_to_self_delay,
min_effective_htlc_capacity_msat,
cs, gossip_index, &fc->uc->seed);
cs, &fc->uc->seed);
subd_send_msg(fc->uc->openingd, take(msg));
msg = towire_opening_funder(fc, fc->funding_satoshi,
@ -848,7 +837,6 @@ static void gossip_peer_released(struct subd *gossip,
{
struct lightningd *ld = gossip->ld;
struct crypto_state cs;
u64 gossip_index;
u8 *gfeatures, *lfeatures;
struct wireaddr addr;
struct channel *c;
@ -861,7 +849,6 @@ static void gossip_peer_released(struct subd *gossip,
c = active_channel_by_id(ld, &fc->peerid, &uc);
if (!fromwire_gossipctl_release_peer_reply(fc, resp, &addr, &cs,
&gossip_index,
&gfeatures, &lfeatures)) {
if (!fromwire_gossipctl_release_peer_replyfail(resp)) {
fatal("Gossip daemon gave invalid reply %s",
@ -884,7 +871,7 @@ static void gossip_peer_released(struct subd *gossip,
assert(!uc);
/* OK, offer peer a channel. */
peer_offer_channel(ld, fc, &addr, &cs, gossip_index,
peer_offer_channel(ld, fc, &addr, &cs,
gfeatures, lfeatures,
fds[0], fds[1]);
}
@ -896,7 +883,6 @@ bool handle_opening_channel(struct lightningd *ld,
const struct pubkey *id,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures, const u8 *lfeatures,
int peer_fd, int gossip_fd)
{
@ -905,7 +891,7 @@ bool handle_opening_channel(struct lightningd *ld,
if (!fc)
return false;
peer_offer_channel(ld, fc, addr, cs, gossip_index, gfeatures, lfeatures,
peer_offer_channel(ld, fc, addr, cs, gfeatures, lfeatures,
peer_fd, gossip_fd);
return true;
}

2
lightningd/opening_control.h

@ -23,7 +23,6 @@ u8 *peer_accept_channel(const tal_t *ctx,
const struct pubkey *peer_id,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures, const u8 *lfeatures,
int peer_fd, int gossip_fd,
const struct channel_id *channel_id,
@ -35,7 +34,6 @@ bool handle_opening_channel(struct lightningd *ld,
const struct pubkey *id,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures, const u8 *lfeatures,
int peer_fd, int gossip_fd);

23
lightningd/peer_control.c

@ -346,7 +346,6 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel,
void channel_errmsg(struct channel *channel,
int peer_fd, int gossip_fd,
const struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id UNUSED,
const char *desc,
const u8 *err_for_them)
@ -393,8 +392,7 @@ void channel_errmsg(struct channel *channel,
/* Hand back to gossipd, with any error packet. */
msg = towire_gossipctl_hand_back_peer(NULL, &channel->peer->id,
cs, gossip_index,
err_for_them);
cs, err_for_them);
subd_send_msg(ld->gossip, take(msg));
subd_send_fd(ld->gossip, peer_fd);
subd_send_fd(ld->gossip, gossip_fd);
@ -412,11 +410,10 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
u8 *local_features;
struct channel *channel;
struct wireaddr addr;
u64 gossip_index;
struct uncommitted_channel *uc;
if (!fromwire_gossip_peer_connected(msg, msg,
&id, &addr, &cs, &gossip_index,
&id, &addr, &cs,
&gfeatures, &lfeatures))
fatal("Gossip gave bad GOSSIP_PEER_CONNECTED message %s",
tal_hex(msg, msg));
@ -441,7 +438,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
}
/* Were we trying to open a channel, and we've raced? */
if (handle_opening_channel(ld, &id, &addr, &cs, gossip_index,
if (handle_opening_channel(ld, &id, &addr, &cs,
gfeatures, lfeatures, peer_fd, gossip_fd))
return;
@ -489,7 +486,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
channel_set_owner(channel, NULL);
channel->peer->addr = addr;
peer_start_channeld(channel, &cs, gossip_index,
peer_start_channeld(channel, &cs,
peer_fd, gossip_fd, NULL,
true);
return;
@ -500,7 +497,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
channel_set_owner(channel, NULL);
channel->peer->addr = addr;
peer_start_closingd(channel, &cs, gossip_index,
peer_start_closingd(channel, &cs,
peer_fd, gossip_fd,
true, NULL);
return;
@ -514,8 +511,7 @@ return_to_gossipd:
send_error:
/* Hand back to gossipd, with an error packet. */
msg = towire_gossipctl_hand_back_peer(msg, &id, &cs, gossip_index,
error);
msg = towire_gossipctl_hand_back_peer(msg, &id, &cs, error);
subd_send_msg(ld->gossip, take(msg));
subd_send_fd(ld->gossip, peer_fd);
subd_send_fd(ld->gossip, gossip_fd);
@ -543,7 +539,6 @@ void peer_sent_nongossip(struct lightningd *ld,
const struct pubkey *id,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures,
const u8 *lfeatures,
int peer_fd, int gossip_fd,
@ -563,7 +558,7 @@ void peer_sent_nongossip(struct lightningd *ld,
/* Open request? */
if (fromwire_peektype(in_msg) == WIRE_OPEN_CHANNEL) {
error = peer_accept_channel(tmpctx,
ld, id, addr, cs, gossip_index,
ld, id, addr, cs,
gfeatures, lfeatures,
peer_fd, gossip_fd, channel_id,
in_msg);
@ -588,7 +583,7 @@ void peer_sent_nongossip(struct lightningd *ld,
if (fromwire_peektype(in_msg) == WIRE_CHANNEL_REESTABLISH
&& channel
&& channel->state == CLOSINGD_COMPLETE) {
peer_start_closingd(channel, cs, gossip_index,
peer_start_closingd(channel, cs,
peer_fd, gossip_fd, true, in_msg);
return;
}
@ -601,7 +596,7 @@ void peer_sent_nongossip(struct lightningd *ld,
send_error:
/* Hand back to gossipd, with an error packet. */
msg = towire_gossipctl_hand_back_peer(ld, id, cs, gossip_index, error);
msg = towire_gossipctl_hand_back_peer(ld, id, cs, error);
subd_send_msg(ld->gossip, take(msg));
subd_send_fd(ld->gossip, peer_fd);
subd_send_fd(ld->gossip, gossip_fd);

2
lightningd/peer_control.h

@ -80,7 +80,6 @@ void peer_sent_nongossip(struct lightningd *ld,
const struct pubkey *id,
const struct wireaddr *addr,
const struct crypto_state *cs,
u64 gossip_index,
const u8 *gfeatures,
const u8 *lfeatures,
int peer_fd, int gossip_fd,
@ -92,7 +91,6 @@ void peer_sent_nongossip(struct lightningd *ld,
void channel_errmsg(struct channel *channel,
int peer_fd, int gossip_fd,
const struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const char *desc,
const u8 *err_for_them);

9
lightningd/subd.c

@ -396,17 +396,16 @@ static bool handle_peer_error(struct subd *sd, const u8 *msg, int fds[2])
struct channel_id channel_id;
char *desc;
struct crypto_state cs;
u64 gossip_index;
u8 *err_for_them;
if (!fromwire_status_peer_error(msg, msg,
&channel_id, &desc,
&cs, &gossip_index, &err_for_them))
&cs, &err_for_them))
return false;
/* Don't free sd; we're may be about to free channel. */
sd->channel = NULL;
sd->errcb(channel, fds[0], fds[1], &cs, gossip_index,
sd->errcb(channel, fds[0], fds[1], &cs,
&channel_id, desc, err_for_them);
return true;
}
@ -587,7 +586,7 @@ static void destroy_subd(struct subd *sd)
if (!outer_transaction)
db_begin_transaction(db);
if (sd->errcb)
sd->errcb(channel, -1, -1, NULL, 0, NULL,
sd->errcb(channel, -1, -1, NULL, NULL,
tal_fmt(sd, "Owning subdaemon %s died (%i)",
sd->name, status),
NULL);
@ -638,7 +637,6 @@ static struct subd *new_subd(struct lightningd *ld,
void (*errcb)(void *channel,
int peer_fd, int gossip_fd,
const struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const char *desc,
const u8 *err_for_them),
@ -726,7 +724,6 @@ struct subd *new_channel_subd_(struct lightningd *ld,
void (*errcb)(void *channel,
int peer_fd, int gossip_fd,
const struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const char *desc,
const u8 *err_for_them),

3
lightningd/subd.h

@ -44,7 +44,6 @@ struct subd {
void (*errcb)(void *channel,
int peer_fd, int gossip_fd,
const struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const char *desc,
const u8 *err_for_them);
@ -116,7 +115,6 @@ struct subd *new_channel_subd_(struct lightningd *ld,
void (*errcb)(void *channel,
int peer_fd, int gossip_fd,
const struct crypto_state *cs,
u64 gossip_index,
const struct channel_id *channel_id,
const char *desc,
const u8 *err_for_them),
@ -130,7 +128,6 @@ struct subd *new_channel_subd_(struct lightningd *ld,
typesafe_cb_postargs(void, void *, (errcb), \
(channel), int, int, \
const struct crypto_state *, \
u64, \
const struct channel_id *, \
const char *, const u8 *), \
typesafe_cb_postargs(void, void *, (billboardcb), \

35
openingd/opening.c

@ -40,7 +40,6 @@
struct state {
struct crypto_state cs;
u64 gossip_index;
struct pubkey next_per_commit[NUM_SIDES];
/* Initially temporary, then final channel id. */
@ -82,14 +81,14 @@ static void negotiation_failed(struct state *state, const char *fmt, ...)
peer_billboard(true, errmsg);
msg = towire_status_peer_error(NULL, &state->channel_id,
errmsg, &state->cs, state->gossip_index,
errmsg, &state->cs,
towire_errorfmt(errmsg,
&state->channel_id,
"You gave bad parameters:%s",
errmsg));
tal_free(errmsg);
status_send_fatal(take(msg), PEER_FD, GOSSIP_FD);
peer_failed(&state->cs, state->gossip_index, &state->channel_id,
peer_failed(&state->cs, &state->channel_id,
"You gave bad parameters: %s", errmsg);
}
@ -230,7 +229,7 @@ static u8 *opening_read_peer_msg(struct state *state)
{
u8 *msg;
while ((msg = read_peer_msg(state, &state->cs, state->gossip_index,
while ((msg = read_peer_msg(state, &state->cs,
&state->channel_id,
sync_crypto_write_arg,
status_fail_io,
@ -329,7 +328,7 @@ static u8 *funder_channel(struct state *state,
&theirs.delayed_payment,
&theirs.htlc,
&state->next_per_commit[REMOTE]))
peer_failed(&state->cs, state->gossip_index,
peer_failed(&state->cs,
&state->channel_id,
"Parsing accept_channel %s", tal_hex(msg, msg));
@ -338,7 +337,7 @@ static u8 *funder_channel(struct state *state,
* The `temporary_channel_id` MUST be the same as the
* `temporary_channel_id` in the `open_channel` message. */
if (!structeq(&id_in, &state->channel_id))
peer_failed(&state->cs, state->gossip_index,
peer_failed(&state->cs,
&state->channel_id,
"accept_channel ids don't match: sent %s got %s",
type_to_string(msg, struct channel_id, &id_in),
@ -419,7 +418,7 @@ static u8 *funder_channel(struct state *state,
&their_funding_pubkey,
LOCAL);
if (!state->channel)
peer_failed(&state->cs, state->gossip_index,
peer_failed(&state->cs,
&state->channel_id,
"could not create channel with given config");
@ -466,7 +465,7 @@ static u8 *funder_channel(struct state *state,
msg = opening_read_peer_msg(state);
if (!fromwire_funding_signed(msg, &id_in, &sig))
peer_failed(&state->cs, state->gossip_index,
peer_failed(&state->cs,
&state->channel_id,
"Parsing funding_signed: %s", tal_hex(msg, msg));
@ -482,7 +481,7 @@ static u8 *funder_channel(struct state *state,
&state->funding_txid, state->funding_txout);
if (!structeq(&id_in, &state->channel_id))
peer_failed(&state->cs, state->gossip_index, &id_in,
peer_failed(&state->cs, &id_in,
"funding_signed ids don't match: expected %s got %s",
type_to_string(msg, struct channel_id,
&state->channel_id),
@ -499,7 +498,7 @@ static u8 *funder_channel(struct state *state,
"Could not meet our fees and reserve");
if (!check_tx_sig(tx, 0, NULL, wscript, &their_funding_pubkey, &sig)) {
peer_failed(&state->cs, state->gossip_index,
peer_failed(&state->cs,
&state->channel_id,
"Bad signature %s on tx %s using key %s",
type_to_string(tmpctx, secp256k1_ecdsa_signature,
@ -518,7 +517,7 @@ static u8 *funder_channel(struct state *state,
state->remoteconf,
tx,
&sig,
&state->cs, state->gossip_index,
&state->cs,
&theirs.revocation,
&theirs.payment,
&theirs.htlc,
@ -574,7 +573,7 @@ static u8 *fundee_channel(struct state *state,
&theirs.htlc,
&state->next_per_commit[REMOTE],
&channel_flags))
peer_failed(&state->cs, state->gossip_index, NULL,
peer_failed(&state->cs, NULL,
"Bad open_channel %s",
tal_hex(peer_msg, peer_msg));
@ -607,7 +606,7 @@ static u8 *fundee_channel(struct state *state,
* greater than `funding_satoshis` * 1000.
*/
if (state->push_msat > state->funding_satoshis * 1000)
peer_failed(&state->cs, state->gossip_index,
peer_failed(&state->cs,
&state->channel_id,
"Our push_msat %"PRIu64
" would be too large for funding_satoshis %"PRIu64,
@ -684,7 +683,7 @@ static u8 *fundee_channel(struct state *state,
&state->funding_txid,
&state->funding_txout,
&theirsig))
peer_failed(&state->cs, state->gossip_index,
peer_failed(&state->cs,
&state->channel_id,
"Parsing funding_created");
@ -693,7 +692,7 @@ static u8 *fundee_channel(struct state *state,
* The sender MUST set `temporary_channel_id` the same as the
* `temporary_channel_id` in the `open_channel` message. */
if (!structeq(&id_in, &state->channel_id))
peer_failed(&state->cs, state->gossip_index, &id_in,
peer_failed(&state->cs, &id_in,
"funding_created ids don't match: sent %s got %s",
type_to_string(msg, struct channel_id,
&state->channel_id),
@ -712,7 +711,7 @@ static u8 *fundee_channel(struct state *state,
&their_funding_pubkey,
REMOTE);
if (!state->channel)
peer_failed(&state->cs, state->gossip_index,
peer_failed(&state->cs,
&state->channel_id,
"We could not create channel with given config");
@ -728,7 +727,7 @@ static u8 *fundee_channel(struct state *state,
if (!check_tx_sig(their_commit, 0, NULL, wscript, &their_funding_pubkey,
&theirsig)) {
peer_failed(&state->cs, state->gossip_index,
peer_failed(&state->cs,
&state->channel_id,
"Bad signature %s on tx %s using key %s",
type_to_string(tmpctx, secp256k1_ecdsa_signature,
@ -776,7 +775,6 @@ static u8 *fundee_channel(struct state *state,
their_commit,
&theirsig,
&state->cs,
state->gossip_index,
&theirs.revocation,
&theirs.payment,
&theirs.htlc,
@ -820,7 +818,6 @@ int main(int argc, char *argv[])
&state->max_to_self_delay,
&state->min_effective_htlc_capacity_msat,
&state->cs,
&state->gossip_index,
&seed))
master_badmsg(WIRE_OPENING_INIT, msg);

3
openingd/opening_wire.csv

@ -9,7 +9,6 @@ opening_init,,our_config,struct channel_config
opening_init,,max_to_self_delay,u32
opening_init,,min_effective_htlc_capacity_msat,u64
opening_init,,crypto_state,struct crypto_state
opening_init,,gossip_index,u64
# Seed to generate all the keys from
opening_init,,seed,struct privkey
@ -35,7 +34,6 @@ 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,,crypto_state,struct crypto_state
opening_funder_reply,,gossip_index,u64
opening_funder_reply,,revocation_basepoint,struct pubkey
opening_funder_reply,,payment_basepoint,struct pubkey
opening_funder_reply,,htlc_basepoint,struct pubkey
@ -60,7 +58,6 @@ 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,,crypto_state,struct crypto_state
opening_fundee_reply,,gossip_index,u64
opening_fundee_reply,,revocation_basepoint,struct pubkey
opening_fundee_reply,,payment_basepoint,struct pubkey
opening_fundee_reply,,htlc_basepoint,struct pubkey

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

8
wallet/test/run-wallet.c

@ -81,7 +81,7 @@ bool fromwire_gossipctl_peer_disconnect_replyfail(const void *p UNNEEDED, bool *
bool fromwire_gossip_getpeers_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey **id UNNEEDED, struct wireaddr **addr UNNEEDED, struct gossip_getnodes_entry ***nodes UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_getpeers_reply called!\n"); abort(); }
/* Generated stub for fromwire_gossip_peer_connected */
bool fromwire_gossip_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey *id UNNEEDED, struct wireaddr *addr UNNEEDED, struct crypto_state *crypto_state UNNEEDED, u64 *gossip_index UNNEEDED, u8 **gfeatures UNNEEDED, u8 **lfeatures UNNEEDED)
bool fromwire_gossip_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey *id UNNEEDED, struct wireaddr *addr UNNEEDED, struct crypto_state *crypto_state UNNEEDED, u8 **gfeatures UNNEEDED, u8 **lfeatures UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_peer_connected called!\n"); abort(); }
/* Generated stub for get_feerate */
u32 get_feerate(const struct chain_topology *topo UNNEEDED, enum feerate feerate UNNEEDED)
@ -97,7 +97,6 @@ bool handle_opening_channel(struct lightningd *ld UNNEEDED,
const struct pubkey *id UNNEEDED,
const struct wireaddr *addr UNNEEDED,
const struct crypto_state *cs UNNEEDED,
u64 gossip_index UNNEEDED,
const u8 *gfeatures UNNEEDED, const u8 *lfeatures UNNEEDED,
int peer_fd UNNEEDED, int gossip_fd UNNEEDED)
{ fprintf(stderr, "handle_opening_channel called!\n"); abort(); }
@ -314,7 +313,6 @@ u8 *peer_accept_channel(const tal_t *ctx UNNEEDED,
const struct pubkey *peer_id UNNEEDED,
const struct wireaddr *addr UNNEEDED,
const struct crypto_state *cs UNNEEDED,
u64 gossip_index UNNEEDED,
const u8 *gfeatures UNNEEDED, const u8 *lfeatures UNNEEDED,
int peer_fd UNNEEDED, int gossip_fd UNNEEDED,
const struct channel_id *channel_id UNNEEDED,
@ -323,7 +321,6 @@ u8 *peer_accept_channel(const tal_t *ctx UNNEEDED,
/* Generated stub for peer_start_channeld */
bool peer_start_channeld(struct channel *channel UNNEEDED,
const struct crypto_state *cs UNNEEDED,
u64 gossip_index UNNEEDED,
int peer_fd UNNEEDED, int gossip_fd UNNEEDED,
const u8 *funding_signed UNNEEDED,
bool reconnected UNNEEDED)
@ -331,7 +328,6 @@ bool peer_start_channeld(struct channel *channel UNNEEDED,
/* Generated stub for peer_start_closingd */
void peer_start_closingd(struct channel *channel UNNEEDED,
const struct crypto_state *cs UNNEEDED,
u64 gossip_index UNNEEDED,
int peer_fd UNNEEDED, int gossip_fd UNNEEDED,
bool reconnected UNNEEDED,
const u8 *channel_reestablish UNNEEDED)
@ -372,7 +368,7 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
/* Generated stub for towire_gossipctl_hand_back_peer */
u8 *towire_gossipctl_hand_back_peer(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED, const struct crypto_state *crypto_state UNNEEDED, u64 gossip_index UNNEEDED, const u8 *msg UNNEEDED)
u8 *towire_gossipctl_hand_back_peer(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED, const struct crypto_state *crypto_state UNNEEDED, const u8 *msg UNNEEDED)
{ fprintf(stderr, "towire_gossipctl_hand_back_peer called!\n"); abort(); }
/* Generated stub for towire_gossipctl_peer_addrhint */
u8 *towire_gossipctl_peer_addrhint(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED, const struct wireaddr *addr UNNEEDED)

Loading…
Cancel
Save