Skip to content

Commit 3b8031e

Browse files
committed
Simplify private chain: single --network-id, remove redundant --chain-prefix
P2Pool always creates genesis shares naturally when chain is empty — no --no-persist flag needed. The P2P prefix already provides network isolation at the transport layer, so a separate chain_id is redundant. Simplified to single --network-id parameter: 0 = public p2pool network (default) nonzero = private chain (stamped in THE metadata bytes 8-11) Restored pool_aps_compressed to metadata bytes 12-15. Removed --chain-prefix and --no-persist flags.
1 parent 820e37c commit 3b8031e

3 files changed

Lines changed: 20 additions & 32 deletions

File tree

src/c2pool/c2pool_refactored.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,11 @@ void print_help() {
221221
std::cout << " Default: /c2pool/ (c2pool always identified by donation address)\n\n";
222222

223223
std::cout << "PRIVATE SHARECHAIN:\n";
224-
std::cout << " --chain-id ID Private chain identifier (hex, e.g. DEADBEEF)\n";
224+
std::cout << " --network-id ID Private network identifier (hex, e.g. DEADBEEF)\n";
225225
std::cout << " Default: 0 (public p2pool network)\n";
226-
std::cout << " --chain-prefix PREFIX P2P magic prefix (4 hex bytes, e.g. C2C2C2C2)\n";
227-
std::cout << " Default: standard p2pool prefix for the coin\n";
228-
std::cout << " --no-persist Create genesis share immediately (don't wait for peers)\n";
229-
std::cout << " Required when starting a new private chain\n\n";
226+
std::cout << " Nonzero: creates a private sharechain. P2P prefix\n";
227+
std::cout << " and THE metadata will carry this ID on the blockchain.\n";
228+
std::cout << " Genesis shares are created automatically when chain is empty.\n\n";
230229

231230
std::cout << "V36 SHARE MESSAGE BLOB (CLI operator control):\n";
232231
std::cout << " --message-blob-hex HEX Encrypted authority-signed message_data blob\n";
@@ -387,9 +386,7 @@ int main(int argc, char* argv[]) {
387386
std::string coinbase_text; // --coinbase-text (replaces /c2pool/ tag)
388387

389388
// Private sharechain
390-
uint32_t chain_id = 0; // 0 = public p2pool network
391-
uint32_t chain_prefix = 0; // 0 = use default p2pool prefix
392-
bool no_persist = false; // create genesis share immediately
389+
uint32_t network_id = 0; // 0 = public p2pool network, nonzero = private
393390

394391
// Track which options were explicitly set via CLI so that --config file
395392
// values only fill in gaps (CLI always wins).
@@ -648,17 +645,9 @@ int main(int argc, char* argv[]) {
648645
coinbase_text = argv[++i];
649646
cli_explicit.insert("coinbase_text");
650647
}
651-
else if (arg == "--chain-id" && i + 1 < argc) {
652-
chain_id = static_cast<uint32_t>(std::stoul(argv[++i], nullptr, 16));
653-
cli_explicit.insert("chain_id");
654-
}
655-
else if (arg == "--chain-prefix" && i + 1 < argc) {
656-
chain_prefix = static_cast<uint32_t>(std::stoul(argv[++i], nullptr, 16));
657-
cli_explicit.insert("chain_prefix");
658-
}
659-
else if (arg == "--no-persist") {
660-
no_persist = true;
661-
cli_explicit.insert("no_persist");
648+
else if ((arg == "--network-id" || arg == "--chain-id") && i + 1 < argc) {
649+
network_id = static_cast<uint32_t>(std::stoul(argv[++i], nullptr, 16));
650+
cli_explicit.insert("network_id");
662651
}
663652
// Legacy support for old --port option
664653
else if (arg == "--port" && i + 1 < argc) {
@@ -1274,7 +1263,7 @@ int main(int argc, char* argv[]) {
12741263
return arr;
12751264
},
12761265
[](const uint256&, uint32_t) -> bool { return true; },
1277-
[the_store, mi, chain_id, chain_prefix](const std::string& chain, uint64_t height,
1266+
[the_store, mi, network_id](const std::string& chain, uint64_t height,
12781267
const std::string& hash, uint64_t ts) {
12791268
c2pool::storage::TheCheckpoint cp;
12801269
cp.chain = chain; cp.block_height = height;
@@ -1284,8 +1273,7 @@ int main(int argc, char* argv[]) {
12841273
cp.sharechain_height = work.sharechain_height;
12851274
cp.miner_count = work.miner_count;
12861275
cp.hashrate_class = c2pool::TheMetadata::encode_hashrate(work.pool_hashrate);
1287-
cp.chain_id_val = chain_id;
1288-
cp.chain_prefix_val = chain_prefix;
1276+
cp.chain_id_val = network_id;
12891277
the_store->store(cp);
12901278
LOG_INFO << "[THE] Checkpoint: " << chain << " height=" << height
12911279
<< " miners=" << cp.miner_count

src/c2pool/storage/the_checkpoint.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct TheCheckpoint {
4242
uint64_t timestamp{0}; // when found
4343
uint8_t status{0}; // 0=pending, 1=verified, 2=mismatch
4444
uint32_t chain_id_val{0}; // 0 = public network, nonzero = private chain
45-
uint32_t chain_prefix_val{0}; // P2P magic prefix (0 = default)
4645

4746
std::vector<uint8_t> serialize() const {
4847
std::vector<uint8_t> out;

src/core/coinbase_builder.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,21 @@ static constexpr size_t MAX_OPERATOR_TEXT_MM = 20;
6262
// Maximum operator text without merged mining
6363
static constexpr size_t MAX_OPERATOR_TEXT_SOLO = 64;
6464

65-
// Public p2pool network chain_id (default — no private chain)
66-
static constexpr uint32_t PUBLIC_CHAIN_ID = 0;
67-
static constexpr uint32_t PUBLIC_CHAIN_PREFIX = 0;
65+
// Public p2pool network identifier (default — standard p2pool P2P prefix)
66+
static constexpr uint32_t PUBLIC_NETWORK_ID = 0;
6867

6968
/// THE metadata — compact pool state for on-chain commitment
7069
struct TheMetadata {
7170
uint8_t version = C2POOL_PROTOCOL_VERSION;
7271
uint32_t sharechain_height = 0; // share chain height at block-find
7372
uint16_t miner_count = 0; // unique miners in PPLNS window
7473
uint8_t hashrate_class = 0; // log2(pool_hashrate_in_h_per_s)
75-
uint32_t chain_id = PUBLIC_CHAIN_ID; // 0 = public network, nonzero = private chain
76-
uint32_t chain_prefix = PUBLIC_CHAIN_PREFIX; // P2P magic prefix (0 = default)
74+
uint32_t network_id = PUBLIC_NETWORK_ID; // P2P prefix as network identifier
75+
// 0 = public p2pool network
76+
// nonzero = private chain (use --network-id)
7777
uint16_t share_period = 0; // current share period (seconds)
7878
uint16_t verified_length = 0; // verified chain length
79+
uint32_t pool_aps_compressed = 0; // compressed pool attempts/s
7980
uint32_t reserved = 0; // future: THE temporal layer flags
8081

8182
/// Pack into bytes (up to max_bytes, truncated from end)
@@ -98,8 +99,8 @@ struct TheMetadata {
9899
push32(sharechain_height); // [1-4]
99100
push16(miner_count); // [5-6]
100101
push8(hashrate_class); // [7]
101-
push32(chain_id); // [8-11] 0 = public network
102-
push32(chain_prefix); // [12-15] P2P magic prefix
102+
push32(network_id); // [8-11] 0 = public, P2P prefix = private
103+
push32(pool_aps_compressed); // [12-15]
103104
push16(share_period); // [16-17]
104105
push16(verified_length); // [18-19]
105106
return out;
@@ -112,8 +113,8 @@ struct TheMetadata {
112113
if (len >= 5) m.sharechain_height = data[1] | (data[2]<<8) | (data[3]<<16) | (data[4]<<24);
113114
if (len >= 7) m.miner_count = data[5] | (data[6]<<8);
114115
if (len >= 8) m.hashrate_class = data[7];
115-
if (len >= 12) m.chain_id = data[8] | (data[9]<<8) | (data[10]<<16) | (data[11]<<24);
116-
if (len >= 16) m.chain_prefix = data[12] | (data[13]<<8) | (data[14]<<16) | (data[15]<<24);
116+
if (len >= 12) m.network_id = data[8] | (data[9]<<8) | (data[10]<<16) | (data[11]<<24);
117+
if (len >= 16) m.pool_aps_compressed = data[12] | (data[13]<<8) | (data[14]<<16) | (data[15]<<24);
117118
if (len >= 18) m.share_period = data[16] | (data[17]<<8);
118119
if (len >= 20) m.verified_length = data[18] | (data[19]<<8);
119120
return m;

0 commit comments

Comments
 (0)