2015-09-25 04:21:18 +02:00
|
|
|
#include <ccan/build_assert/build_assert.h>
|
2016-08-18 06:53:45 +02:00
|
|
|
#include <daemon/lightningd.h>
|
2016-05-05 06:53:34 +02:00
|
|
|
#include <daemon/log.h>
|
2016-08-18 06:53:45 +02:00
|
|
|
#include <daemon/packets.h>
|
2016-01-21 21:11:49 +01:00
|
|
|
#include <daemon/peer.h>
|
2016-08-18 06:53:45 +02:00
|
|
|
#include <daemon/secrets.h>
|
2016-05-05 06:53:34 +02:00
|
|
|
#include <names.h>
|
2016-01-21 21:11:46 +01:00
|
|
|
#include <state.h>
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-05-26 07:55:25 +02:00
|
|
|
static enum state next_state(struct peer *peer,
|
|
|
|
const enum state_input input,
|
|
|
|
const enum state state)
|
2015-09-25 04:21:18 +02:00
|
|
|
{
|
2016-01-21 21:11:46 +01:00
|
|
|
assert(peer->state != state);
|
2016-05-26 07:55:25 +02:00
|
|
|
return state;
|
2016-01-21 21:11:46 +01:00
|
|
|
}
|
|
|
|
|
2016-01-21 21:11:47 +01:00
|
|
|
static void queue_tx_broadcast(const struct bitcoin_tx **broadcast,
|
|
|
|
const struct bitcoin_tx *tx)
|
2016-01-21 21:11:47 +01:00
|
|
|
{
|
|
|
|
assert(!*broadcast);
|
|
|
|
assert(tx);
|
|
|
|
*broadcast = tx;
|
|
|
|
}
|
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
static void send_open_pkt(struct peer *peer,
|
|
|
|
OpenChannel__AnchorOffer anchor)
|
|
|
|
{
|
|
|
|
/* Set up out commit info now: rest gets done in setup_first_commit
|
|
|
|
* once anchor is established. */
|
|
|
|
peer->local.commit = new_commit_info(peer);
|
|
|
|
peer->local.commit->revocation_hash = peer->local.next_revocation_hash;
|
|
|
|
peer_get_revocation_hash(peer, 1, &peer->local.next_revocation_hash);
|
|
|
|
|
|
|
|
queue_pkt_open(peer, anchor);
|
|
|
|
}
|
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
static Pkt *init_from_pkt_open(struct peer *peer, const Pkt *pkt)
|
|
|
|
{
|
|
|
|
struct commit_info *ci = new_commit_info(peer);
|
|
|
|
Pkt *err;
|
|
|
|
|
|
|
|
err = accept_pkt_open(peer, pkt, &ci->revocation_hash,
|
|
|
|
&peer->remote.next_revocation_hash);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* Set up their commit info now: rest gets done in setup_first_commit
|
|
|
|
* once anchor is established. */
|
|
|
|
peer->remote.commit = ci;
|
|
|
|
|
|
|
|
/* Witness script for anchor. */
|
|
|
|
peer->anchor.witnessscript
|
|
|
|
= bitcoin_redeem_2of2(peer, peer->dstate->secpctx,
|
|
|
|
&peer->local.commitkey,
|
|
|
|
&peer->remote.commitkey);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-26 07:55:25 +02:00
|
|
|
enum state state(struct peer *peer,
|
|
|
|
const enum state_input input,
|
2016-06-28 23:19:20 +02:00
|
|
|
const Pkt *pkt,
|
2016-05-26 07:55:25 +02:00
|
|
|
const struct bitcoin_tx **broadcast)
|
2015-09-25 04:21:18 +02:00
|
|
|
{
|
|
|
|
Pkt *err;
|
2016-01-21 21:11:46 +01:00
|
|
|
|
2016-01-21 21:11:47 +01:00
|
|
|
*broadcast = NULL;
|
2016-01-21 21:11:47 +01:00
|
|
|
|
2016-01-21 21:11:46 +01:00
|
|
|
switch (peer->state) {
|
2015-09-25 04:21:18 +02:00
|
|
|
/*
|
|
|
|
* Initial channel opening states.
|
|
|
|
*/
|
2016-01-21 21:11:46 +01:00
|
|
|
case STATE_INIT:
|
|
|
|
if (input_is(input, CMD_OPEN_WITH_ANCHOR)) {
|
2016-08-18 06:53:45 +02:00
|
|
|
send_open_pkt(peer,
|
|
|
|
OPEN_CHANNEL__ANCHOR_OFFER__WILL_CREATE_ANCHOR);
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input,
|
2016-01-21 21:11:46 +01:00
|
|
|
STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR);
|
|
|
|
} else if (input_is(input, CMD_OPEN_WITHOUT_ANCHOR)) {
|
2016-08-18 06:53:45 +02:00
|
|
|
send_open_pkt(peer,
|
|
|
|
OPEN_CHANNEL__ANCHOR_OFFER__WONT_CREATE_ANCHOR);
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input,
|
2016-01-21 21:11:46 +01:00
|
|
|
STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR);
|
|
|
|
}
|
|
|
|
break;
|
2015-09-25 04:21:18 +02:00
|
|
|
case STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR:
|
|
|
|
if (input_is(input, PKT_OPEN)) {
|
2016-08-18 06:53:45 +02:00
|
|
|
err = init_from_pkt_open(peer, pkt);
|
2016-01-21 21:11:46 +01:00
|
|
|
if (err) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, err->error->problem);
|
2016-05-04 08:44:22 +02:00
|
|
|
goto err_breakdown;
|
2016-01-21 21:11:46 +01:00
|
|
|
}
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input, STATE_OPEN_WAIT_FOR_ANCHOR);
|
2015-09-25 04:21:18 +02:00
|
|
|
} else if (input_is_pkt(input)) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "unexpected packet");
|
2016-05-04 08:44:22 +02:00
|
|
|
goto unexpected_pkt;
|
2015-09-25 04:21:18 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR:
|
|
|
|
if (input_is(input, PKT_OPEN)) {
|
2016-08-18 06:53:45 +02:00
|
|
|
err = init_from_pkt_open(peer, pkt);
|
2016-01-21 21:11:46 +01:00
|
|
|
if (err) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, err->error->problem);
|
2016-05-04 08:44:22 +02:00
|
|
|
goto err_breakdown;
|
2016-01-21 21:11:46 +01:00
|
|
|
}
|
2016-01-21 21:11:47 +01:00
|
|
|
bitcoin_create_anchor(peer, BITCOIN_ANCHOR_CREATED);
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input,
|
2016-01-21 21:11:47 +01:00
|
|
|
STATE_OPEN_WAIT_FOR_ANCHOR_CREATE);
|
|
|
|
} else if (input_is_pkt(input)) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "unexpected packet");
|
2016-05-04 08:44:22 +02:00
|
|
|
goto unexpected_pkt;
|
2016-01-21 21:11:47 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_OPEN_WAIT_FOR_ANCHOR_CREATE:
|
|
|
|
if (input_is(input, BITCOIN_ANCHOR_CREATED)) {
|
2016-08-18 06:53:45 +02:00
|
|
|
/* This shouldn't happen! */
|
|
|
|
if (!setup_first_commit(peer)) {
|
|
|
|
err = pkt_err(peer,
|
|
|
|
"Own anchor has insufficient funds");
|
|
|
|
peer_open_complete(peer, err->error->problem);
|
|
|
|
goto err_breakdown;
|
|
|
|
}
|
2016-03-30 08:27:18 +02:00
|
|
|
queue_pkt_anchor(peer);
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input,
|
2016-01-21 21:11:45 +01:00
|
|
|
STATE_OPEN_WAIT_FOR_COMMIT_SIG);
|
2015-09-25 04:21:18 +02:00
|
|
|
} else if (input_is_pkt(input)) {
|
2016-01-21 21:11:47 +01:00
|
|
|
bitcoin_release_anchor(peer, BITCOIN_ANCHOR_CREATED);
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "unexpected packet");
|
2016-05-04 08:44:22 +02:00
|
|
|
goto unexpected_pkt;
|
2015-09-25 04:21:18 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_OPEN_WAIT_FOR_ANCHOR:
|
|
|
|
if (input_is(input, PKT_OPEN_ANCHOR)) {
|
2016-06-28 23:19:20 +02:00
|
|
|
err = accept_pkt_anchor(peer, pkt);
|
2016-01-21 21:11:46 +01:00
|
|
|
if (err) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, err->error->problem);
|
2016-05-04 08:44:22 +02:00
|
|
|
goto err_breakdown;
|
2016-01-21 21:11:46 +01:00
|
|
|
}
|
2016-08-18 06:53:45 +02:00
|
|
|
|
|
|
|
if (!setup_first_commit(peer)) {
|
|
|
|
err = pkt_err(peer, "Insufficient funds for fee");
|
|
|
|
peer_open_complete(peer, err->error->problem);
|
|
|
|
goto err_breakdown;
|
|
|
|
}
|
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
log_debug_struct(peer->log, "Creating sig for %s",
|
|
|
|
struct bitcoin_tx,
|
|
|
|
peer->remote.commit->tx);
|
|
|
|
log_add_struct(peer->log, " using key %s",
|
|
|
|
struct pubkey, &peer->local.commitkey);
|
|
|
|
|
|
|
|
peer->remote.commit->sig = tal(peer->remote.commit,
|
|
|
|
struct bitcoin_signature);
|
|
|
|
peer->remote.commit->sig->stype = SIGHASH_ALL;
|
|
|
|
peer_sign_theircommit(peer, peer->remote.commit->tx,
|
|
|
|
&peer->remote.commit->sig->sig);
|
2016-08-18 06:53:45 +02:00
|
|
|
peer_add_their_commit(peer, &peer->remote.commit->txid,
|
|
|
|
peer->remote.commit->commit_num);
|
2016-08-18 06:53:45 +02:00
|
|
|
|
2016-03-30 08:27:18 +02:00
|
|
|
queue_pkt_open_commit_sig(peer);
|
2016-08-18 06:53:45 +02:00
|
|
|
peer_watch_anchor(peer,
|
|
|
|
peer->local.mindepth,
|
2016-01-21 21:11:47 +01:00
|
|
|
BITCOIN_ANCHOR_DEPTHOK,
|
2016-05-04 08:44:22 +02:00
|
|
|
BITCOIN_ANCHOR_TIMEOUT);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input,
|
2016-01-21 21:11:45 +01:00
|
|
|
STATE_OPEN_WAITING_THEIRANCHOR);
|
2015-09-25 04:21:18 +02:00
|
|
|
} else if (input_is_pkt(input)) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "unexpected packet");
|
2016-05-04 08:44:22 +02:00
|
|
|
goto unexpected_pkt;
|
2015-09-25 04:21:18 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_OPEN_WAIT_FOR_COMMIT_SIG:
|
|
|
|
if (input_is(input, PKT_OPEN_COMMIT_SIG)) {
|
2016-08-18 06:53:45 +02:00
|
|
|
err = accept_pkt_open_commit_sig(peer, pkt,
|
|
|
|
&peer->local.commit->sig);
|
|
|
|
if (!err &&
|
|
|
|
!check_tx_sig(peer->dstate->secpctx,
|
|
|
|
peer->local.commit->tx, 0,
|
|
|
|
NULL, 0,
|
|
|
|
peer->anchor.witnessscript,
|
|
|
|
&peer->remote.commitkey,
|
|
|
|
peer->local.commit->sig))
|
|
|
|
err = pkt_err(peer, "Bad signature");
|
|
|
|
|
2016-01-21 21:11:46 +01:00
|
|
|
if (err) {
|
2016-01-21 21:11:47 +01:00
|
|
|
bitcoin_release_anchor(peer, INPUT_NONE);
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, err->error->problem);
|
2016-05-04 08:44:22 +02:00
|
|
|
goto err_breakdown;
|
2016-01-21 21:11:46 +01:00
|
|
|
}
|
2016-08-18 06:53:46 +02:00
|
|
|
peer->their_commitsigs++;
|
2016-03-30 08:27:18 +02:00
|
|
|
queue_tx_broadcast(broadcast, bitcoin_anchor(peer));
|
2016-01-21 21:11:47 +01:00
|
|
|
peer_watch_anchor(peer,
|
2016-08-18 06:53:45 +02:00
|
|
|
peer->local.mindepth,
|
2016-01-21 21:11:47 +01:00
|
|
|
BITCOIN_ANCHOR_DEPTHOK,
|
2016-05-04 08:44:22 +02:00
|
|
|
INPUT_NONE);
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input,
|
2016-01-21 21:11:46 +01:00
|
|
|
STATE_OPEN_WAITING_OURANCHOR);
|
2015-09-25 04:21:18 +02:00
|
|
|
} else if (input_is_pkt(input)) {
|
2016-01-21 21:11:47 +01:00
|
|
|
bitcoin_release_anchor(peer, INPUT_NONE);
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "unexpected packet");
|
2016-05-04 08:44:22 +02:00
|
|
|
goto unexpected_pkt;
|
2015-09-25 04:21:18 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_OPEN_WAITING_OURANCHOR:
|
2016-01-21 21:11:46 +01:00
|
|
|
if (input_is(input, PKT_OPEN_COMPLETE)) {
|
2016-06-28 23:19:20 +02:00
|
|
|
err = accept_pkt_open_complete(peer, pkt);
|
2016-03-08 01:09:15 +01:00
|
|
|
if (err) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, err->error->problem);
|
2016-05-04 08:44:22 +02:00
|
|
|
goto err_breakdown;
|
2016-03-08 01:09:15 +01:00
|
|
|
}
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input,
|
2016-01-21 21:11:46 +01:00
|
|
|
STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED);
|
|
|
|
}
|
|
|
|
/* Fall thru */
|
|
|
|
case STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED:
|
2015-09-25 04:21:18 +02:00
|
|
|
if (input_is(input, BITCOIN_ANCHOR_DEPTHOK)) {
|
2016-03-30 08:27:18 +02:00
|
|
|
queue_pkt_open_complete(peer);
|
2016-01-21 21:11:46 +01:00
|
|
|
if (peer->state == STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, NULL);
|
|
|
|
return next_state(peer, input, STATE_NORMAL);
|
2016-01-21 21:11:46 +01:00
|
|
|
}
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input,
|
2016-01-21 21:11:45 +01:00
|
|
|
STATE_OPEN_WAIT_FOR_COMPLETE_OURANCHOR);
|
2016-03-24 02:39:41 +01:00
|
|
|
} else if (input_is(input, PKT_CLOSE_CLEARING)) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "Received PKT_CLOSE_CLEARING");
|
2016-03-24 02:39:41 +01:00
|
|
|
goto accept_clearing;
|
2015-09-25 04:21:18 +02:00
|
|
|
} else if (input_is_pkt(input)) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "unexpected packet");
|
2016-03-08 01:08:15 +01:00
|
|
|
goto unexpected_pkt;
|
2015-09-25 04:21:18 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_OPEN_WAITING_THEIRANCHOR:
|
2016-01-21 21:11:46 +01:00
|
|
|
if (input_is(input, PKT_OPEN_COMPLETE)) {
|
2016-06-28 23:19:20 +02:00
|
|
|
err = accept_pkt_open_complete(peer, pkt);
|
2016-03-08 01:09:15 +01:00
|
|
|
if (err) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, err->error->problem);
|
2016-05-04 08:44:22 +02:00
|
|
|
goto err_breakdown;
|
2016-03-08 01:09:15 +01:00
|
|
|
}
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input,
|
2016-01-21 21:11:46 +01:00
|
|
|
STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED);
|
|
|
|
}
|
|
|
|
/* Fall thru */
|
|
|
|
case STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED:
|
2015-09-25 04:21:18 +02:00
|
|
|
if (input_is(input, BITCOIN_ANCHOR_TIMEOUT)) {
|
|
|
|
/* Anchor didn't reach blockchain in reasonable time. */
|
2016-03-30 08:27:18 +02:00
|
|
|
queue_pkt_err(peer, pkt_err(peer, "Anchor timed out"));
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input, STATE_ERR_ANCHOR_TIMEOUT);
|
2015-09-25 04:21:18 +02:00
|
|
|
} else if (input_is(input, BITCOIN_ANCHOR_DEPTHOK)) {
|
2016-03-30 08:27:18 +02:00
|
|
|
queue_pkt_open_complete(peer);
|
2016-01-21 21:11:46 +01:00
|
|
|
if (peer->state == STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, NULL);
|
|
|
|
return next_state(peer, input, STATE_NORMAL);
|
2016-01-21 21:11:46 +01:00
|
|
|
}
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input,
|
2016-01-21 21:11:46 +01:00
|
|
|
STATE_OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR);
|
2016-03-24 02:39:41 +01:00
|
|
|
} else if (input_is(input, PKT_CLOSE_CLEARING)) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "Received PKT_CLOSE_CLEARING");
|
2016-03-24 02:39:41 +01:00
|
|
|
goto accept_clearing;
|
2015-09-25 04:21:18 +02:00
|
|
|
} else if (input_is_pkt(input)) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "unexpected packet");
|
2015-09-25 04:21:18 +02:00
|
|
|
goto unexpected_pkt;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STATE_OPEN_WAIT_FOR_COMPLETE_OURANCHOR:
|
|
|
|
case STATE_OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR:
|
|
|
|
if (input_is(input, PKT_OPEN_COMPLETE)) {
|
2016-05-26 07:55:25 +02:00
|
|
|
/* Ready for business! */
|
|
|
|
peer_open_complete(peer, NULL);
|
|
|
|
return next_state(peer, input, STATE_NORMAL);
|
2016-03-24 02:39:41 +01:00
|
|
|
} else if (input_is(input, PKT_CLOSE_CLEARING)) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "Received PKT_CLOSE_CLEARING");
|
2016-03-24 02:39:41 +01:00
|
|
|
goto accept_clearing;
|
2015-09-25 04:21:18 +02:00
|
|
|
} else if (input_is_pkt(input)) {
|
2016-05-26 07:55:25 +02:00
|
|
|
peer_open_complete(peer, "unexpected packet");
|
2015-09-25 04:21:18 +02:00
|
|
|
goto unexpected_pkt;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-06-28 23:19:20 +02:00
|
|
|
/* Should never happen. */
|
2016-03-31 08:43:20 +02:00
|
|
|
case STATE_NORMAL:
|
2016-05-26 07:55:25 +02:00
|
|
|
case STATE_NORMAL_COMMITTING:
|
2015-09-25 04:21:18 +02:00
|
|
|
case STATE_ERR_INTERNAL:
|
|
|
|
case STATE_ERR_ANCHOR_TIMEOUT:
|
2016-05-06 04:26:32 +02:00
|
|
|
case STATE_ERR_INFORMATION_LEAK:
|
2016-05-04 08:44:22 +02:00
|
|
|
case STATE_ERR_BREAKDOWN:
|
2015-09-25 04:21:18 +02:00
|
|
|
case STATE_CLOSED:
|
|
|
|
case STATE_MAX:
|
2016-05-26 07:55:24 +02:00
|
|
|
case STATE_CLEARING:
|
|
|
|
case STATE_CLEARING_COMMITTING:
|
|
|
|
case STATE_MUTUAL_CLOSING:
|
2016-05-04 08:44:22 +02:00
|
|
|
case STATE_CLOSE_ONCHAIN_CHEATED:
|
|
|
|
case STATE_CLOSE_ONCHAIN_THEIR_UNILATERAL:
|
|
|
|
case STATE_CLOSE_ONCHAIN_OUR_UNILATERAL:
|
|
|
|
case STATE_CLOSE_ONCHAIN_MUTUAL:
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input, STATE_ERR_INTERNAL);
|
2015-09-25 04:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* State machine should handle all possible states. */
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input, STATE_ERR_INTERNAL);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
unexpected_pkt:
|
2016-06-28 23:19:20 +02:00
|
|
|
peer_unexpected_pkt(peer, pkt);
|
2016-01-21 21:11:46 +01:00
|
|
|
|
2015-09-25 04:21:18 +02:00
|
|
|
/* Don't reply to an error with an error. */
|
2016-05-04 08:44:22 +02:00
|
|
|
if (!input_is(input, PKT_ERROR)) {
|
|
|
|
goto breakdown;
|
2016-01-21 21:11:46 +01:00
|
|
|
}
|
2016-06-28 23:19:20 +02:00
|
|
|
err = pkt_err_unexpected(peer, pkt);
|
2016-05-26 07:55:25 +02:00
|
|
|
goto err_breakdown;
|
|
|
|
|
2016-05-04 08:44:22 +02:00
|
|
|
err_breakdown:
|
2016-03-30 08:27:18 +02:00
|
|
|
queue_pkt_err(peer, err);
|
2016-05-04 08:44:22 +02:00
|
|
|
breakdown:
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input, STATE_ERR_BREAKDOWN);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-03-24 02:39:41 +01:00
|
|
|
accept_clearing:
|
2016-06-28 23:19:20 +02:00
|
|
|
err = accept_pkt_close_clearing(peer, pkt);
|
2015-09-25 04:21:18 +02:00
|
|
|
if (err)
|
2016-06-28 23:19:20 +02:00
|
|
|
goto err_breakdown;
|
2016-03-24 02:39:41 +01:00
|
|
|
|
2016-05-26 07:55:24 +02:00
|
|
|
/* If we've sent commit, we're still waiting for it when clearing. */
|
|
|
|
if (peer->state == STATE_NORMAL_COMMITTING)
|
2016-05-26 07:55:25 +02:00
|
|
|
return next_state(peer, input, STATE_CLEARING_COMMITTING);
|
|
|
|
return next_state(peer, input, STATE_CLEARING);
|
2015-09-25 04:21:18 +02:00
|
|
|
}
|