33 static const int64_t c_maxGasEstimate = 50000000;
39 int64_t upperBound = _maxGas;
40 if (upperBound ==
Invalid256 || upperBound > c_maxGasEstimate)
41 upperBound = c_maxGasEstimate;
42 int64_t lowerBound = Transaction::baseGasRequired(!_dest, &_data,
EVMSchedule());
43 Block bk = blockByNumber(_blockNumber);
44 u256 gasPrice = _gasPrice ==
Invalid256 ? gasBidPrice() : _gasPrice;
48 while (upperBound != lowerBound)
50 int64_t mid = (lowerBound + upperBound) / 2;
54 t =
Transaction(_value, gasPrice, mid, _dest, _data, n);
58 EnvInfo const env(bk.
info(), bc().lastBlockHashes(), 0, mid);
61 er = tempState.execute(env, *bc().sealEngine(), t, Permanence::Reverted).first;
62 if (er.
excepted == TransactionException::OutOfGas ||
63 er.
excepted == TransactionException::OutOfGasBase ||
64 er.
excepted == TransactionException::OutOfGasIntrinsic ||
66 er.
excepted == TransactionException::BadJumpDestination)
67 lowerBound = lowerBound == mid ? upperBound : mid;
71 upperBound = upperBound == mid ? lowerBound : mid;
80 return make_pair(upperBound, good ? lastGood : er);
91 return bc().attemptImport(_block, preSeal().db()).first;
96 return blockByNumber(_block).balance(_a);
101 return blockByNumber(_block).transactionsFrom(_a);
106 return blockByNumber(_block).storage(_a, _l);
111 return blockByNumber(_block).storageRoot(_a);
116 return blockByNumber(_block).code(_a);
121 return blockByNumber(_block).codeHash(_a);
126 return blockByNumber(_block).storage(_a);
135 Guard l(x_filtersWatches);
136 f = m_filters.at(m_watches.at(_watchId).id).filter;
148 unsigned begin = min(bc().number() + 1, (
unsigned)numberFromHash(_f.
latest()));
149 unsigned end = min(bc().number(), min(begin, (
unsigned)numberFromHash(_f.
earliest())));
152 if (begin > bc().number())
154 Block temp = postSeal();
155 for (
unsigned i = 0; i < temp.
pending().size(); ++i)
160 for (
unsigned j = 0; j < le.size(); ++j)
163 begin = bc().number();
170 unsigned ancestorIndex;
171 tie(blocks, ancestor, ancestorIndex) = bc().treeRoute(_f.
earliest(), _f.
latest(),
false);
173 for (
size_t i = 0; i < ancestorIndex; i++)
174 prependLogsFromBlock(_f, blocks[i], BlockPolarity::Dead, ret);
188 end = min(end, (
unsigned)numberFromHash(ancestor) + 1);
191 set<unsigned> matchingBlocks;
194 for (
auto u: bc().withBlockBloom(i, end, begin))
195 matchingBlocks.insert(u);
198 for (
unsigned i = end; i <= begin; i++)
199 matchingBlocks.insert(i);
201 for (
auto n: matchingBlocks)
202 prependLogsFromBlock(_f, bc().numberHash(n), BlockPolarity::Live, ret);
204 reverse(ret.begin(), ret.end());
210 auto receipts = bc().receipts(_blockHash).receipts;
211 for (
size_t i = 0; i < receipts.size(); i++)
214 auto th = transaction(_blockHash, i).sha3();
216 for (
unsigned j = 0; j < le.size(); ++j)
225 Guard l(x_filtersWatches);
226 if (!m_filters.count(h))
228 LOG(m_loggerWatch) <<
"FFF" << _f << h;
229 m_filters.insert(make_pair(h, _f));
232 return installWatch(h, _r);
239 Guard l(x_filtersWatches);
240 ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0;
242 LOG(m_loggerWatch) <<
"+++" << ret << _h;
244 #if INITIAL_STATE_AS_CHANGES 247 ch.push_back(InitialChange);
249 Guard l(x_filtersWatches);
250 swap(m_watches[ret].changes, ch);
256 bool ClientBase::uninstallWatch(
unsigned _i)
258 LOG(m_loggerWatch) <<
"XXX" << _i;
260 Guard l(x_filtersWatches);
262 auto it = m_watches.find(_i);
263 if (it == m_watches.end())
265 auto id = it->second.id;
268 auto fit = m_filters.find(
id);
269 if (fit != m_filters.end())
270 if (!--fit->second.refCount)
272 LOG(m_loggerWatch) <<
"*X*" << fit->first <<
":" << fit->second.filter;
273 m_filters.erase(fit);
280 Guard l(x_filtersWatches);
283 auto& w = m_watches.at(_watchId);
286 if (w.lastPoll != chrono::system_clock::time_point::max())
287 w.lastPoll = chrono::system_clock::now();
293 Guard l(x_filtersWatches);
297 auto& w = m_watches.at(_watchId);
301 if (w.lastPoll != chrono::system_clock::time_point::max())
302 w.lastPoll = chrono::system_clock::now();
309 if (_hash == PendingBlockHash)
310 return preSeal().info();
316 return bc().details(_hash);
321 return Transaction(bc().transaction(_transactionHash), CheckTransaction::Cheap);
326 std::pair<h256, unsigned> tl = bc().transactionLocation(_transactionHash);
327 return localisedTransaction(tl.first, tl.second);
332 auto bl = bc().block(_blockHash);
334 if (_i < b[1].itemCount())
335 return Transaction(b[1][_i].data(), CheckTransaction::Cheap);
348 return bc().transactionReceipt(_transactionHash);
353 std::pair<h256, unsigned> tl = bc().transactionLocation(_transactionHash);
358 gasUsed -= bc().transactionReceipt(tl.first, tl.second - 1).cumulativeGasUsed();
363 numberFromHash(tl.first),
371 pair<h256, unsigned> ClientBase::transactionLocation(
h256 const& _transactionHash)
const 373 return bc().transactionLocation(_transactionHash);
378 auto bl = bc().block(_blockHash);
381 for (
unsigned i = 0; i < b[1].
itemCount(); i++)
382 res.emplace_back(b[1][i].
data(), CheckTransaction::Cheap);
388 return bc().transactionHashes(_blockHash);
393 auto bl = bc().block(_blockHash);
395 if (_i < b[2].itemCount())
403 return bc().uncleHashes(_blockHash);
406 unsigned ClientBase::transactionCount(
h256 _blockHash)
const 408 auto bl = bc().block(_blockHash);
413 unsigned ClientBase::uncleCount(
h256 _blockHash)
const 415 auto bl = bc().block(_blockHash);
420 unsigned ClientBase::number()
const 422 return bc().number();
425 h256s ClientBase::pendingHashes()
const 427 return h256s() + postSeal().pendingHashes();
432 return postSeal().info();
437 auto pm = postSeal().info();
438 auto li = Interface::blockDetails(LatestBlock);
439 return BlockDetails((
unsigned)pm.number(), li.totalDifficulty + pm.difficulty(), pm.parentHash(),
h256s{});
445 for (
auto const& i : blockByNumber(_block).addresses())
446 ret.push_back(i.first);
450 u256 ClientBase::gasLimitRemaining()
const 452 return postSeal().gasLimitRemaining();
457 return preSeal().author();
462 if (_number == PendingBlock)
464 if (_number == LatestBlock)
465 return bc().currentHash();
466 return bc().numberHash(_number);
471 if (_blockHash == PendingBlockHash)
472 return bc().number() + 1;
473 else if (_blockHash == LatestBlockHash)
474 return bc().number();
475 else if (_blockHash == EarliestBlockHash)
477 return bc().number(_blockHash);
480 int ClientBase::compareBlockHashes(
h256 _h1,
h256 _h2)
const 492 bool ClientBase::isKnown(
h256 const& _hash)
const 494 return _hash == PendingBlockHash ||
495 _hash == LatestBlockHash ||
496 _hash == EarliestBlockHash ||
502 return _block == PendingBlock ||
503 _block == LatestBlock ||
504 bc().numberHash(_block) !=
h256();
507 bool ClientBase::isKnownTransaction(
h256 const& _transactionHash)
const 509 return bc().isKnownTransaction(_transactionHash);
512 bool ClientBase::isKnownTransaction(
h256 const& _blockHash,
unsigned _i)
const 514 return isKnown(_blockHash) && block(_blockHash).pending().size() > _i;
519 if (_h == PendingBlock)
521 else if (_h == LatestBlock)
522 return block(bc().currentHash());
523 return block(bc().numberHash(_h));
526 int ClientBase::chainId()
const 528 return bc().chainParams().chainID;
CodeDeposit codeDeposit
Failed if an attempted deposit failed due to lack of gas.
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
u256 transactionsFrom(Address const &_address) const
h256 latest() const
hash of latest block which should be filtered
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
bool matches(LogBloom _bloom) const
Transactions const & pending() const
Get the list of pending transactions.
Description of the result of executing a transaction.
std::vector< LocalisedLogEntry > LocalisedLogEntries
Active model of a block within the block chain. Keeps track of all transactions, receipts and state f...
TransactionReceipt const & receipt(unsigned _i) const
Get the transaction receipt for the transaction of the given index.
std::lock_guard< std::mutex > Guard
h256 sha3(IncludeSignature _sig=WithSignature) const
bytesConstRef data() const
The bare data of the RLP.
u256 constexpr Invalid256
std::vector< LogBloom > bloomPossibilities() const
std::vector< byte > bytes
bool isRangeFilter() const
u256 const & cumulativeGasUsed() const
h160s Addresses
A vector of Ethereum addresses.
Address to() const
Synonym for receiveAddress().
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Address toAddress(Public const &_public)
Convert a public key to address.
TransactionException excepted
State const & state() const
Get the backing state object.
std::function< void(GasEstimationProgress const &)> GasEstimationCallback
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
BlockHeader const & info() const
Get the header information on the present block.
void forceSender(Address const &_a)
Force the sender to a particular value. This will result in an invalid transaction RLP...
void addBalance(Address const &_id, u256 const &_amount)
h256 earliest() const
hash of earliest block which should be filtered
std::vector< h256 > h256s
Address from() const
Synonym for safeSender().
std::vector< LogEntry > LogEntries