Browse Source

More fixes & debuging.

cl-refactor
Gav Wood 10 years ago
parent
commit
030745a121
  1. 4
      alethzero/MainWin.cpp
  2. 11
      libethereum/BlockChain.cpp
  3. 2
      libethereum/BlockChain.h
  4. 92
      libethereum/Client.cpp
  5. 6
      libethereum/PeerSession.cpp
  6. 11
      libqethereum/QEthereum.cpp
  7. 4
      libqethereum/QEthereum.h

4
alethzero/MainWin.cpp

@ -179,7 +179,6 @@ Main::Main(QWidget *parent) :
QWebFrame* f = ui->webView->page()->mainFrame();
f->disconnect(SIGNAL(javaScriptWindowObjectCleared()));
m_ethereum->setup(f);
auto qeth = m_ethereum;
connect(f, &QWebFrame::javaScriptWindowObjectCleared, QETH_INSTALL_JS_NAMESPACE(f, qeth, this));
});
@ -1333,7 +1332,10 @@ void Main::on_killBlockchain_triggered()
ui->net->setChecked(false);
m_client.reset();
m_client.reset(new Client("AlethZero", Address(), string(), true));
m_ethereum->setClient(m_client.get());
readSettings();
installWatches();
refreshAll();
}
bool Main::isCreation() const

11
libethereum/BlockChain.cpp

@ -165,19 +165,18 @@ bool contains(T const& _t, V const& _v)
return false;
}
bool BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB)
h256s BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB)
{
#if ETH_CATCH
try
#endif
{
import(_block, _stateDB);
return true;
return import(_block, _stateDB);
}
#if ETH_CATCH
catch (...)
{
return false;
return h256s();
}
#endif
}
@ -302,7 +301,9 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db)
ret = treeRoute(m_lastBlockHash, newHash);
m_lastBlockHash = newHash;
m_extrasDB->Put(m_writeOptions, ldb::Slice("best"), ldb::Slice((char const*)&newHash, 32));
clog(BlockChainNote) << " Imported and best. Has" << (details(bi.parentHash).children.size() - 1) << "siblings.";
clog(BlockChainNote) << " Imported and best. Has" << (details(bi.parentHash).children.size() - 1) << "siblings. Route:";
for (auto r: ret)
clog(BlockChainNote) << r;
}
else
{

2
libethereum/BlockChain.h

@ -111,7 +111,7 @@ public:
void process();
/// Attempt to import the given block.
bool attemptImport(bytes const& _block, OverlayDB const& _stateDB);
h256s attemptImport(bytes const& _block, OverlayDB const& _stateDB);
/// Import block into disk-backed DB
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain.

92
libethereum/Client.cpp

@ -131,6 +131,7 @@ unsigned Client::installWatch(h256 _h)
{
auto ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0;
m_watches[ret] = Watch(_h);
cdebug << "Install watch" << ret << _h;
return ret;
}
@ -148,6 +149,8 @@ unsigned Client::installWatch(TransactionFilter const& _f)
void Client::uninstallWatch(unsigned _i)
{
cdebug << "Uninstall watch" << _i;
lock_guard<mutex> l(m_filterLock);
auto it = m_watches.find(_i);
@ -185,7 +188,10 @@ void Client::noteChanged(h256Set const& _filters)
lock_guard<mutex> l(m_filterLock);
for (auto& i: m_watches)
if (_filters.count(i.second.id))
{
cdebug << "Watch activated" << i.first << i.second.id;
i.second.changes++;
}
}
void Client::startNetwork(unsigned short _listenPort, std::string const& _seedHost, unsigned short _port, NodeMode _mode, unsigned _peers, string const& _publicIP, bool _upnp)
@ -313,43 +319,10 @@ void Client::work(bool _justQueue)
for (auto i: newBlocks)
appendFromNewBlock(i, changeds);
changeds.insert(NewBlockFilter);
changeds.insert(NewPendingFilter); // if there's a new block, then we've probably reset the pending transactions.
}
}
// Synchronise state to block chain.
// This should remove any transactions on our queue that are included within our state.
// It also guarantees that the state reflects the longest (valid!) chain on the block chain.
// This might mean reverting to an earlier state and replaying some blocks, or, (worst-case:
// if there are no checkpoints before our fork) reverting to the genesis block and replaying
// all blocks.
// Resynchronise state with block chain & trans
{
ClientGuard l(this);
if (m_preMine.sync(m_bc) || m_postMine.address() != m_preMine.address())
{
if (m_doMine)
cnote << "New block on chain: Restarting mining operation.";
m_restartMining = true; // need to re-commit to mine.
m_postMine = m_preMine;
}
// returns h256s as blooms, once for each transaction.
h256s newPendingBlooms = m_postMine.sync(m_tq);
if (newPendingBlooms.size())
{
for (auto i: newPendingBlooms)
appendFromNewPending(i, changeds);
changeds.insert(NewPendingFilter);
if (m_doMine)
cnote << "Additional transaction ready: Restarting mining operation.";
m_restartMining = true;
}
}
noteChanged(changeds);
// Do some mining.
if (!_justQueue)
{
if (m_doMine)
@ -390,22 +363,59 @@ void Client::work(bool _justQueue)
m_mineProgress.requirement = mineInfo.requirement;
m_mineProgress.ms += 100;
m_mineProgress.hashes += mineInfo.hashes;
{
ClientGuard l(this);
m_mineHistory.push_back(mineInfo);
}
ClientGuard l(this);
m_mineHistory.push_back(mineInfo);
if (mineInfo.completed)
{
// Import block.
ClientGuard l(this);
m_postMine.completeMine();
m_bc.attemptImport(m_postMine.blockData(), m_stateDB);
h256s hs = m_bc.attemptImport(m_postMine.blockData(), m_stateDB);
if (hs.size())
{
for (auto h: hs)
appendFromNewBlock(h, changeds);
changeds.insert(NewBlockFilter);
//changeds.insert(NewPendingFilter); // if we mined the new block, then we've probably reset the pending transactions.
}
}
}
else
this_thread::sleep_for(chrono::milliseconds(100));
}
// Synchronise state to block chain.
// This should remove any transactions on our queue that are included within our state.
// It also guarantees that the state reflects the longest (valid!) chain on the block chain.
// This might mean reverting to an earlier state and replaying some blocks, or, (worst-case:
// if there are no checkpoints before our fork) reverting to the genesis block and replaying
// all blocks.
// Resynchronise state with block chain & trans
{
ClientGuard l(this);
if (m_preMine.sync(m_bc) || m_postMine.address() != m_preMine.address())
{
if (m_doMine)
cnote << "New block on chain: Restarting mining operation.";
m_restartMining = true; // need to re-commit to mine.
m_postMine = m_preMine;
changeds.insert(NewPendingFilter);
}
// returns h256s as blooms, once for each transaction.
h256s newPendingBlooms = m_postMine.sync(m_tq);
if (newPendingBlooms.size())
{
for (auto i: newPendingBlooms)
appendFromNewPending(i, changeds);
changeds.insert(NewPendingFilter);
if (m_doMine)
cnote << "Additional transaction ready: Restarting mining operation.";
m_restartMining = true;
}
}
noteChanged(changeds);
}
void Client::lock() const

6
libethereum/PeerSession.cpp

@ -31,9 +31,9 @@ using namespace eth;
#define clogS(X) eth::LogOutputStream<X, true>(false) << "| " << std::setw(2) << m_socket.native_handle() << "] "
static const eth::uint c_maxHashes = 4096; ///< Maximum number of hashes GetChain will ever send.
static const eth::uint c_maxBlocks = 2048; ///< Maximum number of blocks Blocks will ever send.
static const eth::uint c_maxBlocksAsk = 512; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain).
static const eth::uint c_maxHashes = 128; ///< Maximum number of hashes GetChain will ever send.
static const eth::uint c_maxBlocks = 32; ///< Maximum number of blocks Blocks will ever send.
static const eth::uint c_maxBlocksAsk = 32; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain).
PeerSession::PeerSession(PeerServer* _s, bi::tcp::socket _socket, uint _rNId, bi::address _peerAddress, unsigned short _peerPort):
m_server(_s),

11
libqethereum/QEthereum.cpp

@ -108,7 +108,7 @@ void QEthereum::clearWatches()
if (m_client)
for (auto i: m_watches)
m_client->uninstallWatch(i);
m_watches.clear();
m_watches.clear();
}
QString QEthereum::secretToAddress(QString _s) const
@ -116,15 +116,6 @@ QString QEthereum::secretToAddress(QString _s) const
return toQJS(KeyPair(toSecret(_s)).address());
}
void QEthereum::setup(QWebFrame*)
{
// Alex: JS codes moved to mainwin until qtwebkit bugs are resolved (#245)
}
void QEthereum::teardown(QWebFrame*)
{
}
Client* QEthereum::client() const
{
return m_client;

4
libqethereum/QEthereum.h

@ -91,13 +91,11 @@ public:
virtual ~QEthereum();
eth::Client* client() const;
void setClient(eth::Client* _c) { m_client = _c; }
/// Call when the client() is going to be deleted to make this object useless but safe.
void clientDieing();
void setup(QWebFrame* _e);
void teardown(QWebFrame* _e);
void setAccounts(QList<eth::KeyPair> _l) { m_accounts = _l; keysChanged(); }
Q_INVOKABLE QString ethTest() const { return "Hello world!"; }

Loading…
Cancel
Save