Browse Source

lightningd/opening: rename functions and wire messages for clarity.

Each one is either funder or fundee now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
3ab3281a4c
  1. 2
      lightningd/gossip_control.c
  2. 76
      lightningd/opening/opening.c
  3. 82
      lightningd/opening/opening_wire.csv
  4. 58
      lightningd/peer_control.c
  5. 2
      lightningd/peer_control.h

2
lightningd/gossip_control.c

@ -95,7 +95,7 @@ static void peer_nongossip(struct subd *gossip, const u8 *msg,
log_info(peer->log, "Gossip ended up receipt of %s",
wire_type_name(fromwire_peektype(inner)));
peer_accept_open(peer, inner);
peer_fundee_open(peer, inner);
}
static int gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)

76
lightningd/opening/opening.c

@ -191,10 +191,10 @@ static u8 *read_next_peer_msg(struct state *state, const tal_t *ctx)
}
}
static u8 *open_channel(struct state *state,
const struct pubkey *our_funding_pubkey,
const struct basepoints *ours,
u32 max_minimum_depth)
static u8 *funder_channel(struct state *state,
const struct pubkey *our_funding_pubkey,
const struct basepoints *ours,
u32 max_minimum_depth)
{
const tal_t *tmpctx = tal_tmpctx(state);
struct channel_id channel_id, id_in;
@ -263,9 +263,9 @@ static u8 *open_channel(struct state *state,
if (!fromwire_accept_channel(msg, NULL, &id_in,
&state->remoteconf->dust_limit_satoshis,
&state->remoteconf
->max_htlc_value_in_flight_msat,
->max_htlc_value_in_flight_msat,
&state->remoteconf
->channel_reserve_satoshis,
->channel_reserve_satoshis,
&minimum_depth,
&state->remoteconf->htlc_minimum_msat,
&state->remoteconf->to_self_delay,
@ -303,18 +303,18 @@ static u8 *open_channel(struct state *state,
check_config_bounds(state, state->remoteconf);
/* Now, ask master create a transaction to pay those two addresses. */
msg = towire_opening_open_reply(tmpctx, our_funding_pubkey,
&their_funding_pubkey);
msg = towire_opening_funder_reply(tmpctx, our_funding_pubkey,
&their_funding_pubkey);
wire_sync_write(REQ_FD, msg);
/* Expect funding tx. */
msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_opening_open_funding(msg, NULL,
&state->funding_txid,
&state->funding_txout))
if (!fromwire_opening_funder_funding(msg, NULL,
&state->funding_txid,
&state->funding_txout))
peer_failed(PEER_FD, &state->cs, NULL,
WIRE_OPENING_PEER_READ_FAILED,
"Expected valid opening_open_funding: %s",
"Expected valid opening_funder_funding: %s",
tal_hex(trc, msg));
state->channel = new_channel(state,
@ -420,24 +420,24 @@ static u8 *open_channel(struct state *state,
* Once the channel funder receives the `funding_signed` message, they
* must broadcast the funding transaction to the Bitcoin network.
*/
return towire_opening_open_funding_reply(state,
state->remoteconf,
&sig,
&state->cs,
&theirs.revocation,
&theirs.payment,
&theirs.delayed_payment,
&state->next_per_commit[REMOTE],
minimum_depth);
return towire_opening_funder_funding_reply(state,
state->remoteconf,
&sig,
&state->cs,
&theirs.revocation,
&theirs.payment,
&theirs.delayed_payment,
&state->next_per_commit[REMOTE],
minimum_depth);
}
/* This is handed the message the peer sent which caused gossip to stop:
* it should be an open_channel */
static u8 *recv_channel(struct state *state,
const struct pubkey *our_funding_pubkey,
const struct basepoints *ours,
u32 minimum_depth,
u32 min_feerate, u32 max_feerate, const u8 *peer_msg)
static u8 *fundee_channel(struct state *state,
const struct pubkey *our_funding_pubkey,
const struct basepoints *ours,
u32 minimum_depth,
u32 min_feerate, u32 max_feerate, const u8 *peer_msg)
{
struct channel_id id_in, channel_id;
struct basepoints theirs;
@ -588,13 +588,13 @@ static u8 *recv_channel(struct state *state,
/* Now, ask master to watch. */
status_trace("asking master to watch funding %s",
type_to_string(trc, struct sha256_double, &state->funding_txid));
msg = towire_opening_accept_reply(state, &state->funding_txid);
msg = towire_opening_fundee_reply(state, &state->funding_txid);
wire_sync_write(REQ_FD, msg);
msg = wire_sync_read(state, REQ_FD);
if (!fromwire_opening_accept_finish(msg, NULL))
if (!fromwire_opening_fundee_finish(msg, NULL))
status_failed(WIRE_OPENING_BAD_PARAM,
"Expected valid opening_accept_finish: %s",
"Expected valid opening_fundee_finish: %s",
tal_hex(trc, msg));
status_trace("master said to finish");
@ -647,7 +647,7 @@ static u8 *recv_channel(struct state *state,
peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_WRITE_FAILED,
"Writing funding_signed");
return towire_opening_accept_finish_reply(state,
return towire_opening_fundee_finish_reply(state,
state->funding_txout,
state->remoteconf,
&theirsig,
@ -711,15 +711,15 @@ int main(int argc, char *argv[])
type_to_string(trc, struct pubkey,
&state->next_per_commit[LOCAL]));
msg = wire_sync_read(state, REQ_FD);
if (fromwire_opening_open(msg, NULL,
&state->funding_satoshis,
&state->push_msat,
&state->feerate_per_kw, &max_minimum_depth))
msg = open_channel(state, &our_funding_pubkey, &our_points,
max_minimum_depth);
else if (fromwire_opening_accept(state, msg, NULL, &minimum_depth,
if (fromwire_opening_funder(msg, NULL,
&state->funding_satoshis,
&state->push_msat,
&state->feerate_per_kw, &max_minimum_depth))
msg = funder_channel(state, &our_funding_pubkey, &our_points,
max_minimum_depth);
else if (fromwire_opening_fundee(state, msg, NULL, &minimum_depth,
&min_feerate, &max_feerate, &peer_msg))
msg = recv_channel(state, &our_funding_pubkey, &our_points,
msg = fundee_channel(state, &our_funding_pubkey, &our_points,
minimum_depth, min_feerate, max_feerate,
peer_msg);

82
lightningd/opening/opening_wire.csv

@ -24,57 +24,57 @@ opening_init,48,crypto_state,struct crypto_state
opening_init,196,seed,struct privkey
# This means we offer the open.
opening_open,1
opening_open,0,funding_satoshis,8
opening_open,8,push_msat,8
opening_open,16,feerate_per_kw,4
opening_open,20,max_minimum_depth,4
opening_funder,1
opening_funder,0,funding_satoshis,8
opening_funder,8,push_msat,8
opening_funder,16,feerate_per_kw,4
opening_funder,20,max_minimum_depth,4
# Reply asks for txid of funding transaction.
opening_open_reply,101
opening_open_reply,0,local_fundingkey,33
opening_open_reply,0,remote_fundingkey,33
opening_funder_reply,101
opening_funder_reply,0,local_fundingkey,33
opening_funder_reply,0,remote_fundingkey,33
# Now we give the funding txid and outnum.
opening_open_funding,2
opening_open_funding,0,txid,struct sha256_double
opening_open_funding,32,txout,u16
opening_funder_funding,2
opening_funder_funding,0,txid,struct sha256_double
opening_funder_funding,32,txout,u16
# This gives their sig, means we can broadcast tx: we're done.
opening_open_funding_reply,102
opening_open_funding_reply,0,their_config,struct channel_config
opening_open_funding_reply,36,first_commit_sig,secp256k1_ecdsa_signature
opening_open_funding_reply,100,crypto_state,struct crypto_state
opening_open_funding_reply,244,revocation_basepoint,33
opening_open_funding_reply,277,payment_basepoint,33
opening_open_funding_reply,310,delayed_payment_basepoint,33
opening_open_funding_reply,343,their_per_commit_point,33
opening_open_funding_reply,376,minimum_depth,4
opening_funder_funding_reply,102
opening_funder_funding_reply,0,their_config,struct channel_config
opening_funder_funding_reply,36,first_commit_sig,secp256k1_ecdsa_signature
opening_funder_funding_reply,100,crypto_state,struct crypto_state
opening_funder_funding_reply,244,revocation_basepoint,33
opening_funder_funding_reply,277,payment_basepoint,33
opening_funder_funding_reply,310,delayed_payment_basepoint,33
opening_funder_funding_reply,343,their_per_commit_point,33
opening_funder_funding_reply,376,minimum_depth,4
# This means they offer the open (contains their offer packet)
opening_accept,3
opening_accept,0,minimum_depth,4
opening_accept,0,min_feerate,4
opening_accept,4,max_feerate,4
opening_accept,8,len,2
opening_accept,10,msg,len*u8
opening_fundee,3
opening_fundee,0,minimum_depth,4
opening_fundee,0,min_feerate,4
opening_fundee,4,max_feerate,4
opening_fundee,8,len,2
opening_fundee,10,msg,len*u8
# This gives the txid of their funding tx to watch.
opening_accept_reply,103
opening_accept_reply,0,funding_txid,struct sha256_double
opening_fundee_reply,103
opening_fundee_reply,0,funding_txid,struct sha256_double
# Acknowledge watch is in place, now can send sig.
opening_accept_finish,4
opening_fundee_finish,4
opening_accept_finish_reply,104
opening_accept_finish_reply,32,funding_txout,u16
opening_accept_finish_reply,0,their_config,struct channel_config
opening_accept_finish_reply,36,first_commit_sig,secp256k1_ecdsa_signature
opening_accept_finish_reply,100,crypto_state,struct crypto_state
opening_accept_finish_reply,244,remote_fundingkey,33
opening_accept_finish_reply,277,revocation_basepoint,33
opening_accept_finish_reply,310,payment_basepoint,33
opening_accept_finish_reply,343,delayed_payment_basepoint,33
opening_accept_finish_reply,377,their_per_commit_point,33
opening_accept_finish_reply,410,funding_satoshis,8
opening_accept_finish_reply,418,push_msat,8
opening_fundee_finish_reply,104
opening_fundee_finish_reply,32,funding_txout,u16
opening_fundee_finish_reply,0,their_config,struct channel_config
opening_fundee_finish_reply,36,first_commit_sig,secp256k1_ecdsa_signature
opening_fundee_finish_reply,100,crypto_state,struct crypto_state
opening_fundee_finish_reply,244,remote_fundingkey,33
opening_fundee_finish_reply,277,revocation_basepoint,33
opening_fundee_finish_reply,310,payment_basepoint,33
opening_fundee_finish_reply,343,delayed_payment_basepoint,33
opening_fundee_finish_reply,377,their_per_commit_point,33
opening_fundee_finish_reply,410,funding_satoshis,8
opening_fundee_finish_reply,418,push_msat,8

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

58
lightningd/peer_control.c

@ -1390,15 +1390,15 @@ static bool opening_release_tx(struct subd *opening, const u8 *resp,
fc->peer->fd = fds[0];
fc->peer->cs = tal(fc->peer, struct crypto_state);
if (!fromwire_opening_open_funding_reply(resp, NULL,
&their_config,
&commit_sig,
fc->peer->cs,
&theirbase.revocation,
&theirbase.payment,
&theirbase.delayed_payment,
&their_per_commit_point,
&fc->peer->minimum_depth)) {
if (!fromwire_opening_funder_funding_reply(resp, NULL,
&their_config,
&commit_sig,
fc->peer->cs,
&theirbase.revocation,
&theirbase.payment,
&theirbase.delayed_payment,
&their_per_commit_point,
&fc->peer->minimum_depth)) {
log_broken(fc->peer->log, "bad OPENING_OPEN_FUNDING_REPLY %s",
tal_hex(resp, resp));
tal_free(fc->peer);
@ -1457,9 +1457,9 @@ static bool opening_gen_funding(struct subd *opening, const u8 *reply,
struct pubkey changekey;
log_debug(fc->peer->log, "Created funding transaction for channel");
if (!fromwire_opening_open_reply(reply, NULL,
&fc->local_fundingkey,
&fc->remote_fundingkey)) {
if (!fromwire_opening_funder_reply(reply, NULL,
&fc->local_fundingkey,
&fc->remote_fundingkey)) {
log_broken(fc->peer->log, "Bad opening_open_reply %s",
tal_hex(fc, reply));
/* Free openingd and peer */
@ -1480,13 +1480,13 @@ static bool opening_gen_funding(struct subd *opening, const u8 *reply,
fc->peer->funding_txid = tal(fc->peer, struct sha256_double);
bitcoin_txid(fc->funding_tx, fc->peer->funding_txid);
msg = towire_opening_open_funding(fc, fc->peer->funding_txid,
fc->peer->funding_outnum);
msg = towire_opening_funder_funding(fc, fc->peer->funding_txid,
fc->peer->funding_outnum);
subd_req(fc, fc->peer->owner, take(msg), -1, 1, opening_release_tx, fc);
return true;
}
static bool opening_accept_finish_response(struct subd *opening,
static bool opening_fundee_finish_response(struct subd *opening,
const u8 *reply,
const int *fds,
struct peer *peer)
@ -1498,12 +1498,12 @@ static bool opening_accept_finish_response(struct subd *opening,
struct config *cfg = &peer->ld->dstate.config;
u8 *initmsg;
log_debug(peer->log, "Got opening_accept_finish_response");
log_debug(peer->log, "Got opening_fundee_finish_response");
assert(tal_count(fds) == 1);
peer->fd = fds[0];
peer->cs = tal(peer, struct crypto_state);
if (!fromwire_opening_accept_finish_reply(reply, NULL,
if (!fromwire_opening_fundee_finish_reply(reply, NULL,
&peer->funding_outnum,
&their_config,
&first_commit_sig,
@ -1515,7 +1515,7 @@ static bool opening_accept_finish_response(struct subd *opening,
&their_per_commit_point,
&peer->funding_satoshi,
&peer->push_msat)) {
log_broken(peer->log, "bad OPENING_ACCEPT_FINISH_REPLY %s",
log_broken(peer->log, "bad OPENING_FUNDEE_FINISH_REPLY %s",
tal_hex(reply, reply));
return false;
}
@ -1551,13 +1551,13 @@ static bool opening_accept_finish_response(struct subd *opening,
return false;
}
static bool opening_accept_reply(struct subd *opening, const u8 *reply,
static bool opening_fundee_reply(struct subd *opening, const u8 *reply,
const int *fds,
struct peer *peer)
{
peer->funding_txid = tal(peer, struct sha256_double);
if (!fromwire_opening_accept_reply(reply, NULL, peer->funding_txid)) {
log_broken(peer->log, "bad OPENING_ACCEPT_REPLY %s",
if (!fromwire_opening_fundee_reply(reply, NULL, peer->funding_txid)) {
log_broken(peer->log, "bad OPENING_FUNDEE_REPLY %s",
tal_hex(reply, reply));
return false;
}
@ -1572,9 +1572,9 @@ static bool opening_accept_reply(struct subd *opening, const u8 *reply,
peer_set_condition(peer, OPENINGD, OPENINGD_AWAITING_LOCKIN);
/* Tell it we're watching. */
subd_req(peer, opening, towire_opening_accept_finish(reply),
subd_req(peer, opening, towire_opening_fundee_finish(reply),
-1, 1,
opening_accept_finish_response, peer);
opening_fundee_finish_response, peer);
return true;
}
@ -1622,7 +1622,7 @@ static void channel_config(struct lightningd *ld,
};
/* Peer has spontaneously exited from gossip due to msg */
void peer_accept_open(struct peer *peer, const u8 *from_peer)
void peer_fundee_open(struct peer *peer, const u8 *from_peer)
{
struct lightningd *ld = peer->ld;
u32 max_to_self_delay, max_minimum_depth;
@ -1675,7 +1675,7 @@ void peer_accept_open(struct peer *peer, const u8 *from_peer)
peer->cs = tal_free(peer->cs);
subd_send_msg(peer->owner, take(msg));
msg = towire_opening_accept(peer, peer->minimum_depth,
msg = towire_opening_fundee(peer, peer->minimum_depth,
7500, 150000, from_peer);
/* Careful here! Their message could push us overlength! */
@ -1683,7 +1683,7 @@ void peer_accept_open(struct peer *peer, const u8 *from_peer)
peer_fail(peer, "Unacceptably long open_channel");
return;
}
subd_req(peer, peer->owner, take(msg), -1, 0, opening_accept_reply, peer);
subd_req(peer, peer->owner, take(msg), -1, 0, opening_fundee_reply, peer);
}
/* Peer has been released from gossip. Start opening. */
@ -1749,9 +1749,9 @@ static bool gossip_peer_released(struct subd *gossip,
subd_send_msg(opening, take(msg));
/* FIXME: Real feerate! */
msg = towire_opening_open(fc, fc->peer->funding_satoshi,
fc->peer->push_msat,
15000, max_minimum_depth);
msg = towire_opening_funder(fc, fc->peer->funding_satoshi,
fc->peer->push_msat,
15000, max_minimum_depth);
subd_req(fc, opening, take(msg), -1, 0, opening_gen_funding, fc);
return true;
}

2
lightningd/peer_control.h

@ -118,7 +118,7 @@ struct peer *peer_from_json(struct lightningd *ld,
const char *buffer,
jsmntok_t *peeridtok);
void peer_accept_open(struct peer *peer, const u8 *msg);
void peer_fundee_open(struct peer *peer, const u8 *msg);
void add_peer(struct lightningd *ld, u64 unique_id,
int fd, const struct pubkey *id,

Loading…
Cancel
Save