Skip to content

Commit ea58e8b

Browse files
committed
Fix sync constants from LTC/DOGE daemon source code
Tip age gate: 24 hours (86400s), not 2 hours (7200s). Reference: litecoin/src/validation.h DEFAULT_MAX_TIP_AGE = 24*60*60 Reference: dogecoin/src/validation.h DEFAULT_MAX_TIP_AGE = 24*60*60 Mining gate depth: maturity + reorg buffer, not maturity alone. LTC: 100 (COINBASE_MATURITY) + 6 (PEGOUT_MATURITY) = 106 DOGE: 240 (nCoinbaseMaturity) + 10 (reorg safety) = 250 All constants now reference LTC/DOGE daemon source, not Bitcoin.
1 parent ccd86b3 commit ea58e8b

4 files changed

Lines changed: 39 additions & 18 deletions

File tree

src/c2pool/c2pool_refactored.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,15 +1389,18 @@ int main(int argc, char* argv[]) {
13891389
// Reference: litecoin/src/consensus/consensus.h COINBASE_MATURITY = 100
13901390
if (ltc_utxo_cache) {
13911391
auto* cache_ptr = ltc_utxo_cache.get();
1392-
constexpr uint32_t LTC_MATURITY = core::coin::LTC_LIMITS.coinbase_maturity;
1393-
embedded_node->set_utxo_ready_fn([cache_ptr, LTC_MATURITY]() {
1392+
// Mining gate: coinbase_maturity + reorg_buffer
1393+
// LTC: 100 + 6 (pegout maturity) = 106
1394+
// Reference: litecoin/src/consensus/consensus.h
1395+
constexpr uint32_t LTC_GATE = core::coin::LTC_MINING_GATE_DEPTH; // 106
1396+
embedded_node->set_utxo_ready_fn([cache_ptr, LTC_GATE]() {
13941397
auto connected = cache_ptr->blocks_connected();
1395-
bool ready = connected >= LTC_MATURITY;
1398+
bool ready = connected >= LTC_GATE;
13961399
if (!ready) {
13971400
static int s_log_ctr = 0;
13981401
if (s_log_ctr++ % 20 == 0)
13991402
LOG_INFO << "[EMB-LTC] UTXO maturity gate: blocks_connected="
1400-
<< connected << " need>=" << LTC_MATURITY;
1403+
<< connected << " need>=" << LTC_GATE;
14011404
}
14021405
return ready;
14031406
});
@@ -3551,15 +3554,18 @@ int main(int argc, char* argv[]) {
35513554
// Reference: dogecoin/src/chainparams.cpp digishieldConsensus.nCoinbaseMaturity = 240
35523555
if (doge_utxo_cache) {
35533556
auto* cache_ptr = doge_utxo_cache.get();
3554-
constexpr uint32_t DOGE_MATURITY = core::coin::DOGE_LIMITS.coinbase_maturity;
3555-
backend->embedded_node().set_utxo_ready_fn([cache_ptr, DOGE_MATURITY]() {
3557+
// Mining gate: coinbase_maturity + reorg_buffer
3558+
// DOGE: 240 + 10 (reorg safety) = 250
3559+
// Reference: dogecoin/src/chainparams.cpp digishieldConsensus
3560+
constexpr uint32_t DOGE_GATE = core::coin::DOGE_MINING_GATE_DEPTH; // 250
3561+
backend->embedded_node().set_utxo_ready_fn([cache_ptr, DOGE_GATE]() {
35563562
auto connected = cache_ptr->blocks_connected();
3557-
bool ready = connected >= DOGE_MATURITY;
3563+
bool ready = connected >= DOGE_GATE;
35583564
if (!ready) {
35593565
static int s_log_ctr = 0;
35603566
if (s_log_ctr++ % 20 == 0)
35613567
LOG_INFO << "[EMB-DOGE] UTXO maturity gate: blocks_connected="
3562-
<< connected << " need>=" << DOGE_MATURITY;
3568+
<< connected << " need>=" << DOGE_GATE;
35633569
}
35643570
return ready;
35653571
});

src/core/coin/utxo.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ static constexpr ChainLimits DOGE_LIMITS = {1'000'000'000'000'000'000LL, 240, 0}
5050
static constexpr uint32_t LTC_MIN_BLOCKS_TO_KEEP = 288;
5151
static constexpr uint32_t DOGE_MIN_BLOCKS_TO_KEEP = 1440;
5252

53+
/// Minimum UTXO depth before mining can start: coinbase_maturity + reorg_buffer.
54+
/// LTC: 100 (COINBASE_MATURITY) + 6 (PEGOUT_MATURITY reorg depth) = 106
55+
/// DOGE: 240 (nCoinbaseMaturity post-DigiShield) + 10 (reorg safety) = 250
56+
/// Reference: litecoin/src/consensus/consensus.h, dogecoin/src/chainparams.cpp
57+
static constexpr uint32_t LTC_MINING_GATE_DEPTH = LTC_LIMITS.coinbase_maturity + LTC_LIMITS.pegout_maturity; // 106
58+
static constexpr uint32_t DOGE_MINING_GATE_DEPTH = DOGE_LIMITS.coinbase_maturity + 10; // 250
59+
60+
/// Tip age threshold for considering chain synced (seconds).
61+
/// Both LTC and DOGE use 24 hours (86400s) as DEFAULT_MAX_TIP_AGE.
62+
/// Reference: litecoin/src/validation.h DEFAULT_MAX_TIP_AGE = 24 * 60 * 60
63+
/// Reference: dogecoin/src/validation.h DEFAULT_MAX_TIP_AGE = 24 * 60 * 60
64+
static constexpr uint32_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60; // 86400s
65+
5366
/// Check if a value is within the valid money range for a chain.
5467
/// Reference: LTC/DOGE amount.h MoneyRange()
5568
inline bool money_range(int64_t v, const ChainLimits& lim) {

src/impl/doge/coin/header_chain.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <impl/ltc/coin/block.hpp>
1313
#include <impl/doge/coin/chain_params.hpp>
14+
#include <core/coin/utxo.hpp> // DEFAULT_MAX_TIP_AGE
1415

1516
#include <core/uint256.hpp>
1617
#include <core/leveldb_store.hpp>
@@ -371,18 +372,17 @@ class HeaderChain {
371372
return m_headers.count(prev_hash) > 0;
372373
}
373374

374-
/// Whether the chain is synced (tip timestamp within 2 hours of wall clock).
375-
/// The 2-hour (7200s) threshold matches Bitcoin Core's IsInitialBlockDownload()
376-
/// check (chainparams.h nMaxTipAge). p2pool uses the same gate implicitly:
377-
/// getblocktemplate() fails until the daemon considers itself synced.
375+
/// Whether the chain is synced (tip timestamp within DEFAULT_MAX_TIP_AGE of wall clock).
376+
/// Both litecoind and dogecoind use 24 hours (86400s) as DEFAULT_MAX_TIP_AGE.
377+
/// Reference: dogecoin/src/validation.h DEFAULT_MAX_TIP_AGE = 24 * 60 * 60
378378
bool is_synced() const {
379379
std::lock_guard<std::mutex> lock(m_mutex);
380380
if (m_tip.IsNull()) return false;
381381
auto it = m_headers.find(m_tip);
382382
if (it == m_headers.end()) return false;
383383
auto now = static_cast<uint32_t>(std::time(nullptr));
384384
uint32_t age = now - it->second.header.m_timestamp;
385-
bool synced = age < 7200; // 2 hours
385+
bool synced = age < core::coin::DEFAULT_MAX_TIP_AGE; // 24 hours (86400s)
386386
// Log state changes (throttled via static)
387387
static bool s_last_synced = false;
388388
if (synced != s_last_synced) {

src/impl/ltc/coin/header_chain.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/// Persistence via LevelDB for fast restarts.
88

99
#include "block.hpp"
10+
#include <core/coin/utxo.hpp> // DEFAULT_MAX_TIP_AGE
1011

1112
#include <core/uint256.hpp>
1213
#include <core/leveldb_store.hpp>
@@ -536,18 +537,19 @@ class HeaderChain {
536537
return m_headers.count(prev_hash) > 0;
537538
}
538539

539-
/// Whether the chain is synced (tip timestamp within 2 hours of wall clock).
540-
/// The 2-hour (7200s) threshold matches Bitcoin Core's IsInitialBlockDownload()
541-
/// check (chainparams.h nMaxTipAge). p2pool uses the same gate implicitly:
542-
/// getblocktemplate() fails until litecoind considers itself synced.
540+
/// Whether the chain is synced (tip timestamp within DEFAULT_MAX_TIP_AGE of wall clock).
541+
/// Both litecoind and dogecoind use 24 hours (86400s) as DEFAULT_MAX_TIP_AGE.
542+
/// Reference: litecoin/src/validation.h DEFAULT_MAX_TIP_AGE = 24 * 60 * 60
543+
/// p2pool uses the same gate implicitly: getblocktemplate() fails until
544+
/// litecoind considers itself synced (tip within nMaxTipAge).
543545
bool is_synced() const {
544546
std::lock_guard<std::mutex> lock(m_mutex);
545547
if (m_tip.IsNull()) return false;
546548
auto it = m_headers.find(m_tip);
547549
if (it == m_headers.end()) return false;
548550
auto now = static_cast<uint32_t>(std::time(nullptr));
549551
uint32_t age = now - it->second.header.m_timestamp;
550-
bool synced = age < 7200; // 2 hours
552+
bool synced = age < core::coin::DEFAULT_MAX_TIP_AGE; // 24 hours (86400s)
551553
// Log state changes (throttled via static)
552554
static bool s_last_synced = false;
553555
if (synced != s_last_synced) {

0 commit comments

Comments
 (0)