Browse Source

coins: update API surface for creating coin movements

Canonicalize the signature for the 'tag-type' of coin moves by unique
constructor/method calls.

Suggested-By: @rustyrussell
nifty/pset-pre
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
de065580f6
  1. 220
      common/coin_mvt.c
  2. 81
      common/coin_mvt.h
  3. 33
      lightningd/chaintopology.c
  4. 29
      lightningd/channel_control.c
  5. 6
      lightningd/onchain_control.c
  6. 126
      onchaind/onchaind.c
  7. 82
      onchaind/test/run-grind_feerate-bug.c
  8. 82
      onchaind/test/run-grind_feerate.c
  9. 22
      wallet/test/run-wallet.c
  10. 8
      wallet/wallet.c

220
common/coin_mvt.c

@ -1,3 +1,4 @@
#include <assert.h>
#include <ccan/ccan/cast/cast.h>
#include <ccan/tal/str/str.h>
#include <common/coin_mvt.h>
@ -62,17 +63,16 @@ struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
return mvt;
}
struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_txid *output_txid,
u32 vout,
struct sha256 *payment_hash,
u32 blockheight,
enum mvt_tag tag,
struct amount_msat amount,
bool is_credit,
enum mvt_unit_type unit)
static struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_txid *output_txid,
u32 vout,
const struct sha256 *payment_hash TAKES,
u32 blockheight, enum mvt_tag tag,
struct amount_msat amount,
bool is_credit,
enum mvt_unit_type unit)
{
struct chain_coin_mvt *mvt = tal(ctx, struct chain_coin_mvt);
@ -88,7 +88,10 @@ struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx,
/* for htlc's that are filled onchain, we also have a
* preimage, NULL otherwise */
mvt->payment_hash = payment_hash;
if (payment_hash)
mvt->payment_hash = tal_dup(mvt, struct sha256, payment_hash);
else
mvt->payment_hash = NULL;
mvt->blockheight = blockheight;
mvt->tag = tag;
@ -104,28 +107,199 @@ struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx,
return mvt;
}
struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx,
static struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_txid *output_txid,
u32 vout,
const struct sha256 *payment_hash TAKES,
u32 blockheight, enum mvt_tag tag,
struct amount_sat amt_sat,
bool is_credit, enum mvt_unit_type unit)
{
struct amount_msat amt_msat;
bool ok;
ok = amount_sat_to_msat(&amt_msat, amt_sat);
assert(ok);
return new_chain_coin_mvt(ctx, account_name, tx_txid,
output_txid, vout, payment_hash,
blockheight, tag, amt_msat, is_credit,
unit);
}
struct chain_coin_mvt *new_coin_withdrawal(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_txid *out_txid,
u32 vout,
u32 blockheight,
struct amount_msat amount,
enum mvt_unit_type unit)
{
return new_chain_coin_mvt(ctx, account_name, tx_txid,
out_txid, vout, NULL, blockheight,
WITHDRAWAL, amount, false, unit);
}
struct chain_coin_mvt *new_coin_withdrawal_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_txid *out_txid,
u32 vout,
u32 blockheight,
struct amount_sat amount,
enum mvt_unit_type unit)
{
struct amount_msat amt_msat;
bool ok;
ok = amount_sat_to_msat(&amt_msat, amount);
assert(ok);
return new_coin_withdrawal(ctx, account_name, tx_txid, out_txid, vout,
blockheight, amt_msat, unit);
}
struct chain_coin_mvt *new_coin_chain_fees(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
u32 blockheight,
struct amount_msat amount,
enum mvt_unit_type unit)
{
return new_chain_coin_mvt(ctx, account_name, tx_txid,
NULL, 0, NULL, blockheight,
CHAIN_FEES, amount, false, unit);
}
struct chain_coin_mvt *new_coin_chain_fees_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
u32 blockheight,
struct amount_sat amount,
enum mvt_unit_type unit)
{
struct amount_msat amt_msat;
bool ok;
ok = amount_sat_to_msat(&amt_msat, amount);
assert(ok);
return new_coin_chain_fees(ctx, account_name, tx_txid,
blockheight, amt_msat, unit);
}
struct chain_coin_mvt *new_coin_journal_entry(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_txid *output_txid,
const struct bitcoin_txid *txid,
const struct bitcoin_txid *out_txid,
u32 vout,
struct sha256 *payment_hash,
u32 blockheight,
enum mvt_tag tag,
struct amount_sat amt_sat,
struct amount_msat amount,
bool is_credit,
enum mvt_unit_type unit)
{
return new_chain_coin_mvt(ctx, account_name, txid,
out_txid, vout, NULL,
blockheight, JOURNAL,
amount, is_credit, unit);
}
struct chain_coin_mvt *new_coin_deposit(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *txid,
u32 vout, u32 blockheight,
struct amount_msat amount,
enum mvt_unit_type unit)
{
return new_chain_coin_mvt(ctx, account_name, txid, txid,
vout, NULL, blockheight, DEPOSIT,
amount, true, unit);
}
struct chain_coin_mvt *new_coin_deposit_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *txid,
u32 vout,
u32 blockheight,
struct amount_sat amount,
enum mvt_unit_type unit)
{
struct amount_msat amt_msat;
if (!amount_sat_to_msat(&amt_msat, amt_sat))
return NULL;
bool ok;
return new_chain_coin_mvt(ctx, account_name, tx_txid,
output_txid, vout, payment_hash,
blockheight, tag, amt_msat, is_credit,
ok = amount_sat_to_msat(&amt_msat, amount);
assert(ok);
return new_coin_deposit(ctx, account_name, txid,
vout, blockheight,
amt_msat, unit);
}
struct chain_coin_mvt *new_coin_penalty_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *txid,
const struct bitcoin_txid *out_txid,
u32 vout,
u32 blockheight,
struct amount_sat amount,
enum mvt_unit_type unit)
{
struct amount_msat amt_msat;
bool ok;
ok = amount_sat_to_msat(&amt_msat, amount);
assert(ok);
return new_chain_coin_mvt(ctx, account_name,
txid, out_txid,
vout, NULL,
blockheight, PENALTY,
amt_msat, false,
unit);
}
struct chain_coin_mvt *new_coin_onchain_htlc_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *txid,
const struct bitcoin_txid *out_txid,
u32 vout,
struct sha256 payment_hash,
u32 blockheight,
struct amount_sat amount,
bool is_credit,
enum mvt_unit_type unit)
{
return new_chain_coin_mvt_sat(ctx, account_name,
txid, out_txid, vout,
take(tal_dup(NULL, struct sha256,
&payment_hash)), blockheight,
ONCHAIN_HTLC, amount, is_credit, unit);
}
struct chain_coin_mvt *new_coin_pushed(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *txid,
u32 blockheight,
struct amount_msat amount,
enum mvt_unit_type unit)
{
return new_chain_coin_mvt(ctx, account_name, txid, NULL, 0,
NULL, blockheight, PUSHED, amount,
false, unit);
}
struct chain_coin_mvt *new_coin_spend_track(const tal_t *ctx,
const struct bitcoin_txid *txid,
const struct bitcoin_txid *out_txid,
u32 vout, u32 blockheight,
enum mvt_unit_type unit)
{
return new_chain_coin_mvt_sat(ctx, "wallet", txid, out_txid, vout,
NULL, blockheight, SPEND_TRACK, AMOUNT_SAT(0),
false, unit);
}
struct coin_mvt *finalize_chain_mvt(const tal_t *ctx,
const struct chain_coin_mvt *chain_mvt,
u32 timestamp,

81
common/coin_mvt.h

@ -135,28 +135,87 @@ struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
enum mvt_tag tag,
bool is_credit,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx,
struct chain_coin_mvt *new_coin_withdrawal(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_txid *output_txid,
const struct bitcoin_txid *out_txid,
u32 vout,
struct sha256 *payment_hash,
u32 blockheight,
enum mvt_tag tag,
struct amount_msat amount,
bool is_credit,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx,
struct chain_coin_mvt *new_coin_withdrawal_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_txid *out_txid,
u32 vout,
u32 blockheight,
struct amount_sat amount,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_coin_chain_fees(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
u32 blockheight,
struct amount_msat amount,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_coin_chain_fees_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
u32 blockheight,
struct amount_sat amount,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_coin_journal_entry(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_txid *output_txid,
const struct bitcoin_txid *txid,
const struct bitcoin_txid *out_txid,
u32 vout,
struct sha256 *payment_hash,
u32 blockheight,
enum mvt_tag tag,
struct amount_sat amt_sat,
struct amount_msat amount,
bool is_credit,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_coin_deposit(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *txid,
u32 vout, u32 blockheight,
struct amount_msat amount,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_coin_deposit_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *txid,
u32 vout,
u32 blockheight,
struct amount_sat amount,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_coin_penalty_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *txid,
const struct bitcoin_txid *out_txid,
u32 vout,
u32 blockheight,
struct amount_sat amount,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_coin_onchain_htlc_sat(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *txid,
const struct bitcoin_txid *out_txid,
u32 vout,
struct sha256 payment_hash,
u32 blockheight,
struct amount_sat amount,
bool is_credit,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_coin_spend_track(const tal_t *ctx,
const struct bitcoin_txid *txid,
const struct bitcoin_txid *out_txid,
u32 vout, u32 blockheight,
enum mvt_unit_type unit);
struct chain_coin_mvt *new_coin_pushed(const tal_t *ctx,
const char *account_name,
const struct bitcoin_txid *txid,
u32 blockheight,
struct amount_msat amount,
enum mvt_unit_type unit);
struct coin_mvt *finalize_chain_mvt(const tal_t *ctx,
const struct chain_coin_mvt *chain_mvt,
u32 timestamp,

33
lightningd/chaintopology.c

@ -680,15 +680,8 @@ static void record_output_spend(struct lightningd *ld,
vout);
*input_amt = utxo->amount;
mvt = new_chain_coin_mvt_sat(ctx, "wallet", txid,
utxo_txid, vout, NULL,
blockheight,
SPEND_TRACK, AMOUNT_SAT(0),
false, BTC);
if (!mvt)
fatal("unable to convert %s to msat",
type_to_string(tmpctx, struct amount_sat,
input_amt));
mvt = new_coin_spend_track(ctx, txid, utxo_txid, vout,
blockheight, BTC);
notify_chain_mvt(ld, mvt);
tal_free(ctx);
}
@ -717,14 +710,8 @@ static void record_tx_outs_and_fees(struct lightningd *ld, const struct bitcoin_
asset = bitcoin_tx_output_get_amount(tx, i);
assert(amount_asset_is_main(&asset));
outval = amount_asset_to_sat(&asset);
mvt = new_chain_coin_mvt_sat(ctx, "wallet", txid,
txid, i, NULL,
blockheight, WITHDRAWAL,
outval, false, BTC);
if (!mvt)
fatal("unable to convert %s to msat",
type_to_string(tmpctx, struct amount_sat, &fee));
mvt = new_coin_withdrawal_sat(ctx, "wallet", txid, txid,
i, blockheight, outval, BTC);
notify_chain_mvt(ld, mvt);
}
@ -735,15 +722,9 @@ static void record_tx_outs_and_fees(struct lightningd *ld, const struct bitcoin_
* fees logged here, to the 'wallet' account (for funding tx).
* You can do this in post by accounting for any 'chain_fees' logged for
* the funding txid when looking at a channel. */
mvt = new_chain_coin_mvt_sat(ctx, "wallet", txid,
NULL, 0, NULL, blockheight,
CHAIN_FEES, fee, false, BTC);
if (!mvt)
fatal("unable to convert %s to msat",
type_to_string(tmpctx, struct amount_sat, &fee));
notify_chain_mvt(ld, mvt);
notify_chain_mvt(ld,
new_coin_chain_fees_sat(ctx, "wallet", txid,
blockheight, fee, BTC));
tal_free(ctx);
}

29
lightningd/channel_control.c

@ -100,15 +100,11 @@ static void record_channel_open(struct channel *channel)
/* if we pushed sats, we should decrement that from the channel balance */
if (amount_msat_greater(channel->push, AMOUNT_MSAT(0))) {
mvt = new_chain_coin_mvt(ctx,
type_to_string(tmpctx,
struct channel_id,
&channel_id),
&channel->funding_txid,
NULL, 0, NULL,
blockheight,
PUSHED, channel->push,
false, BTC);
mvt = new_coin_pushed(ctx, type_to_string(tmpctx,
struct channel_id,
&channel_id),
&channel->funding_txid,
blockheight, channel->push, BTC);
notify_chain_mvt(channel->peer->ld, mvt);
}
} else {
@ -118,15 +114,12 @@ static void record_channel_open(struct channel *channel)
channel_open_amt = channel->our_msat;
}
mvt = new_chain_coin_mvt(ctx,
type_to_string(tmpctx, struct channel_id,
&channel_id),
&channel->funding_txid,
&channel->funding_txid,
channel->funding_outnum,
NULL, blockheight,
DEPOSIT, channel_open_amt,
true, BTC);
mvt = new_coin_deposit(ctx,
type_to_string(tmpctx, struct channel_id,
&channel_id),
&channel->funding_txid,
channel->funding_outnum,
blockheight, channel_open_amt, BTC);
notify_chain_mvt(channel->peer->ld, mvt);
tal_free(ctx);
}

6
lightningd/onchain_control.c

@ -341,9 +341,9 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg)
outpointfilter_add(channel->peer->ld->wallet->owned_outpoints, &u->txid, u->outnum);
wallet_add_utxo(channel->peer->ld->wallet, u, p2wpkh);
mvt = new_chain_coin_mvt_sat(msg, "wallet", &u->txid, &u->txid,
u->outnum, NULL, blockheight,
DEPOSIT, u->amount, true, BTC);
mvt = new_coin_deposit_sat(msg, "wallet", &u->txid,
u->outnum, blockheight,
u->amount, BTC);
notify_chain_mvt(channel->peer->ld, mvt);
}

126
onchaind/onchaind.c

@ -123,7 +123,7 @@ struct tracked_output {
const struct chainparams *chainparams;
/* stashed so we can pass it along to the coin ledger */
struct sha256 *payment_hash;
struct sha256 payment_hash;
};
static void send_coin_mvt(struct chain_coin_mvt *mvt TAKES)
@ -142,12 +142,9 @@ static void record_their_successful_cheat(const struct bitcoin_txid *txid,
struct chain_coin_mvt *mvt;
/* They successfully spent a delayed_to_them output
* that we were expecting to revoke */
mvt = new_chain_coin_mvt_sat(NULL, NULL,
txid, &out->txid,
out->outnum, NULL,
blockheight, PENALTY,
out->sat, false,
BTC);
mvt = new_coin_penalty_sat(NULL, NULL,
txid, &out->txid, out->outnum,
blockheight, out->sat, BTC);
send_coin_mvt(take(mvt));
}
@ -164,14 +161,10 @@ static void record_htlc_fulfilled(const struct bitcoin_txid *txid,
*
* since we really don't know if this was a 'routed' or 'destination'
* htlc here, we record it as a 'deposit/withdrawal' type */
mvt = new_chain_coin_mvt_sat(NULL, NULL,
txid, &out->txid,
out->outnum,
out->payment_hash,
blockheight,
ONCHAIN_HTLC,
out->sat, we_fulfilled,
BTC);
mvt = new_coin_onchain_htlc_sat(NULL, NULL, txid, &out->txid,
out->outnum, out->payment_hash,
blockheight, out->sat, we_fulfilled,
BTC);
send_coin_mvt(take(mvt));
}
@ -180,14 +173,8 @@ static void update_ledger_chain_fees_msat(const struct bitcoin_txid *txid,
u32 blockheight,
struct amount_msat fees)
{
struct chain_coin_mvt *mvt;
mvt = new_chain_coin_mvt(NULL, NULL,
txid, NULL, 0, NULL,
blockheight,
CHAIN_FEES, fees,
false, BTC);
send_coin_mvt(take(mvt));
send_coin_mvt(take(new_coin_chain_fees(NULL, NULL, txid,
blockheight, fees, BTC)));
}
static void update_ledger_chain_fees(const struct bitcoin_txid *txid,
@ -195,17 +182,9 @@ static void update_ledger_chain_fees(const struct bitcoin_txid *txid,
struct amount_sat fees)
{
struct chain_coin_mvt *mvt;
mvt = new_chain_coin_mvt_sat(NULL, NULL,
txid, NULL, 0, NULL,
blockheight,
CHAIN_FEES, fees,
false, BTC);
mvt = new_coin_chain_fees_sat(NULL, NULL, txid,
blockheight, fees, BTC);
if (!mvt)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"unable to convert %s to msat",
type_to_string(tmpctx, struct amount_sat,
&fees));
send_coin_mvt(take(mvt));
}
@ -241,7 +220,6 @@ static void record_mutual_closure(const struct bitcoin_txid *txid,
int output_num)
{
struct amount_msat chain_fees, output_msat;
struct chain_coin_mvt *mvt;
/* First figure out 'fees' we paid on this will include
* - 'residue' that can't fit onchain (< 1 sat)
@ -271,13 +249,8 @@ static void record_mutual_closure(const struct bitcoin_txid *txid,
assert(output_num > -1);
/* Otherwise, we record the channel withdrawal */
mvt = new_chain_coin_mvt(NULL, NULL, txid,
txid, output_num, NULL,
blockheight,
WITHDRAWAL, output_msat,
false, BTC);
send_coin_mvt(take(mvt));
send_coin_mvt(take(new_coin_withdrawal(NULL, NULL, txid, txid, output_num,
blockheight, output_msat, BTC)));
}
static void record_chain_fees_unilateral(const struct bitcoin_txid *txid,
@ -301,7 +274,6 @@ static void record_chain_fees_unilateral(const struct bitcoin_txid *txid,
* that down in the chain fees :/ */
if (!amount_msat_greater_eq_sat(our_msat, our_outs)) {
struct amount_msat missing;
struct chain_coin_mvt *mvt;
if (!amount_sat_sub_msat(&missing, our_outs, our_msat))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
@ -312,12 +284,10 @@ static void record_chain_fees_unilateral(const struct bitcoin_txid *txid,
&our_outs));
/* Log the difference and update our_msat */
mvt = new_chain_coin_mvt(NULL, NULL,
txid, NULL, 0, NULL,
blockheight,
JOURNAL, missing,
true, BTC);
send_coin_mvt(take(mvt));
send_coin_mvt(take(new_coin_journal_entry(NULL, NULL, txid,
NULL, 0, blockheight,
missing,
true, BTC)));
if (!amount_msat_add(&our_msat, our_msat, missing))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"unable to add %s to %s",
@ -349,18 +319,9 @@ static void record_coin_loss(const struct bitcoin_txid *txid,
struct chain_coin_mvt *mvt;
/* We don't for sure know that it's a 'penalty'
* but we write it as that anyway... */
mvt = new_chain_coin_mvt_sat(NULL, NULL,
txid, &out->txid,
out->outnum, NULL,
blockheight,
PENALTY, out->sat, false,
BTC);
if (!mvt)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"unable to convert %s to msat",
type_to_string(tmpctx, struct amount_sat,
&out->sat));
mvt = new_coin_penalty_sat(NULL, NULL, txid, &out->txid,
out->outnum, blockheight, out->sat,
BTC);
send_coin_mvt(take(mvt));
}
@ -370,7 +331,6 @@ static void record_channel_withdrawal_minus_fees(const struct bitcoin_txid *tx_t
u32 blockheight,
struct amount_sat fees)
{
struct chain_coin_mvt *mvt;
struct amount_sat emitted_amt;
if (!amount_sat_sub(&emitted_amt, out->sat, fees))
@ -381,20 +341,10 @@ static void record_channel_withdrawal_minus_fees(const struct bitcoin_txid *tx_t
type_to_string(tmpctx, struct amount_sat,
&out->sat));
mvt = new_chain_coin_mvt_sat(NULL, NULL,
tx_txid, &out->txid,
out->outnum, NULL,
blockheight, WITHDRAWAL,
emitted_amt, false,
BTC);
if (!mvt)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"unable to convert %s to msat",
type_to_string(tmpctx, struct amount_sat,
&out->sat));
send_coin_mvt(take(mvt));
send_coin_mvt(take(new_coin_withdrawal_sat(
NULL, NULL, tx_txid, &out->txid,
out->outnum, blockheight,
emitted_amt, BTC)));
}
@ -1288,7 +1238,7 @@ static void handle_htlc_onchain_fulfill(struct tracked_output *out,
/* we stash the payment_hash into the tracking_output so we
* can pass it along, if needbe, to the coin movement tracker */
out->payment_hash = tal_dup(out, struct sha256, &sha);
out->payment_hash = sha;
/* Tell master we found a preimage. */
status_debug("%s/%s gave us preimage %s",
@ -1714,7 +1664,7 @@ static void handle_preimage(const struct chainparams *chainparams,
}
/* stash the payment_hash so we can track this coin movement */
outs[i]->payment_hash = tal_dup(outs[i], struct sha256, &sha);
outs[i]->payment_hash = sha;
/* Discard any previous resolution. Could be a timeout,
* could be due to multiple identical rhashes in tx. */
@ -2543,7 +2493,6 @@ static void update_ledger_cheat(const struct bitcoin_txid *txid,
/* how much of a difference should we update the
* channel account ledger by? */
struct amount_msat amt;
struct chain_coin_mvt *mvt;
if (amount_msat_eq_sat(our_msat, out->sat))
return;
@ -2558,13 +2507,10 @@ static void update_ledger_cheat(const struct bitcoin_txid *txid,
/* add the difference to our ledger balance */
/* FIXME: elements is not always btc? */
mvt = new_chain_coin_mvt(NULL, NULL,
txid, &out->txid,
out->outnum, NULL,
blockheight,
JOURNAL, amt,
true, BTC);
send_coin_mvt(take(mvt));
send_coin_mvt(take(new_coin_journal_entry(NULL, NULL, txid,
&out->txid, out->outnum,
blockheight, amt,
true, BTC)));
}
/* BOLT #5:
@ -3107,7 +3053,6 @@ static void update_ledger_unknown(const struct bitcoin_txid *txid,
* and our current channel balance as a loss (or gain) */
bool is_credit;
struct amount_msat diff;
struct chain_coin_mvt *mvt;
/* we do nothing if the amount withdrawn via 'salvage' is
* the same as our channel balance */
@ -3129,12 +3074,9 @@ static void update_ledger_unknown(const struct bitcoin_txid *txid,
is_credit = true;
/* FIXME: elements txs not in BTC ?? */
mvt = new_chain_coin_mvt(NULL, NULL,
txid, NULL, 0, NULL,
blockheight,
JOURNAL, diff,
is_credit, BTC);
send_coin_mvt(take(mvt));
send_coin_mvt(take(new_coin_journal_entry(NULL, NULL, txid, NULL, 0,
blockheight, diff,
is_credit, BTC)));
}
static void handle_unknown_commitment(const struct bitcoin_tx *tx,

82
onchaind/test/run-grind_feerate-bug.c

@ -97,32 +97,74 @@ void memleak_remove_referenced(struct htable *memtable UNNEEDED, const void *roo
void memleak_scan_region(struct htable *memtable UNNEEDED,
const void *p UNNEEDED, size_t bytelen UNNEEDED)
{ fprintf(stderr, "memleak_scan_region called!\n"); abort(); }
/* Generated stub for new_chain_coin_mvt */
struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx UNNEEDED,
/* Generated stub for new_coin_chain_fees */
struct chain_coin_mvt *new_coin_chain_fees(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_msat amount UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_chain_fees called!\n"); abort(); }
/* Generated stub for new_coin_chain_fees_sat */
struct chain_coin_mvt *new_coin_chain_fees_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_sat amount UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_chain_fees_sat called!\n"); abort(); }
/* Generated stub for new_coin_journal_entry */
struct chain_coin_mvt *new_coin_journal_entry(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED,
const struct bitcoin_txid *out_txid UNNEEDED,
u32 vout UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_msat amount UNNEEDED,
bool is_credit UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_journal_entry called!\n"); abort(); }
/* Generated stub for new_coin_onchain_htlc_sat */
struct chain_coin_mvt *new_coin_onchain_htlc_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED,
const struct bitcoin_txid *out_txid UNNEEDED,
u32 vout UNNEEDED, struct sha256 payment_hash UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_sat amount UNNEEDED,
bool is_credit UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_onchain_htlc_sat called!\n"); abort(); }
/* Generated stub for new_coin_penalty_sat */
struct chain_coin_mvt *new_coin_penalty_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED,
const struct bitcoin_txid *out_txid UNNEEDED,
u32 vout UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_sat amount UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_penalty_sat called!\n"); abort(); }
/* Generated stub for new_coin_withdrawal */
struct chain_coin_mvt *new_coin_withdrawal(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
const struct bitcoin_txid *output_txid UNNEEDED,
const struct bitcoin_txid *out_txid UNNEEDED,
u32 vout UNNEEDED,
struct sha256 *payment_hash UNNEEDED,
u32 blockheight UNNEEDED,
enum mvt_tag tag UNNEEDED,
struct amount_msat amount UNNEEDED,
bool is_credit UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_chain_coin_mvt called!\n"); abort(); }
/* Generated stub for new_chain_coin_mvt_sat */
struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
const struct bitcoin_txid *output_txid UNNEEDED,
u32 vout UNNEEDED,
struct sha256 *payment_hash UNNEEDED,
u32 blockheight UNNEEDED,
enum mvt_tag tag UNNEEDED,
struct amount_sat amt_sat UNNEEDED,
bool is_credit UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_chain_coin_mvt_sat called!\n"); abort(); }
{ fprintf(stderr, "new_coin_withdrawal called!\n"); abort(); }
/* Generated stub for new_coin_withdrawal_sat */
struct chain_coin_mvt *new_coin_withdrawal_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
const struct bitcoin_txid *out_txid UNNEEDED,
u32 vout UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_sat amount UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_withdrawal_sat called!\n"); abort(); }
/* Generated stub for notleak_ */
void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED)
{ fprintf(stderr, "notleak_ called!\n"); abort(); }

82
onchaind/test/run-grind_feerate.c

@ -109,32 +109,74 @@ void memleak_remove_referenced(struct htable *memtable UNNEEDED, const void *roo
void memleak_scan_region(struct htable *memtable UNNEEDED,
const void *p UNNEEDED, size_t bytelen UNNEEDED)
{ fprintf(stderr, "memleak_scan_region called!\n"); abort(); }
/* Generated stub for new_chain_coin_mvt */
struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx UNNEEDED,
/* Generated stub for new_coin_chain_fees */
struct chain_coin_mvt *new_coin_chain_fees(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_msat amount UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_chain_fees called!\n"); abort(); }
/* Generated stub for new_coin_chain_fees_sat */
struct chain_coin_mvt *new_coin_chain_fees_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_sat amount UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_chain_fees_sat called!\n"); abort(); }
/* Generated stub for new_coin_journal_entry */
struct chain_coin_mvt *new_coin_journal_entry(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED,
const struct bitcoin_txid *out_txid UNNEEDED,
u32 vout UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_msat amount UNNEEDED,
bool is_credit UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_journal_entry called!\n"); abort(); }
/* Generated stub for new_coin_onchain_htlc_sat */
struct chain_coin_mvt *new_coin_onchain_htlc_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED,
const struct bitcoin_txid *out_txid UNNEEDED,
u32 vout UNNEEDED, struct sha256 payment_hash UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_sat amount UNNEEDED,
bool is_credit UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_onchain_htlc_sat called!\n"); abort(); }
/* Generated stub for new_coin_penalty_sat */
struct chain_coin_mvt *new_coin_penalty_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED,
const struct bitcoin_txid *out_txid UNNEEDED,
u32 vout UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_sat amount UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_penalty_sat called!\n"); abort(); }
/* Generated stub for new_coin_withdrawal */
struct chain_coin_mvt *new_coin_withdrawal(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
const struct bitcoin_txid *output_txid UNNEEDED,
const struct bitcoin_txid *out_txid UNNEEDED,
u32 vout UNNEEDED,
struct sha256 *payment_hash UNNEEDED,
u32 blockheight UNNEEDED,
enum mvt_tag tag UNNEEDED,
struct amount_msat amount UNNEEDED,
bool is_credit UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_chain_coin_mvt called!\n"); abort(); }
/* Generated stub for new_chain_coin_mvt_sat */
struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
const struct bitcoin_txid *output_txid UNNEEDED,
u32 vout UNNEEDED,
struct sha256 *payment_hash UNNEEDED,
u32 blockheight UNNEEDED,
enum mvt_tag tag UNNEEDED,
struct amount_sat amt_sat UNNEEDED,
bool is_credit UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_chain_coin_mvt_sat called!\n"); abort(); }
{ fprintf(stderr, "new_coin_withdrawal called!\n"); abort(); }
/* Generated stub for new_coin_withdrawal_sat */
struct chain_coin_mvt *new_coin_withdrawal_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
const struct bitcoin_txid *out_txid UNNEEDED,
u32 vout UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_sat amount UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_withdrawal_sat called!\n"); abort(); }
/* Generated stub for notleak_ */
void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED)
{ fprintf(stderr, "notleak_ called!\n"); abort(); }

22
wallet/test/run-wallet.c

@ -384,19 +384,6 @@ bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
void kill_uncommitted_channel(struct uncommitted_channel *uc UNNEEDED,
const char *why UNNEEDED)
{ fprintf(stderr, "kill_uncommitted_channel called!\n"); abort(); }
/* Generated stub for new_chain_coin_mvt_sat */
struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *tx_txid UNNEEDED,
const struct bitcoin_txid *output_txid UNNEEDED,
u32 vout UNNEEDED,
struct sha256 *payment_hash UNNEEDED,
u32 blockheight UNNEEDED,
enum mvt_tag tag UNNEEDED,
struct amount_sat amt_sat UNNEEDED,
bool is_credit UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_chain_coin_mvt_sat called!\n"); abort(); }
/* Generated stub for new_channel_mvt_invoice_hin */
struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx UNNEEDED,
struct htlc_in *hin UNNEEDED,
@ -417,6 +404,15 @@ struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx UNNEEDED,
struct htlc_out *hout UNNEEDED,
struct channel *channel UNNEEDED)
{ fprintf(stderr, "new_channel_mvt_routed_hout called!\n"); abort(); }
/* Generated stub for new_coin_deposit_sat */
struct chain_coin_mvt *new_coin_deposit_sat(const tal_t *ctx UNNEEDED,
const char *account_name UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED,
u32 vout UNNEEDED,
u32 blockheight UNNEEDED,
struct amount_sat amount UNNEEDED,
enum mvt_unit_type unit UNNEEDED)
{ fprintf(stderr, "new_coin_deposit_sat called!\n"); abort(); }
/* Generated stub for notify_chain_mvt */
void notify_chain_mvt(struct lightningd *ld UNNEEDED, const struct chain_coin_mvt *mvt UNNEEDED)
{ fprintf(stderr, "notify_chain_mvt called!\n"); abort(); }

8
wallet/wallet.c

@ -1696,11 +1696,9 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
/* We only record final ledger movements */
if (blockheight) {
mvt = new_chain_coin_mvt_sat(utxo, "wallet", &utxo->txid,
&utxo->txid, utxo->outnum, NULL,
blockheight ? *blockheight : 0,
DEPOSIT, utxo->amount,
true, BTC);
mvt = new_coin_deposit_sat(utxo, "wallet", &utxo->txid, utxo->outnum,
blockheight ? *blockheight : 0,
utxo->amount, BTC);
notify_chain_mvt(w->ld, mvt);
}

Loading…
Cancel
Save