ltc: fix private-net IDENTIFIER truncation + independent PREFIX (V36 ship-blocker) - #95
Merged
Merged
Conversation
…ship-blocker)
Two defects prevented c2pool from joining any p2pool private net:
(i) --network-id truncated to 32 bits: parsed via
static_cast<uint32_t>(std::stoul(...)) and formatted with setw(8),
so an 8-byte id (e.g. 9765c71ad4c00467) collapsed to its low 4 bytes
(d4c00467). Parse as uint64_t (std::stoull) and format with setw(16);
drop the now-redundant right-pad.
(ii) PREFIX was XOR-derived from IDENTIFIER in set_network_id(), so two
nodes with the same id but a different prefix source got
"prefix doesn't match" -> Peers:0. PREFIX is now an independent
per-network constant, overridable via a new --prefix flag;
set_network_id() no longer derives it. chain_fingerprint_u64() now
hashes the effective prefix_hex().
Adds set_prefix() + --prefix CLI flag and help text. ltc shape only;
btc/dgb/dash/bch receive the identical fix via their stewards.
| else if ((arg == "--network-id" || arg == "--chain-id") && i + 1 < argc) { | ||
| network_id = static_cast<uint32_t>(std::stoul(argv[++i], nullptr, 16)); | ||
| // Full 8-byte identifier: parse as 64-bit, never truncate to 32 bits | ||
| network_id = std::stoull(argv[++i], nullptr, 16); |
| cli_explicit.insert("network_id"); | ||
| } | ||
| else if (arg == "--prefix" && i + 1 < argc) { | ||
| prefix_override_hex = argv[++i]; |
frstrtr
added a commit
that referenced
this pull request
Jun 16, 2026
…ependence btc/v36: network-id/prefix independence (#95 BTC mirror)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two independent defects in c2pool private-sharechain identity that prevented joining any p2pool net (the V36 crossing-soak blocker, #93-class parity fix). LTC shape; btc/dgb/dash/bch get the identical fix via their stewards.
Bug (i) —
--network-idtruncated to 32 bitsmain()parsed the id viastatic_cast<uint32_t>(std::stoul(...))and formatted it withsetw(8), so an 8-byte identifier (e.g.9765c71ad4c00467) collapsed to its low 4 bytes (d4c00467). Two operators passing the same 8-byte id would silently run on different chains.network_idis nowuint64_t, parsed withstd::stoull, formatted withsetw(16); the redundant right-pad is removed.Bug (ii) — PREFIX XOR-derived from IDENTIFIER
set_network_id()derived the transport PREFIX from the IDENTIFIER via an XOR-rotate. A peer that supplies its PREFIX independently (as p2pool does — a fixed per-network constant) computes a different value →prefix doesn't match→Peers:0.--prefixflag.set_network_id()no longer touches PREFIX.chain_fingerprint_u64()now hashes the effectiveprefix_hex().Changes
impl/ltc/config_pool.hpp: drop XOR derivation fromset_network_id(); addset_prefix(); fingerprint over effective prefix.c2pool/c2pool_refactored.cpp:uint64_tid +std::stoull+setw(16); add--prefixflag, override wiring, help text.Test plan
--network-id 9765c71ad4c00467now logs IDENTIFIER9765c71ad4c00467(not00000000d4c00467); with no--prefix, PREFIX = compiled testnet constantad9614f6466a39cf.Merge is operator-gated. Reviewer: dash-consensus-pay-replay.