feat(spv): verify the chain identity of a server on connect

After the handshake the wallet checks server.features genesis_hash and,
when the profile has checkpoints, the header at the highest checkpoint
not above the server's tip (mainnet shares Bitcoin's genesis, so the
checkpoint is what tells the chains apart). A server on another chain is
refused with WrongChainException and the next candidate is tried. Used by
the GUI, peer discovery, the CLI and the server probe. See ADR 0036.
This commit is contained in:
davide committed 2026-11-03 14:01:34 +01:00
1 parent 77f00d1b4e
commit 8bcee27c23
13 files changed
+341 -6

No files matched your search

+10 -2
View File
@@ -28,7 +28,8 @@ try
};
}
catch (Exception ex) when (ex is WalletSpendException or WrongPasswordException
or CertificatePinMismatchException or ElectrumServerException or SpvVerificationException)
or CertificatePinMismatchException or ElectrumServerException or SpvVerificationException
or WrongChainException)
{
Console.Error.WriteLine($"Error: {ex.Message}");
return 1;
@@ -363,7 +364,14 @@ static async Task<ElectrumClient> Connect(string[] o, ChainProfile profile)
var pins = new CertificatePinStore(AppPaths.CertificatePinsPath(profile.Kind));
Console.WriteLine($"Connecting to {host}:{port}{(useSsl ? " (TLS)" : "")}…");
return await ElectrumClient.ConnectAsync(host, port, useSsl, pins);
var client = await ElectrumClient.ConnectAsync(host, port, useSsl, pins);
try { await client.VerifyChainAsync(profile); }
catch
{
await client.DisposeAsync();
throw;
}
return client;
}
static string? Opt(string[] options, string name)