Browse Source

Diagnostics for checking transaction dropping/resubmission

cl-refactor
Gav Wood 10 years ago
parent
commit
3525a62ccb
  1. 25
      libethereum/Client.cpp
  2. 5
      libethereum/Client.h
  3. 12
      libethereum/EthereumHost.cpp
  4. 6
      libethereum/EthereumHost.h

25
libethereum/Client.cpp

@ -505,13 +505,27 @@ void Client::doWork()
bool sgw; bool sgw;
tie(fresh, dead, sgw) = m_bc.sync(m_bq, db, 100); tie(fresh, dead, sgw) = m_bc.sync(m_bq, db, 100);
// TODO: remove transactions from m_tq nicely rather than relying on out of date nonce later on. // insert transactions that we are declaring the dead part of the chain
for (auto const& h: dead) for (auto const& h: dead)
{
clog(ClientNote) << "Dead block:" << h.abridged();
for (auto const& t: m_bc.transactions(h)) for (auto const& t: m_bc.transactions(h))
{
clog(ClientNote) << "Resubmitting transaction " << Transaction(t, CheckSignature::None);
m_tq.import(t); m_tq.import(t);
}
}
// remove transactions from m_tq nicely rather than relying on out of date nonce later on.
for (auto const& h: fresh) for (auto const& h: fresh)
{
clog(ClientChat) << "Mined block:" << h.abridged();
for (auto const& th: m_bc.transactionHashes(h)) for (auto const& th: m_bc.transactionHashes(h))
{
clog(ClientNote) << "Safely dropping transaction " << th;
m_tq.drop(th); m_tq.drop(th);
}
}
stillGotWork = stillGotWork | sgw; stillGotWork = stillGotWork | sgw;
if (!fresh.empty()) if (!fresh.empty())
@ -535,7 +549,7 @@ void Client::doWork()
// TODO: Move transactions pending from m_postMine back to transaction queue. // TODO: Move transactions pending from m_postMine back to transaction queue.
} }
// returns h256s as blooms, once for each transaction. // returns TransactionReceipts, once for each transaction.
cwork << "postSTATE <== TQ"; cwork << "postSTATE <== TQ";
TransactionReceipts newPendingReceipts = m_postMine.sync(m_bc, m_tq, *m_gp); TransactionReceipts newPendingReceipts = m_postMine.sync(m_bc, m_tq, *m_gp);
if (newPendingReceipts.size()) if (newPendingReceipts.size())
@ -548,8 +562,15 @@ void Client::doWork()
if (isMining()) if (isMining())
cnote << "Additional transaction ready: Restarting mining operation."; cnote << "Additional transaction ready: Restarting mining operation.";
resyncStateNeeded = true; resyncStateNeeded = true;
if (auto h = m_host.lock())
h->noteNewTransactions();
} }
} }
if (!changeds.empty())
if (auto h = m_host.lock())
h->noteNewBlocks();
if (resyncStateNeeded) if (resyncStateNeeded)
{ {
ReadGuard l(x_localMiners); ReadGuard l(x_localMiners);

5
libethereum/Client.h

@ -114,6 +114,11 @@ private:
std::array<u256, 9> m_octiles; std::array<u256, 9> m_octiles;
}; };
struct ClientNote: public LogChannel { static const char* name() { return "*C*"; } static const int verbosity = 2; };
struct ClientChat: public LogChannel { static const char* name() { return "=C="; } static const int verbosity = 4; };
struct ClientTrace: public LogChannel { static const char* name() { return "-C-"; } static const int verbosity = 7; };
struct ClientDetail: public LogChannel { static const char* name() { return " C "; } static const int verbosity = 14; };
/** /**
* @brief Main API hub for interfacing with Ethereum. * @brief Main API hub for interfacing with Ethereum.
*/ */

12
libethereum/EthereumHost.cpp

@ -159,9 +159,17 @@ void EthereumHost::doWork()
// If we've finished our initial sync (including getting all the blocks into the chain so as to reduce invalid transactions), start trading transactions & blocks // If we've finished our initial sync (including getting all the blocks into the chain so as to reduce invalid transactions), start trading transactions & blocks
if (!isSyncing() && m_chain.isKnown(m_latestBlockSent)) if (!isSyncing() && m_chain.isKnown(m_latestBlockSent))
{ {
if (m_newTransactions)
{
m_newTransactions = false;
maintainTransactions(); maintainTransactions();
}
if (m_newBlocks)
{
m_newBlocks = false;
maintainBlocks(h); maintainBlocks(h);
} }
}
for (auto p: peerSessions()) for (auto p: peerSessions())
if (shared_ptr<EthereumPeer> const& ep = p.first->cap<EthereumPeer>()) if (shared_ptr<EthereumPeer> const& ep = p.first->cap<EthereumPeer>())
@ -192,8 +200,10 @@ void EthereumHost::maintainTransactions()
{ {
b += ts[h].rlp(); b += ts[h].rlp();
++n; ++n;
m_transactionsSent.insert(h);
} }
for (auto const& t: ts)
m_transactionsSent.insert(t.first);
ep->clearKnownTransactions(); ep->clearKnownTransactions();
if (n || ep->m_requireTransactions) if (n || ep->m_requireTransactions)

6
libethereum/EthereumHost.h

@ -76,6 +76,9 @@ public:
bool isBanned(p2p::NodeId _id) const { return !!m_banned.count(_id); } bool isBanned(p2p::NodeId _id) const { return !!m_banned.count(_id); }
void noteNewTransactions() { m_newTransactions = true; }
void noteNewBlocks() { m_newBlocks = true; }
private: private:
std::vector<std::shared_ptr<EthereumPeer>> randomSelection(unsigned _percent = 25, std::function<bool(EthereumPeer*)> const& _allow = [](EthereumPeer const*){ return true; }); std::vector<std::shared_ptr<EthereumPeer>> randomSelection(unsigned _percent = 25, std::function<bool(EthereumPeer*)> const& _allow = [](EthereumPeer const*){ return true; });
@ -121,6 +124,9 @@ private:
h256Set m_transactionsSent; h256Set m_transactionsSent;
std::set<p2p::NodeId> m_banned; std::set<p2p::NodeId> m_banned;
bool m_newTransactions = false;
bool m_newBlocks = false;
}; };
} }

Loading…
Cancel
Save