mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
daemon: simple close support for the case of one side closing transaction.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
6ba5c3cc3b
commit
fc4c94cb06
@ -6,6 +6,7 @@
|
|||||||
#include <ccan/tal/tal.h>
|
#include <ccan/tal/tal.h>
|
||||||
|
|
||||||
struct sha256_double;
|
struct sha256_double;
|
||||||
|
struct pubkey;
|
||||||
|
|
||||||
/* Create close tx to spend the anchor tx output; doesn't fill in
|
/* Create close tx to spend the anchor tx output; doesn't fill in
|
||||||
* input scriptsig. */
|
* input scriptsig. */
|
||||||
|
@ -219,7 +219,23 @@ Pkt *pkt_err(const tal_t *ctx, const char *msg, ...)
|
|||||||
|
|
||||||
Pkt *pkt_close(const tal_t *ctx, const struct peer *peer)
|
Pkt *pkt_close(const tal_t *ctx, const struct peer *peer)
|
||||||
{
|
{
|
||||||
FIXME_STUB(peer);
|
CloseChannel *c = tal(ctx, CloseChannel);
|
||||||
|
struct signature sig;
|
||||||
|
|
||||||
|
close_channel__init(c);
|
||||||
|
|
||||||
|
/* FIXME: If we're not connected, we don't create close tx. */
|
||||||
|
if (!peer->close_tx) {
|
||||||
|
c->close_fee = 0;
|
||||||
|
memset(&sig, 0, sizeof(sig));
|
||||||
|
c->sig = signature_to_proto(c, &sig);
|
||||||
|
} else {
|
||||||
|
c->close_fee = peer->close_tx->fee;
|
||||||
|
peer_sign_mutual_close(peer, peer->close_tx, &sig);
|
||||||
|
c->sig = signature_to_proto(c, &sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
return make_pkt(ctx, PKT__PKT_CLOSE, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pkt *pkt_close_complete(const tal_t *ctx, const struct peer *peer)
|
Pkt *pkt_close_complete(const tal_t *ctx, const struct peer *peer)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "bitcoind.h"
|
#include "bitcoind.h"
|
||||||
|
#include "close_tx.h"
|
||||||
#include "commit_tx.h"
|
#include "commit_tx.h"
|
||||||
#include "cryptopkt.h"
|
#include "cryptopkt.h"
|
||||||
#include "dns.h"
|
#include "dns.h"
|
||||||
@ -10,6 +11,7 @@
|
|||||||
#include "peer.h"
|
#include "peer.h"
|
||||||
#include "secrets.h"
|
#include "secrets.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
|
#include "timeout.h"
|
||||||
#include <bitcoin/base58.h>
|
#include <bitcoin/base58.h>
|
||||||
#include <bitcoin/script.h>
|
#include <bitcoin/script.h>
|
||||||
#include <bitcoin/tx.h>
|
#include <bitcoin/tx.h>
|
||||||
@ -251,6 +253,7 @@ static struct peer *new_peer(struct lightningd_state *dstate,
|
|||||||
peer->cmd = INPUT_NONE;
|
peer->cmd = INPUT_NONE;
|
||||||
peer->current_htlc = NULL;
|
peer->current_htlc = NULL;
|
||||||
peer->num_htlcs = 0;
|
peer->num_htlcs = 0;
|
||||||
|
peer->close_tx = NULL;
|
||||||
|
|
||||||
/* If we free peer, conn should be closed, but can't be freed
|
/* If we free peer, conn should be closed, but can't be freed
|
||||||
* immediately so don't make peer a parent. */
|
* immediately so don't make peer a parent. */
|
||||||
@ -569,9 +572,25 @@ void peer_watch_tx(struct peer *peer,
|
|||||||
{
|
{
|
||||||
FIXME_STUB(peer);
|
FIXME_STUB(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void send_close_timeout(struct peer *peer)
|
||||||
|
{
|
||||||
|
update_state(peer, INPUT_CLOSE_COMPLETE_TIMEOUT, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void peer_watch_close(struct peer *peer,
|
void peer_watch_close(struct peer *peer,
|
||||||
enum state_input done, enum state_input timedout)
|
enum state_input done, enum state_input timedout)
|
||||||
{
|
{
|
||||||
|
/* We save some work by assuming this. */
|
||||||
|
assert(timedout == INPUT_CLOSE_COMPLETE_TIMEOUT);
|
||||||
|
|
||||||
|
/* FIXME: We didn't send CLOSE, so timeout immediately */
|
||||||
|
if (!peer->conn) {
|
||||||
|
(void)send_close_timeout;
|
||||||
|
/* FIXME: oneshot_timeout(peer->dstate, peer, 0, send_close_timeout, peer); */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
FIXME_STUB(peer);
|
FIXME_STUB(peer);
|
||||||
}
|
}
|
||||||
void peer_unwatch_close_timeout(struct peer *peer, enum state_input timedout)
|
void peer_unwatch_close_timeout(struct peer *peer, enum state_input timedout)
|
||||||
|
@ -94,6 +94,9 @@ struct peer {
|
|||||||
struct htlc_progress *current_htlc;
|
struct htlc_progress *current_htlc;
|
||||||
/* Number of HTLC updates (== number of previous commit txs) */
|
/* Number of HTLC updates (== number of previous commit txs) */
|
||||||
u64 num_htlcs;
|
u64 num_htlcs;
|
||||||
|
|
||||||
|
/* Closing tx, once we've generated it */
|
||||||
|
struct bitcoin_tx *close_tx;
|
||||||
|
|
||||||
/* Current ongoing packetflow */
|
/* Current ongoing packetflow */
|
||||||
struct io_data *io_data;
|
struct io_data *io_data;
|
||||||
|
@ -55,6 +55,19 @@ void peer_sign_theircommit(const struct peer *peer,
|
|||||||
sig);
|
sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void peer_sign_mutual_close(const struct peer *peer,
|
||||||
|
struct bitcoin_tx *close,
|
||||||
|
struct signature *sig)
|
||||||
|
{
|
||||||
|
sign_tx_input(peer->dstate->secpctx,
|
||||||
|
close, 0,
|
||||||
|
peer->anchor.redeemscript,
|
||||||
|
tal_count(peer->anchor.redeemscript),
|
||||||
|
&peer->secrets->commit,
|
||||||
|
&peer->us.commitkey,
|
||||||
|
sig);
|
||||||
|
}
|
||||||
|
|
||||||
static void new_keypair(struct lightningd_state *dstate,
|
static void new_keypair(struct lightningd_state *dstate,
|
||||||
struct privkey *privkey, struct pubkey *pubkey)
|
struct privkey *privkey, struct pubkey *pubkey)
|
||||||
{
|
{
|
||||||
|
@ -16,6 +16,10 @@ void peer_sign_theircommit(const struct peer *peer,
|
|||||||
struct bitcoin_tx *commit,
|
struct bitcoin_tx *commit,
|
||||||
struct signature *sig);
|
struct signature *sig);
|
||||||
|
|
||||||
|
void peer_sign_mutual_close(const struct peer *peer,
|
||||||
|
struct bitcoin_tx *close,
|
||||||
|
struct signature *sig);
|
||||||
|
|
||||||
void peer_secrets_init(struct peer *peer);
|
void peer_secrets_init(struct peer *peer);
|
||||||
|
|
||||||
void peer_get_revocation_hash(const struct peer *peer, u64 index,
|
void peer_get_revocation_hash(const struct peer *peer, u64 index,
|
||||||
|
Loading…
Reference in New Issue
Block a user