Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9d76481
pytest: test for splicing while channel is not announced yet.
rustyrussell Sep 18, 2025
40675ff
lightningd: cancel watching original funding when we switch to the ne…
rustyrussell Sep 18, 2025
57e27bf
lightningd: fix crash in channel_control.
rustyrussell Sep 18, 2025
4c54f5a
pytest: add test that we notice height change of sendpsbt with no cha…
rustyrussell Sep 19, 2025
3494849
wallet: make sure to watch all txids in transactions table.
rustyrussell Sep 19, 2025
20b79f7
memleak: make notleak() work even before memleak is initalized.
rustyrussell Sep 19, 2025
faa4b6f
common: add new_htable() macro to allocate, initialize and setup meml…
rustyrussell Sep 19, 2025
768835e
lightningd: try harder to ensure uniqueness in --dev-save-plugin-io n…
rustyrussell Sep 19, 2025
3b4bea8
bitcoin: remove unused scriptpubkey_opreturn_padded.
rustyrussell Sep 19, 2025
66cfba5
autogenerate-rpc-examples.py: add examples for listchainmoves and lis…
rustyrussell Sep 19, 2025
b587b44
lightningd: remove unused `start_time` field in bitcoind_getfilteredb…
rustyrussell Sep 19, 2025
5b920e5
tests: use timemono not time_now() for duration measurement.
rustyrussell Sep 19, 2025
becfedf
lightningd: fix scb remote_to_self_delay information.
rustyrussell Sep 19, 2025
930e2ec
common: add randbytes() wrapper to override cryptographic entropy: $C…
rustyrussell Sep 19, 2025
c4a4a82
global: replace randombytes_buf() with randbytes() wrapper.
rustyrussell Sep 19, 2025
e119584
pseudorand: make the results in deterministic mode per-caller.
rustyrussell Sep 19, 2025
030cfca
gossipd: remove --dev-gossip-time setting, we'll use CLN_DEV_SET_TIME.
rustyrussell Sep 19, 2025
9f874a6
connectd, gossipd, pay, bcli: use timemono when solely measuring dura…
rustyrussell Sep 19, 2025
492f13b
common/clock_time: wrapper for time_now() so we can override it.
rustyrussell Sep 19, 2025
286de30
global: use clock_time in place of time_now().
rustyrussell Sep 19, 2025
5e8c7f2
lightningd: introduce some changes for dual open id randomness even w…
rustyrussell Sep 19, 2025
be00be5
wallet: make utxo order deterministic if CLN_DEV_ENTROPY_SEED set.
rustyrussell Sep 19, 2025
f049240
topology: in deterministic mode, only return one best candidate for l…
rustyrussell Sep 19, 2025
af8cbc0
lightningd: add --dev-ignore-idb to not complain about bitcoind in in…
rustyrussell Sep 19, 2025
49c4b0f
pyln-testing: introduce canned blocks support to bitcoind fixture.
rustyrussell Sep 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ check-tmpctx:
@if git grep -n 'tal_free[(]tmpctx)' | grep -Ev '^ccan/|/test/|^common/setup.c:|^common/utils.c:'; then echo "Don't free tmpctx!">&2; exit 1; fi

check-discouraged-functions:
@if git grep -E "[^a-z_/](fgets|fputs|gets|scanf|sprintf)\(" -- "*.c" "*.h" ":(exclude)ccan/" ":(exclude)contrib/"; then exit 1; fi
@if git grep -nE "[^a-z_/](fgets|fputs|gets|scanf|sprintf|randombytes_buf|time_now)\(" -- "*.c" "*.h" ":(exclude)ccan/" ":(exclude)contrib/" | grep -Fv '/* discouraged:'; then exit 1; fi

# Don't access amount_msat and amount_sat members directly without a good reason
# since it risks overflow.
Expand Down
11 changes: 0 additions & 11 deletions bitcoin/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,6 @@ u8 *scriptpubkey_p2pkh(const tal_t *ctx, const struct bitcoin_address *addr)
return script;
}

u8 *scriptpubkey_opreturn_padded(const tal_t *ctx)
{
u8 *script = tal_arr(ctx, u8, 0);
u8 random[20];
randombytes_buf(random, sizeof(random));

add_op(&script, OP_RETURN);
script_push_bytes(&script, random, sizeof(random));
return script;
}

/* Create an input script which spends p2pkh */
u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey,
const struct bitcoin_signature *sig)
Expand Down
6 changes: 0 additions & 6 deletions bitcoin/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ u8 *scriptpubkey_p2sh_hash(const tal_t *ctx, const struct ripemd160 *redeemhash)
/* Create an output script using p2pkh */
u8 *scriptpubkey_p2pkh(const tal_t *ctx, const struct bitcoin_address *addr);

/* Create a prunable output script with 20 random bytes.
* This is needed since a spend from a p2wpkh to an `OP_RETURN` without
* any other outputs would result in a transaction smaller than the
* minimum size. */
u8 *scriptpubkey_opreturn_padded(const tal_t *ctx);

/* Create an input script which spends p2pkh */
u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey,
const struct bitcoin_signature *sig);
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/short_channel_id.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "config.h"
#include <bitcoin/short_channel_id.h>
#include <ccan/tal/str/str.h>
#include <sodium/randombytes.h>
#include <common/randbytes.h>
#include <stdio.h>
#include <wire/wire.h>

Expand Down Expand Up @@ -104,6 +104,6 @@ struct short_channel_id fromwire_short_channel_id(const u8 **cursor, size_t *max
struct short_channel_id random_scid(void)
{
struct short_channel_id scid;
randombytes_buf(&scid, sizeof(scid));
randbytes(&scid, sizeof(scid));
return scid;
}
2 changes: 1 addition & 1 deletion bitcoin/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ BITCOIN_TEST_SRC := $(wildcard bitcoin/test/run-*.c)
BITCOIN_TEST_OBJS := $(BITCOIN_TEST_SRC:.c=.o)
BITCOIN_TEST_PROGRAMS := $(BITCOIN_TEST_OBJS:.o=)

BITCOIN_TEST_COMMON_OBJS := common/utils.o common/setup.o common/autodata.o
BITCOIN_TEST_COMMON_OBJS := common/utils.o common/setup.o common/autodata.o common/clock_time.o

$(BITCOIN_TEST_PROGRAMS): $(BITCOIN_TEST_COMMON_OBJS) bitcoin/chainparams.o
$(BITCOIN_TEST_OBJS): $(CCAN_HEADERS) $(BITCOIN_HEADERS) $(BITCOIN_SRC)
Expand Down
16 changes: 8 additions & 8 deletions bitcoin/test/run-secret_eq_consttime.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static struct timerel const_time_test(struct secret *s1,
struct secret *s2,
size_t off)
{
struct timeabs start, end;
struct timemono start, end;
int result = 0;

memset(s1, 0, RUNS * sizeof(*s1));
Expand All @@ -31,16 +31,16 @@ static struct timerel const_time_test(struct secret *s1,
for (size_t i = 0; i < RUNS; i++)
s2[i].data[off] = i;

start = time_now();
start = time_mono();
for (size_t i = 0; i < RUNS; i++)
result += secret_eq_consttime(&s1[i], &s2[i]);
end = time_now();
end = time_mono();

if (result != RUNS / 256)
errx(1, "Expected %u successes at offset %zu, not %u!",
RUNS / 256, off, result);

return time_between(end, start);
return timemono_between(end, start);
}

static inline bool secret_eq_nonconst(const struct secret *a,
Expand All @@ -53,7 +53,7 @@ static struct timerel nonconst_time_test(struct secret *s1,
struct secret *s2,
size_t off)
{
struct timeabs start, end;
struct timemono start, end;
int result = 0;

memset(s1, 0, RUNS * sizeof(*s1));
Expand All @@ -62,16 +62,16 @@ static struct timerel nonconst_time_test(struct secret *s1,
for (size_t i = 0; i < RUNS; i++)
s2[i].data[off] = i;

start = time_now();
start = time_mono();
for (size_t i = 0; i < RUNS; i++)
result += secret_eq_nonconst(&s1[i], &s2[i]);
end = time_now();
end = time_mono();

if (result != RUNS / 256)
errx(1, "Expected %u successes at offset %zu, not %u!",
RUNS / 256, off, result);

return time_between(end, start);
return timemono_between(end, start);
}

static struct secret *s1, *s2;
Expand Down
2 changes: 2 additions & 0 deletions channeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ CHANNELD_COMMON_OBJS := \
common/channel_config.o \
common/channel_id.o \
common/channel_type.o \
common/clock_time.o \
common/cryptomsg.o \
common/daemon.o \
common/daemon_conn.o \
Expand Down Expand Up @@ -84,6 +85,7 @@ CHANNELD_COMMON_OBJS := \
common/psbt_open.o \
common/psbt_internal.o \
common/pseudorand.o \
common/randbytes.o \
common/read_peer_msg.o \
common/setup.o \
common/status.o \
Expand Down
14 changes: 3 additions & 11 deletions channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
/* Needs to be at end, since it doesn't include its own hdrs */
#include "full_channel_error_names_gen.h"

static void memleak_help_htlcmap(struct htable *memtable,
struct htlc_map *htlcs)
{
memleak_scan_htable(memtable, &htlcs->raw);
}

/* This is a dangerous thing! Because we apply HTLCs in many places
* in bulk, we can temporarily go negative. You must check balance_ok()
* at the end! */
Expand Down Expand Up @@ -113,11 +107,9 @@ struct channel *new_full_channel(const tal_t *ctx,
option_wumbo,
opener);

if (channel) {
channel->htlcs = tal(channel, struct htlc_map);
htlc_map_init(channel->htlcs);
memleak_add_helper(channel->htlcs, memleak_help_htlcmap);
}
if (channel)
channel->htlcs = new_htable(channel, htlc_map);

return channel;
}

Expand Down
1 change: 1 addition & 0 deletions channeld/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CHANNELD_TEST_COMMON_OBJS := \
common/msg_queue.o \
common/permute_tx.o \
common/pseudorand.o \
common/randbytes.o \
common/setup.o \
common/utils.o

Expand Down
1 change: 1 addition & 0 deletions channeld/test/run-commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static bool print_superverbose;
#include <common/channel_id.h>
#include <common/daemon.h>
#include <common/key_derive.h>
#include <common/memleak.h>
#include <common/setup.h>
#include <common/status.h>

Expand Down
1 change: 1 addition & 0 deletions cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LIGHTNING_CLI_COMMON_OBJS := \
common/configdir.o \
common/configvar.o \
common/json_parse_simple.o \
common/memleak.o \
common/status_levels.o \
common/utils.o \
common/version.o
Expand Down
1 change: 1 addition & 0 deletions cli/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CLI_TEST_COMMON_OBJS := \
common/htlc_state.o \
common/json_parse_simple.o \
common/pseudorand.o \
common/randbytes.o \
common/memleak.o \
common/msg_queue.o \
common/setup.o \
Expand Down
2 changes: 2 additions & 0 deletions closingd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CLOSINGD_COMMON_OBJS := \
common/bigsize.o \
common/bip32.o \
common/channel_id.o \
common/clock_time.o \
common/close_tx.o \
common/cryptomsg.o \
common/daemon.o \
Expand All @@ -47,6 +48,7 @@ CLOSINGD_COMMON_OBJS := \
common/psbt_keypath.o \
common/psbt_open.o \
common/pseudorand.o \
common/randbytes.o \
common/status_wiregen.o \
common/read_peer_msg.o \
common/setup.o \
Expand Down
2 changes: 2 additions & 0 deletions common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ COMMON_SRC_NOGEN := \
common/channel_config.c \
common/channel_id.c \
common/channel_type.c \
common/clock_time.c \
common/close_tx.c \
common/codex32.c \
common/coin_mvt.c \
Expand Down Expand Up @@ -85,6 +86,7 @@ COMMON_SRC_NOGEN := \
common/psbt_keypath.c \
common/psbt_open.c \
common/pseudorand.c \
common/randbytes.c \
common/random_select.c \
common/read_peer_msg.c \
common/route.c \
Expand Down
2 changes: 1 addition & 1 deletion common/blindedpath.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct tlv_encrypted_data_tlv_payment_relay;
* @next_path_privkey: (out) e(i+1), the next blinding secret (optional)
* @node_alias: (out) the blinded pubkey of the node to tell the recipient.
*
* You create a blinding secret using randombytes_buf(), then call this
* You create a blinding secret using randbytes(), then call this
* iteratively for each node in the path.
*/
u8 *encrypt_tlv_encrypted_data(const tal_t *ctx,
Expand Down
36 changes: 36 additions & 0 deletions common/clock_time.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "config.h"
#include <assert.h>
#include <common/clock_time.h>

static bool used = false;
static struct timeabs dev_override;

bool clock_time_overridden(void)
{
return dev_override.ts.tv_sec != 0;
}

struct timeabs clock_time(void)
{
used = true;
if (!clock_time_overridden())
return time_now(); /* discouraged: use clock_time so we can override */

return dev_override;
}

struct timeabs clock_time_progresses_(u64 *progress)
{
if (!clock_time_overridden())
return clock_time();

return timeabs_add(dev_override, time_from_sec((*progress)++));
}

void dev_override_clock_time(struct timeabs now)
{
assert(!used);

dev_override = now;
assert(clock_time_overridden());
}
19 changes: 19 additions & 0 deletions common/clock_time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef LIGHTNING_COMMON_CLOCK_TIME_H
#define LIGHTNING_COMMON_CLOCK_TIME_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/time/time.h>

/* We use this instead of time_now, for overriding when we want reproducibility */
struct timeabs clock_time(void);

/* If you need a clock that progresses even when reproducible, use this. */
#define clock_time_progresses() ({static u64 progress; clock_time_progresses_(&progress);})
struct timeabs clock_time_progresses_(u64 *progress);

/* dev setting to override time */
void dev_override_clock_time(struct timeabs now);

/* Did someone override time? */
bool clock_time_overridden(void);
#endif /* LIGHTNING_COMMON_CLOCK_TIME_H */
24 changes: 17 additions & 7 deletions common/coin_mvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <ccan/bitops/bitops.h>
#include <ccan/ccan/cast/cast.h>
#include <ccan/tal/str/str.h>
#include <ccan/time/time.h>
#include <common/clock_time.h>
#include <common/coin_mvt.h>
#include <common/node_id.h>
#include <wire/wire.h>
Expand Down Expand Up @@ -154,6 +154,12 @@ static enum mvt_tag mvt_tag_in_db(enum mvt_tag mvt_tag)
abort();
}

/* This puts the coin movements in order */
u64 coinmvt_current_time(void)
{
return clock_time_progresses().ts.tv_sec;
}

const char *mvt_tag_str(enum mvt_tag tag)
{
assert((unsigned)tag < NUM_MVT_TAGS);
Expand Down Expand Up @@ -337,7 +343,7 @@ static struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx,
assert(ok);

return new_chain_coin_mvt(ctx, channel, account_name,
time_now().ts.tv_sec, tx_txid,
coinmvt_current_time(), tx_txid,
outpoint, payment_hash,
blockheight, tags, direction, amt_msat,
/* All amounts that are sat are
Expand Down Expand Up @@ -392,7 +398,7 @@ struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx,
tags = mk_mvt_tags(MVT_CHANNEL_CLOSE);

mvt = new_chain_coin_mvt(ctx, channel, alt_account,
time_now().ts.tv_sec, txid,
coinmvt_current_time(), txid,
out, NULL, blockheight,
tags,
COIN_DEBIT, amount,
Expand Down Expand Up @@ -420,7 +426,7 @@ struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx,
if (is_leased)
mvt_tag_set(&tags, MVT_LEASED);

mvt = new_chain_coin_mvt(ctx, channel, NULL, time_now().ts.tv_sec,
mvt = new_chain_coin_mvt(ctx, channel, NULL, coinmvt_current_time(),
NULL, out, NULL, 0,
tags,
COIN_CREDIT, amount, output_val, 0);
Expand Down Expand Up @@ -473,7 +479,7 @@ struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx,
bool is_leased)
{
return new_coin_channel_open_general(ctx, channel, NULL,
time_now().ts.tv_sec,
coinmvt_current_time(),
out, peer_id, blockheight,
amount, output_val, is_opener, is_leased);
}
Expand Down Expand Up @@ -515,7 +521,7 @@ struct chain_coin_mvt *new_coin_external_spend(const tal_t *ctx,
struct mvt_tags tags)
{
return new_chain_coin_mvt(ctx, NULL, ACCOUNT_NAME_EXTERNAL,
time_now().ts.tv_sec, txid,
coinmvt_current_time(), txid,
outpoint, NULL, blockheight,
tags,
COIN_CREDIT, AMOUNT_MSAT(0), amount, 0);
Expand Down Expand Up @@ -583,7 +589,7 @@ struct channel_coin_mvt *new_coin_channel_push(const tal_t *ctx,
struct mvt_tags tags)
{
return new_coin_channel_push_general(ctx, channel, NULL,
time_now().ts.tv_sec,
coinmvt_current_time(),
direction, amount, tags);
}

Expand Down Expand Up @@ -730,6 +736,10 @@ void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_m
} else
mvt->peer_id = NULL;
mvt->timestamp = fromwire_u64(cursor, max);

/* Align onchaind's timestamps with ours if we're deterministic */
if (clock_time_overridden())
mvt->timestamp = coinmvt_current_time();
}

struct mvt_tags mk_mvt_tags_(enum mvt_tag tag, ...)
Expand Down
3 changes: 3 additions & 0 deletions common/coin_mvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,7 @@ bool mvt_tag_parse(const char *buf, size_t len, enum mvt_tag *tag);
void towire_chain_coin_mvt(u8 **pptr, const struct chain_coin_mvt *mvt);
void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_mvt *mvt);

/* Time helper for deterministic timestamps: always moves forwards */
u64 coinmvt_current_time(void);

#endif /* LIGHTNING_COMMON_COIN_MVT_H */
Loading