@@ -81,21 +81,13 @@ namespace iroha {
8181 }
8282
8383 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_};
8985 insertOne (state_update, rhs);
9086 return state_update;
9187 }
9288
9389 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_};
9991 return rhs.batches_ .access ([this , &state_update](const auto &storage) {
10092 for (auto &&rhs_tx : storage.batches .right | boost::adaptors::map_keys) {
10193 this ->insertOne (state_update, rhs_tx);
@@ -211,42 +203,48 @@ namespace iroha {
211203 void MstState::insertOne (StateUpdateResult &state_update,
212204 const DataType &rhs_batch) {
213205 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+ }
230225
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);
234230
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+ }
242237
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+ }
250248 }
251249
252250 bool MstState::rawInsert (const DataType &rhs_batch) {
@@ -261,7 +259,8 @@ namespace iroha {
261259
262260 void MstState::extractExpiredImpl (const TimeType ¤t_time,
263261 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) {
265264 std::vector<BatchPtr> extracted;
266265 for (auto it = storage.batches .left .begin ();
267266 it != storage.batches .left .end ()
0 commit comments