mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
daemon: don't code check for cleared commits in the main loop, use pending queue.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -320,6 +320,8 @@ void queue_pkt_commit(struct peer *peer)
|
||||
/* Switch to the new commitment. */
|
||||
peer->them.commit = ci;
|
||||
|
||||
peer_check_if_cleared(peer);
|
||||
|
||||
/* Now send message */
|
||||
update_commit__init(u);
|
||||
u->sig = signature_to_proto(u, &ci->sig.sig);
|
||||
@@ -348,6 +350,7 @@ void queue_pkt_revocation(struct peer *peer)
|
||||
= tal(peer->us.commit->prev, struct sha256);
|
||||
peer_get_revocation_preimage(peer, peer->commit_tx_counter-1,
|
||||
peer->us.commit->prev->revocation_preimage);
|
||||
peer_check_if_cleared(peer);
|
||||
u->revocation_preimage
|
||||
= sha256_to_proto(u, peer->us.commit->prev->revocation_preimage);
|
||||
|
||||
@@ -708,6 +711,8 @@ Pkt *accept_pkt_commit(struct peer *peer, const Pkt *pkt)
|
||||
peer->commit_tx_counter++;
|
||||
peer_get_revocation_hash(peer, peer->commit_tx_counter + 1,
|
||||
&peer->us.next_revocation_hash);
|
||||
|
||||
peer_check_if_cleared(peer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -736,6 +741,7 @@ Pkt *accept_pkt_revocation(struct peer *peer, const Pkt *pkt)
|
||||
|
||||
proto_to_sha256(r->revocation_preimage,
|
||||
peer->them.commit->prev->revocation_preimage);
|
||||
peer_check_if_cleared(peer);
|
||||
|
||||
/* Save next revocation hash. */
|
||||
proto_to_sha256(r->next_revocation_hash,
|
||||
|
||||
@@ -216,7 +216,7 @@ static void queue_cmd_(struct peer *peer,
|
||||
try_command(peer);
|
||||
};
|
||||
|
||||
static void UNNEEDED queue_input(struct peer *peer,
|
||||
static void queue_input(struct peer *peer,
|
||||
enum state_input input,
|
||||
const union input *idata)
|
||||
{
|
||||
@@ -266,12 +266,6 @@ static void state_event(struct peer *peer,
|
||||
|
||||
state_single(peer, input, idata);
|
||||
|
||||
if (peer->cleared != INPUT_NONE && !committed_to_htlcs(peer)) {
|
||||
enum state_input all_done = peer->cleared;
|
||||
peer->cleared = INPUT_NONE;
|
||||
state_single(peer, all_done, NULL);
|
||||
}
|
||||
|
||||
pend = list_pop(&peer->pending_input, struct pending_input, list);
|
||||
if (pend) {
|
||||
state_event(peer, pend->input, &pend->idata);
|
||||
@@ -281,6 +275,18 @@ static void state_event(struct peer *peer,
|
||||
try_command(peer);
|
||||
}
|
||||
|
||||
void peer_check_if_cleared(struct peer *peer)
|
||||
{
|
||||
if (peer->cleared == INPUT_NONE)
|
||||
return;
|
||||
|
||||
if (committed_to_htlcs(peer))
|
||||
return;
|
||||
|
||||
queue_input(peer, peer->cleared, NULL);
|
||||
peer->cleared = INPUT_NONE;
|
||||
}
|
||||
|
||||
static struct io_plan *pkt_out(struct io_conn *conn, struct peer *peer)
|
||||
{
|
||||
struct out_pkt out;
|
||||
@@ -1128,6 +1134,8 @@ void peer_watch_htlcs_cleared(struct peer *peer,
|
||||
assert(peer->cleared == INPUT_NONE);
|
||||
assert(all_done != INPUT_NONE);
|
||||
peer->cleared = all_done;
|
||||
|
||||
peer_check_if_cleared(peer);
|
||||
}
|
||||
|
||||
/* Create a bitcoin close tx, using last signature they sent. */
|
||||
|
||||
@@ -209,6 +209,9 @@ void setup_listeners(struct lightningd_state *dstate, unsigned int portnum);
|
||||
/* Populates very first peer->{us,them}.commit->{tx,cstate} */
|
||||
bool setup_first_commit(struct peer *peer);
|
||||
|
||||
/* Call this after commit changes, or revocation accepted/sent. */
|
||||
void peer_check_if_cleared(struct peer *peer);
|
||||
|
||||
void peer_add_htlc_expiry(struct peer *peer,
|
||||
const struct abs_locktime *expiry);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user