Skip to content

Commit 08fb55e

Browse files
authored
Merge pull request #291 from frstrtr/dgb/82-gate-grind-wire
dgb(#82): won-block dual-path broadcaster — grind->reconstruct->submit, both arms ACCEPT on node B
2 parents c5894cd + 6aed26d commit 08fb55e

6 files changed

Lines changed: 583 additions & 18 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ jobs:
8484
dgb_gentx_coinbase_test nmc_auxpow_merkle_test nmc_template_builder_test nmc_auxpow_wire_test nmc_reconstruct_won_block_test dgb_gentx_share_path_test dgb_other_tx_resolver_test \
8585
dgb_other_tx_assembler_test dgb_reconstruct_won_block_test dgb_reconstruct_closure_test dgb_gentx_unpack_test dgb_work_source_test dgb_template_builder_test dgb_embedded_coin_node_test dgb_embedded_tx_select_test dgb_coinbase_value_parity_test \
8686
rpc_request_test softfork_check_test genesis_check_test algo_select_test digishield_walk_test header_chain_test \
87-
dgb_coin_node_seam_test dgb_block_broadcast_test dgb_won_block_dispatch_test dgb_forced_won_share_dualpath_test dgb_scrypt_pow_test dgb_nonce_grinder_test dgb_regrind_block_test \
88-
v37_test \
87+
dgb_coin_node_seam_test dgb_block_broadcast_test dgb_won_block_dispatch_test dgb_forced_won_share_dualpath_test dgb_scrypt_pow_test dgb_nonce_grinder_test dgb_regrind_block_test dgb_won_block_finalize_test v37_test \
8988
-j$(nproc)
9089
9190
- name: Run tests
@@ -217,8 +216,7 @@ jobs:
217216
dgb_gentx_coinbase_test nmc_auxpow_merkle_test nmc_template_builder_test nmc_auxpow_wire_test nmc_reconstruct_won_block_test dgb_gentx_share_path_test dgb_other_tx_resolver_test \
218217
dgb_other_tx_assembler_test dgb_reconstruct_won_block_test dgb_reconstruct_closure_test dgb_gentx_unpack_test dgb_work_source_test dgb_template_builder_test dgb_embedded_coin_node_test dgb_embedded_tx_select_test dgb_coinbase_value_parity_test \
219218
rpc_request_test softfork_check_test genesis_check_test algo_select_test digishield_walk_test header_chain_test \
220-
dgb_coin_node_seam_test dgb_block_broadcast_test dgb_won_block_dispatch_test dgb_forced_won_share_dualpath_test dgb_scrypt_pow_test dgb_nonce_grinder_test dgb_regrind_block_test \
221-
test_coin_broadcaster test_multiaddress_pplns test_pplns_stress \
219+
dgb_coin_node_seam_test dgb_block_broadcast_test dgb_won_block_dispatch_test dgb_forced_won_share_dualpath_test dgb_scrypt_pow_test dgb_nonce_grinder_test dgb_regrind_block_test dgb_won_block_finalize_test test_coin_broadcaster test_multiaddress_pplns test_pplns_stress \
222220
v37_test \
223221
-j$(nproc)
224222

scripts/dgb_regtest_won_block_soak.sh

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ provision "$DATADIR_B" "$RPCPORT_B"
9292
wait_rpc() { local n=0; until "$@" getblockcount >/dev/null 2>&1; do n=$((n+1)); [ $n -gt 60 ] && die "rpc never came up: $*"; sleep 0.5; done; }
9393
tip_b() { cli_b getblockcount; }
9494

95+
# pre-flight: a stale c2pool-dgb from a prior run holds the FIXED pool P2P
96+
# listen port (5024, PREFIX-derived) -> ARM A aborts on "bind: Address already
97+
# in use" and the gate FAILS as a phantom timeout. Free it before substrate up.
98+
# DGB-only match; never touches other coins or the bitcoin-family regtest band.
99+
kill_stale_c2pool() {
100+
local pids; pids="$(pgrep -f 'c2pool-dgb .*--run' 2>/dev/null || true)"
101+
[ -z "$pids" ] && return 0
102+
log "pre-flight: freeing pool P2P port from stale c2pool-dgb: $pids"
103+
kill $pids 2>/dev/null || true; sleep 2
104+
pids="$(pgrep -f 'c2pool-dgb .*--run' 2>/dev/null || true)"
105+
[ -n "$pids" ] && { kill -9 $pids 2>/dev/null || true; sleep 1; }
106+
return 0
107+
}
108+
kill_stale_c2pool
109+
95110
# --- substrate: two peered regtest nodes --------------------------------------
96111
log "starting node A (regtest RPC $RPCPORT_A / P2P $P2PPORT_A)"
97112
"$DAEMON_BIN" -regtest -datadir="$DATADIR_A" -rpcport=$RPCPORT_A -port=$P2PPORT_A -daemon >/dev/null
@@ -105,13 +120,21 @@ cli_a createwallet "$PAYOUT_LABEL" >/dev/null 2>&1 || cli_a loadwallet "$PAYOUT_
105120
ADDR_A="$(cli_a getnewaddress "$PAYOUT_LABEL")"
106121
log "mining 101 maturity blocks to $ADDR_A"
107122
cli_a generatetoaddress 101 "$ADDR_A" >/dev/null
123+
# Wait for node B to FULLY IBD-sync node A's chain before baselining. Otherwise
124+
# BASE_B captures B mid-sync (e.g. 96 < A=101) and the ARM A won-detector
125+
# (tip_b > BASE_B) fires on B's normal sync catch-up rather than on a genuine
126+
# c2pool-relayed won block -- a false positive that defeats the gate.
127+
HEIGHT_A="$(cli_a getblockcount)"
128+
n=0; until [ "$(tip_b)" -ge "$HEIGHT_A" ]; do
129+
n=$((n+1)); [ $n -gt 120 ] && die "node B never synced to A height $HEIGHT_A (got $(tip_b))"; sleep 0.5
130+
done
108131
BASE_B="$(tip_b)"
109132

110133
# regtest magic + genesis are read from the running daemon's chainparams so the
111134
# embedded backend's getheaders bootstrap matches node A exactly (no hand-typed
112135
# consensus literal). DGB regtest magic is fixed in DigiByte Core chainparams.
113136
DGB_REGTEST_GENESIS="$(cli_a getblockhash 0)"
114-
: "${DGB_REGTEST_MAGIC:?set DGB_REGTEST_MAGIC to the DigiByte regtest pchMessageStart hex (from chainparams)}"
137+
: "${DGB_REGTEST_MAGIC:=fabfb5da}" # DGB regtest pchMessageStart (DigiByte Core chainparams); override for a custom regtest
115138
log "substrate OK: node A height $(cli_a getblockcount), peer B $BASE_B, genesis $DGB_REGTEST_GENESIS"
116139

117140
# --- ARM A (P2P PRIMARY): live UpdateTip won block relayed to node B ----------
@@ -121,7 +144,8 @@ log "ARM A: launching embedded c2pool-dgb against node A (regtest diff -> natura
121144
--coin-rpc 127.0.0.1:$RPCPORT_A \
122145
--coin-rpc-auth "$DATADIR_A/digibyte.conf" \
123146
--coin-magic "$DGB_REGTEST_MAGIC" \
124-
--coin-genesis "$DGB_REGTEST_GENESIS" >/tmp/c2pool-dgb-soak.log 2>&1 &
147+
--coin-genesis "$DGB_REGTEST_GENESIS" --regtest --regtest-force-won-share \
148+
--soak-regrind >/tmp/c2pool-dgb-soak.log 2>&1 &
125149
C2POOL_PID=$!
126150
log "c2pool-dgb PID $C2POOL_PID; waiting for a won share to relay a coinbase-only block to node B"
127151
n=0
@@ -130,16 +154,37 @@ until [ "$(tip_b)" -gt "$BASE_B" ]; do
130154
sleep 0.5
131155
done
132156
WON_HASH="$(cli_b getblockhash "$(tip_b)")"
133-
NTX="$(cli_b getblock "$WON_HASH" | grep -o '"tx"[^]]*]' | grep -o '"[0-9a-f]\{64\}"' | wc -l)"
157+
NTX="$(cli_b getblock "$WON_HASH" | tr -d '\n' | grep -o '"tx"[^]]*]' | grep -o '"[0-9a-f]\{64\}"' | wc -l)"
134158
[ "$NTX" -eq 1 ] || die "ARM A: won block $WON_HASH has $NTX txs, expected 1 (coinbase-only, PROP 1)"
135159
log "ARM A OK: P2P-relayed coinbase-only won block $WON_HASH accepted by peer node B (PROP 1 + ARM A)"
136160
kill "$C2POOL_PID" >/dev/null 2>&1; C2POOL_PID=""
137161

138-
# --- ARM B (RPC FALLBACK): GATED on integrator isolation-mechanism decision ----
139-
# No --no-p2p-relay flag exists; isolating the submitblock fallback from the P2P arm
140-
# is an open design call (see header item 2). Until integrator picks the mechanism,
141-
# ARM B is NOT asserted -- shipping a placeholder assert would be the silent-gap the
142-
# gate exists to prevent.
143-
log "ARM B: GATED -- submitblock-fallback isolation mechanism pending integrator decision (header item 2)"
162+
# --- ARM B (RPC FALLBACK, ISOLATED): submitblock-only via --no-p2p-relay -------
163+
# The --no-p2p-relay flag (main_dgb.cpp) suppresses the embedded P2P `block`
164+
# relay sink, leaving the external-digibyted submitblock RPC fallback as the
165+
# SOLE path to the network. A second forced won block reaching node B with the
166+
# P2P arm muted proves ARM B reaches the network INDEPENDENTLY (header item 2,
167+
# now resolved by the flag).
168+
BASE_B2="$(tip_b)"
169+
log "ARM B (isolated): relaunching c2pool-dgb with --no-p2p-relay (submitblock fallback only)"
170+
"$C2POOL_DGB" --run \
171+
--coin-daemon 127.0.0.1:$P2PPORT_A \
172+
--coin-rpc 127.0.0.1:$RPCPORT_A \
173+
--coin-rpc-auth "$DATADIR_A/digibyte.conf" \
174+
--coin-magic "$DGB_REGTEST_MAGIC" \
175+
--coin-genesis "$DGB_REGTEST_GENESIS" --regtest --regtest-force-won-share \
176+
--soak-regrind --no-p2p-relay >/tmp/c2pool-dgb-soak-armb.log 2>&1 &
177+
C2POOL_PID=$!
178+
log "c2pool-dgb (ARM B) PID $C2POOL_PID; waiting for submitblock-only won block on node B"
179+
n=0
180+
until [ "$(tip_b)" -gt "$BASE_B2" ]; do
181+
n=$((n+1)); [ $n -gt 240 ] && die "ARM B: no won block reached node B within 120s (submitblock RPC fallback)"
182+
sleep 0.5
183+
done
184+
WON_HASH_B="$(cli_b getblockhash "$(tip_b)")"
185+
NTX_B="$(cli_b getblock "$WON_HASH_B" | tr -d '\n' | grep -o '"tx"[^]]*]' | grep -o '"[0-9a-f]\{64\}"' | wc -l)"
186+
[ "$NTX_B" -eq 1 ] || die "ARM B: won block $WON_HASH_B has $NTX_B txs, expected 1 (coinbase-only, PROP 1)"
187+
log "ARM B OK: submitblock-RPC-only coinbase-only won block $WON_HASH_B accepted by peer node B (PROP 1 + ARM B, P2P arm suppressed)"
188+
kill "$C2POOL_PID" >/dev/null 2>&1; C2POOL_PID=""
144189

145-
log "ARM A proven; ARM B + digibyted provisioning are the two remaining live-leg items for the #82 gate."
190+
log "BOTH ARMS PROVEN: ARM A (P2P relay) block $WON_HASH + ARM B (submitblock isolated) block $WON_HASH_B each accepted by peer node B. #82 dual-path broadcaster gate satisfied (digibyted self-provisioned)."

0 commit comments

Comments
 (0)