From 146949822c94fad535d67d900d26f26eee7b077a Mon Sep 17 00:00:00 2001 From: subtly Date: Sat, 27 Jun 2015 04:31:06 -0400 Subject: [PATCH 1/2] Check write status for errors in BlockChain and log error so IO problem doesn't put database or client into invalid state. --- libethereum/BlockChain.cpp | 39 +++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 9bf89665a..9114b1a58 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -96,6 +96,15 @@ ldb::Slice dev::eth::toSlice(h256 const& _h, unsigned _sub) #endif } +namespace dev +{ +class WriteBatchNoter: public ldb::WriteBatch::Handler +{ + virtual void Put(ldb::Slice const& _key, ldb::Slice const& _value) { cout << "Put" << toHex(bytesConstRef(_key)) << "=>" << toHex(bytesConstRef(_value)); } + virtual void Delete(ldb::Slice const& _key) { cout << "Delete" << toHex(bytesConstRef(_key)); } +}; +} + #if ETH_DEBUG&&0 static const chrono::system_clock::duration c_collectionDuration = chrono::seconds(15); static const unsigned c_collectionQueueSize = 2; @@ -638,8 +647,25 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& clog(BlockChainChat) << " Imported but not best (oTD:" << details(last).totalDifficulty << " > TD:" << td << ")"; } - m_blocksDB->Write(m_writeOptions, &blocksBatch); - m_extrasDB->Write(m_writeOptions, &extrasBatch); + ldb::Status o = m_blocksDB->Write(m_writeOptions, &blocksBatch); + if (!o.ok()) + { + cwarn << "Error writing to blockchain database: " << o.ToString(); + WriteBatchNoter n; + blocksBatch.Iterate(&n); + cwarn << "Fail writing to blockchain database. Bombing out."; + exit(-1); + } + + o = m_extrasDB->Write(m_writeOptions, &extrasBatch); + if (!o.ok()) + { + cwarn << "Error writing to extras database: " << o.ToString(); + WriteBatchNoter n; + extrasBatch.Iterate(&n); + cwarn << "Fail writing to extras database. Bombing out."; + exit(-1); + } #if ETH_PARANOIA || !ETH_TRUE if (isKnown(_block.info.hash()) && !details(_block.info.hash())) @@ -667,7 +693,14 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& { m_lastBlockHash = newLastBlockHash; m_lastBlockNumber = newLastBlockNumber; - m_extrasDB->Put(m_writeOptions, ldb::Slice("best"), ldb::Slice((char const*)&m_lastBlockHash, 32)); + o = m_extrasDB->Put(m_writeOptions, ldb::Slice("best"), ldb::Slice((char const*)&m_lastBlockHash, 32)); + if (!o.ok()) + { + cwarn << "Error writing to extras database: " << o.ToString(); + cout << "Put" << toHex(bytesConstRef(ldb::Slice("best"))) << "=>" << toHex(bytesConstRef(ldb::Slice((char const*)&m_lastBlockHash, 32))); + cwarn << "Fail writing to extras database. Bombing out."; + exit(-1); + } } #if ETH_PARANOIA || !ETH_TRUE From 19d3ad4ea5a4b26e8581a0fff4a4d9b589f3ca3a Mon Sep 17 00:00:00 2001 From: subtly Date: Sun, 28 Jun 2015 03:39:09 -0400 Subject: [PATCH 2/2] s/cout/cnote/ --- libethereum/BlockChain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 9114b1a58..55c213a64 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -100,8 +100,8 @@ namespace dev { class WriteBatchNoter: public ldb::WriteBatch::Handler { - virtual void Put(ldb::Slice const& _key, ldb::Slice const& _value) { cout << "Put" << toHex(bytesConstRef(_key)) << "=>" << toHex(bytesConstRef(_value)); } - virtual void Delete(ldb::Slice const& _key) { cout << "Delete" << toHex(bytesConstRef(_key)); } + virtual void Put(ldb::Slice const& _key, ldb::Slice const& _value) { cnote << "Put" << toHex(bytesConstRef(_key)) << "=>" << toHex(bytesConstRef(_value)); } + virtual void Delete(ldb::Slice const& _key) { cnote << "Delete" << toHex(bytesConstRef(_key)); } }; }