Browse Source

Gas fixes.

Trie fixes.
cl-refactor
Gav Wood 10 years ago
parent
commit
f799303ea5
  1. 1
      libdevcore/Exceptions.h
  2. 5
      libdevcrypto/MemoryDB.h
  3. 17
      libdevcrypto/OverlayDB.cpp
  4. 8
      libdevcrypto/TrieDB.h
  5. 8
      libethereum/Client.cpp
  6. 15
      libevm/VM.cpp

1
libdevcore/Exceptions.h

@ -46,6 +46,7 @@ struct BadRLP: virtual RLPException {};
struct NoNetworking: virtual Exception {}; struct NoNetworking: virtual Exception {};
struct NoUPnPDevice: virtual Exception {}; struct NoUPnPDevice: virtual Exception {};
struct RootNotFound: virtual Exception {}; struct RootNotFound: virtual Exception {};
struct BadRoot: virtual Exception {};
struct FileError: virtual Exception {}; struct FileError: virtual Exception {};
struct InterfaceNotSupported: virtual Exception { public: InterfaceNotSupported(std::string _f): Exception("Interface " + _f + " not supported.") {} }; struct InterfaceNotSupported: virtual Exception { public: InterfaceNotSupported(std::string _f): Exception("Interface " + _f + " not supported.") {} };

5
libdevcrypto/MemoryDB.h

@ -52,7 +52,8 @@ public:
void purge(); void purge();
bytes lookupAux(h256 _h) const { auto h = aux(_h); return m_aux.count(h) ? m_aux.at(h) : bytes(); } bytes lookupAux(h256 _h) const { auto h = aux(_h); return m_aux.count(h) ? m_aux.at(h) : bytes(); }
void insertAux(h256 _h, bytesConstRef _v) { m_auxKey = aux(_h); m_aux[m_auxKey] = _v.toBytes(); } void removeAux(h256 _h) { m_auxActive.erase(aux(_h)); }
void insertAux(h256 _h, bytesConstRef _v) { auto h = aux(_h); m_auxActive.insert(h); m_aux[h] = _v.toBytes(); }
std::set<h256> keys() const; std::set<h256> keys() const;
@ -61,7 +62,7 @@ protected:
std::map<h256, std::string> m_over; std::map<h256, std::string> m_over;
std::map<h256, unsigned> m_refCount; std::map<h256, unsigned> m_refCount;
h256 m_auxKey; std::set<h256> m_auxActive;
std::map<h256, bytes> m_aux; std::map<h256, bytes> m_aux;
mutable bool m_enforceRefs = false; mutable bool m_enforceRefs = false;

17
libdevcrypto/OverlayDB.cpp

@ -52,14 +52,15 @@ void OverlayDB::commit()
if (m_refCount[i.first]) if (m_refCount[i.first])
m_db->Put(m_writeOptions, ldb::Slice((char const*)i.first.data(), i.first.size), ldb::Slice(i.second.data(), i.second.size())); m_db->Put(m_writeOptions, ldb::Slice((char const*)i.first.data(), i.first.size), ldb::Slice(i.second.data(), i.second.size()));
} }
if (m_auxKey && m_aux.count(m_auxKey)) for (auto const& i: m_auxActive)
{ if (m_aux.count(i))
m_db->Put(m_writeOptions, m_auxKey.ref(), bytesConstRef(&m_aux[m_auxKey])); {
cdebug << "Committing aux: " << m_auxKey; m_db->Put(m_writeOptions, i.ref(), bytesConstRef(&m_aux[i]));
m_aux.erase(m_auxKey); cdebug << "Committing aux: " << i;
cdebug << "Discarding " << keysOf(m_aux); m_aux.erase(i);
} }
m_auxKey = h256(); cdebug << "Discarding " << keysOf(m_aux);
m_auxActive.clear();
m_aux.clear(); m_aux.clear();
m_over.clear(); m_over.clear();
m_refCount.clear(); m_refCount.clear();

8
libdevcrypto/TrieDB.h

@ -93,7 +93,7 @@ public:
/// True if the trie is initialised but empty (i.e. that the DB contains the root node which is empty). /// True if the trie is initialised but empty (i.e. that the DB contains the root node which is empty).
bool isEmpty() const { return m_root == c_shaNull && node(m_root).size(); } bool isEmpty() const { return m_root == c_shaNull && node(m_root).size(); }
h256 root() const { assert(node(m_root).size()); /*std::cout << "Returning root as " << ret << " (really " << m_root << ")" << std::endl;*/ return m_root; } // patch the root in the case of the empty trie. TODO: handle this properly. h256 root() const { if (!node(m_root).size()) BOOST_THROW_EXCEPTION(BadRoot()); /*std::cout << "Returning root as " << ret << " (really " << m_root << ")" << std::endl;*/ return m_root; } // patch the root in the case of the empty trie. TODO: handle this properly.
void debugPrint() {} void debugPrint() {}
@ -404,8 +404,12 @@ public:
void setRoot(h256 _root) void setRoot(h256 _root)
{ {
if (!m_secure.isNull())
Super::db()->removeAux(m_secure.root());
m_secure.setRoot(_root); m_secure.setRoot(_root);
Super::setRoot(h256(Super::db()->lookupAux(m_secure.root()))); auto rb = Super::db()->lookupAux(m_secure.root());
auto r = h256(rb);
Super::setRoot(r);
} }
h256 root() const { return m_secure.root(); } h256 root() const { return m_secure.root(); }

8
libethereum/Client.cpp

@ -278,13 +278,9 @@ LocalisedLogEntries Client::checkWatch(unsigned _watchId)
LocalisedLogEntries ret; LocalisedLogEntries ret;
try { try {
#if ETH_DEBUG // cdebug << "checkWatch" << _watchId;
cdebug << "checkWatch" << _watchId;
#endif
auto& w = m_watches.at(_watchId); auto& w = m_watches.at(_watchId);
#if ETH_DEBUG // cdebug << "lastPoll updated to " << chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
cdebug << "lastPoll updated to " << chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
#endif
std::swap(ret, w.changes); std::swap(ret, w.changes);
w.lastPoll = chrono::system_clock::now(); w.lastPoll = chrono::system_clock::now();
} catch (...) {} } catch (...) {}

15
libevm/VM.cpp

@ -75,21 +75,20 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
{ {
// INSTRUCTION... // INSTRUCTION...
Instruction inst = (Instruction)_ext.getCode(m_curPC); Instruction inst = (Instruction)_ext.getCode(m_curPC);
auto metric = c_metrics[(int)inst];
int gasPriceTier = metric.gasPriceTier;
if (gasPriceTier == InvalidTier)
BOOST_THROW_EXCEPTION(BadInstruction());
// FEES... // FEES...
bigint runGas; bigint runGas = c_tierStepGas[metric.gasPriceTier];
bigint newTempSize = m_temp.size(); bigint newTempSize = m_temp.size();
bigint copySize = 0; bigint copySize = 0;
// should work, but just seems to result in immediate errorless exit on initial execution. yeah. weird. // should work, but just seems to result in immediate errorless exit on initial execution. yeah. weird.
//m_onFail = std::function<void()>(onOperation); //m_onFail = std::function<void()>(onOperation);
auto metric = c_metrics[(int)inst];
int gasPriceTier = metric.gasPriceTier;
if (gasPriceTier == InvalidTier)
BOOST_THROW_EXCEPTION(BadInstruction());
else
runGas = c_tierStepGas[metric.gasPriceTier];
require(metric.args); require(metric.args);
auto onOperation = [&]() auto onOperation = [&]()
@ -186,7 +185,7 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
newTempSize = (newTempSize + 31) / 32 * 32; newTempSize = (newTempSize + 31) / 32 * 32;
if (newTempSize > m_temp.size()) if (newTempSize > m_temp.size())
runGas += gasForMem(newTempSize) - gasForMem(m_temp.size()); runGas += gasForMem(newTempSize) - gasForMem(m_temp.size());
runGas += c_copyGas * (copySize + 31) / 32; runGas += c_copyGas * ((copySize + 31) / 32);
onOperation(); onOperation();
// if (_onOp) // if (_onOp)

Loading…
Cancel
Save