From 737ccaee8d73347ad1e48a558c9a486e660272a1 Mon Sep 17 00:00:00 2001 From: cifer Date: Sun, 25 Feb 2018 12:14:01 +0800 Subject: [PATCH 1/2] 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 a8dbd0e118..8e8c1213ab 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -125,7 +125,9 @@ void database::reindex( fc::path data_dir ) 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" ); @@ -171,6 +173,7 @@ void database::open( ("last_block->id", last_block)("head_block_id",head_block_num()) ); reindex( data_dir ); } + _opened = true; } FC_CAPTURE_LOG_AND_RETHROW( (data_dir) ) } @@ -214,6 +217,8 @@ void database::close(bool rewind) _block_id_to_block.close(); _fork_db.reset(); + + _opened = false; } } } diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index d8fb726dad..69e96fc0fe 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -508,6 +508,14 @@ namespace graphene { namespace chain { flat_map _checkpoints; node_property_object _node_property_object; + + /** + * 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 bb30f3f08581dacad35b3fdc2381cdb21e726bb6 Mon Sep 17 00:00:00 2001 From: cifer Date: Mon, 26 Feb 2018 10:59:51 +0800 Subject: [PATCH 2/2] 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 69e96fc0fe..21ec4c421f 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -513,7 +513,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; };