Skip to content

Commit 0564c5b

Browse files
committed
Merge pull request #6337
6a4b97e Testing infrastructure: mocktime fixes (Gavin Andresen)
2 parents 24f2489 + 6a4b97e commit 0564c5b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/init.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
868868

869869
fAlerts = GetBoolArg("-alerts", DEFAULT_ALERTS);
870870

871+
// Option to startup with mocktime set (used for regression testing):
872+
SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op
873+
871874
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
872875

873876
// Initialize elliptic curve code

src/rpcmisc.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,19 @@ UniValue setmocktime(const UniValue& params, bool fHelp)
378378
if (!Params().MineBlocksOnDemand())
379379
throw runtime_error("setmocktime for regression testing (-regtest mode) only");
380380

381-
LOCK(cs_main);
381+
// cs_vNodes is locked and node send/receive times are updated
382+
// atomically with the time change to prevent peers from being
383+
// disconnected because we think we haven't communicated with them
384+
// in a long time.
385+
LOCK2(cs_main, cs_vNodes);
382386

383387
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
384388
SetMockTime(params[0].get_int64());
385389

390+
uint64_t t = GetTime();
391+
BOOST_FOREACH(CNode* pnode, vNodes) {
392+
pnode->nLastSend = pnode->nLastRecv = t;
393+
}
394+
386395
return NullUniValue;
387396
}

0 commit comments

Comments
 (0)