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:
1 parent
77f00d1b4e
commit
8bcee27c23
13 files changed
+341
-6
No files matched your search
@@ -101,13 +101,17 @@ async Task<(bool Ok, int? Height)> Probe((string Host, int Port, bool Ssl) s)
|
||||
var r = await c.RequestAsync("server.features", ct);
|
||||
var genesis = r.TryGetProperty("genesis_hash", out var g) ? g.GetString() : null;
|
||||
var hashFn = r.TryGetProperty("hash_function", out var hf) ? hf.GetString() : null;
|
||||
if (genesis != profile.GenesisHash)
|
||||
throw new Exception($"genesis_hash {genesis} != expected {profile.GenesisHash} (wrong chain)");
|
||||
if (hashFn != "sha256") throw new Exception($"hash_function '{hashFn}' (expected sha256)");
|
||||
var pruning = r.TryGetProperty("pruning", out var pr) && pr.ValueKind == JsonValueKind.Number;
|
||||
return (0, $"genesis ok, pruning={(pruning ? pr.ToString() : "none")}", pruning);
|
||||
});
|
||||
|
||||
await Step("chain identity", async ct =>
|
||||
{
|
||||
await c.VerifyChainAsync(profile, ct);
|
||||
return (0, "genesis and checkpoint match the profile", false);
|
||||
});
|
||||
|
||||
var tipInfo = await Step("headers.subscribe", async ct =>
|
||||
{
|
||||
var r = await c.RequestAsync("blockchain.headers.subscribe", ct);
|
||||
|
||||
Reference in new issue
Block a user