Merge pull request #1692 from ethereum/rpc-mining-time

Use maxMiningTime in mining as opposed to poll counter
This commit is contained in:
chriseth 2017-02-14 13:50:57 +01:00 committed by GitHub
commit 91d5515c33
2 changed files with 12 additions and 11 deletions

View File

@ -243,27 +243,30 @@ void RPCSession::test_mineBlocks(int _number)
u256 startBlock = fromBigEndian<u256>(fromHex(rpcCall("eth_blockNumber").asString())); u256 startBlock = fromBigEndian<u256>(fromHex(rpcCall("eth_blockNumber").asString()));
BOOST_REQUIRE(rpcCall("test_mineBlocks", { to_string(_number) }, true) == true); BOOST_REQUIRE(rpcCall("test_mineBlocks", { to_string(_number) }, true) == true);
bool mined = false;
// We auto-calibrate the time it takes to mine the transaction. // We auto-calibrate the time it takes to mine the transaction.
// It would be better to go without polling, but that would probably need a change to the test client // It would be better to go without polling, but that would probably need a change to the test client
auto startTime = std::chrono::steady_clock::now();
unsigned sleepTime = m_sleepTime; unsigned sleepTime = m_sleepTime;
size_t polls = 0; size_t tries = 0;
for (; polls < 14 && !mined; ++polls) for (; ; ++tries)
{ {
std::this_thread::sleep_for(chrono::milliseconds(sleepTime)); std::this_thread::sleep_for(chrono::milliseconds(sleepTime));
auto endTime = std::chrono::steady_clock::now();
unsigned timeSpent = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();
if (timeSpent > m_maxMiningTime)
BOOST_FAIL("Error in test_mineBlocks: block mining timeout!");
if (fromBigEndian<u256>(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number) if (fromBigEndian<u256>(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number)
mined = true; break;
else else
sleepTime *= 2; sleepTime *= 2;
} }
if (polls > 1) if (tries > 1)
{ {
m_successfulMineRuns = 0; m_successfulMineRuns = 0;
m_sleepTime += 2; m_sleepTime += 2;
} }
else if (polls == 1) else if (tries == 1)
{ {
m_successfulMineRuns++; m_successfulMineRuns++;
if (m_successfulMineRuns > 5) if (m_successfulMineRuns > 5)
@ -273,9 +276,6 @@ void RPCSession::test_mineBlocks(int _number)
m_sleepTime--; m_sleepTime--;
} }
} }
if (!mined)
BOOST_FAIL("Error in test_mineBlocks: block mining timeout!");
} }
void RPCSession::test_modifyTimestamp(size_t _timestamp) void RPCSession::test_modifyTimestamp(size_t _timestamp)

View File

@ -126,7 +126,8 @@ private:
IPCSocket m_ipcSocket; IPCSocket m_ipcSocket;
size_t m_rpcSequence = 1; size_t m_rpcSequence = 1;
unsigned m_sleepTime = 10; unsigned m_maxMiningTime = 15000; // 15 seconds
unsigned m_sleepTime = 10; // 10 milliseconds
unsigned m_successfulMineRuns = 0; unsigned m_successfulMineRuns = 0;
std::vector<std::string> m_accounts; std::vector<std::string> m_accounts;