From c8bc78e8ed4770e4c81e55a307a0d737b09a8117 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 24 Apr 2025 06:45:38 +0930 Subject: [PATCH 1/4] CI: enable tracing so we test that code. We have a crash right now, which passed CI! Signed-off-by: Rusty Russell --- .github/scripts/setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/scripts/setup.sh b/.github/scripts/setup.sh index ef7556964c31..cf3d9c9685ee 100755 --- a/.github/scripts/setup.sh +++ b/.github/scripts/setup.sh @@ -54,6 +54,7 @@ sudo apt-get -qq install --no-install-recommends --allow-unauthenticated -yy \ valgrind \ wget \ xsltproc \ + systemtap-sdt-dev \ zlib1g-dev echo "tester ALL=(root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/tester From e3f121967d54d5500c8afd8e4e596d4458163943 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 24 Apr 2025 06:47:31 +0930 Subject: [PATCH 2/4] trace: don't mess up pointers when we reallocate. It's convenient to have pointers, but we have to do fixups. Signed-off-by: Rusty Russell --- common/trace.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/common/trace.c b/common/trace.c index c65d7f374fec..e0cb10620d58 100644 --- a/common/trace.c +++ b/common/trace.c @@ -232,10 +232,28 @@ static struct span *trace_span_slot(void) /* In the unlikely case this fails, double it */ if (!s) { + /* Adjust current and parents when we reallocate! */ + size_t num_active = tal_count(active_spans); + size_t current_off COMPILER_WANTS_INIT("11.4.0-1ubuntu1~22.04 -03"); + size_t parent_off[num_active]; + if (current) + current_off = current - active_spans; + for (size_t i = 0; i < num_active; i++) { + if (!active_spans[i].parent) + continue; + parent_off[i] = active_spans[i].parent - active_spans; + } TRACE_DBG("%u: out of %zu spans, doubling!\n", getpid(), tal_count(active_spans)); tal_resizez(&active_spans, tal_count(active_spans) * 2); s = trace_span_find(0); + if (current) + current = active_spans + current_off; + for (size_t i = 0; i < num_active; i++) { + if (!active_spans[i].parent) + continue; + active_spans[i].parent = active_spans + parent_off[i]; + } } assert(s->parent == NULL); From ec6129ae269779bd541a285420c2dde89864b616 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 24 Apr 2025 06:48:16 +0930 Subject: [PATCH 3/4] trace: prevent memleak report. notleak() doesn't work for lightningd since the first span is created before memleak (or anything else!) is initialized, so we have to mark it manually. Signed-off-by: Rusty Russell --- common/trace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/trace.c b/common/trace.c index e0cb10620d58..eade3171f790 100644 --- a/common/trace.c +++ b/common/trace.c @@ -184,10 +184,15 @@ static inline void trace_check_tree(void) {} static void trace_init(void) { const char *dev_trace_file; + const char notleak_name[] = "struct span **NOTLEAK**"; + if (active_spans) return; - active_spans = notleak(tal_arrz(NULL, struct span, 1)); + active_spans = tal_arrz(NULL, struct span, 1); + /* We're usually too early for memleak to be initialized, so mark + * this notleak manually! */ + tal_set_name(active_spans, notleak_name); current = NULL; dev_trace_file = getenv("CLN_DEV_TRACE_FILE"); From 1d69d9cc728718c3e2e0f232ca4a4441a4d4216f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 24 Apr 2025 13:44:50 +0930 Subject: [PATCH 4/4] bkpr: fix unittest when HAVE_USDT=1 ``` pseudorand_u64 called! Aborted (core dumped) make: *** [Makefile:786: unittest/plugins/bkpr/test/run-bkpr_db] Error 134 ``` Signed-off-by: Rusty Russell --- lightningd/test/run-find_my_abspath.c | 3 --- plugins/bkpr/test/Makefile | 1 + plugins/bkpr/test/run-bkpr_db.c | 3 --- plugins/bkpr/test/run-recorder.c | 3 --- 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index 47e5553b0727..94ccb892ca93 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -266,9 +266,6 @@ void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED) /* Generated stub for trace_span_end */ void trace_span_end(const void *key UNNEEDED) { fprintf(stderr, "trace_span_end called!\n"); abort(); } -/* Generated stub for trace_span_resume_ */ -void trace_span_resume_(const void *key UNNEEDED, const char *lbl UNNEEDED) -{ fprintf(stderr, "trace_span_resume_ called!\n"); abort(); } /* Generated stub for trace_span_start_ */ void trace_span_start_(const char *name UNNEEDED, const void *key UNNEEDED) { fprintf(stderr, "trace_span_start_ called!\n"); abort(); } diff --git a/plugins/bkpr/test/Makefile b/plugins/bkpr/test/Makefile index 0b5a6393cb63..eae658005e0c 100644 --- a/plugins/bkpr/test/Makefile +++ b/plugins/bkpr/test/Makefile @@ -17,6 +17,7 @@ BOOKKEEPER_TEST_COMMON_OBJS := \ common/key_derive.o \ common/memleak.o \ common/node_id.o \ + common/pseudorand.o \ common/setup.o \ common/trace.o \ common/timeout.o \ diff --git a/plugins/bkpr/test/run-bkpr_db.c b/plugins/bkpr/test/run-bkpr_db.c index ecf21f1772c7..10ba59aea78f 100644 --- a/plugins/bkpr/test/run-bkpr_db.c +++ b/plugins/bkpr/test/run-bkpr_db.c @@ -219,9 +219,6 @@ bool param_check(struct command *cmd UNNEEDED, const char *buffer UNNEEDED, const jsmntok_t tokens[] UNNEEDED, ...) { fprintf(stderr, "param_check called!\n"); abort(); } -/* Generated stub for pseudorand_u64 */ -uint64_t pseudorand_u64(void) -{ fprintf(stderr, "pseudorand_u64 called!\n"); abort(); } /* Generated stub for toks_alloc */ jsmntok_t *toks_alloc(const tal_t *ctx UNNEEDED) { fprintf(stderr, "toks_alloc called!\n"); abort(); } diff --git a/plugins/bkpr/test/run-recorder.c b/plugins/bkpr/test/run-recorder.c index 8f46a7eee66f..16cd8e9b7877 100644 --- a/plugins/bkpr/test/run-recorder.c +++ b/plugins/bkpr/test/run-recorder.c @@ -225,9 +225,6 @@ bool param_check(struct command *cmd UNNEEDED, const char *buffer UNNEEDED, const jsmntok_t tokens[] UNNEEDED, ...) { fprintf(stderr, "param_check called!\n"); abort(); } -/* Generated stub for pseudorand_u64 */ -uint64_t pseudorand_u64(void) -{ fprintf(stderr, "pseudorand_u64 called!\n"); abort(); } /* Generated stub for toks_alloc */ jsmntok_t *toks_alloc(const tal_t *ctx UNNEEDED) { fprintf(stderr, "toks_alloc called!\n"); abort(); }