Browse Source

Tidy up gaurds. Shorted extraData to max size.

cl-refactor
Gav Wood 10 years ago
parent
commit
f29cb461c9
  1. 34
      libethereum/BlockChain.cpp
  2. 31
      libethereum/State.cpp

34
libethereum/BlockChain.cpp

@ -871,33 +871,21 @@ template <class T> static unsigned getHashSize(unordered_map<h256, T> const& _ma
void BlockChain::updateStats() const void BlockChain::updateStats() const
{ {
{
ReadGuard l(x_blocks);
m_lastStats.memBlocks = 0; m_lastStats.memBlocks = 0;
DEV_READ_GUARDED(x_blocks)
for (auto const& i: m_blocks) for (auto const& i: m_blocks)
m_lastStats.memBlocks += i.second.size() + 64; m_lastStats.memBlocks += i.second.size() + 64;
} DEV_READ_GUARDED(x_details)
{
ReadGuard l(x_details);
m_lastStats.memDetails = getHashSize(m_details); m_lastStats.memDetails = getHashSize(m_details);
} DEV_READ_GUARDED(x_logBlooms)
{ DEV_READ_GUARDED(x_blocksBlooms)
ReadGuard l1(x_logBlooms);
ReadGuard l2(x_blocksBlooms);
m_lastStats.memLogBlooms = getHashSize(m_logBlooms) + getHashSize(m_blocksBlooms); m_lastStats.memLogBlooms = getHashSize(m_logBlooms) + getHashSize(m_blocksBlooms);
} DEV_READ_GUARDED(x_receipts)
{
ReadGuard l(x_receipts);
m_lastStats.memReceipts = getHashSize(m_receipts); m_lastStats.memReceipts = getHashSize(m_receipts);
} DEV_READ_GUARDED(x_blockHashes)
{
ReadGuard l(x_blockHashes);
m_lastStats.memBlockHashes = getHashSize(m_blockHashes); m_lastStats.memBlockHashes = getHashSize(m_blockHashes);
} DEV_READ_GUARDED(x_transactionAddresses)
{
ReadGuard l(x_transactionAddresses);
m_lastStats.memTransactionAddresses = getHashSize(m_transactionAddresses); m_lastStats.memTransactionAddresses = getHashSize(m_transactionAddresses);
}
} }
void BlockChain::garbageCollect(bool _force) void BlockChain::garbageCollect(bool _force)
@ -954,10 +942,8 @@ void BlockChain::garbageCollect(bool _force)
void BlockChain::checkConsistency() void BlockChain::checkConsistency()
{ {
{ DEV_WRITE_GUARDED(x_details)
WriteGuard l(x_details);
m_details.clear(); m_details.clear();
}
ldb::Iterator* it = m_blocksDB->NewIterator(m_readOptions); ldb::Iterator* it = m_blocksDB->NewIterator(m_readOptions);
for (it->SeekToFirst(); it->Valid(); it->Next()) for (it->SeekToFirst(); it->Valid(); it->Next())
if (it->key().size() == 32) if (it->key().size() == 32)
@ -969,15 +955,11 @@ void BlockChain::checkConsistency()
{ {
auto dp = details(p); auto dp = details(p);
if (asserts(contains(dp.children, h))) if (asserts(contains(dp.children, h)))
{
cnote << "Apparently the database is corrupt. Not much we can do at this stage..."; cnote << "Apparently the database is corrupt. Not much we can do at this stage...";
}
if (assertsEqual(dp.number, dh.number - 1)) if (assertsEqual(dp.number, dh.number - 1))
{
cnote << "Apparently the database is corrupt. Not much we can do at this stage..."; cnote << "Apparently the database is corrupt. Not much we can do at this stage...";
} }
} }
}
delete it; delete it;
} }

31
libethereum/State.cpp

@ -445,7 +445,8 @@ u256 State::enactOn(VerifiedBlockRef const& _block, BlockChain const& _bc, Impor
#if ETH_TIMED_ENACTMENTS #if ETH_TIMED_ENACTMENTS
enactment = t.elapsed(); enactment = t.elapsed();
cnote << "popVer/popGrand/syncReset/enactment = " << populateVerify << "/" << populateGrand << "/" << syncReset << "/" << enactment; if (populateVerify + populateGrand + syncReset + enactment > 0.5)
clog(StateChat) << "popVer/popGrand/syncReset/enactment = " << populateVerify << "/" << populateGrand << "/" << syncReset << "/" << enactment;
#endif #endif
return ret; return ret;
} }
@ -513,18 +514,17 @@ pair<TransactionReceipts, bool> State::sync(BlockChain const& _bc, TransactionQu
{ {
if (t.gasPrice() >= _gp.ask(*this)) if (t.gasPrice() >= _gp.ask(*this))
{ {
// Timer t; // Timer t;
if (lh.empty()) if (lh.empty())
lh = _bc.lastHashes(); lh = _bc.lastHashes();
execute(lh, t); execute(lh, t);
ret.first.push_back(m_receipts.back()); ret.first.push_back(m_receipts.back());
++goodTxs; ++goodTxs;
// cnote << "TX took:" << t.elapsed() * 1000; // cnote << "TX took:" << t.elapsed() * 1000;
} }
else if (t.gasPrice() < _gp.ask(*this) * 9 / 10) else if (t.gasPrice() < _gp.ask(*this) * 9 / 10)
{ {
// less than 90% of our ask price for gas. drop. clog(StateTrace) << t.sha3() << "Dropping El Cheapo transaction (<90% of ask price)";
cnote << t.sha3() << "Dropping El Cheapo transaction (<90% of ask price)";
_tq.drop(t.sha3()); _tq.drop(t.sha3());
} }
} }
@ -536,22 +536,13 @@ pair<TransactionReceipts, bool> State::sync(BlockChain const& _bc, TransactionQu
if (req > got) if (req > got)
{ {
// too old // too old
/* for (Transaction const& mt: m_transactions) clog(StateTrace) << t.sha3() << "Dropping old transaction (nonce too low)";
{
if (mt.from() == t.from())
{
if (mt.nonce() < t.nonce())
cnote << t.sha3() << "Dropping old transaction (nonce too low)";
else if (mt.nonce() == t.nonce() && mt.gasPrice() <= t.gasPrice())
cnote << t.sha3() << "Dropping old transaction (gas price lower)";
}
}*/
_tq.drop(t.sha3()); _tq.drop(t.sha3());
} }
else if (got > req + _tq.waiting(t.sender())) else if (got > req + _tq.waiting(t.sender()))
{ {
// too new // too new
cnote << t.sha3() << "Dropping new transaction (too many nonces ahead)"; clog(StateTrace) << t.sha3() << "Dropping new transaction (too many nonces ahead)";
_tq.drop(t.sha3()); _tq.drop(t.sha3());
} }
else else
@ -562,7 +553,7 @@ pair<TransactionReceipts, bool> State::sync(BlockChain const& _bc, TransactionQu
bigint const& got = *boost::get_error_info<errinfo_got>(e); bigint const& got = *boost::get_error_info<errinfo_got>(e);
if (got > m_currentBlock.gasLimit) if (got > m_currentBlock.gasLimit)
{ {
cnote << t.sha3() << "Dropping over-gassy transaction (gas > block's gas limit)"; clog(StateTrace) << t.sha3() << "Dropping over-gassy transaction (gas > block's gas limit)";
_tq.drop(t.sha3()); _tq.drop(t.sha3());
} }
else else
@ -576,14 +567,14 @@ pair<TransactionReceipts, bool> State::sync(BlockChain const& _bc, TransactionQu
catch (Exception const& _e) catch (Exception const& _e)
{ {
// Something else went wrong - drop it. // Something else went wrong - drop it.
cnote << t.sha3() << "Dropping invalid transaction:" << diagnostic_information(_e); clog(StateTrace) << t.sha3() << "Dropping invalid transaction:" << diagnostic_information(_e);
_tq.drop(t.sha3()); _tq.drop(t.sha3());
} }
catch (std::exception const&) catch (std::exception const&)
{ {
// Something else went wrong - drop it. // Something else went wrong - drop it.
_tq.drop(t.sha3()); _tq.drop(t.sha3());
cnote << t.sha3() << "Transaction caused low-level exception :("; cwarn << t.sha3() << "Transaction caused low-level exception :(";
} }
} }
if (chrono::steady_clock::now() > deadline) if (chrono::steady_clock::now() > deadline)
@ -965,6 +956,8 @@ void State::commitToMine(BlockChain const& _bc, bytes const& _extraData)
m_currentBlock.stateRoot = m_state.root(); m_currentBlock.stateRoot = m_state.root();
m_currentBlock.parentHash = m_previousBlock.hash(); m_currentBlock.parentHash = m_previousBlock.hash();
m_currentBlock.extraData = _extraData; m_currentBlock.extraData = _extraData;
if (m_currentBlock.extraData.size() > 32)
m_currentBlock.extraData.resize(32);
m_committedToMine = true; m_committedToMine = true;
} }

Loading…
Cancel
Save