From a050ee1e6170bbd861380f51668c0e9ad4794fad Mon Sep 17 00:00:00 2001 From: Brannon King Date: Tue, 3 Mar 2020 11:35:25 -0700 Subject: [PATCH] changed sync requirement, use hash_bytes --- src/claimtrie/sqlite.h | 5 +++-- src/claimtrie/uints.h | 6 ++++-- src/pubkey.h | 2 +- src/script/standard.h | 2 +- src/txdb.cpp | 4 ++-- src/validation.cpp | 2 +- src/validation.h | 2 +- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/claimtrie/sqlite.h b/src/claimtrie/sqlite.h index ff1798b5a..f429eb58d 100644 --- a/src/claimtrie/sqlite.h +++ b/src/claimtrie/sqlite.h @@ -105,14 +105,15 @@ namespace sqlite return code; } - inline int sync(database& db, std::size_t attempts = 200) + inline int sync(database& db, std::size_t attempts = 20) { int code = SQLITE_OK; for (auto i = 0u; i < attempts; ++i) { code = sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr); if (code != SQLITE_OK) { + sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_PASSIVE, nullptr, nullptr); using namespace std::chrono_literals; - std::this_thread::sleep_for(100ms); + std::this_thread::sleep_for(200ms); continue; } break; diff --git a/src/claimtrie/uints.h b/src/claimtrie/uints.h index 1420d8ec9..3c2069111 100644 --- a/src/claimtrie/uints.h +++ b/src/claimtrie/uints.h @@ -5,6 +5,8 @@ #include #include +#include + class uint160 : public CBaseBlob<160> { public: @@ -47,7 +49,7 @@ namespace std { { size_t operator()(const uint160& k) const { - return *reinterpret_cast(k.begin()); + return robin_hood::hash_bytes(k.begin(), k.size()); } }; @@ -56,7 +58,7 @@ namespace std { { size_t operator()(const uint256& k) const { - return *reinterpret_cast(k.begin()); + return robin_hood::hash_bytes(k.begin(), k.size()); } }; } diff --git a/src/pubkey.h b/src/pubkey.h index 9ca51e1dd..80d356de7 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -42,7 +42,7 @@ namespace std { { size_t operator()(const CKeyID& k) const { - return *reinterpret_cast(k.begin()); + return robin_hood::hash_bytes(k.begin(), k.size()); } }; } diff --git a/src/script/standard.h b/src/script/standard.h index 59bf18805..3435ad14e 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -33,7 +33,7 @@ namespace std { { size_t operator()(const CScriptID& k) const { - return *reinterpret_cast(k.begin()); + return robin_hood::hash_bytes(k.begin(), k.size()); } }; } diff --git a/src/txdb.cpp b/src/txdb.cpp index 47d1ee182..3ceff33cf 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -148,7 +148,7 @@ bool CCoinsViewDB::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBloc code = sqlite::sync(db); if (code != SQLITE_OK) { LogPrintf("%s: Error syncing coin database. SQLite error: %d\n", __func__, code); - return false; + // don't return false as it may happen if someone else is reading our DB } } return true; @@ -338,7 +338,7 @@ bool CBlockTreeDB::BatchWrite(const std::vectorGetCacheSize())) return state.Error("out of disk space"); if (syncToDisk && !pclaimTrie->SyncToDisk()) - return state.Error("Failed to write to claim trie database"); + LogPrintf("Failed to sync claim trie database to disk"); // Flush the chainstate (which may refer to block index entries). if (!pcoinsTip->Flush(syncToDisk)) return AbortNode(state, "Failed to write to coin database"); diff --git a/src/validation.h b/src/validation.h index b19ee751b..04c5368cc 100644 --- a/src/validation.h +++ b/src/validation.h @@ -148,7 +148,7 @@ extern std::atomic_bool g_is_mempool_loaded; struct BlockMapHasher { std::size_t operator()(const CBlockIndex* block) const { - return *reinterpret_cast(block->hash.begin()); + return robin_hood::hash_bytes(block->hash.begin(), block->hash.size()); } };