Skip to content

Commit 7e41e4b

Browse files
committedApr 24, 2018
1 parent 04d40b4 commit 7e41e4b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed
 

‎libraries/plugins/account_history/account_history_plugin.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ void account_history_plugin_impl::update_account_histories( const signed_block&
8282
{
8383
graphene::chain::database& db = database();
8484
const vector<optional< operation_history_object > >& hist = db.get_applied_operations();
85+
bool is_first = true;
86+
auto skip_oho_id = [&is_first,&db,this]() {
87+
if( is_first && db._undo_db.enabled() ) // this ensures that the current id is rolled back on undo
88+
{
89+
db.remove( db.create<operation_history_object>( []( operation_history_object& obj) {} ) );
90+
is_first = false;
91+
}
92+
else
93+
_oho_index->use_next_id();
94+
};
95+
8596
for( const optional< operation_history_object >& o_op : hist )
8697
{
8798
optional<operation_history_object> oho;
@@ -105,7 +116,7 @@ void account_history_plugin_impl::update_account_histories( const signed_block&
105116
{
106117
// Note: the 2nd and 3rd checks above are for better performance, when the db is not clean,
107118
// they will break consistency of account_stats.total_ops and removed_ops and most_recent_op
108-
_oho_index->use_next_id();
119+
skip_oho_id();
109120
continue;
110121
}
111122
else if( !_partial_operations )
@@ -178,7 +189,7 @@ void account_history_plugin_impl::update_account_histories( const signed_block&
178189
}
179190
}
180191
if (_partial_operations && ! oho.valid())
181-
_oho_index->use_next_id();
192+
skip_oho_id();
182193
}
183194
}
184195

‎libraries/plugins/elasticsearch/elasticsearch_plugin.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ void elasticsearch_plugin_impl::update_account_histories( const signed_block& b
9090
{
9191
graphene::chain::database& db = database();
9292
const vector<optional< operation_history_object > >& hist = db.get_applied_operations();
93+
bool is_first = true;
94+
auto skip_oho_id = [&is_first,&db,this]() {
95+
if( is_first && db._undo_db.enabled() ) // this ensures that the current id is rolled back on undo
96+
{
97+
db.remove( db.create<operation_history_object>( []( operation_history_object& obj) {} ) );
98+
is_first = false;
99+
}
100+
else
101+
_oho_index->use_next_id();
102+
};
93103
for( const optional< operation_history_object >& o_op : hist ) {
94104
optional <operation_history_object> oho;
95105

@@ -109,7 +119,7 @@ void elasticsearch_plugin_impl::update_account_histories( const signed_block& b
109119
};
110120

111121
if( !o_op.valid() ) {
112-
_oho_index->use_next_id();
122+
skip_oho_id();
113123
continue;
114124
}
115125
oho = create_oho();

0 commit comments

Comments
 (0)