Skip to content

Commit dc49514

Browse files
authored
Merge pull request #2 from FairCoinOfficial/fix/ibd-mnsync-bootstrap
Fix node self-deadlock when reviving a stalled PoW→PoS chain
2 parents 7eeefb3 + f959d9f commit dc49514

5 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/chainparams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class CMainParams : public CChainParams
434434

435435
nPoolMaxTransactions = 3;
436436
strSporkKey = "044072106100b738bb99d24f2230708ebebdca687a01f8d0ce138551da829cf4e28ac499242806279787afc5293c97b72694f111e91c376cdb0d0fda8778ad4425";
437-
strObfuscationPoolDummyAddress = "";
437+
strObfuscationPoolDummyAddress = "FRZou2ApnnNyHGJRqoHgVLDF71Yviuhfz2"; // valid FairCoin addr; used only to build the collateral-check dummy tx (must be standard, never broadcast)
438438
nStartMasternodePayments = 1744156800; // April 9, 2026
439439
}
440440

src/main.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include <boost/filesystem/fstream.hpp>
3737
#include <boost/lexical_cast.hpp>
3838
#include <boost/thread.hpp>
39-
#include <boost/version.hpp>
4039

4140
using namespace boost;
4241
using namespace std;
@@ -205,9 +204,7 @@ struct CMainSignals {
205204

206205
void RegisterValidationInterface(CValidationInterface* pwalletIn)
207206
{
208-
#if BOOST_VERSION >= 107300
209207
using namespace boost::placeholders;
210-
#endif
211208
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
212209
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
213210
g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
@@ -218,9 +215,7 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn)
218215

219216
void UnregisterValidationInterface(CValidationInterface* pwalletIn)
220217
{
221-
#if BOOST_VERSION >= 107300
222218
using namespace boost::placeholders;
223-
#endif
224219
g_signals.BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
225220
g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn));
226221
g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
@@ -1881,7 +1876,7 @@ bool IsInitialBlockDownload()
18811876
if (lockIBDState)
18821877
return false;
18831878
bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 ||
1884-
pindexBestHeader->GetBlockTime() < GetTime() - 6 * 60 * 60); // ~144 blocks behind -> 2 x fork detection time
1879+
pindexBestHeader->GetBlockTime() < GetTime() - GetArg("-maxtipage", 6 * 60 * 60)); // ~144 blocks behind -> 2 x fork detection time; -maxtipage overrides the staleness window (default 6h)
18851880
if (!state)
18861881
lockIBDState = true;
18871882
return state;

src/masternode-sync.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool CMasternodeSync::IsBlockchainSynced()
3535
static int64_t lastProcess = GetTime();
3636

3737
// if the last call to this function was more than 60 minutes ago (client was in sleep mode) reset the sync process
38-
if (GetTime() - lastProcess > 60 * 60) {
38+
if (GetTime() - lastProcess > GetArg("-maxtipage", 60 * 60)) {
3939
Reset();
4040
fBlockchainSynced = false;
4141
}
@@ -52,7 +52,7 @@ bool CMasternodeSync::IsBlockchainSynced()
5252
if (pindex == NULL) return false;
5353

5454

55-
if (pindex->nTime + 60 * 60 < GetTime())
55+
if (pindex->nTime + GetArg("-maxtipage", 60 * 60) < GetTime())
5656
return false;
5757

5858
fBlockchainSynced = true;
@@ -237,13 +237,13 @@ void CMasternodeSync::Process()
237237
if (tick++ % MASTERNODE_SYNC_TIMEOUT != 0) return;
238238

239239
if (IsSynced()) {
240-
/*
241-
Resync if we lose all masternodes from sleep/wake or failure to sync originally
240+
/*
241+
Stay synced once finished. Previously this Reset() every tick whenever there were
242+
0 enabled masternodes, which on a small/bootstrapping network (legitimately 0 MNs)
243+
caused an endless resync loop so sync never stabilized. New masternodes are still
244+
picked up via normal mnb processing; a restart re-syncs from scratch anyway.
242245
*/
243-
if (mnodeman.CountEnabled() == 0) {
244-
Reset();
245-
} else
246-
return;
246+
return;
247247
}
248248

249249
//try syncing again
@@ -261,6 +261,16 @@ void CMasternodeSync::Process()
261261
if (Params().NetworkID() != CBaseChainParams::REGTEST &&
262262
!IsBlockchainSynced() && RequestedMasternodeAssets > MASTERNODE_SYNC_SPORKS) return;
263263

264+
// Advance the sync asset by time when it stalls. On small/zero-masternode networks no peer
265+
// ever returns LIST/MNW/BUDGET items, and the per-peer "fulfilled request" gating then leaves
266+
// the asset stuck forever (so IsSynced() is never reached). When real data exists the normal
267+
// data-driven transitions above fire well before this timeout, so this only affects the empty case.
268+
if (RequestedMasternodeAssets >= MASTERNODE_SYNC_SPORKS &&
269+
GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5) {
270+
GetNextAsset();
271+
return;
272+
}
273+
264274
TRY_LOCK(cs_vNodes, lockRecv);
265275
if (!lockRecv) return;
266276

src/masternode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void CMasternode::Check(bool forceCheck)
211211
if (!unitTest) {
212212
CValidationState state;
213213
CMutableTransaction tx = CMutableTransaction();
214-
CTxOut vout = CTxOut(9999.99 * COIN, obfuscationPool.collateralPubKey);
214+
CTxOut vout = CTxOut(4999.99 * COIN, obfuscationPool.collateralPubKey); // MASTER_NODE_AMOUNT (5000) minus 0.01 fee margin
215215
tx.vin.push_back(vin);
216216
tx.vout.push_back(vout);
217217

@@ -572,7 +572,7 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS)
572572

573573
CValidationState state;
574574
CMutableTransaction tx = CMutableTransaction();
575-
CTxOut vout = CTxOut(9999.99 * COIN, obfuscationPool.collateralPubKey);
575+
CTxOut vout = CTxOut(4999.99 * COIN, obfuscationPool.collateralPubKey); // MASTER_NODE_AMOUNT (5000) minus 0.01 fee margin
576576
tx.vin.push_back(vin);
577577
tx.vout.push_back(vout);
578578

src/masternodeman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
959959

960960
CValidationState state;
961961
CMutableTransaction tx = CMutableTransaction();
962-
CTxOut vout = CTxOut(9999.99 * COIN, obfuscationPool.collateralPubKey);
962+
CTxOut vout = CTxOut(4999.99 * COIN, obfuscationPool.collateralPubKey); // MASTER_NODE_AMOUNT (5000) minus 0.01 fee margin
963963
tx.vin.push_back(vin);
964964
tx.vout.push_back(vout);
965965

0 commit comments

Comments
 (0)