21 #if !defined(ETH_EMSCRIPTEN) 35 OverlayDB::~OverlayDB()
37 if (m_db.use_count() == 1 && m_db.get())
38 ctrace <<
"Closing state DB";
51 ldb::WriteBatch batch;
57 for (
auto const& i: m_main)
60 batch.Put(ldb::Slice((
char const*)i.first.data(), i.first.size), ldb::Slice(i.second.first.data(), i.second.first.size()));
63 for (
auto const& i: m_aux)
66 bytes b = i.first.asBytes();
72 for (
unsigned i = 0; i < 10; ++i)
74 ldb::Status o = m_db->Write(m_writeOptions, &batch);
79 cwarn <<
"Fail writing to state database. Bombing out.";
82 cwarn <<
"Error writing to state database: " << o.ToString();
85 cwarn <<
"Sleeping for" << (i + 1) <<
"seconds, then retrying.";
86 this_thread::sleep_for(chrono::seconds(i + 1));
100 bytes ret = MemoryDB::lookupAux(_h);
101 if (!ret.empty() || !m_db)
108 cwarn <<
"Aux not found: " << _h;
112 void OverlayDB::rollback()
120 std::string OverlayDB::lookup(
h256 const& _h)
const 122 std::string ret = MemoryDB::lookup(_h);
123 if (ret.empty() && m_db)
124 m_db->Get(m_readOptions, ldb::Slice((
char const*)_h.
data(), 32), &ret);
128 bool OverlayDB::exists(
h256 const& _h)
const 130 if (MemoryDB::exists(_h))
134 m_db->Get(m_readOptions, ldb::Slice((
char const*)_h.
data(), 32), &ret);
138 void OverlayDB::kill(
h256 const& _h)
140 #if ETH_PARANOIA || 1 141 if (!MemoryDB::kill(_h))
145 m_db->Get(m_readOptions, ldb::Slice((
char const*)_h.
data(), 32), &ret);
149 cnote <<
"Decreasing DB node ref count below zero with no DB node. Probably have a corrupt Trie." << _h;
158 bool OverlayDB::deepkill(
h256 const& _h)
164 ldb::Status s = m_db->Delete(m_writeOptions, ldb::Slice((
char const*)_h.
data(), 32));
173 #endif // ETH_EMSCRIPTEN
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
std::hash for asio::adress
std::shared_ptr< typename Signal< Args... >::HandlerAux > Handler
#define DEV_WRITE_GUARDED(MUTEX)
#define DEV_READ_GUARDED(MUTEX)
std::vector< byte > bytes
vector_ref< byte const > bytesConstRef
bytes asBytes(std::string const &_b)
Converts a string to a byte array containing the string's (byte) data.
boost::unique_lock< boost::shared_mutex > WriteGuard
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
virtual void Put(ldb::Slice const &_key, ldb::Slice const &_value)
virtual void Delete(ldb::Slice const &_key)
AddressHash commit(AccountMap const &_cache, SecureTrieDB< Address, DB > &_state)