Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 20479be

Browse files
committed
Fix mining in solidity tests using test.mineBlocks - BlockChainSync should be in Idle mode (i.e. sync is complete) in order for mining to start.
1 parent d21a19a commit 20479be

File tree

6 files changed

+24
-3
lines changed

6 files changed

+24
-3
lines changed

libethereum/BlockChainSync.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class BlockChainSync: public HasInvariants
5858
/// Restart sync
5959
void restartSync();
6060

61+
/// Called after all blocks have been downloaded
62+
/// Public only for test mode
63+
void completeSync();
64+
6165
/// Called by peer to report status
6266
void onPeerStatus(std::shared_ptr<EthereumPeer> _peer);
6367

@@ -84,9 +88,6 @@ class BlockChainSync: public HasInvariants
8488
/// Resume downloading after witing state
8589
void continueSync();
8690

87-
/// Called after all blocks have been donloaded
88-
void completeSync();
89-
9091
/// Enter waiting state
9192
void pauseSync();
9293

libethereum/ClientTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,13 @@ void ClientTest::onNewBlocks(h256s const& _blocks, h256Hash& io_changed)
116116
if(--m_blocksToMine <= 0)
117117
stopSealing();
118118
}
119+
120+
bool ClientTest::completeSync()
121+
{
122+
auto h = m_host.lock();
123+
if (!h)
124+
return false;
125+
126+
h->completeSync();
127+
return true;
128+
}

libethereum/ClientTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ClientTest: public Client
5151
void modifyTimestamp(u256 const& _timestamp);
5252
void rewindToBlock(unsigned _number);
5353
bool addBlock(std::string const& _rlp);
54+
bool completeSync();
5455

5556
protected:
5657
unsigned m_blocksToMine;

libethereum/EthereumHost.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ void EthereumHost::reset()
421421
m_transactionsSent.clear();
422422
}
423423

424+
void EthereumHost::completeSync()
425+
{
426+
RecursiveGuard l(x_sync);
427+
m_sync->completeSync();
428+
}
429+
424430
void EthereumHost::doWork()
425431
{
426432
bool netChange = ensureInitialised();

libethereum/EthereumHost.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class EthereumHost: public p2p::HostCapability<EthereumPeer>, Worker
7070
void setNetworkId(u256 _n) { m_networkId = _n; }
7171

7272
void reset();
73+
/// Don't sync further - used only in test mode
74+
void completeSync();
7375

7476
bool isSyncing() const;
7577
bool isBanned(p2p::NodeID const& _id) const { return !!m_banned.count(_id); }

libweb3jsonrpc/Test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ bool Test::test_rewindToBlock(int _number)
9494
try
9595
{
9696
m_eth.rewind(_number);
97+
asClientTest(m_eth).completeSync();
9798
}
9899
catch (std::exception const&)
99100
{

0 commit comments

Comments
 (0)