Skip to content

Commit a5f17c4

Browse files
committed
Fix AutoRatchet: use chain depth for confirmation, not absheight
p2pool uses tracker.get_height() (chain depth) for confirm_count tracking (data.py:2576). c2pool was using m_absheight which grows faster due to forks/orphans, causing CONFIRMED transition ~100 shares earlier than p2pool. This desync made every subsequent c2pool share fail GENTX on p2pool (24k+ failures overnight).
1 parent ac5bd1d commit a5f17c4

1 file changed

Lines changed: 14 additions & 23 deletions

File tree

src/impl/ltc/auto_ratchet.hpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,10 @@ class AutoRatchet
9696
return {current_version, target_version_};
9797
}
9898

99-
// Count votes and actual new-format shares in window
99+
// Count votes and actual new-format shares in window.
100+
// p2pool uses tracker.get_height() (chain depth) for both sampling
101+
// and confirmation counting. This matches data.py:2488,2576.
100102
int32_t height = tracker.chain.get_height(best_share_hash);
101-
102-
// Use absheight (monotonically increasing) for confirm_count tracking.
103-
// chain.get_height() returns chain DEPTH which plateaus after pruning
104-
// at ~CHAIN_LENGTH, preventing confirm_count from ever reaching 800.
105-
int32_t abs_height = 0;
106-
if (tracker.chain.contains(best_share_hash)) {
107-
tracker.chain.get(best_share_hash).share.invoke([&](auto* obj) {
108-
abs_height = static_cast<int32_t>(obj->m_absheight);
109-
});
110-
}
111103
int32_t sample = std::min(height, static_cast<int32_t>(chain_length));
112104

113105
int32_t target_votes = 0; // shares voting desired_version >= target
@@ -173,11 +165,12 @@ class AutoRatchet
173165
{
174166
state_ = RatchetState::ACTIVATED;
175167
activated_at_ = now_seconds();
176-
activated_height_ = abs_height;
168+
activated_height_ = height;
177169
// Credit retroactive shares for late-joining nodes
178-
int32_t retroactive = std::max(0, abs_height - static_cast<int32_t>(chain_length));
170+
// p2pool data.py:2535: retroactive = max(0, height - net.CHAIN_LENGTH)
171+
int32_t retroactive = std::max(0, height - static_cast<int32_t>(chain_length));
179172
confirm_count_ = retroactive;
180-
last_seen_height_ = abs_height;
173+
last_seen_height_ = height;
181174

182175
LOG_INFO << "[AutoRatchet] VOTING -> ACTIVATED ("
183176
<< vote_pct << "% of " << total << " shares vote V"
@@ -213,21 +206,19 @@ class AutoRatchet
213206
}
214207
else if (activated_height_ > 0)
215208
{
216-
// Track cumulative height increases using absheight (monotonic).
217-
// chain depth (get_height) plateaus at ~CHAIN_LENGTH after pruning,
218-
// preventing confirm_count from reaching 800. absheight always grows.
219-
if (last_seen_height_ > 0 && abs_height > last_seen_height_)
220-
confirm_count_ += (abs_height - last_seen_height_);
221-
last_seen_height_ = abs_height;
209+
// Track cumulative height increases using chain depth.
210+
// p2pool data.py:2576: uses tracker.get_height() (chain depth).
211+
if (last_seen_height_ > 0 && height > last_seen_height_)
212+
confirm_count_ += (height - last_seen_height_);
213+
last_seen_height_ = height;
222214

223215
{
224216
static int ac_log = 0;
225217
if (ac_log++ % 20 == 0)
226218
LOG_INFO << "[AutoRatchet] ACTIVATED: vote=" << vote_pct
227219
<< "% share=" << share_pct << "% full=" << (full_window ? "True" : "False")
228-
<< " height=" << abs_height
229-
<< " confirm=" << confirm_count_ << "/" << confirmation_window
230-
<< " chain_depth=" << height;
220+
<< " height=" << height
221+
<< " confirm=" << confirm_count_ << "/" << confirmation_window;
231222
}
232223

233224
if (confirm_count_ >= static_cast<int32_t>(confirmation_window) &&

0 commit comments

Comments
 (0)