Skip to content

Commit 6c3e227

Browse files
committed
Fix GENTX mismatch: segwit_data serialization divergence in ref_hash
generate_share_transaction() skipped serializing empty segwit_data in the ref_hash computation, while share_init_verify() always serialized it (empty branch + zero root for PossiblyNoneType). This caused intermittent GENTX mismatches when shares had no segwit_data (m_segwit_data == nullopt): the hash_link-derived gentx (from share_init_verify) differed from the recomputed gentx (from generate_share_transaction), failing attempt_verify. 4 out of 1020 shares affected (0.4%), causing p2pool to reject c2pool's shares and eventually evict c2pool from PPLNS entirely. Fix: add the else branch to generate_share_transaction's segwit serialization, matching share_init_verify exactly. Also enables cross-check for all shares (was limited to first 5).
1 parent 54666b6 commit 6c3e227

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/impl/ltc/share_check.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,16 @@ uint256 generate_share_transaction(const ShareT& share, TrackerT& tracker, bool
13271327
{
13281328
if constexpr (ver >= ltc::SEGWIT_ACTIVATION_VERSION)
13291329
{
1330-
if (share.m_segwit_data.has_value())
1330+
// PossiblyNoneType: ALWAYS serialize (p2pool writes default when None).
1331+
// Must match share_init_verify — both paths must produce identical ref_hash.
1332+
if (share.m_segwit_data.has_value()) {
13311333
ref_stream << share.m_segwit_data.value();
1334+
} else {
1335+
std::vector<uint256> empty_branch;
1336+
ref_stream << empty_branch;
1337+
uint256 zero_root;
1338+
ref_stream << zero_root;
1339+
}
13321340
}
13331341
}
13341342

@@ -3219,7 +3227,7 @@ uint256 create_local_share(
32193227
// to verify p2pool would produce the same gentx_hash.
32203228
{
32213229
static int xcheck_count = 0;
3222-
if (xcheck_count < 5) {
3230+
if (true) { // Always cross-check (was: xcheck_count < 5)
32233231
uint256 verify_hash = generate_share_transaction<MergedMiningShare>(*heap_share, tracker, true, (MergedMiningShare::version >= 36));
32243232
bool xcheck_ok = (verify_hash == gentx_hash_for_header);
32253233
if (xcheck_ok) {

0 commit comments

Comments
 (0)