aboutsummaryrefslogtreecommitdiff
path: root/src/rpcmisc.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2015-06-19 10:42:39 -0400
committerGavin Andresen <gavinandresen@gmail.com>2015-06-24 15:18:55 -0400
commit6a4b97e8633c64593d7d0c9bd18079e52bc03e82 (patch)
tree518903d0d15fc2614e4b5ad51d8687a15160206f /src/rpcmisc.cpp
parent91389e51c78ae3565b037e31dd5382b52bd75136 (diff)
Testing infrastructure: mocktime fixes
New, undocumented-on-purpose -mocktime=timestamp command-line argument to startup with mocktime set. Needed because time-related blockchain sanity checks are done on startup, before a test has a chance to make a setmocktime RPC call. And changed the setmocktime RPC call so calling it will not result in currently connected peers being disconnected due to inactivity timeouts.
Diffstat (limited to 'src/rpcmisc.cpp')
-rw-r--r--src/rpcmisc.cpp11
1 files changed, 10 insertions, 1 deletions
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;
}