mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
daemon: fix close fee negotiation.
We always set *matches to false (outside the branch, oops). We also distinguish the case where we ack from the case where they acked, which removes a FIXME and makes it work. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
4c136dde98
commit
0e07cc7a36
3 changed files with 30 additions and 10 deletions
|
@ -405,6 +405,8 @@ void queue_pkt_close_signature(struct peer *peer)
|
||||||
peer_sign_mutual_close(peer, close_tx, &our_close_sig);
|
peer_sign_mutual_close(peer, close_tx, &our_close_sig);
|
||||||
c->sig = signature_to_proto(c, &our_close_sig);
|
c->sig = signature_to_proto(c, &our_close_sig);
|
||||||
c->close_fee = peer->closing.our_fee;
|
c->close_fee = peer->closing.our_fee;
|
||||||
|
log_info(peer->log, "queue_pkt_close_signature: offered close fee %"
|
||||||
|
PRIu64, c->close_fee);
|
||||||
|
|
||||||
queue_pkt(peer, PKT__PKT_CLOSE_SIGNATURE, c);
|
queue_pkt(peer, PKT__PKT_CLOSE_SIGNATURE, c);
|
||||||
}
|
}
|
||||||
|
@ -748,12 +750,17 @@ Pkt *accept_pkt_close_clearing(struct peer *peer, const Pkt *pkt)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pkt *accept_pkt_close_sig(struct peer *peer, const Pkt *pkt, bool *matches)
|
Pkt *accept_pkt_close_sig(struct peer *peer, const Pkt *pkt, bool *acked,
|
||||||
|
bool *we_agree)
|
||||||
{
|
{
|
||||||
const CloseSignature *c = pkt->close_signature;
|
const CloseSignature *c = pkt->close_signature;
|
||||||
struct bitcoin_tx *close_tx;
|
struct bitcoin_tx *close_tx;
|
||||||
struct bitcoin_signature theirsig;
|
struct bitcoin_signature theirsig;
|
||||||
|
|
||||||
|
log_info(peer->log, "accept_pkt_close_sig: they offered close fee %"
|
||||||
|
PRIu64, c->close_fee);
|
||||||
|
*acked = *we_agree = false;
|
||||||
|
|
||||||
/* BOLT #2:
|
/* BOLT #2:
|
||||||
*
|
*
|
||||||
* The sender MUST set `close_fee` lower than or equal to the fee of the
|
* The sender MUST set `close_fee` lower than or equal to the fee of the
|
||||||
|
@ -805,7 +812,8 @@ Pkt *accept_pkt_close_sig(struct peer *peer, const Pkt *pkt, bool *matches)
|
||||||
peer->closing.their_fee = c->close_fee;
|
peer->closing.their_fee = c->close_fee;
|
||||||
|
|
||||||
if (peer->closing.our_fee == peer->closing.their_fee) {
|
if (peer->closing.our_fee == peer->closing.their_fee) {
|
||||||
*matches = true;
|
log_info(peer->log, "accept_pkt_close_sig: That's an ack");
|
||||||
|
*acked = true;
|
||||||
} else {
|
} else {
|
||||||
/* Adjust our fee to close on their fee. */
|
/* Adjust our fee to close on their fee. */
|
||||||
u64 sum;
|
u64 sum;
|
||||||
|
@ -817,10 +825,13 @@ Pkt *accept_pkt_close_sig(struct peer *peer, const Pkt *pkt, bool *matches)
|
||||||
if (peer->closing.our_fee & 1)
|
if (peer->closing.our_fee & 1)
|
||||||
peer->closing.our_fee++;
|
peer->closing.our_fee++;
|
||||||
|
|
||||||
/* FIXME: Fees may *now* be equal, and they'll
|
log_info(peer->log, "accept_pkt_close_sig: we change to %"PRIu64,
|
||||||
* consider this an ACK! */
|
peer->closing.our_fee);
|
||||||
|
|
||||||
|
/* Corner case: we may now agree with them. */
|
||||||
|
if (peer->closing.our_fee == peer->closing.their_fee)
|
||||||
|
*we_agree = true;
|
||||||
}
|
}
|
||||||
*matches = false;
|
|
||||||
|
|
||||||
/* FIXME: Dynamic fee! */
|
/* FIXME: Dynamic fee! */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
16
state.c
16
state.c
|
@ -516,13 +516,21 @@ enum command_status state(struct peer *peer,
|
||||||
break;
|
break;
|
||||||
case STATE_WAIT_FOR_CLOSE_SIG:
|
case STATE_WAIT_FOR_CLOSE_SIG:
|
||||||
if (input_is(input, PKT_CLOSE_SIGNATURE)) {
|
if (input_is(input, PKT_CLOSE_SIGNATURE)) {
|
||||||
bool matches;
|
bool acked, we_agree;
|
||||||
err = accept_pkt_close_sig(peer, idata->pkt, &matches);
|
err = accept_pkt_close_sig(peer, idata->pkt,
|
||||||
|
&acked, &we_agree);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_start_unilateral_close;
|
goto err_start_unilateral_close;
|
||||||
|
|
||||||
/* Did they offer the same fee we did? */
|
/* Are we about to offer the same fee they did? */
|
||||||
if (matches) {
|
if (we_agree) {
|
||||||
|
/* Offer the new fee. */
|
||||||
|
queue_pkt_close_signature(peer);
|
||||||
|
acked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do fees now match? */
|
||||||
|
if (acked) {
|
||||||
peer_unwatch_close_timeout(peer,
|
peer_unwatch_close_timeout(peer,
|
||||||
INPUT_CLOSE_COMPLETE_TIMEOUT);
|
INPUT_CLOSE_COMPLETE_TIMEOUT);
|
||||||
|
|
||||||
|
|
3
state.h
3
state.h
|
@ -110,7 +110,8 @@ Pkt *accept_pkt_commit(struct peer *peer, const Pkt *pkt);
|
||||||
|
|
||||||
Pkt *accept_pkt_revocation(struct peer *peer, const Pkt *pkt);
|
Pkt *accept_pkt_revocation(struct peer *peer, const Pkt *pkt);
|
||||||
Pkt *accept_pkt_close_clearing(struct peer *peer, const Pkt *pkt);
|
Pkt *accept_pkt_close_clearing(struct peer *peer, const Pkt *pkt);
|
||||||
Pkt *accept_pkt_close_sig(struct peer *peer, const Pkt *pkt, bool *matches);
|
Pkt *accept_pkt_close_sig(struct peer *peer, const Pkt *pkt,
|
||||||
|
bool *acked, bool *we_agree);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* committed_to_htlcs: do we have any locked-in HTLCs?
|
* committed_to_htlcs: do we have any locked-in HTLCs?
|
||||||
|
|
Loading…
Add table
Reference in a new issue