From 0d3027653621b49ca25c996529ea1b040d5887d7 Mon Sep 17 00:00:00 2001 From: "d.yakovitsky" Date: Thu, 23 Aug 2018 17:51:16 +0300 Subject: [PATCH 1/2] Fix : Segmentation fault when running several witness nodes on the same machine https://github.com/bitshares/bitshares-core/issues/377 --- libraries/chain/db_getter.cpp | 2 +- libraries/db/include/graphene/db/undo_database.hpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/chain/db_getter.cpp b/libraries/chain/db_getter.cpp index 06e5359cae..c04c8cd73e 100644 --- a/libraries/chain/db_getter.cpp +++ b/libraries/chain/db_getter.cpp @@ -99,7 +99,7 @@ node_property_object& database::node_properties() uint32_t database::last_non_undoable_block_num() const { - return head_block_num() - _undo_db.size(); + return head_block_num() - ( _undo_db.size() - _undo_db.active_sessions()); } const account_statistics_object& database::get_account_stats_by_owner( account_id_type owner )const diff --git a/libraries/db/include/graphene/db/undo_database.hpp b/libraries/db/include/graphene/db/undo_database.hpp index 9f10486960..cf6f06247d 100644 --- a/libraries/db/include/graphene/db/undo_database.hpp +++ b/libraries/db/include/graphene/db/undo_database.hpp @@ -129,6 +129,7 @@ namespace graphene { namespace db { std::size_t size()const { return _stack.size(); } void set_max_size(size_t new_max_size) { _max_size = new_max_size; } size_t max_size()const { return _max_size; } + uint32_t active_sessions()const { return _active_sessions; } const undo_state& head()const; From 2169226ddeeaf39e0ce8e92a513eef9444cb2c94 Mon Sep 17 00:00:00 2001 From: "d.yakovitsky" Date: Thu, 23 Aug 2018 18:05:05 +0300 Subject: [PATCH 2/2] Fix: Segmentation fault when running several witness nodes on the same machine. (see https://github.com/bitshares/bitshares-core/issues/377) --- libraries/chain/db_getter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libraries/chain/db_getter.cpp b/libraries/chain/db_getter.cpp index c04c8cd73e..4b4c0ee10d 100644 --- a/libraries/chain/db_getter.cpp +++ b/libraries/chain/db_getter.cpp @@ -99,7 +99,14 @@ node_property_object& database::node_properties() uint32_t database::last_non_undoable_block_num() const { - return head_block_num() - ( _undo_db.size() - _undo_db.active_sessions()); + //see https://github.com/bitshares/bitshares-core/issues/377 + /* + There is a case when a value of undo_db.size() is greater then head_block_num(), + and as result we get a wrong value for last_non_undoable_block_num. + To resolve it we should take into account a number of active_sessions in calculations of + last_non_undoable_block_num (active sessions are related to a new block which is under generation). + */ + return head_block_num() - ( _undo_db.size() - _undo_db.active_sessions() ); } const account_statistics_object& database::get_account_stats_by_owner( account_id_type owner )const