Ethereum  PoC-8
The C++ Implementation of Ethereum
Client.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #include "Client.h"
23 #include "Block.h"
24 #include "EthereumCapability.h"
25 #include "Executive.h"
26 #include "SnapshotStorage.h"
27 #include "TransactionQueue.h"
28 #include <libdevcore/DBFactory.h>
29 #include <libdevcore/Log.h>
30 #include <libp2p/Host.h>
31 #include <boost/filesystem.hpp>
32 #include <chrono>
33 #include <memory>
34 #include <thread>
35 
36 using namespace std;
37 using namespace dev;
38 using namespace dev::eth;
39 using namespace p2p;
40 namespace fs = boost::filesystem;
41 
42 static_assert(BOOST_VERSION >= 106400, "Wrong boost headers version");
43 
44 namespace
45 {
46 std::string filtersToString(h256Hash const& _fs)
47 {
48  std::stringstream str;
49  str << "{";
50  unsigned i = 0;
51  for (h256 const& f : _fs)
52  {
53  str << (i++ ? ", " : "");
54  if (f == PendingChangedFilter)
55  str << "pending";
56  else if (f == ChainChangedFilter)
57  str << "chain";
58  else
59  str << f;
60  }
61  str << "}";
62  return str.str();
63 }
64 } // namespace
65 
66 std::ostream& dev::eth::operator<<(std::ostream& _out, ActivityReport const& _r)
67 {
68  _out << "Since " << toString(_r.since) << " (" << std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - _r.since).count();
69  _out << "): " << _r.ticks << "ticks";
70  return _out;
71 }
72 
73 Client::Client(ChainParams const& _params, int _networkID, p2p::Host& _host,
74  std::shared_ptr<GasPricer> _gpForAdoption, fs::path const& _dbPath,
75  fs::path const& _snapshotPath, WithExisting _forceAction, TransactionQueue::Limits const& _l)
76  : Worker("eth", 0),
77  m_bc(_params, _dbPath, _forceAction,
78  [](unsigned d, unsigned t) {
79  std::cerr << "REVISING BLOCKCHAIN: Processed " << d << " of " << t << "...\r";
80  }),
81  m_tq(_l),
82  m_gp(_gpForAdoption ? _gpForAdoption : make_shared<TrivialGasPricer>()),
83  m_preSeal(chainParams().accountStartNonce),
84  m_postSeal(chainParams().accountStartNonce),
85  m_working(chainParams().accountStartNonce)
86 {
87  init(_host, _dbPath, _snapshotPath, _forceAction, _networkID);
88 }
89 
91 {
92  m_signalled.notify_all(); // to wake up the thread from Client::doWork()
93  stopWorking();
94  terminate();
95 }
96 
97 void Client::init(p2p::Host& _extNet, fs::path const& _dbPath,
98  fs::path const& _snapshotDownloadPath, WithExisting _forceAction, u256 _networkId)
99 {
101 
102  // Cannot be opened until after blockchain is open, since BlockChain may upgrade the database.
103  // TODO: consider returning the upgrade mechanism here. will delaying the opening of the blockchain database
104  // until after the construction.
105  m_stateDB = State::openDB(_dbPath, bc().genesisHash(), _forceAction);
106  // LAZY. TODO: move genesis state construction/commiting to stateDB openning and have this just take the root from the genesis block.
109 
110  m_bq.setChain(bc());
111 
112  m_lastGetWork = std::chrono::system_clock::now() - chrono::seconds(30);
113  m_tqReady = m_tq.onReady([=]() {
114  this->onTransactionQueueReady();
115  }); // TODO: should read m_tq->onReady(thisThread, syncTransactionQueue);
116  m_tqReplaced = m_tq.onReplaced([=](h256 const&) { m_needStateReset = true; });
117  m_bqReady = m_bq.onReady([=]() {
118  this->onBlockQueueReady();
119  }); // TODO: should read m_bq->onReady(thisThread, syncBlockQueue);
120  m_bq.setOnBad([=](Exception& ex) { this->onBadBlock(ex); });
121  bc().setOnBad([=](Exception& ex) { this->onBadBlock(ex); });
122  bc().setOnBlockImport([=](BlockHeader const& _info) {
123  if (auto h = m_host.lock())
124  h->onBlockImported(_info);
125  });
126 
127  if (_forceAction == WithExisting::Rescue)
128  bc().rescue(m_stateDB);
129 
130  m_gp->update(bc());
131 
132  // create Ethereum capability only if we're not downloading the snapshot
133  if (_snapshotDownloadPath.empty())
134  {
135  auto ethCapability = make_shared<EthereumCapability>(
136  _extNet.capabilityHost(), bc(), m_stateDB, m_tq, m_bq, _networkId);
137  _extNet.registerCapability(ethCapability);
138  m_host = ethCapability;
139  }
140 
141  // create Warp capability if we either download snapshot or can give out snapshot
142  auto const importedSnapshot = importedSnapshotPath(_dbPath, bc().genesisHash());
143  bool const importedSnapshotExists = fs::exists(importedSnapshot);
144  if (!_snapshotDownloadPath.empty() || importedSnapshotExists)
145  {
146  std::shared_ptr<SnapshotStorageFace> snapshotStorage(
147  importedSnapshotExists ? createSnapshotStorage(importedSnapshot) : nullptr);
148  auto warpCapability = make_shared<WarpCapability>(
149  _extNet.capabilityHost(), bc(), _networkId, _snapshotDownloadPath, snapshotStorage);
150  _extNet.registerCapability(warpCapability);
151  m_warpHost = warpCapability;
152  }
153 
154  doWork(false);
155 }
156 
157 ImportResult Client::queueBlock(bytes const& _block, bool _isSafe)
158 {
159  if (m_bq.status().verified + m_bq.status().verifying + m_bq.status().unverified > 10000)
160  this_thread::sleep_for(std::chrono::milliseconds(500));
161  return m_bq.import(&_block, _isSafe);
162 }
163 
164 tuple<ImportRoute, bool, unsigned> Client::syncQueue(unsigned _max)
165 {
166  stopWorking();
167  return bc().sync(m_bq, m_stateDB, _max);
168 }
169 
171 {
172  // BAD BLOCK!!!
173  bytes const* block = boost::get_error_info<errinfo_block>(_ex);
174  if (!block)
175  {
176  cwarn << "ODD: onBadBlock called but exception (" << _ex.what() << ") has no block in it.";
177  cwarn << boost::diagnostic_information(_ex);
178  return;
179  }
180 
181  badBlock(*block, _ex.what());
182 }
183 
185 {
186  while (true)
187  {
188  function<void()> f;
190  if (!m_functionQueue.empty())
191  {
192  f = m_functionQueue.front();
193  m_functionQueue.pop();
194  }
195  if (f)
196  f();
197  else
198  break;
199  }
200 }
201 
203 {
204  if (auto h = m_host.lock())
205  return h->networkId();
206  return 0;
207 }
208 
209 void Client::setNetworkId(u256 const& _n)
210 {
211  if (auto h = m_host.lock())
212  h->setNetworkId(_n);
213 }
214 
215 bool Client::isSyncing() const
216 {
217  if (auto h = m_host.lock())
218  return h->isSyncing();
219  return false;
220 }
221 
223 {
224  if (auto h = m_host.lock())
225  {
226  SyncState state = h->status().state;
227  return state != SyncState::Idle || h->bq().items().first > 10;
228  }
229  return false;
230 }
231 
233 {
234  // Synchronise the state according to the head of the block chain.
235  // TODO: currently it contains keys for *all* blocks. Make it remove old ones.
236  LOG(m_loggerDetail) << "startedWorking()";
237 
239  m_preSeal.sync(bc());
241  {
246  }
247 }
248 
250 {
251  // Synchronise the state according to the head of the block chain.
252  // TODO: currently it contains keys for *all* blocks. Make it remove old ones.
254  m_preSeal.sync(bc());
256  {
261  }
262 }
263 
265 {
266  reopenChain(bc().chainParams(), _we);
267 }
268 
270 {
271  m_signalled.notify_all(); // to wake up the thread from Client::doWork()
272  bool wasSealing = wouldSeal();
273  if (wasSealing)
274  stopSealing();
275  stopWorking();
276 
277  m_tq.clear();
278  m_bq.clear();
280 
281  {
283  WriteGuard l2(x_preSeal);
284  WriteGuard l3(x_working);
285 
286  m_preSeal = Block(chainParams().accountStartNonce);
287  m_postSeal = Block(chainParams().accountStartNonce);
288  m_working = Block(chainParams().accountStartNonce);
289 
290  m_stateDB = OverlayDB();
291  bc().reopen(_p, _we);
292  m_stateDB = State::openDB(db::databasePath(), bc().genesisHash(), _we);
293 
297  m_working = Block(chainParams().accountStartNonce);
298  }
299 
300  if (auto h = m_host.lock())
301  h->reset();
302 
303  startedWorking();
304  doWork();
305 
306  startWorking();
307  if (wasSealing)
308  startSealing();
309 }
310 
311 void Client::executeInMainThread(function<void ()> const& _function)
312 {
314  m_functionQueue.push(_function);
315  m_signalled.notify_all();
316 }
317 
319 {
321  {
322  if (!m_postSeal.pending().size())
323  return;
324  m_tq.clear();
327  }
328 
329  startSealing();
330  h256Hash changeds;
331  noteChanged(changeds);
332 }
333 
334 void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Hash& io_changed, h256 _sha3)
335 {
337  io_changed.insert(PendingChangedFilter);
338  m_specialFilters.at(PendingChangedFilter).push_back(_sha3);
339  for (pair<h256 const, InstalledFilter>& i: m_filters)
340  {
341  // acceptable number.
342  auto m = i.second.filter.matches(_receipt);
343  if (m.size())
344  {
345  // filter catches them
346  for (LogEntry const& l: m)
347  i.second.changes.push_back(LocalisedLogEntry(l));
348  io_changed.insert(i.first);
349  }
350  }
351 }
352 
353 void Client::appendFromBlock(h256 const& _block, BlockPolarity _polarity, h256Hash& io_changed)
354 {
355  // TODO: more precise check on whether the txs match.
356  auto receipts = bc().receipts(_block).receipts;
357 
359  io_changed.insert(ChainChangedFilter);
360  m_specialFilters.at(ChainChangedFilter).push_back(_block);
361  for (pair<h256 const, InstalledFilter>& i: m_filters)
362  {
363  // acceptable number & looks like block may contain a matching log entry.
364  for (size_t j = 0; j < receipts.size(); j++)
365  {
366  auto tr = receipts[j];
367  auto m = i.second.filter.matches(tr);
368  if (m.size())
369  {
370  auto transactionHash = transaction(_block, j).sha3();
371  // filter catches them
372  for (LogEntry const& l: m)
373  i.second.changes.push_back(LocalisedLogEntry(l, _block, (BlockNumber)bc().number(_block), transactionHash, j, 0, _polarity));
374  io_changed.insert(i.first);
375  }
376  }
377  }
378 }
379 
380 unsigned static const c_syncMin = 1;
381 unsigned static const c_syncMax = 1000;
382 double static const c_targetDuration = 1;
383 
385 {
386 // cdebug << "syncBlockQueue()";
387 
388  ImportRoute ir;
389  unsigned count;
390  Timer t;
391  tie(ir, m_syncBlockQueue, count) = bc().sync(m_bq, m_stateDB, m_syncAmount);
392  double elapsed = t.elapsed();
393 
394  if (count)
395  {
396  LOG(m_logger) << count << " blocks imported in " << unsigned(elapsed * 1000) << " ms ("
397  << (count / elapsed) << " blocks/s) in #" << bc().number();
398  }
399 
400  if (elapsed > c_targetDuration * 1.1 && count > c_syncMin)
401  m_syncAmount = max(c_syncMin, count * 9 / 10);
402  else if (count == m_syncAmount && elapsed < c_targetDuration * 0.9 && m_syncAmount < c_syncMax)
403  m_syncAmount = min(c_syncMax, m_syncAmount * 11 / 10 + 1);
404  if (ir.liveBlocks.empty())
405  return;
406  onChainChanged(ir);
407 }
408 
410 {
412 
413  Timer timer;
414 
415  h256Hash changeds;
416  TransactionReceipts newPendingReceipts;
417 
419  {
420  if (m_working.isSealed())
421  {
422  ctrace << "Skipping txq sync for a sealed block.";
423  return;
424  }
425 
426  tie(newPendingReceipts, m_syncTransactionQueue) = m_working.sync(bc(), m_tq, *m_gp);
427  }
428 
429  if (newPendingReceipts.empty())
430  {
431  auto s = m_tq.status();
432  ctrace << "No transactions to process. " << m_working.pending().size() << " pending, " << s.current << " queued, " << s.future << " future, " << s.unverified << " unverified";
433  return;
434  }
435 
439 
441  for (size_t i = 0; i < newPendingReceipts.size(); i++)
442  appendFromNewPending(newPendingReceipts[i], changeds, m_postSeal.pending()[i].sha3());
443 
444  // Tell farm about new transaction (i.e. restart mining).
446 
447  // Tell watches about the new transactions.
448  noteChanged(changeds);
449 
450  // Tell network about the new transactions.
451  if (auto h = m_host.lock())
452  h->noteNewTransactions();
453 
454  ctrace << "Processed " << newPendingReceipts.size() << " transactions in" << (timer.elapsed() * 1000) << "(" << (bool)m_syncTransactionQueue << ")";
455 }
456 
457 void Client::onDeadBlocks(h256s const& _blocks, h256Hash& io_changed)
458 {
459  // insert transactions that we are declaring the dead part of the chain
460  for (auto const& h: _blocks)
461  {
462  LOG(m_loggerDetail) << "Dead block: " << h;
463  for (auto const& t: bc().transactions(h))
464  {
465  LOG(m_loggerDetail) << "Resubmitting dead-block transaction "
467  ctrace << "Resubmitting dead-block transaction " << Transaction(t, CheckTransaction::None);
469  }
470  }
471 
472  for (auto const& h: _blocks)
473  appendFromBlock(h, BlockPolarity::Dead, io_changed);
474 }
475 
476 void Client::onNewBlocks(h256s const& _blocks, h256Hash& io_changed)
477 {
478  // remove transactions from m_tq nicely rather than relying on out of date nonce later on.
479  for (auto const& h: _blocks)
480  LOG(m_loggerDetail) << "Live block: " << h;
481 
482  if (auto h = m_host.lock())
483  h->noteNewBlocks();
484 
485  for (auto const& h: _blocks)
486  appendFromBlock(h, BlockPolarity::Live, io_changed);
487 }
488 
490 {
492  if (bc().currentHash() == m_working.info().parentHash())
493  return;
494 
495  restartMining();
496 }
497 
499 {
500  bool preChanged = false;
501  Block newPreMine(chainParams().accountStartNonce);
503  newPreMine = m_preSeal;
504 
505  // TODO: use m_postSeal to avoid re-evaluating our own blocks.
506  preChanged = newPreMine.sync(bc());
507 
509  if (!preChanged && m_preSeal.author() == m_postSeal.author())
510  {
512  return;
513  }
514 
516  m_preSeal = newPreMine;
518  m_working = newPreMine;
520  if (!m_postSeal.isSealed() || m_postSeal.info().hash() != newPreMine.info().parentHash())
521  for (auto const& t : m_postSeal.pending())
522  {
523  LOG(m_loggerDetail) << "Resubmitting post-seal transaction " << t;
524  // ctrace << "Resubmitting post-seal transaction " << t;
525  auto ir = m_tq.import(t, IfDropped::Retry);
526  if (ir != ImportResult::Success)
528  }
531 
533 
534  // Quick hack for now - the TQ at this point already has the prior pending transactions in it;
535  // we should resync with it manually until we are stricter about what constitutes "knowing".
537 }
538 
540 {
541  Block newPreMine(chainParams().accountStartNonce);
543  newPreMine = m_preSeal;
544 
546  m_working = newPreMine;
549 
552 }
553 
555 {
556 // ctrace << "onChainChanged()";
557  h256Hash changeds;
558  onDeadBlocks(_ir.deadBlocks, changeds);
559  for (auto const& t: _ir.goodTranactions)
560  {
561  LOG(m_loggerDetail) << "Safely dropping transaction " << t.sha3();
562  m_tq.dropGood(t);
563  }
564  onNewBlocks(_ir.liveBlocks, changeds);
565  if (!isMajorSyncing())
567  noteChanged(changeds);
569 }
570 
572 {
573  return chrono::system_clock::now() - m_lastGetWork < chrono::seconds(30);
574 }
575 
577 {
578  LOG(m_loggerDetail) << "Post state changed.";
579  m_signalled.notify_all();
580  m_remoteWorking = false;
581 }
582 
584 {
585  if (m_wouldSeal == true)
586  return;
587  LOG(m_logger) << "Mining Beneficiary: " << author();
588  if (author())
589  {
590  m_wouldSeal = true;
591  m_signalled.notify_all();
592  }
593  else
594  LOG(m_logger) << "You need to set an author in order to seal!";
595 }
596 
598 {
599  if ((wouldSeal() || remoteActive()) && !isMajorSyncing())
600  {
601  if (sealEngine()->shouldSeal(this))
602  {
603  m_wouldButShouldnot = false;
604 
605  LOG(m_loggerDetail) << "Rejigging seal engine...";
607  {
608  if (m_working.isSealed())
609  {
610  LOG(m_logger) << "Tried to seal sealed block...";
611  return;
612  }
613  // TODO is that needed? we have "Generating seal on" below
614  LOG(m_loggerDetail) << "Starting to seal block #" << m_working.info().number();
616  }
618  {
622  }
623 
624  if (wouldSeal())
625  {
626  sealEngine()->onSealGenerated([=](bytes const& _header) {
627  LOG(m_logger) << "Block sealed #" << BlockHeader(_header, HeaderData).number();
628  if (this->submitSealed(_header))
629  m_onBlockSealed(_header);
630  else
631  LOG(m_logger) << "Submitting block failed...";
632  });
633  ctrace << "Generating seal on " << m_sealingInfo.hash(WithoutSeal) << " #" << m_sealingInfo.number();
635  }
636  }
637  else
638  m_wouldButShouldnot = true;
639  }
640  if (!m_wouldSeal)
642 }
643 
644 void Client::noteChanged(h256Hash const& _filters)
645 {
647  if (_filters.size())
648  LOG(m_loggerWatch) << "noteChanged: " << filtersToString(_filters);
649  // accrue all changes left in each filter into the watches.
650  for (auto& w: m_watches)
651  if (_filters.count(w.second.id))
652  {
653  if (m_filters.count(w.second.id))
654  {
655  LOG(m_loggerWatch) << "!!! " << w.first << " " << w.second.id.abridged();
656  w.second.changes += m_filters.at(w.second.id).changes;
657  }
658  else if (m_specialFilters.count(w.second.id))
659  for (h256 const& hash: m_specialFilters.at(w.second.id))
660  {
662  << "!!! " << w.first << " "
663  << (w.second.id == PendingChangedFilter ?
664  "pending" :
665  w.second.id == ChainChangedFilter ? "chain" : "???");
666  w.second.changes.push_back(LocalisedLogEntry(SpecialLogEntry, hash));
667  }
668  }
669  // clear the filters now.
670  for (auto& i: m_filters)
671  i.second.changes.clear();
672  for (auto& i: m_specialFilters)
673  i.second.clear();
674 }
675 
676 void Client::doWork(bool _doWait)
677 {
678  bool t = true;
679  if (m_syncBlockQueue.compare_exchange_strong(t, false))
680  syncBlockQueue();
681 
682  if (m_needStateReset)
683  {
684  resetState();
685  m_needStateReset = false;
686  }
687 
688  t = true;
689  bool isSealed = false;
691  isSealed = m_working.isSealed();
692  if (!isSealed && !isMajorSyncing() && !m_remoteWorking && m_syncTransactionQueue.compare_exchange_strong(t, false))
694 
695  tick();
696 
697  rejigSealing();
698 
700 
702  isSealed = m_working.isSealed();
703  // If the block is sealed, we have to wait for it to tickle through the block queue
704  // (which only signals as wanting to be synced if it is ready).
705  if (!m_syncBlockQueue && !m_syncTransactionQueue && (_doWait || isSealed) && isWorking())
706  {
707  std::unique_lock<std::mutex> l(x_signalled);
708  m_signalled.wait_for(l, chrono::seconds(1));
709  }
710 }
711 
713 {
714  if (chrono::system_clock::now() - m_lastTick > chrono::seconds(1))
715  {
716  m_report.ticks++;
718  m_bq.tick();
719  m_lastTick = chrono::system_clock::now();
720  if (m_report.ticks == 15)
722  }
723 }
724 
726 {
727  if (chrono::system_clock::now() - m_lastGarbageCollection > chrono::seconds(5))
728  {
729  // watches garbage collection
730  vector<unsigned> toUninstall;
732  for (auto key: keysOf(m_watches))
733  if (m_watches[key].lastPoll != chrono::system_clock::time_point::max() && chrono::system_clock::now() - m_watches[key].lastPoll > chrono::seconds(20))
734  {
735  toUninstall.push_back(key);
737  << "GC: Uninstall " << key << " ("
738  << chrono::duration_cast<chrono::seconds>(
739  chrono::system_clock::now() - m_watches[key].lastPoll)
740  .count()
741  << " s old)";
742  }
743  for (auto i: toUninstall)
744  uninstallWatch(i);
745 
746  // blockchain GC
747  bc().garbageCollect();
748 
749  m_lastGarbageCollection = chrono::system_clock::now();
750  }
751 }
752 
754 {
755  startWorking();
756 }
757 
758 Block Client::block(h256 const& _block) const
759 {
760  try
761  {
762  Block ret(bc(), m_stateDB);
763  ret.populateFromChain(bc(), _block);
764  return ret;
765  }
766  catch (Exception& ex)
767  {
768  ex << errinfo_block(bc().block(_block));
769  onBadBlock(ex);
770  return Block(bc());
771  }
772 }
773 
774 Block Client::block(h256 const& _blockHash, PopulationStatistics* o_stats) const
775 {
776  try
777  {
778  Block ret(bc(), m_stateDB);
779  PopulationStatistics s = ret.populateFromChain(bc(), _blockHash);
780  if (o_stats)
781  swap(s, *o_stats);
782  return ret;
783  }
784  catch (Exception& ex)
785  {
786  ex << errinfo_block(bc().block(_blockHash));
787  onBadBlock(ex);
788  return Block(bc());
789  }
790 }
791 
793 {
794  doWork(false);
795 }
796 
798 {
800 }
801 
803 {
804  auto h = m_host.lock();
805  if (!h)
806  return SyncStatus();
807  SyncStatus status = h->status();
808  status.majorSyncing = isMajorSyncing();
809  return status;
810 }
811 
813 {
814  TransactionSkeleton ret(_t);
815 
816  // Default gas value meets the intrinsic gas requirements of both
817  // send value and create contract transactions and is the same default
818  // value used by geth and testrpc.
819  const u256 defaultTransactionGas = 90000;
820  if (ret.nonce == Invalid256)
821  ret.nonce = max<u256>(postSeal().transactionsFrom(ret.from), m_tq.maxNonce(ret.from));
822  if (ret.gasPrice == Invalid256)
823  ret.gasPrice = gasBidPrice();
824  if (ret.gas == Invalid256)
825  ret.gas = defaultTransactionGas;
826 
827  return ret;
828 }
829 
830 bool Client::submitSealed(bytes const& _header)
831 {
832  bytes newBlock;
833  {
835  {
836  UpgradeGuard l2(l);
837  if (!m_working.sealBlock(_header))
838  return false;
839  }
842  newBlock = m_working.blockData();
843  }
844 
845  // OPTIMISE: very inefficient to not utilise the existing OverlayDB in m_postSeal that contains all trie changes.
846  return m_bq.import(&newBlock, true) == ImportResult::Success;
847 }
848 
849 void Client::rewind(unsigned _n)
850 {
851  executeInMainThread([=]() {
852  bc().rewind(_n);
854  });
855 
856  for (unsigned i = 0; i < 10; ++i)
857  {
858  u256 n;
860  n = m_working.info().number();
861  if (n == _n + 1)
862  break;
863  this_thread::sleep_for(std::chrono::milliseconds(50));
864  }
865  auto h = m_host.lock();
866  if (h)
867  h->reset();
868  m_tq.clear();
869  m_bq.clear();
870 }
871 
873 {
875  ts.from = toAddress(_secret);
876  Transaction t(ts, _secret);
877  return importTransaction(t);
878 }
879 
881 {
883 
884  // Use the Executive to perform basic validation of the transaction
885  // (e.g. transaction signature, account balance) using the state of
886  // the latest block in the client's blockchain. This can throw but
887  // we'll catch the exception at the RPC level.
888  Block currentBlock = block(bc().currentHash());
889  Executive e(currentBlock, bc());
890  e.initialize(_t);
891  ImportResult res = m_tq.import(_t.rlp());
892  switch (res)
893  {
895  break;
897  BOOST_THROW_EXCEPTION(ZeroSignatureTransaction());
899  BOOST_THROW_EXCEPTION(GasPriceTooLow());
901  BOOST_THROW_EXCEPTION(PendingTransactionAlreadyExists());
903  BOOST_THROW_EXCEPTION(TransactionAlreadyInChain());
904  default:
905  BOOST_THROW_EXCEPTION(UnknownTransactionValidationError());
906  }
907 
908  return _t.sha3();
909 }
910 
911 // TODO: remove try/catch, allow exceptions
912 ExecutionResult Client::call(Address const& _from, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber, FudgeFactor _ff)
913 {
914  ExecutionResult ret;
915  try
916  {
917  Block temp = blockByNumber(_blockNumber);
918  u256 nonce = max<u256>(temp.transactionsFrom(_from), m_tq.maxNonce(_from));
919  u256 gas = _gas == Invalid256 ? gasLimitRemaining() : _gas;
920  u256 gasPrice = _gasPrice == Invalid256 ? gasBidPrice() : _gasPrice;
921  Transaction t(_value, gasPrice, gas, _dest, _data, nonce);
922  t.forceSender(_from);
923  if (_ff == FudgeFactor::Lenient)
924  temp.mutableState().addBalance(_from, (u256)(t.gas() * t.gasPrice() + t.value()));
925  ret = temp.execute(bc().lastBlockHashes(), t, Permanence::Reverted);
926  }
927  catch (...)
928  {
929  cwarn << boost::current_exception_diagnostic_information();
930  }
931  return ret;
932 }
933 
934 std::tuple<h256, h256, h256> Client::getWork()
935 {
936  // lock the work so a later submission isn't invalidated by processing a transaction elsewhere.
937  // this will be reset as soon as a new block arrives, allowing more transactions to be
938  // processed.
939  bool oldShould = shouldServeWork();
940  m_lastGetWork = chrono::system_clock::now();
941  if (!sealEngine()->shouldSeal(this))
942  return std::tuple<h256, h256, h256>();
943 
944  // if this request has made us bother to serve work, prep it now.
945  if (!oldShould && shouldServeWork())
947  else
948  // otherwise, set this to true so that it gets prepped next time.
949  m_remoteWorking = true;
950 
951  return sealEngine()->getWork(m_sealingInfo);
952 }
dev::eth::SealEngineFace::getWork
virtual std::tuple< h256, h256, h256 > getWork(BlockHeader const &)
Definition: SealEngine.h:51
dev::eth::Client::m_preSeal
Block m_preSeal
The present state of the client.
Definition: Client.h:343
dev::eth::BlockQueue::tick
void tick()
Notes that time has moved on and some blocks that used to be "in the future" may no be valid.
Definition: BlockQueue.cpp:349
dev::eth::TransactionQueue::topTransactions
Transactions topTransactions(unsigned _limit, h256Hash const &_avoid=h256Hash()) const
Definition: TransactionQueue.cpp:102
dev::eth::Client::reopenChain
void reopenChain(ChainParams const &_p, WithExisting _we=WithExisting::Trust)
Reloads the blockchain. Just for debug use.
Definition: Client.cpp:269
dev::eth::Client::~Client
virtual ~Client()
Destructor.
Definition: Client.cpp:90
dev::eth::errinfo_block
boost::error_info< struct tag_block, bytes > errinfo_block
Definition: State.h:48
dev::eth::TransactionBase::value
u256 value() const
Definition: TransactionBase.h:115
dev::eth::BlockQueue::status
BlockQueueStatus status() const
Get some infomration on the current status.
Definition: BlockQueue.cpp:379
dev::eth::Block::commitToSeal
void commitToSeal(BlockChain const &_bc, bytes const &_extraData={})
Definition: Block.cpp:728
dev::eth::Client::startedWorking
void startedWorking() override
Called when Worker is starting.
Definition: Client.cpp:232
dev::eth::ImportResult::AlreadyKnown
@ AlreadyKnown
dev::eth::Block::mutableState
State & mutableState()
Definition: Block.h:175
dev::eth::TransactionSkeleton
Definition: Common.h:184
dev::eth::Block::blockData
bytes const & blockData() const
Definition: Block.h:270
dev::eth::ClientBase::uninstallWatch
bool uninstallWatch(unsigned _watchId) override
Definition: ClientBase.cpp:256
dev::eth::Client::init
void init(p2p::Host &_extNet, boost::filesystem::path const &_dbPath, boost::filesystem::path const &_snapshotPath, WithExisting _forceAction, u256 _networkId)
Definition: Client.cpp:97
dev::eth::ClientBase::m_loggerWatch
Logger m_loggerWatch
Definition: ClientBase.h:190
dev::eth::SyncStatus::majorSyncing
bool majorSyncing
Definition: CommonNet.h:102
dev::eth::ClientBase::m_watches
std::map< unsigned, ClientWatch > m_watches
Each and every watch - these reference a filter.
Definition: ClientBase.h:188
dev::eth::TransactionBase::gas
u256 gas() const
Definition: TransactionBase.h:121
dev::eth::Client::m_wouldButShouldnot
bool m_wouldButShouldnot
True if the last time we called rejigSealing wouldSeal() was true but sealer's shouldSeal() was false...
Definition: Client.h:364
dev::eth::Client::syncQueue
std::tuple< ImportRoute, bool, unsigned > syncQueue(unsigned _max=1)
Freeze worker thread and sync some of the block queue.
Definition: Client.cpp:164
dev::eth::Client::sealEngine
SealEngineFace * sealEngine() const override
Get the seal engine.
Definition: Client.h:184
dev::eth::Client::bc
BlockChain & bc() override
InterfaceStub methods.
Definition: Client.h:241
dev::eth::Client::m_syncAmount
unsigned m_syncAmount
Number of blocks to sync in each go.
Definition: Client.h:371
dev::eth::ImportResult
ImportResult
Definition: Common.h:97
dev::eth::Transaction
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Definition: Transaction.h:86
dev::db::databasePath
fs::path databasePath()
Definition: DBFactory.cpp:97
dev::eth::Client::m_sealingInfo
BlockHeader m_sealingInfo
The header we're attempting to seal on (derived from m_postSeal).
Definition: Client.h:348
dev::eth::BlockHeader::hash
h256 hash(IncludeSeal _i=WithSeal) const
Definition: BlockHeader.cpp:119
dev::eth::BlockChain::rescue
void rescue(OverlayDB const &_db)
Rescue the database.
Definition: BlockChain.cpp:1041
dev::eth::HeaderData
@ HeaderData
Definition: BlockHeader.h:69
dev::eth::BlockHeader
Encapsulation of a block header. Class to contain all of a block header's data. It is able to parse a...
Definition: BlockHeader.h:97
dev::eth::Client::startWorking
void startWorking()
should be called after the constructor of the most derived class finishes.
Definition: Client.h:217
dev::eth::Client::x_working
SharedMutex x_working
Lock on m_working.
Definition: Client.h:346
dev::Worker::stopWorking
void stopWorking()
Stop worker thread; causes call to stopWorking().
Definition: Worker.cpp:100
dev::UpgradableGuard
boost::upgrade_lock< boost::shared_mutex > UpgradableGuard
Definition: Guards.h:45
dev::eth::BlockQueueStatus::verified
size_t verified
Definition: BlockQueue.h:46
dev::eth::Transactions
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
Definition: Transaction.h:122
SnapshotStorage.h
dev::eth::Client::m_lastGarbageCollection
std::chrono::system_clock::time_point m_lastGarbageCollection
When did we last both doing GC on the watches?
Definition: Client.h:366
dev::eth::CheckTransaction::None
@ None
dev::eth::Block::populateFromChain
PopulationStatistics populateFromChain(BlockChain const &_bc, h256 const &_hash, ImportRequirements::value _ir=ImportRequirements::None)
Construct state object from arbitrary point in blockchain.
Definition: Block.cpp:156
dev::eth::SyncStatus
Definition: CommonNet.h:96
dev::SecureFixedHash< 32 >
dev::eth::State::openDB
static OverlayDB openDB(boost::filesystem::path const &_path, h256 const &_genesisHash, WithExisting _we=WithExisting::Trust)
Open a DB - useful for passing into the constructor & keeping for other states that are necessary.
Definition: State.cpp:60
dev::eth::TransactionBase::rlp
bytes rlp(IncludeSignature _sig=WithSignature) const
Definition: TransactionBase.h:109
dev::eth::Client::x_functionQueue
SharedMutex x_functionQueue
Definition: Client.h:375
dev::eth::BlockChain::reopen
void reopen(WithExisting _we=WithExisting::Trust, ProgressCallback const &_pc=ProgressCallback())
Reopen everything.
Definition: BlockChain.h:113
dev::eth::ChainParams
Definition: ChainParams.h:38
dev::eth::Client::m_host
std::weak_ptr< EthereumCapability > m_host
Definition: Client.h:353
dev::Guard
std::lock_guard< std::mutex > Guard
Definition: Guards.h:41
dev::eth::FudgeFactor
FudgeFactor
Definition: Interface.h:51
std::swap
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
Definition: Interface.h:282
dev::eth::Client::wouldSeal
bool wouldSeal() const override
Are we sealing now?
Definition: Client.h:171
dev::Timer
Definition: Common.h:256
dev::eth::Block::author
Address author() const
Get the author address for any transactions we do and rewards we get.
Definition: Block.h:109
dev::eth::TransactionSkeleton::gasPrice
u256 gasPrice
Definition: Common.h:192
dev::eth::ClientBase::transactions
Transactions transactions(h256 _blockHash) const override
Definition: ClientBase.cpp:376
dev::eth::TransactionQueue::onReady
Handler onReady(T const &_t)
Register a handler that will be called once there is a new transaction imported.
Definition: TransactionQueue.h:119
dev::eth::Client::m_syncTransactionQueue
std::atomic< bool > m_syncTransactionQueue
Definition: Client.h:378
dev::eth::Client::syncStatus
SyncStatus syncStatus() const override
Get some information on the block syncing.
Definition: Client.cpp:802
dev::eth::Client::submitSealed
virtual bool submitSealed(bytes const &_s)
Submit.
Definition: Client.cpp:830
dev::eth::PopulationStatistics
Definition: Block.h:55
dev::eth::Block::transactionsFrom
u256 transactionsFrom(Address const &_address) const
Definition: Block.h:127
dev::eth::Client::m_logger
Logger m_logger
Definition: Client.h:388
dev::eth::BlockChain::sync
std::tuple< ImportRoute, bool, unsigned > sync(BlockQueue &_bq, OverlayDB const &_stateDB, unsigned _max)
Definition: BlockChain.cpp:443
dev::eth::BlockChain::number
unsigned number(h256 const &_hash) const
Get a number for the given hash (or the most recent mined if none given). Thread-safe.
Definition: BlockChain.h:224
dev::eth::badBlock
void badBlock(bytesConstRef _block, string const &_err)
Definition: Common.cpp:141
dev::eth
Definition: BasicAuthority.h:32
dev::eth::Client::submitTransaction
h256 submitTransaction(TransactionSkeleton const &_t, Secret const &_secret) override
Definition: Client.cpp:872
dev::eth::Client::m_syncBlockQueue
std::atomic< bool > m_syncBlockQueue
Definition: Client.h:379
dev::eth::Client::doneWorking
void doneWorking() override
Called when Worker is exiting.
Definition: Client.cpp:249
dev::eth::Client::startSealing
void startSealing() override
Start sealing.
Definition: Client.cpp:583
dev::eth::Client::chainParams
ChainParams const & chainParams() const
Get information on this chain.
Definition: Client.h:89
dev::toString
std::string toString(std::chrono::time_point< T > const &_e, std::string const &_format="%F %T")
Definition: CommonIO.h:86
dev::eth::Client::pending
Transactions pending() const override
Retrieve pending transactions.
Definition: Client.cpp:797
dev::FixedHash
Definition: FixedHash.h:47
dev::eth::Client::callQueuedFunctions
void callQueuedFunctions()
Executes the pending functions in m_functionQueue.
Definition: Client.cpp:184
dev::Timer::elapsed
double elapsed() const
Definition: Common.h:261
DEV_GUARDED
#define DEV_GUARDED(MUTEX)
Simple block guard. The expression/block following is guarded though the given mutex....
Definition: Guards.h:132
dev::eth::Client::networkId
u256 networkId() const override
Gets the network id.
Definition: Client.cpp:202
dev::eth::TransactionQueue::dropGood
void dropGood(Transaction const &_t)
Definition: TransactionQueue.cpp:335
dev::eth::Permanence::Reverted
@ Reverted
dev::eth::Client::m_warpHost
std::weak_ptr< WarpCapability > m_warpHost
Definition: Client.h:354
dev::eth::Executive::initialize
void initialize(bytesConstRef _transaction)
Initializes the executive for evaluating a transaction. You must call finalize() at some point follow...
Definition: Executive.h:132
dev::eth::State::addBalance
void addBalance(Address const &_id, u256 const &_amount)
Definition: State.cpp:346
dev::eth::Client::m_tqReady
Handler m_tqReady
Definition: Client.h:359
dev::WithExisting
WithExisting
Definition: Common.h:292
dev::Exception
Base class for all exceptions.
Definition: Exceptions.h:39
LOG
#define LOG
Definition: Log.h:63
dev::WriteGuard
boost::unique_lock< boost::shared_mutex > WriteGuard
Definition: Guards.h:47
dev::eth::Client::x_preSeal
SharedMutex x_preSeal
Lock on m_preSeal.
Definition: Client.h:342
dev::eth::Client::m_needStateReset
std::atomic< bool > m_needStateReset
Need reset working state to premin on next sync.
Definition: Client.h:350
dev::eth::TransactionQueue::status
Status status() const
Definition: TransactionQueue.h:110
dev::eth::BlockQueue::clear
void clear()
Clear everything.
Definition: BlockQueue.cpp:67
dev::eth::TransactionSkeleton::nonce
u256 nonce
Definition: Common.h:190
dev::eth::BlockPolarity
BlockPolarity
Definition: Common.h:81
dev::eth::Client::importTransaction
h256 importTransaction(Transaction const &_t) override
Imports the given transaction into the transaction queue.
Definition: Client.cpp:880
dev::eth::Client::onNewBlocks
virtual void onNewBlocks(h256s const &_blocks, h256Hash &io_changed)
Called on chain changes.
Definition: Client.cpp:476
EthereumCapability.h
dev::eth::Client::resetState
void resetState()
Clear working state of transactions.
Definition: Client.cpp:539
dev::eth::toAddress
Address toAddress(std::string const &_s)
Convert the given string into an address.
Definition: Common.cpp:56
dev::eth::Client::getWork
std::tuple< h256, h256, h256 > getWork() override
Definition: Client.cpp:934
dev::h256Hash
std::unordered_set< h256 > h256Hash
Definition: FixedHash.h:365
dev::h256s
std::vector< h256 > h256s
Definition: FixedHash.h:361
dev::eth::Client::appendFromNewPending
void appendFromNewPending(TransactionReceipt const &_receipt, h256Hash &io_changed, h256 _sha3)
Definition: Client.cpp:334
Block.h
dev::eth::Client::m_wouldSeal
std::atomic< bool > m_wouldSeal
True if we /should/ be sealing.
Definition: Client.h:363
dev::eth::BlockHeader::parentHash
h256 const & parentHash() const
Definition: BlockHeader.h:157
dev::eth::Client::m_stateDB
OverlayDB m_stateDB
Acts as the central point for the state database, so multiple States can share it.
Definition: Client.h:341
dev::eth::ImportResult::AlreadyInChain
@ AlreadyInChain
dev::eth::Client::block
dev::eth::Block block(h256 const &_blockHash, PopulationStatistics *o_stats) const
Get the block.
Definition: Client.cpp:774
dev::eth::TransactionQueue::Limits
Definition: TransactionQueue.h:47
dev::eth::IfDropped::Retry
@ Retry
Import transaction even if it was dropped before.
dev::eth::Client::call
ExecutionResult call(Address const &_secret, u256 _value, Address _dest, bytes const &_data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber, FudgeFactor _ff=FudgeFactor::Strict) override
Makes the given call. Nothing is recorded into the state.
Definition: Client.cpp:912
Client.h
dev::eth::Block::execute
ExecutionResult execute(LastBlockHashesFace const &_lh, Transaction const &_t, Permanence _p=Permanence::Committed, OnOpFunc const &_onOp=OnOpFunc())
Definition: Block.cpp:657
dev::eth::BlockChain::receipts
BlockReceipts receipts(h256 const &_hash) const
Definition: BlockChain.h:166
dev::eth::BlockQueue::onReady
Handler onReady(std::function< void(void)> _t)
Definition: BlockQueue.h:269
DEV_WRITE_GUARDED
#define DEV_WRITE_GUARDED(MUTEX)
Definition: Guards.h:136
dev::eth::Client::gasLimitRemaining
u256 gasLimitRemaining() const override
Get the remaining gas limit in this block.
Definition: Client.h:115
dev::bytes
std::vector< byte > bytes
Definition: Common.h:72
dev::eth::Client::m_remoteWorking
std::atomic< bool > m_remoteWorking
Has the remote worker recently been reset?
Definition: Client.h:349
dev::eth::Client::restartMining
void restartMining()
Update m_preSeal, m_working, m_postSeal blocks from the latest state of the chain.
Definition: Client.cpp:498
dev::eth::Block::pending
Transactions const & pending() const
Get the list of pending transactions.
Definition: Block.h:183
dev::eth::Client::resyncStateFromChain
void resyncStateFromChain()
Called after processing blocks by onChainChanged(_ir)
Definition: Client.cpp:489
dev::eth::TransactionReceipts
std::vector< TransactionReceipt > TransactionReceipts
Definition: TransactionReceipt.h:69
dev::eth::createSnapshotStorage
std::unique_ptr< SnapshotStorageFace > createSnapshotStorage(fs::path const &_snapshotDirPath)
Definition: SnapshotStorage.cpp:98
dev::eth::Executive
Message-call/contract-creation executor; useful for executing transactions.
Definition: Executive.h:104
dev::eth::Client::m_bq
BlockQueue m_bq
Maintains a list of incoming blocks not yet on the blockchain (to be imported).
Definition: Client.h:336
dev::eth::ImportRoute::liveBlocks
h256s liveBlocks
Definition: Common.h:92
dev::eth::Client::m_extraData
bytes m_extraData
Definition: Client.h:381
dev::eth::BlockChain::setOnBad
void setOnBad(std::function< void(Exception &)> _t)
Change the function that is called with a bad block.
Definition: BlockChain.h:292
dev::eth::BlockHeader::number
int64_t number() const
Definition: BlockHeader.h:166
dev::eth::SealEngineFace::cancelGeneration
virtual void cancelGeneration()
Definition: SealEngine.h:78
dev::eth::TransactionBase::gasPrice
u256 gasPrice() const
Definition: TransactionBase.h:118
dev::eth::SyncState
SyncState
Definition: CommonNet.h:85
Executive.h
dev::eth::TransactionBase::sha3
h256 sha3(IncludeSignature _sig=WithSignature) const
Definition: TransactionBase.cpp:212
dev::eth::BlockReceipts::receipts
TransactionReceipts receipts
Definition: BlockDetails.h:85
dev::eth::Client::queueBlock
ImportResult queueBlock(bytes const &_block, bool _isSafe=false)
Queues a block for import.
Definition: Client.cpp:157
dev::eth::LogEntry
Definition: LogEntry.h:35
dev::eth::SealEngineFace::generateSeal
virtual void generateSeal(BlockHeader const &_bi)=0
dev::eth::BlockQueueStatus::unverified
size_t unverified
Definition: BlockQueue.h:48
dev::eth::Block::isSealed
bool isSealed() const
Definition: Block.h:266
dev::eth::Client::syncBlockQueue
void syncBlockQueue()
Signal handler for when the block queue needs processing.
Definition: Client.cpp:384
dev::eth::ClientBase::m_specialFilters
std::unordered_map< h256, h256s > m_specialFilters
The dictionary of special filters and their additional data.
Definition: ClientBase.h:186
dev::OverlayDB
Definition: OverlayDB.h:34
dev::eth::Client::postSeal
Block postSeal() const override
Definition: Client.h:247
dev::Invalid256
constexpr u256 Invalid256
Definition: Common.h:147
DBFactory.h
dev::eth::Client::m_gp
std::shared_ptr< GasPricer > m_gp
The gas pricer.
Definition: Client.h:339
dev::eth::Client::clearPending
void clearPending()
Clears pending transactions. Just for debug use.
Definition: Client.cpp:318
dev::eth::Client::m_onBlockSealed
Signal< bytes const & > m_onBlockSealed
Called if we have sealed a new block.
Definition: Client.h:383
dev::eth::BlockChain::setOnBlockImport
void setOnBlockImport(std::function< void(BlockHeader const &)> _t)
Change the function that is called when a new block is imported.
Definition: BlockChain.h:295
dev::eth::Client::gasBidPrice
u256 gasBidPrice() const override
Get the gas bid price.
Definition: Client.h:117
dev::eth::Client::rewind
void rewind(unsigned _n)
Rewind to a prior head.
Definition: Client.cpp:849
dev::eth::ImportRoute::deadBlocks
h256s deadBlocks
Definition: Common.h:91
dev::eth::BlockQueueStatus::verifying
size_t verifying
Definition: BlockQueue.h:47
dev::eth::Client::flushTransactions
void flushTransactions() override
Blocks until all pending transactions have been processed.
Definition: Client.cpp:792
dev::eth::Client::stopSealing
void stopSealing() override
Stop sealing.
Definition: Client.h:169
DEV_READ_GUARDED
#define DEV_READ_GUARDED(MUTEX)
Definition: Guards.h:134
dev::UpgradeGuard
boost::upgrade_to_unique_lock< boost::shared_mutex > UpgradeGuard
Definition: Guards.h:46
dev::eth::ActivityReport::since
std::chrono::system_clock::time_point since
Definition: Client.h:68
dev::eth::Client::onChainChanged
void onChainChanged(ImportRoute const &_ir)
Definition: Client.cpp:554
dev::eth::Client::appendFromBlock
void appendFromBlock(h256 const &_blockHash, BlockPolarity _polarity, h256Hash &io_changed)
Definition: Client.cpp:353
dev::eth::TransactionQueue::clear
void clear()
Clear the queue.
Definition: TransactionQueue.cpp:344
dev::eth::Client::m_bqReady
Handler m_bqReady
Definition: Client.h:361
dev::keysOf
std::vector< T > keysOf(std::map< T, U > const &_m)
Definition: CommonData.h:286
dev::eth::Client::m_functionQueue
std::queue< std::function< void()> > m_functionQueue
Functions waiting to be executed in the main thread.
Definition: Client.h:376
dev::eth::Client::m_signalled
std::condition_variable m_signalled
Definition: Client.h:356
dev::eth::BlockPolarity::Live
@ Live
dev::eth::BlockNumber
unsigned BlockNumber
Definition: Common.h:64
dev::eth::TransactionQueue::maxNonce
u256 maxNonce(Address const &_a) const
Definition: TransactionQueue.cpp:184
dev::eth::SealEngineFace::onSealGenerated
virtual void onSealGenerated(std::function< void(bytes const &s)> const &_f)=0
dev::eth::ClientBase::number
unsigned number() const override
Definition: ClientBase.cpp:420
dev::eth::Client::x_signalled
Mutex x_signalled
Definition: Client.h:357
dev::eth::Client::m_tqReplaced
Handler< h256 const & > m_tqReplaced
Definition: Client.h:360
dev::eth::Client::remoteActive
bool remoteActive() const
Definition: Client.cpp:571
dev::eth::BlockPolarity::Dead
@ Dead
dev::WithExisting::Rescue
@ Rescue
std
Definition: FixedHash.h:393
dev::eth::Success
@ Success
Definition: Common.h:223
dev::eth::ImportResult::OverbidGasPrice
@ OverbidGasPrice
dev::eth::TransactionQueue::Status::current
size_t current
Definition: TransactionQueue.h:104
dev::eth::ClientBase::x_filtersWatches
Mutex x_filtersWatches
}
Definition: ClientBase.h:184
dev::eth::Client::checkWatchGarbage
void checkWatchGarbage()
Does garbage collection on watches.
Definition: Client.cpp:725
dev::u256
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
Definition: Common.h:121
dev::eth::operator<<
std::ostream & operator<<(std::ostream &_out, BlockHeader const &_bi)
Definition: BlockHeader.h:217
dev::eth::Client::shouldServeWork
bool shouldServeWork() const
Is there an active and valid remote worker?
Definition: Client.h:327
dev::eth::Client::m_tq
TransactionQueue m_tq
Maintains a list of incoming transactions not yet in a block on the blockchain.
Definition: Client.h:337
dev::eth::ClientBase::blockByNumber
Block blockByNumber(BlockNumber _h) const
Definition: ClientBase.cpp:517
dev::Worker::isWorking
bool isWorking() const
Returns if worker thread is present.
Definition: Worker.h:76
dev::eth::BlockChain::garbageCollect
void garbageCollect(bool _force=false)
Deallocate unused data.
Definition: BlockChain.cpp:1211
dev::eth::Client::isMajorSyncing
bool isMajorSyncing() const override
Are we syncing the chain?
Definition: Client.cpp:222
dev::eth::Block::sealBlock
bool sealBlock(bytes const &_header)
Definition: Block.h:262
dev::eth::TransactionReceipt
Definition: TransactionReceipt.h:40
dev::eth::ImportRoute
Definition: Common.h:90
dev::eth::Client::onDeadBlocks
void onDeadBlocks(h256s const &_blocks, h256Hash &io_changed)
Called on chain changes.
Definition: Client.cpp:457
dev
Definition: Address.cpp:21
dev::eth::Client::m_working
Block m_working
The state of the client which we're sealing (i.e. it'll have all the rewards added),...
Definition: Client.h:347
dev::eth::BlockQueue::setChain
void setChain(BlockChain const &_bc)
Definition: BlockQueue.h:229
dev::eth::Client::tick
void tick()
Ticks various system-level objects.
Definition: Client.cpp:712
dev::eth::ImportResult::ZeroSignature
@ ZeroSignature
dev::eth::Client::isSyncing
bool isSyncing() const override
Are we updating the chain (syncing or importing a new block)?
Definition: Client.cpp:215
dev::eth::Block::info
BlockHeader const & info() const
Get the header information on the present block.
Definition: Block.h:273
dev::eth::Client::onBadBlock
void onBadBlock(Exception &_ex) const
Definition: Client.cpp:170
dev::eth::ExecutionResult
Description of the result of executing a transaction.
Definition: Transaction.h:71
dev::eth::Client::prepareForTransaction
void prepareForTransaction() override
Definition: Client.cpp:753
dev::eth::ChainParams::author
Address author
Definition: ChainParams.h:49
dev::eth::Client::m_lastGetWork
std::chrono::system_clock::time_point m_lastGetWork
Is there an active and valid remote worker?
Definition: Client.h:351
dev::Worker::terminate
void terminate()
Blocks caller into worker thread has finished.
Definition: Worker.cpp:116
dev::eth::ClientBase::m_filters
std::unordered_map< h256, InstalledFilter > m_filters
The dictionary of filters that are active.
Definition: ClientBase.h:185
cwarn
#define cwarn
dev::eth::ImportRoute::goodTranactions
std::vector< Transaction > goodTranactions
Definition: Common.h:93
dev::eth::ActivityReport
Definition: Client.h:66
dev::eth::Client::noteChanged
void noteChanged(h256Hash const &_filters)
Definition: Client.cpp:644
dev::Exception::what
const char * what() const noexcept override
Definition: Exceptions.h:40
dev::eth::Client::onPostStateChanged
void onPostStateChanged()
Definition: Client.cpp:576
dev::eth::Client::m_lastTick
std::chrono::system_clock::time_point m_lastTick
When did we last tick()?
Definition: Client.h:368
dev::eth::BlockChain::rewind
void rewind(unsigned _newHead)
Alter the head of the chain to some prior block along it.
Definition: BlockChain.cpp:1091
dev::eth::Client::syncTransactionQueue
void syncTransactionQueue()
Signal handler for when the block queue needs processing.
Definition: Client.cpp:409
dev::eth::LocalisedLogEntry
Definition: LogEntry.h:54
dev::eth::SyncState::Idle
@ Idle
Initial chain sync complete. Waiting for new packets.
dev::eth::Block::setAuthor
void setAuthor(Address const &_id)
Definition: Block.h:113
dev::eth::Client::m_report
ActivityReport m_report
Definition: Client.h:373
dev::eth::BlockQueue::setOnBad
void setOnBad(T const &_t)
Definition: BlockQueue.h:272
dev::eth::Client::setNetworkId
void setNetworkId(u256 const &_n) override
Sets the network id.
Definition: Client.cpp:209
dev::eth::Client::m_postSeal
Block m_postSeal
The state of the client which we're sealing (i.e. it'll have all the rewards added).
Definition: Client.h:345
dev::eth::Client::activityReport
ActivityReport activityReport()
Get a report of activity.
Definition: Client.h:199
dev::eth::ClientBase::transaction
Transaction transaction(h256 _transactionHash) const override
Definition: ClientBase.cpp:319
dev::eth::TransactionQueue::import
ImportResult import(bytes const &_tx, IfDropped _ik=IfDropped::Ignore)
Definition: TransactionQueue.h:64
dev::eth::TransactionBase::forceSender
void forceSender(Address const &_a)
Force the sender to a particular value. This will result in an invalid transaction RLP.
Definition: TransactionBase.h:87
dev::eth::ActivityReport::ticks
unsigned ticks
Definition: Client.h:67
dev::eth::importedSnapshotPath
fs::path importedSnapshotPath(fs::path const &_dataDir, h256 const &_genesisHash)
Definition: SnapshotStorage.cpp:103
Log.h
dev::eth::Client::populateTransactionWithDefaults
TransactionSkeleton populateTransactionWithDefaults(TransactionSkeleton const &_t) const override
Populate the uninitialized fields in the supplied transaction with default values.
Definition: Client.cpp:812
dev::eth::Block
Active model of a block within the block chain. Keeps track of all transactions, receipts and state f...
Definition: Block.h:69
dev::eth::FudgeFactor::Lenient
@ Lenient
TransactionQueue.h
dev::eth::Client::x_postSeal
SharedMutex x_postSeal
Lock on m_postSeal.
Definition: Client.h:344
dev::eth::Client::m_loggerDetail
Logger m_loggerDetail
Definition: Client.h:389
dev::eth::TransactionSkeleton::gas
u256 gas
Definition: Common.h:191
dev::eth::Client::m_onChainChanged
Signal< h256s const &, h256s const & > m_onChainChanged
Called when blockchain was changed.
Definition: Client.h:386
dev::eth::Client::author
Address author() const override
Get the block author address.
Definition: Client.h:147
dev::eth::WithoutSeal
@ WithoutSeal
Definition: BlockHeader.h:41
dev::eth::BlockChain::genesisBlock
Block genesisBlock(OverlayDB const &_db) const
Get a pre-made genesis State object.
Definition: BlockChain.cpp:1479
dev::eth::Client::rejigSealing
void rejigSealing()
Called when wouldSeal(), pendingTransactions() have changed.
Definition: Client.cpp:597
dev::eth::Client::onTransactionQueueReady
void onTransactionQueueReady()
Magically called when m_tq needs syncing. Be nice and don't block.
Definition: Client.h:304
dev::eth::Client::doWork
void doWork() override
Called continuously following sleep for m_idleWaitMs.
Definition: Client.h:271
dev::eth::Client::executeInMainThread
void executeInMainThread(std::function< void()> const &_function)
Queues a function to be executed in the main thread (that owns the blockchain, etc).
Definition: Client.cpp:311
dev::eth::TransactionSkeleton::from
Address from
Definition: Common.h:186
dev::eth::Block::sync
std::pair< TransactionReceipts, bool > sync(BlockChain const &_bc, TransactionQueue &_tq, GasPricer const &_gp, unsigned _msTimeout=100)
Definition: Block.cpp:307
dev::eth::BlockQueue::import
ImportResult import(bytesConstRef _block, bool _isOurs=false)
Import a block into the queue.
Definition: BlockQueue.cpp:169
ctrace
#define ctrace
dev::eth::TransactionQueue::onReplaced
Handler< h256 const & > onReplaced(T const &_t)
Register a handler that will be called once asynchronous verification is comeplte an transaction has ...
Definition: TransactionQueue.h:125
dev::Worker
Definition: Worker.h:49
DEV_TIMED_FUNCTION_ABOVE
#define DEV_TIMED_FUNCTION_ABOVE(MS)
Definition: Common.h:281
dev::eth::Client::onBlockQueueReady
void onBlockQueueReady()
Magically called when m_bq needs syncing. Be nice and don't block.
Definition: Client.h:307