Skip to content

Commit 2539b4f

Browse files
committed
bookkeeper: save last timestamp to avoid another query in find_consolidated_fees.
If the fees are not *all* of the fees (as we do in next patch), the query would be wrong. Plus, as the FIXME suggests, we should just save it as we're getting the fee_sums, not do a whole new query! Signed-off-by: Rusty Russell <[email protected]>
1 parent 2c02f6d commit 2539b4f

File tree

4 files changed

+5
-28
lines changed

4 files changed

+5
-28
lines changed

plugins/bkpr/incomestmt.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,7 @@ static struct onchain_fee **find_consolidated_fees(const tal_t *ctx,
290290
fee->debit = AMOUNT_MSAT(0);
291291
fee->acct_name = tal_steal(fee, sums[i]->acct_name);
292292
fee->txid = *sums[i]->txid;
293-
294-
fee->timestamp =
295-
onchain_fee_last_timestamp(bkpr, sums[i]->acct_name,
296-
sums[i]->txid);
297-
293+
fee->timestamp = sums[i]->last_timestamp;
298294
tal_arr_expand(&fee_sums, fee);
299295
}
300296

plugins/bkpr/onchain_fee.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,13 @@ static struct fee_sum **fee_sums_by_txid_and_account(const tal_t *ctx,
366366
sum->txid = tal_dup(sum, struct bitcoin_txid,
367367
&ofs[i]->txid);
368368
credit = debit = AMOUNT_MSAT(0);
369+
sum->last_timestamp = 0;
369370
}
370371
ok = amount_msat_accumulate(&credit, ofs[i]->credit);
371372
assert(ok);
372373
ok = amount_msat_accumulate(&debit, ofs[i]->debit);
374+
if (ofs[i]->timestamp > sum->last_timestamp)
375+
sum->last_timestamp = ofs[i]->timestamp;
373376
}
374377

375378
/* Final, if any */
@@ -679,24 +682,6 @@ struct fee_sum **find_account_onchain_fees(const tal_t *ctx,
679682
return fee_sums_by_txid_and_account(ctx, ofs);
680683
}
681684

682-
/* FIXME: Put this value into fee_sums! */
683-
u64 onchain_fee_last_timestamp(const struct bkpr *bkpr,
684-
const char *acct_name,
685-
const struct bitcoin_txid *txid)
686-
{
687-
struct onchain_fee **ofs;
688-
u64 timestamp = 0;
689-
690-
ofs = account_get_chain_fees(tmpctx, bkpr, acct_name);
691-
for (size_t i = 0; i < tal_count(ofs); i++) {
692-
if (!bitcoin_txid_eq(&ofs[i]->txid, txid))
693-
continue;
694-
if (ofs[i]->timestamp > timestamp)
695-
timestamp = ofs[i]->timestamp;
696-
}
697-
return timestamp;
698-
}
699-
700685
/* If we're freeing the entire hash table, remove destructors from
701686
* individual entries! */
702687
static void ofees_hash_destroy(struct ofees_hash *ofees_hash)

plugins/bkpr/onchain_fee.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ struct fee_sum **find_account_onchain_fees(const tal_t *ctx,
6767
struct fee_sum **calculate_onchain_fee_sums(const tal_t *ctx,
6868
const struct bkpr *bkpr);
6969

70-
/* Find the last timestamp for the onchain fees for this txid + account */
71-
u64 onchain_fee_last_timestamp(const struct bkpr *bkpr,
72-
const char *acct_name,
73-
const struct bitcoin_txid *txid);
74-
7570
/* Update our onchain fees now? */
7671
char *maybe_update_onchain_fees(const tal_t *ctx,
7772
struct command *cmd,

plugins/bkpr/recorder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct fee_sum {
1818
const char *acct_name;
1919
struct bitcoin_txid *txid;
2020
struct amount_msat fees_paid;
21+
u64 last_timestamp;
2122
};
2223

2324
struct txo_pair {

0 commit comments

Comments
 (0)