@@ -81,21 +81,13 @@ namespace iroha {
81
81
}
82
82
83
83
StateUpdateResult MstState::operator +=(const DataType &rhs) {
84
- auto state_update = StateUpdateResult{
85
- std::make_shared<MstState>(empty (
86
- completer_, std::make_shared<iroha::StorageLimitDummy>(), log_)),
87
- std::make_shared<MstState>(empty (
88
- completer_, std::make_shared<iroha::StorageLimitDummy>(), log_))};
84
+ auto state_update = StateUpdateResult{completer_, log_};
89
85
insertOne (state_update, rhs);
90
86
return state_update;
91
87
}
92
88
93
89
StateUpdateResult MstState::operator +=(const MstState &rhs) {
94
- auto state_update = StateUpdateResult{
95
- std::make_shared<MstState>(empty (
96
- completer_, std::make_shared<iroha::StorageLimitDummy>(), log_)),
97
- std::make_shared<MstState>(empty (
98
- completer_, std::make_shared<iroha::StorageLimitDummy>(), log_))};
90
+ auto state_update = StateUpdateResult{completer_, log_};
99
91
return rhs.batches_ .access ([this , &state_update](const auto &storage) {
100
92
for (auto &&rhs_tx : storage.batches .right | boost::adaptors::map_keys) {
101
93
this ->insertOne (state_update, rhs_tx);
@@ -211,42 +203,48 @@ namespace iroha {
211
203
void MstState::insertOne (StateUpdateResult &state_update,
212
204
const DataType &rhs_batch) {
213
205
log_->info (" batch: {}" , *rhs_batch);
214
- batches_.extract ([this , &state_update, &rhs_batch](
215
- auto &storage) -> std::vector<BatchPtr> {
216
- auto corresponding = storage.batches .right .find (rhs_batch);
217
- if (corresponding == storage.batches .right .end ()) {
218
- // when state does not contain transaction
219
- if (this ->rawInsert (rhs_batch)) {
220
- // there is enough room for the new batch
221
- BOOST_VERIFY_MSG (state_update.updated_state_ ->rawInsert (rhs_batch),
222
- " Could not insert new MST batch to state update." );
223
- } else {
224
- // there is not enough room for the new batch
225
- log_->info (" Dropped a batch because it did not fit into storage: {}" ,
226
- *rhs_batch);
227
- }
228
- return {};
229
- }
206
+ if (auto opt_completed_batch =
207
+ batches_.move ([this , &state_update, &rhs_batch](
208
+ auto &storage) -> boost::optional<BatchPtr> {
209
+ auto corresponding = storage.batches .right .find (rhs_batch);
210
+ if (corresponding == storage.batches .right .end ()) {
211
+ // when state does not contain transaction
212
+ if (this ->rawInsert (rhs_batch)) {
213
+ // there is enough room for the new batch
214
+ BOOST_VERIFY_MSG (
215
+ state_update.updated_state_ ->rawInsert (rhs_batch),
216
+ " Could not insert new MST batch to state update." );
217
+ } else {
218
+ // there is not enough room for the new batch
219
+ log_->info (
220
+ " Dropped a batch because it did not fit into storage: {}" ,
221
+ *rhs_batch);
222
+ }
223
+ return boost::none;
224
+ }
230
225
231
- DataType found = corresponding->first ;
232
- // Append new signatures to the existing state
233
- auto inserted_new_signatures = mergeSignaturesInBatch (found, rhs_batch);
226
+ DataType found = corresponding->first ;
227
+ // Append new signatures to the existing state
228
+ auto inserted_new_signatures =
229
+ mergeSignaturesInBatch (found, rhs_batch);
234
230
235
- if (completer_->isCompleted (found)) {
236
- // state already has completed transaction,
237
- // remove from state and return it
238
- storage.batches .right .erase (found);
239
- state_update.completed_state_ ->rawInsert (found);
240
- return {found};
241
- }
231
+ if (completer_->isCompleted (found)) {
232
+ // state already has completed transaction,
233
+ // remove from state and return it
234
+ storage.batches .right .erase (found);
235
+ return found;
236
+ }
242
237
243
- // if batch still isn't completed, return it, if new signatures were
244
- // inserted
245
- if (inserted_new_signatures) {
246
- state_update.updated_state_ ->rawInsert (found);
247
- }
248
- return {};
249
- });
238
+ // if batch still isn't completed, return it, if new signatures
239
+ // were inserted
240
+ if (inserted_new_signatures) {
241
+ state_update.updated_state_ ->rawInsert (found);
242
+ }
243
+ return boost::none;
244
+ })) {
245
+ state_update.completed_state_ .emplace_back (
246
+ std::move (*opt_completed_batch));
247
+ }
250
248
}
251
249
252
250
bool MstState::rawInsert (const DataType &rhs_batch) {
@@ -261,7 +259,8 @@ namespace iroha {
261
259
262
260
void MstState::extractExpiredImpl (const TimeType ¤t_time,
263
261
boost::optional<MstState &> opt_extracted) {
264
- auto extracted = batches_.extract ([this , ¤t_time](auto &storage) {
262
+ auto extracted = batches_.extractMultiple ([this ,
263
+ ¤t_time](auto &storage) {
265
264
std::vector<BatchPtr> extracted;
266
265
for (auto it = storage.batches .left .begin ();
267
266
it != storage.batches .left .end ()
0 commit comments