M1.2 + parallel work: switch CTxDB& signatures to CTxDBBase&; snapshotnet, version bump
Build All Platforms / test-linux-unit (push) Failing after 40s
Build All Platforms / build-linux-qt (push) Failing after 40s
Build All Platforms / build-linux-daemon (push) Failing after 40s
Build All Platforms / build-windows-qt (push) Has been cancelled
Build All Platforms / build-windows-daemon (push) Has been cancelled
Build All Platforms / build-macos (push) Has been cancelled
Build All Platforms / release (push) Has been cancelled
Build All Platforms / Trigger TRI-PI ARM64 Build (push) Has been cancelled

M1.2 (mechanical):
  Convert every CTxDB& parameter and reference across main.{h,cpp},
  wallet.{h,cpp}, and smessage.cpp to CTxDBBase&. Local instantiations
  like `CTxDB txdb("r");` are deliberately left as concrete LevelDB —
  they'll move behind a factory in M1.4 once the parity harness exists.

  CTxDB IS-A CTxDBBase, so all existing call sites continue to compile:
  a CTxDB instance binds to a CTxDBBase& parameter automatically.
  Forward declaration `class CTxDB;` in main.h replaced with
  `class CTxDBBase;`.

Parallel work (snapshotnet + version bump to 5.9.4 + checkpoints/init
/protocol/version edits) included so origin/master matches the local
working tree in one push.

NOT YET COMPILE-TESTED: pushed at the user's explicit request before
the build verification step. If CI fails, expected breakage is in
files that include main.h transitively but not txdb-base.h — fix is
to add `#include "txdb-base.h"` (or rely on the existing txdb.h which
pulls it in).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-25 02:52:12 -07:00
parent b28525057a
commit f13e512712
15 changed files with 878 additions and 49 deletions
+53 -1
View File
@@ -15,6 +15,7 @@
#include "openssl_compat.h"
#include "bootstrap.h"
#include "utxosnapshot.h"
#include "snapshotnet.h"
#include "tor/tor_embedded.h"
#include "tor/onion_v3.h"
#include "tor/tor_process.h"
@@ -108,6 +109,31 @@ bool ShutdownRequested()
return fRequestShutdown;
}
// P2P UTXO snapshot fetcher. Started from AppInit2 step 11.6 when the chain
// is empty and snapshot mode is enabled. Saves utxo-snapshot.bin on success
// and requests shutdown so a fresh boot can load it via Step 6c.
static void ThreadSnapshotFetch(void* parg)
{
RenameThread("Triangles-snapfetch");
// Give peers ~30s to connect and complete version handshake.
for (int i = 0; i < 30 && !fRequestShutdown; ++i)
MilliSleep(1000);
if (fRequestShutdown) return;
int snapTimeoutSec = (int)GetArg("-snapshottimeout", 600);
printf("SnapshotNet: starting P2P snapshot fetch (timeout=%ds)...\n", snapTimeoutSec);
std::string err;
if (SnapshotNet::TryFetchSnapshot(GetDataDir(), snapTimeoutSec, err)) {
printf("SnapshotNet: snapshot saved. Shutting down — restart the daemon to load it.\n");
uiInterface.InitMessage(_("UTXO snapshot saved. Restart the node to load it."));
StartShutdown();
} else {
printf("SnapshotNet: P2P snapshot fetch failed: %s\n", err.c_str());
printf("SnapshotNet: falling back to genesis sync. Use -bootstrap for legacy HTTP fallback.\n");
}
}
void ThreadDeferredStartup(void* parg)
{
// Make this thread recognisable as the deferred startup worker.
@@ -888,17 +914,25 @@ bool AppInit2()
// ********************************************************* Step 6b: bootstrap download (daemon)
// Automatic: if data dir has no blockchain, bootstrap without asking.
// Can also be forced with -bootstrap flag, or disabled with -nobootstrap.
//
// v5.9.5: P2P UTXO snapshot fetch is the default for fresh installs (Step 11.6).
// The legacy clearnet HTTP bootstrap only runs when the user explicitly requests
// it via -bootstrap, or when -snapshot=0 disables the P2P fetcher.
#ifndef QT_GUI
{
bool wantsBootstrap = GetBoolArg("-bootstrap", false);
bool noBootstrap = GetBoolArg("-nobootstrap", false);
bool snapshotMode = GetBoolArg("-snapshot", true);
fs::path dataPath = GetDataDir();
bool needsBootstrap = Bootstrap::NeedsBootstrap(dataPath);
if (needsBootstrap && !noBootstrap) {
if (needsBootstrap && !noBootstrap && !snapshotMode) {
printf("Bootstrap: no blockchain data found — downloading automatically.\n");
printf("Bootstrap: (use -nobootstrap to skip)\n");
wantsBootstrap = true;
} else if (needsBootstrap && snapshotMode && !wantsBootstrap) {
printf("Bootstrap: no blockchain data found — will fetch UTXO snapshot via P2P after network start.\n");
printf("Bootstrap: (use -bootstrap for legacy clearnet HTTP bootstrap, or -snapshot=0 to disable P2P fetcher)\n");
}
if (wantsBootstrap)
@@ -1432,6 +1466,24 @@ bool AppInit2()
if (fServer)
NewThread(ThreadRPCServer, NULL);
// ********************************************************* Step 11.6: P2P UTXO snapshot fetch
// If the chain is empty and snapshot mode is enabled (default), spawn a
// background thread that waits for snapshot-capable peers, downloads the
// canonical snapshot via P2P, and saves it to utxo-snapshot.bin. On
// success, requests a clean shutdown so the user can restart and have
// Step 6c load the snapshot in a fresh boot.
{
bool snapshotMode = GetBoolArg("-snapshot", true);
bool needsSnapshot = (nBestHeight <= 0);
bool haveSnapshotFile = fs::exists(GetDataDir() / "utxo-snapshot.bin");
if (snapshotMode && needsSnapshot && !haveSnapshotFile &&
Checkpoints::GetBestSnapshotHeight() > 0)
{
NewThread(ThreadSnapshotFetch, NULL);
}
}
{
LOCK(cs_DeferredStartup);
fDeferredStartupRunning = true;