mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Auto-calibrate mining sleep time.
This commit is contained in:
parent
53f68a155f
commit
b9f5b675a6
@ -244,18 +244,37 @@ void RPCSession::test_mineBlocks(int _number)
|
||||
u256 startBlock = fromBigEndian<u256>(fromHex(rpcCall("eth_blockNumber").asString()));
|
||||
rpcCall("test_mineBlocks", { to_string(_number) }, true);
|
||||
|
||||
//@TODO do not use polling - but that would probably need a change to the test client
|
||||
unsigned sleepTime = 10;
|
||||
for (size_t polls = 0; polls < 10; ++polls)
|
||||
bool mined = false;
|
||||
|
||||
// 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
|
||||
|
||||
unsigned sleepTime = m_sleepTime;
|
||||
size_t polls = 0;
|
||||
for (; polls < 10 && !mined; ++polls)
|
||||
{
|
||||
if (fromBigEndian<u256>(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number)
|
||||
return;
|
||||
std::this_thread::sleep_for(chrono::milliseconds(sleepTime));
|
||||
if (sleepTime > 500)
|
||||
cout << "Mining timeout, sleeping for " << sleepTime << " ms" << endl;
|
||||
if (fromBigEndian<u256>(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number)
|
||||
mined = true;
|
||||
else
|
||||
sleepTime *= 2;
|
||||
}
|
||||
if (polls > 1)
|
||||
{
|
||||
m_successfulMineRuns = 0;
|
||||
m_sleepTime += 2;
|
||||
}
|
||||
else if (polls == 1)
|
||||
{
|
||||
m_successfulMineRuns++;
|
||||
if (m_successfulMineRuns > 5)
|
||||
{
|
||||
m_successfulMineRuns = 0;
|
||||
m_sleepTime--;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mined)
|
||||
BOOST_FAIL("Error in test_mineBlocks: block mining timeout!");
|
||||
}
|
||||
|
||||
|
@ -124,6 +124,8 @@ private:
|
||||
|
||||
IPCSocket m_ipcSocket;
|
||||
size_t m_rpcSequence = 1;
|
||||
unsigned m_sleepTime = 10;
|
||||
unsigned m_successfulMineRuns = 0;
|
||||
|
||||
std::vector<std::string> m_accounts;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user