Browse Source

onchain: add initial onchain state.

We have a race where we start onchaind, but state is unchanged, so checks
like peer_control.c's:

	peer_ready = (peer->owner && peer->state == CHANNELD_AWAITING_LOCKIN);
	if (!peer_ready) {
		log_unusual(peer->log,
			    "Funding tx confirmed, but peer state %s %s",
			    peer_state_name(peer->state),
			    peer->owner ? peer->owner->name : "unowned");
	} else {
		subd_send_msg(peer->owner,
			      take(towire_channel_funding_locked(peer,
								 peer->scid)));
	}

Can send to the wrong daemon.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
d04b7af56e
  1. 8
      lightningd/peer_control.c
  2. 3
      lightningd/peer_state.h

8
lightningd/peer_control.c

@ -517,6 +517,7 @@ static bool peer_reconnected(struct lightningd *ld,
get_gossip_fd_for_closingd_reconnect(ld, id, peer->unique_id, fd, cs); get_gossip_fd_for_closingd_reconnect(ld, id, peer->unique_id, fd, cs);
return true; return true;
case FUNDING_SPEND_SEEN:
case ONCHAIND_CHEATED: case ONCHAIND_CHEATED:
case ONCHAIND_THEIR_UNILATERAL: case ONCHAIND_THEIR_UNILATERAL:
case ONCHAIND_OUR_UNILATERAL: case ONCHAIND_OUR_UNILATERAL:
@ -1151,8 +1152,7 @@ static int handle_onchain_init_reply(struct peer *peer, const u8 *msg)
return -1; return -1;
} }
/* We could come from almost any state. */ peer_set_condition(peer, FUNDING_SPEND_SEEN, state);
peer_set_condition(peer, peer->state, state);
/* Tell it about any preimages we know. */ /* Tell it about any preimages we know. */
onchaind_tell_fulfill(peer); onchaind_tell_fulfill(peer);
@ -1392,6 +1392,10 @@ static enum watch_result funding_spent(struct peer *peer,
struct pubkey ourkey; struct pubkey ourkey;
peer_fail_permanent_str(peer, "Funding transaction spent"); peer_fail_permanent_str(peer, "Funding transaction spent");
/* We could come from almost any state. */
peer_set_condition(peer, peer->state, FUNDING_SPEND_SEEN);
peer->owner = new_subd(peer->ld, peer->ld, peer->owner = new_subd(peer->ld, peer->ld,
"lightning_onchaind", peer, "lightning_onchaind", peer,
onchain_wire_type_name, onchain_wire_type_name,

3
lightningd/peer_state.h

@ -26,6 +26,9 @@ enum peer_state {
/* Waiting for onchain event. */ /* Waiting for onchain event. */
CLOSINGD_COMPLETE, CLOSINGD_COMPLETE,
/* We've seen the funding spent, we're waiting for onchaind. */
FUNDING_SPEND_SEEN,
/* Various onchain states. */ /* Various onchain states. */
ONCHAIND_CHEATED, ONCHAIND_CHEATED,
ONCHAIND_THEIR_UNILATERAL, ONCHAIND_THEIR_UNILATERAL,

Loading…
Cancel
Save