Browse Source

Fix haveCode() issue.

cl-refactor
Gav Wood 11 years ago
parent
commit
e0e36afcdc
  1. 3
      libethereum/AddressState.h
  2. 2
      libethereum/State.cpp
  3. 2
      libethereum/State.h

3
libethereum/AddressState.h

@ -51,8 +51,9 @@ public:
void setStorage(u256 _p, u256 _v) { m_storageOverlay[_p] = _v; }
bool isFreshCode() const { return !m_codeHash; }
bool codeBearing() const { return m_codeHash != EmptySHA3; }
bool codeCacheValid() const { return m_codeHash == EmptySHA3 || !m_codeHash || m_codeCache.size(); }
h256 codeHash() const { assert(m_codeHash); return m_codeHash; }
bool haveCode() const { return m_codeHash != EmptySHA3 || m_codeCache.size(); }
bytes const& code() const { assert(m_codeHash == EmptySHA3 || !m_codeHash || m_codeCache.size()); return m_codeCache; }
void setCode(bytesConstRef _code) { assert(!m_codeHash); m_codeCache = _code.toBytes(); }
void noteCode(bytesConstRef _code) { assert(sha3(_code) == m_codeHash); m_codeCache = _code.toBytes(); }

2
libethereum/State.cpp

@ -141,7 +141,7 @@ void State::ensureCached(std::map<Address, AddressState>& _cache, Address _a, bo
bool ok;
tie(it, ok) = _cache.insert(make_pair(_a, s));
}
if (_requireCode && it != _cache.end() && !it->second.isFreshCode() && !it->second.haveCode())
if (_requireCode && it != _cache.end() && !it->second.isFreshCode() && !it->second.codeCacheValid())
it->second.noteCode(it->second.codeHash() == EmptySHA3 ? bytesConstRef() : bytesConstRef(m_db.lookup(it->second.codeHash())));
}

2
libethereum/State.h

@ -309,7 +309,7 @@ inline std::ostream& operator<<(std::ostream& _out, State const& _s)
else
{
_out << (d.count(i.first) ? "[ ! " : "[ * ") << "]" << i.first << ": " << std::dec << i.second.nonce() << "@" << i.second.balance();
if (i.second.isFreshCode() || i.second.haveCode())
if (i.second.codeBearing())
{
_out << " *" << i.second.oldRoot();
TrieDB<h256, Overlay> memdb(const_cast<Overlay*>(&_s.m_db), i.second.oldRoot()); // promise we won't alter the overlay! :)

Loading…
Cancel
Save