From 60538c5a935787521a5ad8c2a7dce52b5f250f3a Mon Sep 17 00:00:00 2001 From: bitflash-maintainer Date: Sat, 5 Sep 2026 03:16:00 +0000 Subject: compactblock: import BIP152-style compact block relay from upstream 1.2.23 Brings src/compactblock.{cpp,h} and test_compactblock.cpp across verbatim from the upstream-v1.2.23 tag, and gives them a build. 1.2.23 is not a newer release of the line this fork ships. It is a lightweight tag (7ab5a8c) cut 2026-07-30, on a lineage that upstream/main (e0be70e, 2026-08-20) does not contain and no remote branch carries -- 272 commits that are not ours, against 376 of ours that are not theirs, from a merge-base at 56df983. Merging that tag would have deleted 18 files from src/, selftest.{cpp,h} and the whole 14-test suite among them, so the content is ported file by file instead. Compact block relay is the piece worth having: a peer that advertises sendcmpct gets 48-bit keyed short IDs per transaction rather than the transaction bytes, and reconstructs the block from its own mempool. It is purely additive on the wire -- a peer that never sends sendcmpct keeps receiving full block messages, so no coordinated upgrade is needed. This commit is the primitives and their unit test only. Nothing calls BuildCompactBlock or TryReconstructBlock yet: the P2P message handlers (sendcmpct/cmpctblock/getblocktxn/blocktxn) live in 1.2.23's main.cpp and are deliberately left for a follow-up, so that no attacker-controlled bytes reach this code until that wiring is reviewed on its own. The files needed no API adaptation -- mapTransactions, BEGIN/END and IMPLEMENT_SERIALIZE are unchanged across the divergence, and it compiled clean first time. Upstream never wired test_compactblock.cpp into its own Makefile, so it had never been built there; it links standalone the way test_bip32 does, supplying its own mapTransactions and GetAppDir to keep main.cpp out of the link. TEST_LIBS is overridable for the same reason NODE_LIBS is: the pinned dep tree ships libsodium as a static archive only. All 17 checks in test_compactblock pass, all 14 selftests still pass, and the consensus constants are unchanged against e4f898c. --- src/Makefile | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/Makefile') diff --git a/src/Makefile b/src/Makefile index b931007..888110f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -55,7 +55,8 @@ LIBS = -L$(SECP_LIB) -lsecp256k1 \ HEADERS = headers_core.h headers.h util.h main.h serialize.h uint256.h \ key.h bignum.h script.h db.h base58.h net.h nostr.h \ randomx_pow.h btfaddr.h btfchan.h btfrv.h btftunnel.h \ - selftest.h walletcmd.h wallet_sqlite.h compat.h sockcount.h proxy.h tor.h font_roboto.h + selftest.h walletcmd.h wallet_sqlite.h compat.h sockcount.h proxy.h tor.h font_roboto.h \ + compactblock.h IMGUI_OBJS = obj/imgui.o obj/imgui_draw.o obj/imgui_tables.o \ obj/imgui_widgets.o obj/imgui_impl_glfw.o obj/imgui_impl_opengl3.o @@ -64,7 +65,7 @@ NODE_OBJS = obj/util.o obj/script.o obj/db.o obj/net.o obj/main.o \ obj/sha.o obj/nostr.o obj/randomx_pow.o \ obj/btfaddr.o obj/btfchan.o obj/btfrv.o obj/btftunnel.o obj/rpc.o \ obj/selftest.o obj/bip32.o obj/walletcmd.o obj/wallet_sqlite.o \ - obj/proxy.o obj/tor.o + obj/proxy.o obj/tor.o obj/compactblock.o GUI_OBJS = obj/gui.o obj/main_gui.o @@ -194,13 +195,28 @@ fuzz-script-smoke: fuzz-script ./fuzz-script -runs=128 ../work/fuzz-corpus/script clean: - rm -rf obj obj-node obj-fuzz bitflash bitflash-node fuzz-net-message fuzz-script test_bip32 + rm -rf obj obj-node obj-fuzz bitflash bitflash-node fuzz-net-message fuzz-script test_bip32 test_compactblock test_bip32: test_bip32.cpp bip32.cpp bip32.h bip39_english.h $(CXX) $(CXXFLAGS) -o $@ test_bip32.cpp bip32.cpp -lssl -lcrypto -tests: test_bip32 bitflash-node +# Upstream shipped test_compactblock.cpp with no build rule at all, so it was +# never compiled there. It links the standalone way test_bip32 does: it supplies +# its own mapTransactions and GetAppDir so main.cpp stays out of the link, and +# only needs sha.cpp/util.cpp for Hash() and the logging helpers. +# +# TEST_LIBS is overridable for the same reason NODE_LIBS is: the pinned dep tree +# ships libsodium as a static archive only, so a build against it passes +# TEST_LIBS="... -l:libsodium.a ...". +TEST_LIBS ?= -lsodium -lssl -lcrypto -lpthread + +test_compactblock: test_compactblock.cpp compactblock.cpp compactblock.h $(HEADERS) + $(CXX) $(CXXFLAGS) -o $@ test_compactblock.cpp compactblock.cpp sha.cpp util.cpp \ + $(TEST_LIBS) + +tests: test_bip32 test_compactblock bitflash-node ./test_bip32 + ./test_compactblock ./bitflash-node -selftest=wallet-keypool ./bitflash-node -selftest=wallet-hd ./bitflash-node -selftest=wallet-format -- cgit v1.2.3