Browse Source

log polarity

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
990e4e0d44
  1. 37
      libethereum/Client.cpp
  2. 11
      libethereum/Client.h
  3. 6
      libevm/ExtVMFace.h

37
libethereum/Client.cpp

@ -480,7 +480,7 @@ void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Hash&
} }
} }
void Client::appendFromNewBlock(h256 const& _block, h256Hash& io_changed) void Client::appendFromBlock(h256 const& _block, bool _polarity, h256Hash& io_changed)
{ {
// TODO: more precise check on whether the txs match. // TODO: more precise check on whether the txs match.
auto d = m_bc.info(_block); auto d = m_bc.info(_block);
@ -503,7 +503,7 @@ void Client::appendFromNewBlock(h256 const& _block, h256Hash& io_changed)
auto transactionHash = transaction(d.hash(), j).sha3(); auto transactionHash = transaction(d.hash(), j).sha3();
// filter catches them // filter catches them
for (LogEntry const& l: m) for (LogEntry const& l: m)
i.second.changes.push_back(LocalisedLogEntry(l, d, transactionHash, j, logIndex)); i.second.changes.push_back(LocalisedLogEntry(l, d, transactionHash, j, logIndex, _polarity));
io_changed.insert(i.first); io_changed.insert(i.first);
} }
} }
@ -656,10 +656,10 @@ void Client::syncTransactionQueue()
h->noteNewTransactions(); h->noteNewTransactions();
} }
void Client::onChainChanged(ImportRoute const& _ir) void Client::onDeadBlocks(h256s const& _blocks, h256Hash& io_changed)
{ {
// insert transactions that we are declaring the dead part of the chain // insert transactions that we are declaring the dead part of the chain
for (auto const& h: _ir.deadBlocks()) for (auto const& h: _blocks)
{ {
clog(ClientNote) << "Dead block:" << h; clog(ClientNote) << "Dead block:" << h;
for (auto const& t: m_bc.transactions(h)) for (auto const& t: m_bc.transactions(h))
@ -669,8 +669,14 @@ void Client::onChainChanged(ImportRoute const& _ir)
} }
} }
for (auto const& h: _blocks)
appendFromBlock(h, false, io_changed);
}
void Client::onNewBlocks(h256s const& _blocks, h256Hash& io_changed)
{
// remove transactions from m_tq nicely rather than relying on out of date nonce later on. // remove transactions from m_tq nicely rather than relying on out of date nonce later on.
for (auto const& h: _ir.liveBlocks()) for (auto const& h: _blocks)
{ {
clog(ClientChat) << "Live block:" << h; clog(ClientChat) << "Live block:" << h;
for (auto const& th: m_bc.transactionHashes(h)) for (auto const& th: m_bc.transactionHashes(h))
@ -683,12 +689,12 @@ void Client::onChainChanged(ImportRoute const& _ir)
if (auto h = m_host.lock()) if (auto h = m_host.lock())
h->noteNewBlocks(); h->noteNewBlocks();
h256Hash changeds; for (auto const& h: _blocks)
for (auto const& h: _ir.liveBlocks()) appendFromBlock(h, true, io_changed);
appendFromNewBlock(h, changeds); }
// RESTART MINING
void Client::restartMining()
{
bool preChanged = false; bool preChanged = false;
State newPreMine; State newPreMine;
DEV_READ_GUARDED(x_preMine) DEV_READ_GUARDED(x_preMine)
@ -717,15 +723,20 @@ void Client::onChainChanged(ImportRoute const& _ir)
DEV_READ_GUARDED(x_working) DEV_WRITE_GUARDED(x_postMine) DEV_READ_GUARDED(x_working) DEV_WRITE_GUARDED(x_postMine)
m_postMine = m_working; m_postMine = m_working;
changeds.insert(PendingChangedFilter);
onPostStateChanged(); onPostStateChanged();
} }
}
void Client::onChainChanged(ImportRoute const& _ir)
{
h256Hash changeds;
onDeadBlocks(_ir.deadBlocks(), changeds);
onNewBlocks(_ir.liveBlocks(), changeds);
restartMining();
// Quick hack for now - the TQ at this point already has the prior pending transactions in it; // Quick hack for now - the TQ at this point already has the prior pending transactions in it;
// we should resync with it manually until we are stricter about what constitutes "knowing". // we should resync with it manually until we are stricter about what constitutes "knowing".
onTransactionQueueReady(); onTransactionQueueReady();
noteChanged(changeds); noteChanged(changeds);
} }

11
libethereum/Client.h

@ -251,7 +251,7 @@ protected:
/// Collate the changed filters for the hash of the given block. /// Collate the changed filters for the hash of the given block.
/// Insert any filters that are activated into @a o_changed. /// Insert any filters that are activated into @a o_changed.
void appendFromNewBlock(h256 const& _blockHash, h256Hash& io_changed); void appendFromBlock(h256 const& _blockHash, bool _polarity, h256Hash& io_changed);
/// Record that the set of filters @a _filters have changed. /// Record that the set of filters @a _filters have changed.
/// This doesn't actually make any callbacks, but incrememnts some counters in m_watches. /// This doesn't actually make any callbacks, but incrememnts some counters in m_watches.
@ -270,6 +270,15 @@ private:
/// Called when wouldMine(), turboMining(), isChainBad(), forceMining(), pendingTransactions() have changed. /// Called when wouldMine(), turboMining(), isChainBad(), forceMining(), pendingTransactions() have changed.
void rejigMining(); void rejigMining();
/// Called on chain changes
void onDeadBlocks(h256s const& _blocks, h256Hash& io_changed);
/// Called on chain changes
void onNewBlocks(h256s const& _blocks, h256Hash& io_changed);
/// Called after processing blocks by onChainChanged(_ir)
void restartMining();
/// Magically called when the chain has changed. An import route is provided. /// Magically called when the chain has changed. An import route is provided.
/// Called by either submitWork() or in our main thread through syncBlockQueue(). /// Called by either submitWork() or in our main thread through syncBlockQueue().
void onChainChanged(ImportRoute const& _ir); void onChainChanged(ImportRoute const& _ir);

6
libevm/ExtVMFace.h

@ -75,8 +75,9 @@ struct LocalisedLogEntry: public LogEntry
BlockInfo const& _bi, BlockInfo const& _bi,
h256 _th, h256 _th,
unsigned _ti, unsigned _ti,
unsigned _li unsigned _li,
): LogEntry(_le), blockHash(_bi.hash()), blockNumber((BlockNumber)_bi.number), transactionHash(_th), transactionIndex(_ti), logIndex(_li), mined(true) {}; bool _polarity = true
): LogEntry(_le), blockHash(_bi.hash()), blockNumber((BlockNumber)_bi.number), transactionHash(_th), transactionIndex(_ti), logIndex(_li), mined(true), polarity(_polarity) {};
h256 blockHash = h256(); h256 blockHash = h256();
BlockNumber blockNumber = 0; BlockNumber blockNumber = 0;
@ -84,6 +85,7 @@ struct LocalisedLogEntry: public LogEntry
unsigned transactionIndex = 0; unsigned transactionIndex = 0;
unsigned logIndex = 0; unsigned logIndex = 0;
bool mined = false; bool mined = false;
bool polarity = true;
h256 special = h256(); h256 special = h256();
}; };

Loading…
Cancel
Save