From 0bcf6d4d65c323f07de85ccda44ade4c80ddf06d Mon Sep 17 00:00:00 2001 From: cifer Date: Sun, 25 Feb 2018 12:14:01 +0800 Subject: [PATCH 1/3] Fix #436 object_database created outside of witness data directory --- libraries/chain/db_management.cpp | 7 ++++++- libraries/chain/include/graphene/chain/database.hpp | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/chain/db_management.cpp b/libraries/chain/db_management.cpp index 68f6fad1..f22a46df 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -119,7 +119,9 @@ void database::reindex(fc::path data_dir, const genesis_state_type& initial_allo void database::wipe(const fc::path& data_dir, bool include_blocks) { ilog("Wiping database", ("include_blocks", include_blocks)); - close(); + if (_opened) { + close(); + } object_database::wipe(data_dir); if( include_blocks ) fc::remove_all( data_dir / "database" ); @@ -148,6 +150,7 @@ void database::open( ("last_block->id", last_block->id())("head_block_num",head_block_num()) ); } } + _opened = true; } FC_CAPTURE_LOG_AND_RETHROW( (data_dir) ) } @@ -198,6 +201,8 @@ void database::close(bool rewind) _block_id_to_block.close(); _fork_db.reset(); + + _opened = false; } void database::force_slow_replays() diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 84d1ea9b..6b9d973a 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -561,6 +561,14 @@ namespace graphene { namespace chain { node_property_object _node_property_object; fc::hash_ctr_rng _random_number_generator; bool _slow_replays = false; + + /** + * Whether database is successfully opened or not. + * + * The database is considered open when there's no exception + * or assertion fail during database::open() method. + */ + bool _opened = false; }; namespace detail From f1ffd52e1e7c764513a3bfe53ee941643ad5b66e Mon Sep 17 00:00:00 2001 From: cifer Date: Mon, 26 Feb 2018 10:59:51 +0800 Subject: [PATCH 2/3] supplement more comments on database::_opened variable --- libraries/chain/include/graphene/chain/database.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 6b9d973a..b513fd2f 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -566,7 +566,8 @@ namespace graphene { namespace chain { * Whether database is successfully opened or not. * * The database is considered open when there's no exception - * or assertion fail during database::open() method. + * or assertion fail during database::open() method, and + * database::close() has not been called, or failed during execution. */ bool _opened = false; }; From b3c64c83b248c1549c825bdf14717adc7f07b5c5 Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 14 Jan 2019 13:55:13 -0500 Subject: [PATCH 3/3] prevent segfault when destructing application obj --- libraries/chain/db_management.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/chain/db_management.cpp b/libraries/chain/db_management.cpp index f22a46df..a0a78682 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -157,6 +157,9 @@ void database::open( void database::close(bool rewind) { + if (!_opened) + return; + // TODO: Save pending tx's on close() clear_pending();