mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-10 17:44:22 +01:00
Minor cleanups: things found while debugging the database code.
1. Fix #ifdef DEBUG code in signature.c so it compiles. 2. Don't set peer->closing.our_script in queue_pkt_close_shutdown: it's assigned in caller already. 3. Wrap setting of htlc's rval in set_htlc_rval() function. 4. Log where we were when unexpected packet comes in. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -51,8 +51,8 @@ static void dump_tx(const char *msg,
|
||||
fprintf(stderr, "%02x", script[i]);
|
||||
if (key) {
|
||||
fprintf(stderr, "\nPubkey: ");
|
||||
for (i = 0; i < sizeof(key->der); i++)
|
||||
fprintf(stderr, "%02x", key->der[i]);
|
||||
for (i = 0; i < sizeof(key->pubkey); i++)
|
||||
fprintf(stderr, "%02x", ((u8 *)&key->pubkey)[i]);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (h) {
|
||||
|
||||
@@ -239,14 +239,9 @@ void queue_pkt_err(struct peer *peer, Pkt *err)
|
||||
|
||||
void queue_pkt_close_shutdown(struct peer *peer)
|
||||
{
|
||||
u8 *redeemscript;
|
||||
CloseShutdown *c = tal(peer, CloseShutdown);
|
||||
|
||||
close_shutdown__init(c);
|
||||
redeemscript = bitcoin_redeem_single(c, peer->dstate->secpctx,
|
||||
&peer->local.finalkey);
|
||||
peer->closing.our_script = scriptpubkey_p2sh(peer, redeemscript);
|
||||
|
||||
c->scriptpubkey.data = tal_dup_arr(c, u8,
|
||||
peer->closing.our_script,
|
||||
tal_count(peer->closing.our_script),
|
||||
@@ -473,7 +468,7 @@ Pkt *accept_pkt_htlc_fulfill(struct peer *peer, const Pkt *pkt, struct htlc **h,
|
||||
*was_already_fulfilled = true;
|
||||
} else {
|
||||
*was_already_fulfilled = false;
|
||||
(*h)->r = tal_dup(*h, struct rval, &r);
|
||||
set_htlc_rval(peer, *h, &r);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -327,12 +327,13 @@ static bool peer_comms_err(struct peer *peer, Pkt *err)
|
||||
return false;
|
||||
}
|
||||
|
||||
void peer_unexpected_pkt(struct peer *peer, const Pkt *pkt)
|
||||
void peer_unexpected_pkt(struct peer *peer, const Pkt *pkt, const char *where)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
log_unusual(peer->log, "Received unexpected pkt %u (%s)",
|
||||
pkt->pkt_case, pkt_name(pkt->pkt_case));
|
||||
log_unusual(peer->log, "%s: received unexpected pkt %u (%s) in %s",
|
||||
where, pkt->pkt_case, pkt_name(pkt->pkt_case),
|
||||
state_name(peer->state));
|
||||
|
||||
if (pkt->pkt_case != PKT__PKT_ERROR)
|
||||
return;
|
||||
@@ -352,12 +353,20 @@ void peer_unexpected_pkt(struct peer *peer, const Pkt *pkt)
|
||||
}
|
||||
|
||||
/* Unexpected packet received: stop listening, start breakdown procedure. */
|
||||
static bool peer_received_unexpected_pkt(struct peer *peer, const Pkt *pkt)
|
||||
static bool peer_received_unexpected_pkt(struct peer *peer, const Pkt *pkt,
|
||||
const char *where)
|
||||
{
|
||||
peer_unexpected_pkt(peer, pkt);
|
||||
peer_unexpected_pkt(peer, pkt, where);
|
||||
return peer_comms_err(peer, pkt_err_unexpected(peer, pkt));
|
||||
}
|
||||
|
||||
void set_htlc_rval(struct peer *peer,
|
||||
struct htlc *htlc, const struct rval *rval)
|
||||
{
|
||||
assert(!htlc->r);
|
||||
htlc->r = tal_dup(htlc, struct rval, rval);
|
||||
}
|
||||
|
||||
static void route_htlc_onwards(struct peer *peer,
|
||||
struct htlc *htlc,
|
||||
u64 msatoshis,
|
||||
@@ -486,8 +495,7 @@ static void their_htlc_added(struct peer *peer, struct htlc *htlc,
|
||||
log_info(peer->log, "Immediately resolving HTLC %"PRIu64,
|
||||
htlc->id);
|
||||
|
||||
assert(!htlc->r);
|
||||
htlc->r = tal_dup(htlc, struct rval, &payment->r);
|
||||
set_htlc_rval(peer, htlc, &payment->r);
|
||||
command_htlc_fulfill(peer, htlc);
|
||||
goto free_rest;
|
||||
|
||||
@@ -517,8 +525,7 @@ static void our_htlc_fulfilled(struct peer *peer, struct htlc *htlc,
|
||||
const struct rval *preimage)
|
||||
{
|
||||
if (htlc->src) {
|
||||
assert(!htlc->src->r);
|
||||
htlc->src->r = tal_dup(htlc->src, struct rval, htlc->r);
|
||||
set_htlc_rval(htlc->src->peer, htlc->src, htlc->r);
|
||||
command_htlc_fulfill(htlc->src->peer, htlc->src);
|
||||
} else {
|
||||
complete_pay_command(peer, htlc);
|
||||
@@ -650,7 +657,7 @@ static bool closing_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
assert(peer->state == STATE_MUTUAL_CLOSING);
|
||||
|
||||
if (pkt->pkt_case != PKT__PKT_CLOSE_SIGNATURE)
|
||||
return peer_received_unexpected_pkt(peer, pkt);
|
||||
return peer_received_unexpected_pkt(peer, pkt, __func__);
|
||||
|
||||
log_info(peer->log, "closing_pkt_in: they offered close fee %"PRIu64,
|
||||
c->close_fee);
|
||||
@@ -1033,7 +1040,7 @@ static bool shutdown_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
err = handle_pkt_commit(peer, pkt);
|
||||
break;
|
||||
case PKT__PKT_ERROR:
|
||||
peer_unexpected_pkt(peer, pkt);
|
||||
peer_unexpected_pkt(peer, pkt, __func__);
|
||||
return peer_comms_err(peer, NULL);
|
||||
|
||||
case PKT__PKT_AUTH:
|
||||
@@ -1043,7 +1050,7 @@ static bool shutdown_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
case PKT__PKT_OPEN_COMPLETE:
|
||||
case PKT__PKT_CLOSE_SIGNATURE:
|
||||
default:
|
||||
peer_unexpected_pkt(peer, pkt);
|
||||
peer_unexpected_pkt(peer, pkt, __func__);
|
||||
err = pkt_err_unexpected(peer, pkt);
|
||||
break;
|
||||
}
|
||||
@@ -1144,7 +1151,7 @@ static bool normal_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
}
|
||||
/* Fall thru. */
|
||||
default:
|
||||
return peer_received_unexpected_pkt(peer, pkt);
|
||||
return peer_received_unexpected_pkt(peer, pkt, __func__);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
@@ -2105,7 +2112,7 @@ struct htlc *peer_new_htlc(struct peer *peer,
|
||||
static struct io_plan *reconnect_pkt_in(struct io_conn *conn, struct peer *peer)
|
||||
{
|
||||
if (peer->inpkt->pkt_case != PKT__PKT_RECONNECT) {
|
||||
peer_received_unexpected_pkt(peer, peer->inpkt);
|
||||
peer_received_unexpected_pkt(peer, peer->inpkt, __func__);
|
||||
return pkt_out(conn, peer);
|
||||
}
|
||||
|
||||
@@ -3920,9 +3927,7 @@ static void json_fulfillhtlc(struct command *cmd,
|
||||
return;
|
||||
}
|
||||
|
||||
assert(!htlc->r);
|
||||
htlc->r = tal_dup(htlc, struct rval, &r);
|
||||
|
||||
set_htlc_rval(peer, htlc, &r);
|
||||
if (command_htlc_fulfill(peer, htlc))
|
||||
command_success(cmd, null_response(cmd));
|
||||
else
|
||||
|
||||
@@ -236,6 +236,9 @@ struct peer *new_peer(struct lightningd_state *dstate,
|
||||
enum state state,
|
||||
enum state_input offer_anchor);
|
||||
|
||||
void set_htlc_rval(struct peer *peer,
|
||||
struct htlc *htlc, const struct rval *rval);
|
||||
|
||||
/* Populates very first peer->{local,remote}.commit->{tx,cstate} */
|
||||
bool setup_first_commit(struct peer *peer);
|
||||
|
||||
@@ -263,7 +266,7 @@ struct htlc *command_htlc_add(struct peer *peer, u64 msatoshis,
|
||||
struct htlc *src,
|
||||
const u8 *route);
|
||||
|
||||
void peer_unexpected_pkt(struct peer *peer, const Pkt *pkt);
|
||||
void peer_unexpected_pkt(struct peer *peer, const Pkt *pkt, const char *where);
|
||||
|
||||
/* Peer has completed open, or problem (if non-NULL). */
|
||||
void peer_open_complete(struct peer *peer, const char *problem);
|
||||
|
||||
Reference in New Issue
Block a user