mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
channel: remove enum channel_side, rename htlc_side to side.
We had enum channel_side (OURS, THEIRS) for which end of a channel we had, and htlc_side (LOCAL, REMOTE) for who proposed the HTLC. Combine these both into simply "enum side". Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -123,7 +123,7 @@ static bool change_funding(uint64_t anchor_satoshis,
|
|||||||
struct channel_state *initial_cstate(const tal_t *ctx,
|
struct channel_state *initial_cstate(const tal_t *ctx,
|
||||||
uint64_t anchor_satoshis,
|
uint64_t anchor_satoshis,
|
||||||
uint64_t fee_rate,
|
uint64_t fee_rate,
|
||||||
enum channel_side funding)
|
enum side funding)
|
||||||
{
|
{
|
||||||
uint64_t fee_msat;
|
uint64_t fee_msat;
|
||||||
struct channel_state *cstate = talz(ctx, struct channel_state);
|
struct channel_state *cstate = talz(ctx, struct channel_state);
|
||||||
@@ -161,7 +161,7 @@ struct channel_state *initial_cstate(const tal_t *ctx,
|
|||||||
|
|
||||||
/* FIXME: Write exact variant! */
|
/* FIXME: Write exact variant! */
|
||||||
uint64_t approx_max_feerate(const struct channel_state *cstate,
|
uint64_t approx_max_feerate(const struct channel_state *cstate,
|
||||||
enum channel_side side)
|
enum side side)
|
||||||
{
|
{
|
||||||
uint64_t max_funds;
|
uint64_t max_funds;
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ uint64_t approx_max_feerate(const struct channel_state *cstate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool can_afford_feerate(const struct channel_state *cstate, uint64_t fee_rate,
|
bool can_afford_feerate(const struct channel_state *cstate, uint64_t fee_rate,
|
||||||
enum channel_side side)
|
enum side side)
|
||||||
{
|
{
|
||||||
u64 fee_msat = calculate_fee_msat(cstate->num_nondust, fee_rate);
|
u64 fee_msat = calculate_fee_msat(cstate->num_nondust, fee_rate);
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ void adjust_fee(struct channel_state *cstate, uint64_t fee_rate)
|
|||||||
|
|
||||||
fee_msat = calculate_fee_msat(cstate->num_nondust, fee_rate);
|
fee_msat = calculate_fee_msat(cstate->num_nondust, fee_rate);
|
||||||
|
|
||||||
recalculate_fees(&cstate->side[OURS], &cstate->side[THEIRS], fee_msat);
|
recalculate_fees(&cstate->side[LOCAL], &cstate->side[REMOTE], fee_msat);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool force_fee(struct channel_state *cstate, uint64_t fee)
|
bool force_fee(struct channel_state *cstate, uint64_t fee)
|
||||||
@@ -193,8 +193,8 @@ bool force_fee(struct channel_state *cstate, uint64_t fee)
|
|||||||
/* Beware overflow! */
|
/* Beware overflow! */
|
||||||
if (fee > 0xFFFFFFFFFFFFFFFFULL / 1000)
|
if (fee > 0xFFFFFFFFFFFFFFFFULL / 1000)
|
||||||
return false;
|
return false;
|
||||||
recalculate_fees(&cstate->side[OURS], &cstate->side[THEIRS], fee * 1000);
|
recalculate_fees(&cstate->side[LOCAL], &cstate->side[REMOTE], fee * 1000);
|
||||||
return cstate->side[OURS].fee_msat + cstate->side[THEIRS].fee_msat == fee * 1000;
|
return cstate->side[LOCAL].fee_msat + cstate->side[REMOTE].fee_msat == fee * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a HTLC to @creator if it can afford it. */
|
/* Add a HTLC to @creator if it can afford it. */
|
||||||
@@ -204,8 +204,8 @@ bool cstate_add_htlc(struct channel_state *cstate, const struct htlc *htlc,
|
|||||||
size_t nondust;
|
size_t nondust;
|
||||||
struct channel_oneside *creator, *recipient;
|
struct channel_oneside *creator, *recipient;
|
||||||
|
|
||||||
creator = &cstate->side[htlc_channel_side(htlc)];
|
creator = &cstate->side[htlc_owner(htlc)];
|
||||||
recipient = &cstate->side[!htlc_channel_side(htlc)];
|
recipient = &cstate->side[!htlc_owner(htlc)];
|
||||||
|
|
||||||
/* Remember to count the new one in total txsize if not dust! */
|
/* Remember to count the new one in total txsize if not dust! */
|
||||||
nondust = cstate->num_nondust;
|
nondust = cstate->num_nondust;
|
||||||
@@ -224,8 +224,8 @@ bool cstate_add_htlc(struct channel_state *cstate, const struct htlc *htlc,
|
|||||||
|
|
||||||
/* Remove htlc from creator, credit it to beneficiary. */
|
/* Remove htlc from creator, credit it to beneficiary. */
|
||||||
static void remove_htlc(struct channel_state *cstate,
|
static void remove_htlc(struct channel_state *cstate,
|
||||||
enum channel_side creator,
|
enum side creator,
|
||||||
enum channel_side beneficiary,
|
enum side beneficiary,
|
||||||
const struct htlc *htlc)
|
const struct htlc *htlc)
|
||||||
{
|
{
|
||||||
size_t nondust;
|
size_t nondust;
|
||||||
@@ -252,14 +252,12 @@ static void remove_htlc(struct channel_state *cstate,
|
|||||||
|
|
||||||
void cstate_fail_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
void cstate_fail_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
||||||
{
|
{
|
||||||
remove_htlc(cstate, htlc_channel_side(htlc), htlc_channel_side(htlc),
|
remove_htlc(cstate, htlc_owner(htlc), htlc_owner(htlc), htlc);
|
||||||
htlc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cstate_fulfill_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
void cstate_fulfill_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
||||||
{
|
{
|
||||||
remove_htlc(cstate, htlc_channel_side(htlc), !htlc_channel_side(htlc),
|
remove_htlc(cstate, htlc_owner(htlc), !htlc_owner(htlc), htlc);
|
||||||
htlc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct channel_state *copy_cstate(const tal_t *ctx,
|
struct channel_state *copy_cstate(const tal_t *ctx,
|
||||||
@@ -272,7 +270,7 @@ void force_add_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
|||||||
{
|
{
|
||||||
struct channel_oneside *creator;
|
struct channel_oneside *creator;
|
||||||
|
|
||||||
creator = &cstate->side[htlc_channel_side(htlc)];
|
creator = &cstate->side[htlc_owner(htlc)];
|
||||||
creator->num_htlcs++;
|
creator->num_htlcs++;
|
||||||
creator->pay_msat -= htlc->msatoshis;
|
creator->pay_msat -= htlc->msatoshis;
|
||||||
|
|
||||||
@@ -282,40 +280,40 @@ void force_add_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void force_remove_htlc(struct channel_state *cstate,
|
static void force_remove_htlc(struct channel_state *cstate,
|
||||||
enum channel_side beneficiary,
|
enum side beneficiary,
|
||||||
const struct htlc *htlc)
|
const struct htlc *htlc)
|
||||||
{
|
{
|
||||||
cstate->side[beneficiary].pay_msat += htlc->msatoshis;
|
cstate->side[beneficiary].pay_msat += htlc->msatoshis;
|
||||||
cstate->side[htlc_channel_side(htlc)].num_htlcs--;
|
cstate->side[htlc_owner(htlc)].num_htlcs--;
|
||||||
if (!is_dust(htlc->msatoshis / 1000))
|
if (!is_dust(htlc->msatoshis / 1000))
|
||||||
cstate->num_nondust--;
|
cstate->num_nondust--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void force_fail_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
void force_fail_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
||||||
{
|
{
|
||||||
force_remove_htlc(cstate, htlc_channel_side(htlc), htlc);
|
force_remove_htlc(cstate, htlc_owner(htlc), htlc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void force_fulfill_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
void force_fulfill_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
||||||
{
|
{
|
||||||
force_remove_htlc(cstate, !htlc_channel_side(htlc), htlc);
|
force_remove_htlc(cstate, !htlc_owner(htlc), htlc);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool balance_after_force(struct channel_state *cstate)
|
bool balance_after_force(struct channel_state *cstate)
|
||||||
{
|
{
|
||||||
/* We should not spend more than anchor */
|
/* We should not spend more than anchor */
|
||||||
if (cstate->side[OURS].pay_msat + cstate->side[THEIRS].pay_msat
|
if (cstate->side[LOCAL].pay_msat + cstate->side[REMOTE].pay_msat
|
||||||
> cstate->anchor * 1000)
|
> cstate->anchor * 1000)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Check for wrap. */
|
/* Check for wrap. */
|
||||||
if (cstate->side[OURS].pay_msat > cstate->anchor * 1000)
|
if (cstate->side[LOCAL].pay_msat > cstate->anchor * 1000)
|
||||||
return false;
|
return false;
|
||||||
if (cstate->side[THEIRS].pay_msat > cstate->anchor * 1000)
|
if (cstate->side[REMOTE].pay_msat > cstate->anchor * 1000)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (cstate->num_nondust
|
if (cstate->num_nondust
|
||||||
> cstate->side[OURS].num_htlcs + cstate->side[THEIRS].num_htlcs)
|
> cstate->side[LOCAL].num_htlcs + cstate->side[REMOTE].num_htlcs)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Recalc fees. */
|
/* Recalc fees. */
|
||||||
|
|||||||
@@ -2,12 +2,19 @@
|
|||||||
#define LIGHTNING_DAEMON_CHANNEL_H
|
#define LIGHTNING_DAEMON_CHANNEL_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "bitcoin/locktime.h"
|
#include "bitcoin/locktime.h"
|
||||||
|
#include <assert.h>
|
||||||
#include <ccan/crypto/sha256/sha256.h>
|
#include <ccan/crypto/sha256/sha256.h>
|
||||||
|
#include <ccan/str/str.h>
|
||||||
#include <ccan/tal/tal.h>
|
#include <ccan/tal/tal.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
struct htlc;
|
struct htlc;
|
||||||
|
|
||||||
|
enum side {
|
||||||
|
LOCAL,
|
||||||
|
REMOTE
|
||||||
|
};
|
||||||
|
|
||||||
struct channel_oneside {
|
struct channel_oneside {
|
||||||
/* Payment and fee is in millisatoshi. */
|
/* Payment and fee is in millisatoshi. */
|
||||||
uint32_t pay_msat, fee_msat;
|
uint32_t pay_msat, fee_msat;
|
||||||
@@ -15,13 +22,6 @@ struct channel_oneside {
|
|||||||
unsigned int num_htlcs;
|
unsigned int num_htlcs;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum channel_side {
|
|
||||||
/* Output for us, htlcs we offered to them. */
|
|
||||||
OURS,
|
|
||||||
/* Output for them, htlcs they offered to us. */
|
|
||||||
THEIRS
|
|
||||||
};
|
|
||||||
|
|
||||||
struct channel_state {
|
struct channel_state {
|
||||||
/* Satoshis paid by anchor. */
|
/* Satoshis paid by anchor. */
|
||||||
uint64_t anchor;
|
uint64_t anchor;
|
||||||
@@ -44,7 +44,7 @@ struct channel_state {
|
|||||||
struct channel_state *initial_cstate(const tal_t *ctx,
|
struct channel_state *initial_cstate(const tal_t *ctx,
|
||||||
uint64_t anchor_satoshis,
|
uint64_t anchor_satoshis,
|
||||||
uint64_t fee_rate,
|
uint64_t fee_rate,
|
||||||
enum channel_side side);
|
enum side side);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* copy_cstate: Make a deep copy of channel_state
|
* copy_cstate: Make a deep copy of channel_state
|
||||||
@@ -92,21 +92,21 @@ void cstate_fulfill_htlc(struct channel_state *cstate, const struct htlc *htlc);
|
|||||||
/**
|
/**
|
||||||
* approx_max_feerate: what's the most side could raise fee rate to?
|
* approx_max_feerate: what's the most side could raise fee rate to?
|
||||||
* @cstate: The channel state
|
* @cstate: The channel state
|
||||||
* @side: OURS or THEIRS
|
* @side: LOCAL or REMOTE
|
||||||
*
|
*
|
||||||
* This is not exact! To check if their offer is valid, use can_afford_feerate.
|
* This is not exact! To check if their offer is valid, use can_afford_feerate.
|
||||||
*/
|
*/
|
||||||
uint64_t approx_max_feerate(const struct channel_state *cstate,
|
uint64_t approx_max_feerate(const struct channel_state *cstate,
|
||||||
enum channel_side side);
|
enum side side);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* can_afford_feerate: could this side pay for the fee if changed to fee_rate?
|
* can_afford_feerate: could this side pay for the fee if changed to fee_rate?
|
||||||
* @cstate: The channel state
|
* @cstate: The channel state
|
||||||
* @fee_rate: the new fee rate proposed
|
* @fee_rate: the new fee rate proposed
|
||||||
* @side: OURS or THEIRS
|
* @side: LOCAL or REMOTE
|
||||||
*/
|
*/
|
||||||
bool can_afford_feerate(const struct channel_state *cstate, uint64_t fee_rate,
|
bool can_afford_feerate(const struct channel_state *cstate, uint64_t fee_rate,
|
||||||
enum channel_side side);
|
enum side side);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adjust_fee: Change fee rate.
|
* adjust_fee: Change fee rate.
|
||||||
@@ -139,4 +139,20 @@ void force_fail_htlc(struct channel_state *cstate, const struct htlc *htlc);
|
|||||||
void force_fulfill_htlc(struct channel_state *cstate, const struct htlc *htlc);
|
void force_fulfill_htlc(struct channel_state *cstate, const struct htlc *htlc);
|
||||||
bool balance_after_force(struct channel_state *cstate);
|
bool balance_after_force(struct channel_state *cstate);
|
||||||
|
|
||||||
|
static inline const char *side_to_str(enum side side)
|
||||||
|
{
|
||||||
|
switch (side) {
|
||||||
|
case LOCAL: return "LOCAL";
|
||||||
|
case REMOTE: return "REMOTE";
|
||||||
|
}
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline enum side str_to_side(const char *str)
|
||||||
|
{
|
||||||
|
if (streq(str, "LOCAL"))
|
||||||
|
return LOCAL;
|
||||||
|
assert(streq(str, "REMOTE"));
|
||||||
|
return REMOTE;
|
||||||
|
}
|
||||||
#endif /* LIGHTNING_DAEMON_CHANNEL_H */
|
#endif /* LIGHTNING_DAEMON_CHANNEL_H */
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ u8 *wscript_for_htlc(const tal_t *ctx,
|
|||||||
const struct peer *peer,
|
const struct peer *peer,
|
||||||
const struct htlc *h,
|
const struct htlc *h,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
enum htlc_side side)
|
enum side side)
|
||||||
{
|
{
|
||||||
const struct peer_visible_state *this_side, *other_side;
|
const struct peer_visible_state *this_side, *other_side;
|
||||||
u8 *(*fn)(const tal_t *, secp256k1_context *,
|
u8 *(*fn)(const tal_t *, secp256k1_context *,
|
||||||
@@ -63,7 +63,7 @@ static size_t count_htlcs(const struct htlc_map *htlcs, int flag)
|
|||||||
u8 *commit_output_to_us(const tal_t *ctx,
|
u8 *commit_output_to_us(const tal_t *ctx,
|
||||||
const struct peer *peer,
|
const struct peer *peer,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
enum htlc_side side,
|
enum side side,
|
||||||
u8 **wscript)
|
u8 **wscript)
|
||||||
{
|
{
|
||||||
u8 *tmp;
|
u8 *tmp;
|
||||||
@@ -90,7 +90,7 @@ u8 *commit_output_to_us(const tal_t *ctx,
|
|||||||
u8 *commit_output_to_them(const tal_t *ctx,
|
u8 *commit_output_to_them(const tal_t *ctx,
|
||||||
const struct peer *peer,
|
const struct peer *peer,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
enum htlc_side side,
|
enum side side,
|
||||||
u8 **wscript)
|
u8 **wscript)
|
||||||
{
|
{
|
||||||
u8 *tmp;
|
u8 *tmp;
|
||||||
@@ -132,7 +132,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
|
|||||||
struct peer *peer,
|
struct peer *peer,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
const struct channel_state *cstate,
|
const struct channel_state *cstate,
|
||||||
enum htlc_side side,
|
enum side side,
|
||||||
bool *otherside_only)
|
bool *otherside_only)
|
||||||
{
|
{
|
||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
@@ -164,28 +164,28 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
|
|||||||
tx->output_count = 0;
|
tx->output_count = 0;
|
||||||
pays_to[LOCAL] = add_output(tx, commit_output_to_us(tx, peer, rhash,
|
pays_to[LOCAL] = add_output(tx, commit_output_to_us(tx, peer, rhash,
|
||||||
side, NULL),
|
side, NULL),
|
||||||
cstate->side[OURS].pay_msat / 1000,
|
cstate->side[LOCAL].pay_msat / 1000,
|
||||||
&total);
|
&total);
|
||||||
if (pays_to[LOCAL])
|
if (pays_to[LOCAL])
|
||||||
log_debug(peer->log, "Pays %u to local: %s",
|
log_debug(peer->log, "Pays %u to local: %s",
|
||||||
cstate->side[OURS].pay_msat / 1000,
|
cstate->side[LOCAL].pay_msat / 1000,
|
||||||
tal_hexstr(tx, tx->output[tx->output_count-1].script,
|
tal_hexstr(tx, tx->output[tx->output_count-1].script,
|
||||||
tx->output[tx->output_count-1].script_length));
|
tx->output[tx->output_count-1].script_length));
|
||||||
else
|
else
|
||||||
log_debug(peer->log, "DOES NOT pay %u to local",
|
log_debug(peer->log, "DOES NOT pay %u to local",
|
||||||
cstate->side[OURS].pay_msat / 1000);
|
cstate->side[LOCAL].pay_msat / 1000);
|
||||||
pays_to[REMOTE] = add_output(tx, commit_output_to_them(tx, peer, rhash,
|
pays_to[REMOTE] = add_output(tx, commit_output_to_them(tx, peer, rhash,
|
||||||
side, NULL),
|
side, NULL),
|
||||||
cstate->side[THEIRS].pay_msat / 1000,
|
cstate->side[REMOTE].pay_msat / 1000,
|
||||||
&total);
|
&total);
|
||||||
if (pays_to[REMOTE])
|
if (pays_to[REMOTE])
|
||||||
log_debug(peer->log, "Pays %u to remote: %s",
|
log_debug(peer->log, "Pays %u to remote: %s",
|
||||||
cstate->side[THEIRS].pay_msat / 1000,
|
cstate->side[REMOTE].pay_msat / 1000,
|
||||||
tal_hexstr(tx, tx->output[tx->output_count-1].script,
|
tal_hexstr(tx, tx->output[tx->output_count-1].script,
|
||||||
tx->output[tx->output_count-1].script_length));
|
tx->output[tx->output_count-1].script_length));
|
||||||
else
|
else
|
||||||
log_debug(peer->log, "DOES NOT pay %u to remote",
|
log_debug(peer->log, "DOES NOT pay %u to remote",
|
||||||
cstate->side[THEIRS].pay_msat / 1000);
|
cstate->side[REMOTE].pay_msat / 1000);
|
||||||
|
|
||||||
/* If their tx doesn't pay to them, or our tx doesn't pay to us... */
|
/* If their tx doesn't pay to them, or our tx doesn't pay to us... */
|
||||||
*otherside_only = !pays_to[side];
|
*otherside_only = !pays_to[side];
|
||||||
|
|||||||
@@ -12,20 +12,20 @@ u8 *wscript_for_htlc(const tal_t *ctx,
|
|||||||
const struct peer *peer,
|
const struct peer *peer,
|
||||||
const struct htlc *h,
|
const struct htlc *h,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
enum htlc_side side);
|
enum side side);
|
||||||
|
|
||||||
/* Returns scriptpubkey: *wscript is NULL if it's a direct p2wpkh. */
|
/* Returns scriptpubkey: *wscript is NULL if it's a direct p2wpkh. */
|
||||||
u8 *commit_output_to_us(const tal_t *ctx,
|
u8 *commit_output_to_us(const tal_t *ctx,
|
||||||
const struct peer *peer,
|
const struct peer *peer,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
enum htlc_side side,
|
enum side side,
|
||||||
u8 **wscript);
|
u8 **wscript);
|
||||||
|
|
||||||
/* Returns scriptpubkey: *wscript is NULL if it's a direct p2wpkh. */
|
/* Returns scriptpubkey: *wscript is NULL if it's a direct p2wpkh. */
|
||||||
u8 *commit_output_to_them(const tal_t *ctx,
|
u8 *commit_output_to_them(const tal_t *ctx,
|
||||||
const struct peer *peer,
|
const struct peer *peer,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
enum htlc_side side,
|
enum side side,
|
||||||
u8 **wscript);
|
u8 **wscript);
|
||||||
|
|
||||||
/* Create commitment tx to spend the anchor tx output; doesn't fill in
|
/* Create commitment tx to spend the anchor tx output; doesn't fill in
|
||||||
@@ -34,6 +34,6 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
|
|||||||
struct peer *peer,
|
struct peer *peer,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
const struct channel_state *cstate,
|
const struct channel_state *cstate,
|
||||||
enum htlc_side side,
|
enum side side,
|
||||||
bool *otherside_only);
|
bool *otherside_only);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
53
daemon/db.c
53
daemon/db.c
@@ -384,10 +384,10 @@ static void load_peer_commit_info(struct peer *peer)
|
|||||||
fatal("load_peer_commit_info:step gave %i cols, not 7",
|
fatal("load_peer_commit_info:step gave %i cols, not 7",
|
||||||
sqlite3_column_count(stmt));
|
sqlite3_column_count(stmt));
|
||||||
|
|
||||||
if (streq(sqlite3_column_str(stmt, 1), "OURS"))
|
if (streq(sqlite3_column_str(stmt, 1), "LOCAL"))
|
||||||
cip = &peer->local.commit;
|
cip = &peer->local.commit;
|
||||||
else {
|
else {
|
||||||
if (!streq(sqlite3_column_str(stmt, 1), "THEIRS"))
|
if (!streq(sqlite3_column_str(stmt, 1), "REMOTE"))
|
||||||
fatal("load_peer_commit_info:bad side %s",
|
fatal("load_peer_commit_info:bad side %s",
|
||||||
sqlite3_column_str(stmt, 1));
|
sqlite3_column_str(stmt, 1));
|
||||||
cip = &peer->remote.commit;
|
cip = &peer->remote.commit;
|
||||||
@@ -439,9 +439,9 @@ static void load_peer_commit_info(struct peer *peer)
|
|||||||
* and do normally-impossible things in intermediate states. So we
|
* and do normally-impossible things in intermediate states. So we
|
||||||
* mangle cstate balances manually. */
|
* mangle cstate balances manually. */
|
||||||
static void apply_htlc(struct channel_state *cstate, const struct htlc *htlc,
|
static void apply_htlc(struct channel_state *cstate, const struct htlc *htlc,
|
||||||
enum htlc_side side)
|
enum side side)
|
||||||
{
|
{
|
||||||
const char *sidestr = (side == LOCAL ? "LOCAL" : "REMOTE");
|
const char *sidestr = side_to_str(side);
|
||||||
|
|
||||||
if (!htlc_has(htlc, HTLC_FLAG(side,HTLC_F_WAS_COMMITTED)))
|
if (!htlc_has(htlc, HTLC_FLAG(side,HTLC_F_WAS_COMMITTED)))
|
||||||
return;
|
return;
|
||||||
@@ -485,13 +485,13 @@ static void load_peer_htlcs(struct peer *peer)
|
|||||||
peer->local.commit_fee_rate,
|
peer->local.commit_fee_rate,
|
||||||
peer->local.offer_anchor
|
peer->local.offer_anchor
|
||||||
== CMD_OPEN_WITH_ANCHOR ?
|
== CMD_OPEN_WITH_ANCHOR ?
|
||||||
OURS : THEIRS);
|
LOCAL : REMOTE);
|
||||||
peer->remote.commit->cstate = initial_cstate(peer,
|
peer->remote.commit->cstate = initial_cstate(peer,
|
||||||
peer->anchor.satoshis,
|
peer->anchor.satoshis,
|
||||||
peer->remote.commit_fee_rate,
|
peer->remote.commit_fee_rate,
|
||||||
peer->local.offer_anchor
|
peer->local.offer_anchor
|
||||||
== CMD_OPEN_WITH_ANCHOR ?
|
== CMD_OPEN_WITH_ANCHOR ?
|
||||||
OURS : THEIRS);
|
LOCAL : REMOTE);
|
||||||
|
|
||||||
/* We rebuild cstate by running *every* HTLC through. */
|
/* We rebuild cstate by running *every* HTLC through. */
|
||||||
while ((err = sqlite3_step(stmt)) != SQLITE_DONE) {
|
while ((err = sqlite3_step(stmt)) != SQLITE_DONE) {
|
||||||
@@ -614,19 +614,19 @@ static void load_peer_htlcs(struct peer *peer)
|
|||||||
peer->remote.staging_cstate = copy_cstate(peer, peer->remote.commit->cstate);
|
peer->remote.staging_cstate = copy_cstate(peer, peer->remote.commit->cstate);
|
||||||
peer->local.staging_cstate = copy_cstate(peer, peer->local.commit->cstate);
|
peer->local.staging_cstate = copy_cstate(peer, peer->local.commit->cstate);
|
||||||
log_debug(peer->log, "Local staging: pay %u/%u fee %u/%u htlcs %u/%u",
|
log_debug(peer->log, "Local staging: pay %u/%u fee %u/%u htlcs %u/%u",
|
||||||
peer->local.staging_cstate->side[OURS].pay_msat,
|
peer->local.staging_cstate->side[LOCAL].pay_msat,
|
||||||
peer->local.staging_cstate->side[THEIRS].pay_msat,
|
peer->local.staging_cstate->side[REMOTE].pay_msat,
|
||||||
peer->local.staging_cstate->side[OURS].fee_msat,
|
peer->local.staging_cstate->side[LOCAL].fee_msat,
|
||||||
peer->local.staging_cstate->side[THEIRS].fee_msat,
|
peer->local.staging_cstate->side[REMOTE].fee_msat,
|
||||||
peer->local.staging_cstate->side[OURS].num_htlcs,
|
peer->local.staging_cstate->side[LOCAL].num_htlcs,
|
||||||
peer->local.staging_cstate->side[THEIRS].num_htlcs);
|
peer->local.staging_cstate->side[REMOTE].num_htlcs);
|
||||||
log_debug(peer->log, "Remote staging: pay %u/%u fee %u/%u htlcs %u/%u",
|
log_debug(peer->log, "Remote staging: pay %u/%u fee %u/%u htlcs %u/%u",
|
||||||
peer->remote.staging_cstate->side[OURS].pay_msat,
|
peer->remote.staging_cstate->side[LOCAL].pay_msat,
|
||||||
peer->remote.staging_cstate->side[THEIRS].pay_msat,
|
peer->remote.staging_cstate->side[REMOTE].pay_msat,
|
||||||
peer->remote.staging_cstate->side[OURS].fee_msat,
|
peer->remote.staging_cstate->side[LOCAL].fee_msat,
|
||||||
peer->remote.staging_cstate->side[THEIRS].fee_msat,
|
peer->remote.staging_cstate->side[REMOTE].fee_msat,
|
||||||
peer->remote.staging_cstate->side[OURS].num_htlcs,
|
peer->remote.staging_cstate->side[LOCAL].num_htlcs,
|
||||||
peer->remote.staging_cstate->side[THEIRS].num_htlcs);
|
peer->remote.staging_cstate->side[REMOTE].num_htlcs);
|
||||||
|
|
||||||
tal_free(ctx);
|
tal_free(ctx);
|
||||||
}
|
}
|
||||||
@@ -1076,8 +1076,9 @@ bool db_set_anchor(struct peer *peer)
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
errmsg = db_exec(ctx, peer->dstate,
|
errmsg = db_exec(ctx, peer->dstate,
|
||||||
"INSERT INTO commit_info VALUES(x'%s', 'OURS', 0, x'%s', %"PRIi64", %s, NULL);",
|
"INSERT INTO commit_info VALUES(x'%s', '%s', 0, x'%s', %"PRIi64", %s, NULL);",
|
||||||
peerid,
|
peerid,
|
||||||
|
side_to_str(LOCAL),
|
||||||
tal_hexstr(ctx, &peer->local.commit->revocation_hash,
|
tal_hexstr(ctx, &peer->local.commit->revocation_hash,
|
||||||
sizeof(peer->local.commit->revocation_hash)),
|
sizeof(peer->local.commit->revocation_hash)),
|
||||||
peer->local.commit->order,
|
peer->local.commit->order,
|
||||||
@@ -1087,8 +1088,9 @@ bool db_set_anchor(struct peer *peer)
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
errmsg = db_exec(ctx, peer->dstate,
|
errmsg = db_exec(ctx, peer->dstate,
|
||||||
"INSERT INTO commit_info VALUES(x'%s', 'THEIRS', 0, x'%s', %"PRIi64", %s, NULL);",
|
"INSERT INTO commit_info VALUES(x'%s', '%s', 0, x'%s', %"PRIi64", %s, NULL);",
|
||||||
peerid,
|
peerid,
|
||||||
|
side_to_str(REMOTE),
|
||||||
tal_hexstr(ctx, &peer->remote.commit->revocation_hash,
|
tal_hexstr(ctx, &peer->remote.commit->revocation_hash,
|
||||||
sizeof(peer->remote.commit->revocation_hash)),
|
sizeof(peer->remote.commit->revocation_hash)),
|
||||||
peer->remote.commit->order,
|
peer->remote.commit->order,
|
||||||
@@ -1422,22 +1424,19 @@ bool db_htlc_failed(struct peer *peer, const struct htlc *htlc)
|
|||||||
return !errmsg;
|
return !errmsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool db_new_commit_info(struct peer *peer, enum channel_side side,
|
bool db_new_commit_info(struct peer *peer, enum side side,
|
||||||
const struct sha256 *prev_rhash)
|
const struct sha256 *prev_rhash)
|
||||||
{
|
{
|
||||||
struct commit_info *ci;
|
struct commit_info *ci;
|
||||||
const char *sidestr;
|
|
||||||
const char *errmsg, *ctx = tal(peer, char);
|
const char *errmsg, *ctx = tal(peer, char);
|
||||||
const char *peerid = pubkey_to_hexstr(ctx, peer->dstate->secpctx, peer->id);
|
const char *peerid = pubkey_to_hexstr(ctx, peer->dstate->secpctx, peer->id);
|
||||||
|
|
||||||
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
||||||
|
|
||||||
assert(peer->dstate->db->in_transaction);
|
assert(peer->dstate->db->in_transaction);
|
||||||
if (side == OURS) {
|
if (side == LOCAL) {
|
||||||
sidestr = "OURS";
|
|
||||||
ci = peer->local.commit;
|
ci = peer->local.commit;
|
||||||
} else {
|
} else {
|
||||||
sidestr = "THEIRS";
|
|
||||||
ci = peer->remote.commit;
|
ci = peer->remote.commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1449,7 +1448,7 @@ bool db_new_commit_info(struct peer *peer, enum channel_side side,
|
|||||||
sig_to_sql(ctx, peer->dstate->secpctx, ci->sig),
|
sig_to_sql(ctx, peer->dstate->secpctx, ci->sig),
|
||||||
ci->order,
|
ci->order,
|
||||||
sql_hex_or_null(ctx, prev_rhash, sizeof(*prev_rhash)),
|
sql_hex_or_null(ctx, prev_rhash, sizeof(*prev_rhash)),
|
||||||
peerid, sidestr);
|
peerid, side_to_str(side));
|
||||||
if (errmsg)
|
if (errmsg)
|
||||||
log_broken(peer->log, "%s:%s", __func__, errmsg);
|
log_broken(peer->log, "%s:%s", __func__, errmsg);
|
||||||
tal_free(ctx);
|
tal_free(ctx);
|
||||||
@@ -1467,7 +1466,7 @@ bool db_remove_their_prev_revocation_hash(struct peer *peer)
|
|||||||
assert(peer->dstate->db->in_transaction);
|
assert(peer->dstate->db->in_transaction);
|
||||||
|
|
||||||
// CREATE TABLE commit_info (peer "SQL_PUBKEY", side TEXT, commit_num INT, revocation_hash "SQL_SHA256", xmit_order INT, sig "SQL_SIGNATURE", prev_revocation_hash "SQL_SHA256", PRIMARY KEY(peer, side));
|
// CREATE TABLE commit_info (peer "SQL_PUBKEY", side TEXT, commit_num INT, revocation_hash "SQL_SHA256", xmit_order INT, sig "SQL_SIGNATURE", prev_revocation_hash "SQL_SHA256", PRIMARY KEY(peer, side));
|
||||||
errmsg = db_exec(ctx, peer->dstate, "UPDATE commit_info SET prev_revocation_hash=NULL WHERE peer=x'%s' AND side='THEIRS' and prev_revocation_hash IS NOT NULL;",
|
errmsg = db_exec(ctx, peer->dstate, "UPDATE commit_info SET prev_revocation_hash=NULL WHERE peer=x'%s' AND side='REMOTE' and prev_revocation_hash IS NOT NULL;",
|
||||||
peerid);
|
peerid);
|
||||||
if (errmsg)
|
if (errmsg)
|
||||||
log_broken(peer->log, "%s:%s", __func__, errmsg);
|
log_broken(peer->log, "%s:%s", __func__, errmsg);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ bool db_update_htlc_state(struct peer *peer, const struct htlc *htlc,
|
|||||||
bool db_update_feechange_state(struct peer *peer,
|
bool db_update_feechange_state(struct peer *peer,
|
||||||
const struct feechange *f,
|
const struct feechange *f,
|
||||||
enum htlc_state oldstate);
|
enum htlc_state oldstate);
|
||||||
bool db_new_commit_info(struct peer *peer, enum channel_side side,
|
bool db_new_commit_info(struct peer *peer, enum side side,
|
||||||
const struct sha256 *prev_rhash);
|
const struct sha256 *prev_rhash);
|
||||||
bool db_remove_their_prev_revocation_hash(struct peer *peer);
|
bool db_remove_their_prev_revocation_hash(struct peer *peer);
|
||||||
bool db_update_next_revocation_hash(struct peer *peer);
|
bool db_update_next_revocation_hash(struct peer *peer);
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#ifndef LIGHTNING_DAEMON_FEECHANGE_H
|
#ifndef LIGHTNING_DAEMON_FEECHANGE_H
|
||||||
#define LIGHTNING_DAEMON_FEECHANGE_H
|
#define LIGHTNING_DAEMON_FEECHANGE_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "channel.h"
|
||||||
#include "feechange_state.h"
|
#include "feechange_state.h"
|
||||||
#include "htlc.h"
|
|
||||||
|
struct peer;
|
||||||
|
|
||||||
struct feechange {
|
struct feechange {
|
||||||
/* What's the status */
|
/* What's the status */
|
||||||
@@ -11,7 +13,7 @@ struct feechange {
|
|||||||
u64 fee_rate;
|
u64 fee_rate;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline enum htlc_side feechange_side(enum feechange_state state)
|
static inline enum side feechange_side(enum feechange_state state)
|
||||||
{
|
{
|
||||||
if (state <= SENT_FEECHANGE_ACK_REVOCATION) {
|
if (state <= SENT_FEECHANGE_ACK_REVOCATION) {
|
||||||
return LOCAL;
|
return LOCAL;
|
||||||
|
|||||||
@@ -27,11 +27,6 @@
|
|||||||
#define HTLC_F_WAS_COMMITTED 0x10
|
#define HTLC_F_WAS_COMMITTED 0x10
|
||||||
|
|
||||||
/* Each of the above flags applies to both sides */
|
/* Each of the above flags applies to both sides */
|
||||||
enum htlc_side {
|
|
||||||
LOCAL,
|
|
||||||
REMOTE
|
|
||||||
};
|
|
||||||
|
|
||||||
#define HTLC_FLAG(side,flag) ((flag) << ((side) * 5))
|
#define HTLC_FLAG(side,flag) ((flag) << ((side) * 5))
|
||||||
|
|
||||||
#define HTLC_REMOTE_F_PENDING HTLC_FLAG(REMOTE,HTLC_F_PENDING)
|
#define HTLC_REMOTE_F_PENDING HTLC_FLAG(REMOTE,HTLC_F_PENDING)
|
||||||
@@ -49,11 +44,11 @@ enum htlc_side {
|
|||||||
struct htlc {
|
struct htlc {
|
||||||
/* Useful for debugging, and decoding via ->src. */
|
/* Useful for debugging, and decoding via ->src. */
|
||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
/* Block number where we abort if it's still live (OURS only) */
|
/* Block number where we abort if it's still live (LOCAL only) */
|
||||||
u32 deadline;
|
u32 deadline;
|
||||||
/* What's the status. */
|
/* What's the status. */
|
||||||
enum htlc_state state;
|
enum htlc_state state;
|
||||||
/* The unique ID for this peer and this direction (ours or theirs) */
|
/* The unique ID for this peer and this direction (LOCAL or REMOTE) */
|
||||||
u64 id;
|
u64 id;
|
||||||
/* The amount in millisatoshi. */
|
/* The amount in millisatoshi. */
|
||||||
u64 msatoshis;
|
u64 msatoshis;
|
||||||
@@ -67,7 +62,7 @@ struct htlc {
|
|||||||
/* FIXME: We could union these together: */
|
/* FIXME: We could union these together: */
|
||||||
/* Routing information sent with this HTLC. */
|
/* Routing information sent with this HTLC. */
|
||||||
const u8 *routing;
|
const u8 *routing;
|
||||||
/* Previous HTLC (if any) which made us offer this (OURS only) */
|
/* Previous HTLC (if any) which made us offer this (LOCAL only) */
|
||||||
struct htlc *src;
|
struct htlc *src;
|
||||||
const u8 *fail;
|
const u8 *fail;
|
||||||
};
|
};
|
||||||
@@ -85,7 +80,7 @@ static inline bool htlc_has(const struct htlc *h, int flag)
|
|||||||
return htlc_state_flags(h->state) & flag;
|
return htlc_state_flags(h->state) & flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline enum htlc_side htlc_state_owner(enum htlc_state state)
|
static inline enum side htlc_state_owner(enum htlc_state state)
|
||||||
{
|
{
|
||||||
if (state < RCVD_ADD_HTLC) {
|
if (state < RCVD_ADD_HTLC) {
|
||||||
assert((htlc_state_flags(state)
|
assert((htlc_state_flags(state)
|
||||||
@@ -100,19 +95,11 @@ static inline enum htlc_side htlc_state_owner(enum htlc_state state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline enum htlc_side htlc_owner(const struct htlc *h)
|
static inline enum side htlc_owner(const struct htlc *h)
|
||||||
{
|
{
|
||||||
return htlc_state_owner(h->state);
|
return htlc_state_owner(h->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: Transitional function. */
|
|
||||||
static inline enum channel_side htlc_channel_side(const struct htlc *h)
|
|
||||||
{
|
|
||||||
if (htlc_owner(h) == LOCAL)
|
|
||||||
return OURS;
|
|
||||||
return THEIRS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void htlc_undostate(struct htlc *h,
|
void htlc_undostate(struct htlc *h,
|
||||||
enum htlc_state oldstate, enum htlc_state newstate);
|
enum htlc_state oldstate, enum htlc_state newstate);
|
||||||
|
|
||||||
@@ -131,7 +118,7 @@ static inline size_t htlc_hash(u64 id)
|
|||||||
}
|
}
|
||||||
HTABLE_DEFINE_TYPE(struct htlc, htlc_key, htlc_hash, htlc_cmp, htlc_map);
|
HTABLE_DEFINE_TYPE(struct htlc, htlc_key, htlc_hash, htlc_cmp, htlc_map);
|
||||||
|
|
||||||
static inline struct htlc *htlc_get(struct htlc_map *htlcs, u64 id, enum htlc_side owner)
|
static inline struct htlc *htlc_get(struct htlc_map *htlcs, u64 id, enum side owner)
|
||||||
{
|
{
|
||||||
struct htlc *h;
|
struct htlc *h;
|
||||||
struct htlc_map_iter it;
|
struct htlc_map_iter it;
|
||||||
|
|||||||
@@ -346,9 +346,9 @@ static char *to_string_(const tal_t *ctx,
|
|||||||
u.cstate->fee_rate,
|
u.cstate->fee_rate,
|
||||||
u.cstate->num_nondust,
|
u.cstate->num_nondust,
|
||||||
to_string(ctx, lr, struct channel_oneside,
|
to_string(ctx, lr, struct channel_oneside,
|
||||||
&u.cstate->side[OURS]),
|
&u.cstate->side[LOCAL]),
|
||||||
to_string(ctx, lr, struct channel_oneside,
|
to_string(ctx, lr, struct channel_oneside,
|
||||||
&u.cstate->side[THEIRS]));
|
&u.cstate->side[REMOTE]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ struct htlc_output_map {
|
|||||||
struct htlc_output_map *get_htlc_output_map(const tal_t *ctx,
|
struct htlc_output_map *get_htlc_output_map(const tal_t *ctx,
|
||||||
const struct peer *peer,
|
const struct peer *peer,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
enum htlc_side side,
|
enum side side,
|
||||||
unsigned int commit_num)
|
unsigned int commit_num)
|
||||||
{
|
{
|
||||||
struct htlc_map_iter it;
|
struct htlc_map_iter it;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ struct sha256;
|
|||||||
struct htlc_output_map *get_htlc_output_map(const tal_t *ctx,
|
struct htlc_output_map *get_htlc_output_map(const tal_t *ctx,
|
||||||
const struct peer *peer,
|
const struct peer *peer,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
enum htlc_side side,
|
enum side side,
|
||||||
unsigned int commit_num);
|
unsigned int commit_num);
|
||||||
|
|
||||||
/* If this scriptPubkey pays to a HTLC, get the full wscript */
|
/* If this scriptPubkey pays to a HTLC, get the full wscript */
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ Pkt *accept_pkt_htlc_add(struct peer *peer, const Pkt *pkt, struct htlc **h)
|
|||||||
* A node MUST NOT add a HTLC if it would result in it
|
* A node MUST NOT add a HTLC if it would result in it
|
||||||
* offering more than 300 HTLCs in the remote commitment transaction.
|
* offering more than 300 HTLCs in the remote commitment transaction.
|
||||||
*/
|
*/
|
||||||
if (peer->remote.staging_cstate->side[THEIRS].num_htlcs == 300)
|
if (peer->remote.staging_cstate->side[REMOTE].num_htlcs == 300)
|
||||||
return pkt_err(peer, "Too many HTLCs");
|
return pkt_err(peer, "Too many HTLCs");
|
||||||
|
|
||||||
/* BOLT #2:
|
/* BOLT #2:
|
||||||
|
|||||||
@@ -652,7 +652,7 @@ static void retry_all_routing(struct peer *restarted_peer)
|
|||||||
static bool adjust_cstate_side(struct channel_state *cstate,
|
static bool adjust_cstate_side(struct channel_state *cstate,
|
||||||
struct htlc *h,
|
struct htlc *h,
|
||||||
enum htlc_state old, enum htlc_state new,
|
enum htlc_state old, enum htlc_state new,
|
||||||
enum htlc_side side)
|
enum side side)
|
||||||
{
|
{
|
||||||
int oldf = htlc_state_flags(old), newf = htlc_state_flags(new);
|
int oldf = htlc_state_flags(old), newf = htlc_state_flags(new);
|
||||||
bool old_committed, new_committed;
|
bool old_committed, new_committed;
|
||||||
@@ -701,7 +701,7 @@ static void adjust_cstate_fee_side(struct channel_state *cstate,
|
|||||||
const struct feechange *f,
|
const struct feechange *f,
|
||||||
enum feechange_state old,
|
enum feechange_state old,
|
||||||
enum feechange_state new,
|
enum feechange_state new,
|
||||||
enum htlc_side side)
|
enum side side)
|
||||||
{
|
{
|
||||||
/* We applied changes to staging_cstate when we first received
|
/* We applied changes to staging_cstate when we first received
|
||||||
* feechange packet, so we could make sure it was valid. Don't
|
* feechange packet, so we could make sure it was valid. Don't
|
||||||
@@ -1034,7 +1034,7 @@ static Pkt *handle_pkt_commit(struct peer *peer, const Pkt *pkt)
|
|||||||
peer->local.commit = ci;
|
peer->local.commit = ci;
|
||||||
peer->local.commit->order = peer->order_counter++;
|
peer->local.commit->order = peer->order_counter++;
|
||||||
|
|
||||||
if (!db_new_commit_info(peer, OURS, NULL)) {
|
if (!db_new_commit_info(peer, LOCAL, NULL)) {
|
||||||
db_abort_transaction(peer);
|
db_abort_transaction(peer);
|
||||||
return pkt_err(peer, "Database error");
|
return pkt_err(peer, "Database error");
|
||||||
}
|
}
|
||||||
@@ -1745,7 +1745,7 @@ const char *command_htlc_add(struct peer *peer, u64 msatoshis,
|
|||||||
* A node MUST NOT add a HTLC if it would result in it
|
* A node MUST NOT add a HTLC if it would result in it
|
||||||
* offering more than 300 HTLCs in the remote commitment transaction.
|
* offering more than 300 HTLCs in the remote commitment transaction.
|
||||||
*/
|
*/
|
||||||
if (peer->remote.staging_cstate->side[OURS].num_htlcs == 300) {
|
if (peer->remote.staging_cstate->side[LOCAL].num_htlcs == 300) {
|
||||||
log_unusual(peer->log, "add_htlc: fail: already at limit");
|
log_unusual(peer->log, "add_htlc: fail: already at limit");
|
||||||
*error_code = SERVICE_UNAVAILABLE_503;
|
*error_code = SERVICE_UNAVAILABLE_503;
|
||||||
return "channel full";
|
return "channel full";
|
||||||
@@ -2236,7 +2236,7 @@ static void do_commit(struct peer *peer, struct command *jsoncmd)
|
|||||||
tal_free(peer->remote.commit);
|
tal_free(peer->remote.commit);
|
||||||
peer->remote.commit = ci;
|
peer->remote.commit = ci;
|
||||||
peer->remote.commit->order = peer->order_counter++;
|
peer->remote.commit->order = peer->order_counter++;
|
||||||
if (!db_new_commit_info(peer, THEIRS, peer->their_prev_revocation_hash))
|
if (!db_new_commit_info(peer, REMOTE, peer->their_prev_revocation_hash))
|
||||||
goto database_error;
|
goto database_error;
|
||||||
|
|
||||||
/* We don't need to remember their commit if we don't give sig. */
|
/* We don't need to remember their commit if we don't give sig. */
|
||||||
@@ -3023,7 +3023,7 @@ static bool outputscript_eq(const struct bitcoin_tx_output *out,
|
|||||||
static bool map_onchain_outputs(struct peer *peer,
|
static bool map_onchain_outputs(struct peer *peer,
|
||||||
const struct sha256 *rhash,
|
const struct sha256 *rhash,
|
||||||
const struct bitcoin_tx *tx,
|
const struct bitcoin_tx *tx,
|
||||||
enum htlc_side side,
|
enum side side,
|
||||||
unsigned int commit_num)
|
unsigned int commit_num)
|
||||||
{
|
{
|
||||||
u8 *to_us, *to_them, *to_them_wscript, *to_us_wscript;
|
u8 *to_us, *to_them, *to_them_wscript, *to_us_wscript;
|
||||||
@@ -3216,7 +3216,7 @@ static enum watch_result our_htlc_timeout_depth(struct peer *peer,
|
|||||||
static enum watch_result our_htlc_depth(struct peer *peer,
|
static enum watch_result our_htlc_depth(struct peer *peer,
|
||||||
unsigned int depth,
|
unsigned int depth,
|
||||||
const struct sha256_double *txid,
|
const struct sha256_double *txid,
|
||||||
enum htlc_side whose_commit,
|
enum side whose_commit,
|
||||||
unsigned int out_num)
|
unsigned int out_num)
|
||||||
{
|
{
|
||||||
struct htlc *h = peer->onchain.htlcs[out_num];
|
struct htlc *h = peer->onchain.htlcs[out_num];
|
||||||
@@ -3949,8 +3949,8 @@ struct bitcoin_tx *peer_create_close_tx(struct peer *peer, u64 fee)
|
|||||||
log_debug(peer->log,
|
log_debug(peer->log,
|
||||||
"creating close-tx with fee %"PRIu64" amounts %u/%u to ",
|
"creating close-tx with fee %"PRIu64" amounts %u/%u to ",
|
||||||
fee,
|
fee,
|
||||||
cstate.side[OURS].pay_msat / 1000,
|
cstate.side[LOCAL].pay_msat / 1000,
|
||||||
cstate.side[THEIRS].pay_msat / 1000);
|
cstate.side[REMOTE].pay_msat / 1000);
|
||||||
log_add_struct(peer->log, "%s", struct pubkey, &peer->local.finalkey);
|
log_add_struct(peer->log, "%s", struct pubkey, &peer->local.finalkey);
|
||||||
log_add_struct(peer->log, "/%s", struct pubkey, &peer->remote.finalkey);
|
log_add_struct(peer->log, "/%s", struct pubkey, &peer->remote.finalkey);
|
||||||
|
|
||||||
@@ -3960,8 +3960,8 @@ struct bitcoin_tx *peer_create_close_tx(struct peer *peer, u64 fee)
|
|||||||
&peer->anchor.txid,
|
&peer->anchor.txid,
|
||||||
peer->anchor.index,
|
peer->anchor.index,
|
||||||
peer->anchor.satoshis,
|
peer->anchor.satoshis,
|
||||||
cstate.side[OURS].pay_msat / 1000,
|
cstate.side[LOCAL].pay_msat / 1000,
|
||||||
cstate.side[THEIRS].pay_msat / 1000);
|
cstate.side[REMOTE].pay_msat / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Creation the bitcoin anchor tx, spending output user provided. */
|
/* Creation the bitcoin anchor tx, spending output user provided. */
|
||||||
@@ -4035,7 +4035,7 @@ bool setup_first_commit(struct peer *peer)
|
|||||||
peer->local.commit_fee_rate,
|
peer->local.commit_fee_rate,
|
||||||
peer->local.offer_anchor
|
peer->local.offer_anchor
|
||||||
== CMD_OPEN_WITH_ANCHOR ?
|
== CMD_OPEN_WITH_ANCHOR ?
|
||||||
OURS : THEIRS);
|
LOCAL : REMOTE);
|
||||||
if (!peer->local.commit->cstate)
|
if (!peer->local.commit->cstate)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -4044,7 +4044,7 @@ bool setup_first_commit(struct peer *peer)
|
|||||||
peer->remote.commit_fee_rate,
|
peer->remote.commit_fee_rate,
|
||||||
peer->local.offer_anchor
|
peer->local.offer_anchor
|
||||||
== CMD_OPEN_WITH_ANCHOR ?
|
== CMD_OPEN_WITH_ANCHOR ?
|
||||||
OURS : THEIRS);
|
LOCAL : REMOTE);
|
||||||
if (!peer->remote.commit->cstate)
|
if (!peer->remote.commit->cstate)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -4171,7 +4171,7 @@ static void json_add_abstime(struct json_result *response,
|
|||||||
static void json_add_htlcs(struct json_result *response,
|
static void json_add_htlcs(struct json_result *response,
|
||||||
const char *id,
|
const char *id,
|
||||||
struct peer *peer,
|
struct peer *peer,
|
||||||
enum htlc_side owner)
|
enum side owner)
|
||||||
{
|
{
|
||||||
struct htlc_map_iter it;
|
struct htlc_map_iter it;
|
||||||
struct htlc *h;
|
struct htlc *h;
|
||||||
@@ -4228,10 +4228,10 @@ static void json_getpeers(struct command *cmd,
|
|||||||
}
|
}
|
||||||
last = p->local.commit->cstate;
|
last = p->local.commit->cstate;
|
||||||
|
|
||||||
json_add_num(response, "our_amount", last->side[OURS].pay_msat);
|
json_add_num(response, "our_amount", last->side[LOCAL].pay_msat);
|
||||||
json_add_num(response, "our_fee", last->side[OURS].fee_msat);
|
json_add_num(response, "our_fee", last->side[LOCAL].fee_msat);
|
||||||
json_add_num(response, "their_amount", last->side[THEIRS].pay_msat);
|
json_add_num(response, "their_amount", last->side[REMOTE].pay_msat);
|
||||||
json_add_num(response, "their_fee", last->side[THEIRS].fee_msat);
|
json_add_num(response, "their_fee", last->side[REMOTE].fee_msat);
|
||||||
json_add_htlcs(response, "our_htlcs", p, LOCAL);
|
json_add_htlcs(response, "our_htlcs", p, LOCAL);
|
||||||
json_add_htlcs(response, "their_htlcs", p, REMOTE);
|
json_add_htlcs(response, "their_htlcs", p, REMOTE);
|
||||||
json_object_end(response);
|
json_object_end(response);
|
||||||
|
|||||||
4
state.c
4
state.c
@@ -164,7 +164,7 @@ enum state state(struct peer *peer,
|
|||||||
db_abort_transaction(peer);
|
db_abort_transaction(peer);
|
||||||
goto err_breakdown;
|
goto err_breakdown;
|
||||||
}
|
}
|
||||||
if (!db_new_commit_info(peer, THEIRS, NULL)) {
|
if (!db_new_commit_info(peer, REMOTE, NULL)) {
|
||||||
err = pkt_err(peer, "database error");
|
err = pkt_err(peer, "database error");
|
||||||
peer_open_complete(peer, err->error->problem);
|
peer_open_complete(peer, err->error->problem);
|
||||||
db_abort_transaction(peer);
|
db_abort_transaction(peer);
|
||||||
@@ -230,7 +230,7 @@ enum state state(struct peer *peer,
|
|||||||
db_abort_transaction(peer);
|
db_abort_transaction(peer);
|
||||||
goto err_breakdown;
|
goto err_breakdown;
|
||||||
}
|
}
|
||||||
if (!db_new_commit_info(peer, OURS, NULL)) {
|
if (!db_new_commit_info(peer, LOCAL, NULL)) {
|
||||||
bitcoin_release_anchor(peer, INPUT_NONE);
|
bitcoin_release_anchor(peer, INPUT_NONE);
|
||||||
err = pkt_err(peer, "database error");
|
err = pkt_err(peer, "database error");
|
||||||
peer_open_complete(peer, err->error->problem);
|
peer_open_complete(peer, err->error->problem);
|
||||||
|
|||||||
Reference in New Issue
Block a user