|
@ -169,18 +169,6 @@ State::~State() |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Address State::nextActiveAddress(Address _a) const |
|
|
|
|
|
{ |
|
|
|
|
|
auto it = m_state.lower_bound(_a); |
|
|
|
|
|
if ((*it).first == _a) |
|
|
|
|
|
++it; |
|
|
|
|
|
if (it == m_state.end()) |
|
|
|
|
|
// exchange comments if we want to wraparound
|
|
|
|
|
|
// it = m_state.begin();
|
|
|
|
|
|
return Address(); |
|
|
|
|
|
return (*it).first; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
StateDiff State::diff(State const& _c) const |
|
|
StateDiff State::diff(State const& _c) const |
|
|
{ |
|
|
{ |
|
|
StateDiff ret; |
|
|
StateDiff ret; |
|
@ -189,13 +177,14 @@ StateDiff State::diff(State const& _c) const |
|
|
std::set<Address> trieAds; |
|
|
std::set<Address> trieAds; |
|
|
std::set<Address> trieAdsD; |
|
|
std::set<Address> trieAdsD; |
|
|
|
|
|
|
|
|
auto trie = TrieDB<Address, OverlayDB>(const_cast<OverlayDB*>(&m_db), rootHash()); |
|
|
auto trie = SecureTrieDB<Address, OverlayDB>(const_cast<OverlayDB*>(&m_db), rootHash()); |
|
|
auto trieD = TrieDB<Address, OverlayDB>(const_cast<OverlayDB*>(&_c.m_db), _c.rootHash()); |
|
|
auto trieD = SecureTrieDB<Address, OverlayDB>(const_cast<OverlayDB*>(&_c.m_db), _c.rootHash()); |
|
|
|
|
|
|
|
|
for (auto i: trie) |
|
|
// TODO: fix
|
|
|
ads.insert(i.first), trieAds.insert(i.first); |
|
|
// for (auto i: trie)
|
|
|
for (auto i: trieD) |
|
|
// ads.insert(i.first), trieAds.insert(i.first);
|
|
|
ads.insert(i.first), trieAdsD.insert(i.first); |
|
|
// for (auto i: trieD)
|
|
|
|
|
|
// ads.insert(i.first), trieAdsD.insert(i.first);
|
|
|
for (auto i: m_cache) |
|
|
for (auto i: m_cache) |
|
|
ads.insert(i.first); |
|
|
ads.insert(i.first); |
|
|
for (auto i: _c.m_cache) |
|
|
for (auto i: _c.m_cache) |
|
@ -357,9 +346,10 @@ map<Address, u256> State::addresses() const |
|
|
for (auto i: m_cache) |
|
|
for (auto i: m_cache) |
|
|
if (i.second.isAlive()) |
|
|
if (i.second.isAlive()) |
|
|
ret[i.first] = i.second.balance(); |
|
|
ret[i.first] = i.second.balance(); |
|
|
for (auto const& i: m_state) |
|
|
// TODO: fix.
|
|
|
if (m_cache.find(i.first) == m_cache.end()) |
|
|
// for (auto const& i: m_state)
|
|
|
ret[i.first] = RLP(i.second)[1].toInt<u256>(); |
|
|
// if (m_cache.find(i.first) == m_cache.end())
|
|
|
|
|
|
// ret[i.first] = RLP(i.second)[1].toInt<u256>();
|
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -592,9 +582,10 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce) |
|
|
{ |
|
|
{ |
|
|
cwarn << "Bad state root!"; |
|
|
cwarn << "Bad state root!"; |
|
|
cnote << "Given to be:" << m_currentBlock.stateRoot; |
|
|
cnote << "Given to be:" << m_currentBlock.stateRoot; |
|
|
cnote << TrieDB<Address, OverlayDB>(&m_db, m_currentBlock.stateRoot); |
|
|
// TODO: Fix
|
|
|
|
|
|
// cnote << SecureTrieDB<Address, OverlayDB>(&m_db, m_currentBlock.stateRoot);
|
|
|
cnote << "Calculated to be:" << rootHash(); |
|
|
cnote << "Calculated to be:" << rootHash(); |
|
|
cnote << m_state; |
|
|
// cnote << m_state;
|
|
|
cnote << *this; |
|
|
cnote << *this; |
|
|
// Rollback the trie.
|
|
|
// Rollback the trie.
|
|
|
m_db.rollback(); |
|
|
m_db.rollback(); |
|
@ -939,7 +930,7 @@ u256 State::storage(Address _id, u256 _memory) const |
|
|
return mit->second; |
|
|
return mit->second; |
|
|
|
|
|
|
|
|
// Not in the storage cache - go to the DB.
|
|
|
// Not in the storage cache - go to the DB.
|
|
|
TrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&m_db), it->second.baseRoot()); // promise we won't change the overlay! :)
|
|
|
SecureTrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&m_db), it->second.baseRoot()); // promise we won't change the overlay! :)
|
|
|
string payload = memdb.at(_memory); |
|
|
string payload = memdb.at(_memory); |
|
|
u256 ret = payload.size() ? RLP(payload).toInt<u256>() : 0; |
|
|
u256 ret = payload.size() ? RLP(payload).toInt<u256>() : 0; |
|
|
it->second.setStorage(_memory, ret); |
|
|
it->second.setStorage(_memory, ret); |
|
@ -957,9 +948,10 @@ map<u256, u256> State::storage(Address _id) const |
|
|
// Pull out all values from trie storage.
|
|
|
// Pull out all values from trie storage.
|
|
|
if (it->second.baseRoot()) |
|
|
if (it->second.baseRoot()) |
|
|
{ |
|
|
{ |
|
|
TrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&m_db), it->second.baseRoot()); // promise we won't alter the overlay! :)
|
|
|
// TODO: fix
|
|
|
for (auto const& i: memdb) |
|
|
// SecureTrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&m_db), it->second.baseRoot()); // promise we won't alter the overlay! :)
|
|
|
ret[i.first] = RLP(i.second).toInt<u256>(); |
|
|
// for (auto const& i: memdb)
|
|
|
|
|
|
// ret[i.first] = RLP(i.second).toInt<u256>();
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Then merge cached storage over the top.
|
|
|
// Then merge cached storage over the top.
|
|
@ -1010,24 +1002,24 @@ bool State::isTrieGood(bool _enforceRefs, bool _requireNoLeftOvers) const |
|
|
cwarn << "LEFTOVERS" << (e ? "[enforced" : "[unenforced") << "refs]"; |
|
|
cwarn << "LEFTOVERS" << (e ? "[enforced" : "[unenforced") << "refs]"; |
|
|
cnote << "Left:" << lo; |
|
|
cnote << "Left:" << lo; |
|
|
cnote << "Keys:" << m_db.keys(); |
|
|
cnote << "Keys:" << m_db.keys(); |
|
|
m_state.debugStructure(cerr); |
|
|
// m_state.debugStructure(cerr);
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
// TODO: Enable once fixed.
|
|
|
// TODO: Enable once fixed.
|
|
|
for (auto const& i: m_state) |
|
|
/* for (auto const& i: m_state)
|
|
|
{ |
|
|
{ |
|
|
RLP r(i.second); |
|
|
RLP r(i.second); |
|
|
TrieDB<h256, OverlayDB> storageDB(const_cast<OverlayDB*>(&m_db), r[2].toHash<h256>()); // promise not to alter OverlayDB.
|
|
|
SecureTrieDB<h256, OverlayDB> storageDB(const_cast<OverlayDB*>(&m_db), r[2].toHash<h256>()); // promise not to alter OverlayDB.
|
|
|
for (auto const& j: storageDB) { (void)j; } |
|
|
for (auto const& j: storageDB) { (void)j; } |
|
|
if (!e && r[3].toHash<h256>() != EmptySHA3 && m_db.lookup(r[3].toHash<h256>()).empty()) |
|
|
if (!e && r[3].toHash<h256>() != EmptySHA3 && m_db.lookup(r[3].toHash<h256>()).empty()) |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
}*/ |
|
|
} |
|
|
} |
|
|
catch (InvalidTrie const&) |
|
|
catch (InvalidTrie const&) |
|
|
{ |
|
|
{ |
|
|
cwarn << "BAD TRIE" << (e ? "[enforced" : "[unenforced") << "refs]"; |
|
|
cwarn << "BAD TRIE" << (e ? "[enforced" : "[unenforced") << "refs]"; |
|
|
cnote << m_db.keys(); |
|
|
cnote << m_db.keys(); |
|
|
m_state.debugStructure(cerr); |
|
|
// m_state.debugStructure(cerr);
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
@ -1194,9 +1186,10 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, State const& _s) |
|
|
std::set<u256> cached; |
|
|
std::set<u256> cached; |
|
|
if (r) |
|
|
if (r) |
|
|
{ |
|
|
{ |
|
|
TrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&_s.m_db), r[2].toHash<h256>()); // promise we won't alter the overlay! :)
|
|
|
SecureTrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&_s.m_db), r[2].toHash<h256>()); // promise we won't alter the overlay! :)
|
|
|
for (auto const& j: memdb) |
|
|
// TODO: fix
|
|
|
mem[j.first] = RLP(j.second).toInt<u256>(), back.insert(j.first); |
|
|
// for (auto const& j: memdb)
|
|
|
|
|
|
// mem[j.first] = RLP(j.second).toInt<u256>(), back.insert(j.first);
|
|
|
} |
|
|
} |
|
|
if (cache) |
|
|
if (cache) |
|
|
for (auto const& j: cache->storageOverlay()) |
|
|
for (auto const& j: cache->storageOverlay()) |
|
|