mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
onchaind: send message when peer's transactions are irrevocably committed.
We currently rely on a zero exit status. That's the only difference between onchain finished handling and other per-peer daemons, so instead we should have an explicit "done" message. This is both clearer, and allows us to unify. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
f83ee6d5ea
commit
cb82bf7aa2
@@ -1019,26 +1019,6 @@ static enum watch_result funding_announce_cb(struct peer *peer,
|
|||||||
return DELETE_WATCH;
|
return DELETE_WATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void peer_onchain_finished(struct subd *subd, int status)
|
|
||||||
{
|
|
||||||
/* Moved on? Eg. reorg, and it has a new onchaind. */
|
|
||||||
if (!subd->peer || subd->peer->owner != subd)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Unlink peer from us, so it doesn't try to free us in destroy_peer */
|
|
||||||
subd->peer->owner = NULL;
|
|
||||||
|
|
||||||
if (status != 0) {
|
|
||||||
log_broken(subd->peer->log, "onchaind died status %i", status);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: Remove peer from db. */
|
|
||||||
log_info(subd->peer->log, "onchaind complete, forgetting peer");
|
|
||||||
|
|
||||||
/* Peer is gone. */
|
|
||||||
tal_free(subd->peer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We dump all the known preimages when onchaind starts up. */
|
/* We dump all the known preimages when onchaind starts up. */
|
||||||
static void onchaind_tell_fulfill(struct peer *peer)
|
static void onchaind_tell_fulfill(struct peer *peer)
|
||||||
@@ -1239,6 +1219,19 @@ static int handle_onchain_htlc_timeout(struct peer *peer, const u8 *msg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int handle_irrevocably_resolved(struct peer *peer, const u8 *msg)
|
||||||
|
{
|
||||||
|
/* FIXME: Remove peer from db. */
|
||||||
|
log_info(peer->log, "onchaind complete, forgetting peer");
|
||||||
|
|
||||||
|
/* Peer is gone: don't free sd yet though; it will exit. */
|
||||||
|
peer->owner->peer = NULL;
|
||||||
|
peer->owner = NULL;
|
||||||
|
|
||||||
|
tal_free(peer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int onchain_msg(struct subd *sd, const u8 *msg, const int *fds)
|
static int onchain_msg(struct subd *sd, const u8 *msg, const int *fds)
|
||||||
{
|
{
|
||||||
enum onchain_wire_type t = fromwire_peektype(msg);
|
enum onchain_wire_type t = fromwire_peektype(msg);
|
||||||
@@ -1262,6 +1255,9 @@ static int onchain_msg(struct subd *sd, const u8 *msg, const int *fds)
|
|||||||
case WIRE_ONCHAIN_HTLC_TIMEOUT:
|
case WIRE_ONCHAIN_HTLC_TIMEOUT:
|
||||||
return handle_onchain_htlc_timeout(sd->peer, msg);
|
return handle_onchain_htlc_timeout(sd->peer, msg);
|
||||||
|
|
||||||
|
case WIRE_ONCHAIN_ALL_IRREVOCABLY_RESOLVED:
|
||||||
|
return handle_irrevocably_resolved(sd->peer, msg);
|
||||||
|
|
||||||
/* We send these, not receive them */
|
/* We send these, not receive them */
|
||||||
case WIRE_ONCHAIN_INIT:
|
case WIRE_ONCHAIN_INIT:
|
||||||
case WIRE_ONCHAIN_SPENT:
|
case WIRE_ONCHAIN_SPENT:
|
||||||
@@ -1338,7 +1334,7 @@ static enum watch_result funding_spent(struct peer *peer,
|
|||||||
"lightning_onchaind", peer,
|
"lightning_onchaind", peer,
|
||||||
onchain_wire_type_name,
|
onchain_wire_type_name,
|
||||||
onchain_msg,
|
onchain_msg,
|
||||||
NULL, peer_onchain_finished,
|
NULL, peer_owner_finished,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
if (!peer->owner) {
|
if (!peer->owner) {
|
||||||
|
|||||||
@@ -934,6 +934,9 @@ static void wait_for_resolved(struct tracked_output **outs)
|
|||||||
master_badmsg(-1, msg);
|
master_badmsg(-1, msg);
|
||||||
tal_free(msg);
|
tal_free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wire_sync_write(REQ_FD,
|
||||||
|
take(towire_onchain_all_irrevocably_resolved(outs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_state(enum peer_state state)
|
static void set_state(enum peer_state state)
|
||||||
|
|||||||
@@ -78,3 +78,6 @@ onchain_missing_htlc_output,,htlc,struct htlc_stub
|
|||||||
# onchaind->master: this HTLC has timed out (after reasonable_depth)
|
# onchaind->master: this HTLC has timed out (after reasonable_depth)
|
||||||
onchain_htlc_timeout,5010
|
onchain_htlc_timeout,5010
|
||||||
onchain_htlc_timeout,,htlc,struct htlc_stub
|
onchain_htlc_timeout,,htlc,struct htlc_stub
|
||||||
|
|
||||||
|
# onchaind->master: this peer can be forgotten
|
||||||
|
onchain_all_irrevocably_resolved,5011
|
||||||
|
|||||||
|
Reference in New Issue
Block a user