aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-06-29 16:39:58 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-06-29 16:41:29 +0200
commit0564c5b795d1be675a0ac0a2e8038db0970ac376 (patch)
tree18ebd1a489a1b5210d193f34ffdd3bfb45ece78f /src
parent24f24896d602bef3323c5ff66bbccc92448e89d5 (diff)
parent6a4b97e8633c64593d7d0c9bd18079e52bc03e82 (diff)
downloadbitcoin-0564c5b795d1be675a0ac0a2e8038db0970ac376.tar.xz
Merge pull request #6337
6a4b97e Testing infrastructure: mocktime fixes (Gavin Andresen)
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp3
-rw-r--r--src/rpcmisc.cpp11
2 files changed, 13 insertions, 1 deletions
diff --git a/src/init.cpp b/src/init.cpp
index bcdd1f2f3d..c4e3573de3 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -868,6 +868,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
fAlerts = GetBoolArg("-alerts", DEFAULT_ALERTS);
+ // Option to startup with mocktime set (used for regression testing):
+ SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op
+
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
// Initialize elliptic curve code
diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp
index 1d47bc06a5..cab57d7027 100644
--- a/src/rpcmisc.cpp
+++ b/src/rpcmisc.cpp
@@ -378,10 +378,19 @@ UniValue setmocktime(const UniValue& params, bool fHelp)
if (!Params().MineBlocksOnDemand())
throw runtime_error("setmocktime for regression testing (-regtest mode) only");
- LOCK(cs_main);
+ // cs_vNodes is locked and node send/receive times are updated
+ // atomically with the time change to prevent peers from being
+ // disconnected because we think we haven't communicated with them
+ // in a long time.
+ LOCK2(cs_main, cs_vNodes);
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
SetMockTime(params[0].get_int64());
+ uint64_t t = GetTime();
+ BOOST_FOREACH(CNode* pnode, vNodes) {
+ pnode->nLastSend = pnode->nLastRecv = t;
+ }
+
return NullUniValue;
}