This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
Feature/mst shared limit #2230
Open
MBoldyrev
wants to merge
5
commits into
feature/shared-storage-limit
Choose a base branch
from
feature/mst-shared-limit
base: feature/shared-storage-limit
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/mst shared limit #2230
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "multi_sig_transactions/propagation_to_pcs.hpp" | ||
|
||
#include <utility> | ||
|
||
#include "interfaces/iroha_internal/transaction_batch.hpp" | ||
#include "logger/logger.hpp" | ||
|
||
using namespace iroha; | ||
|
||
MstToPcsPropagation::MstToPcsPropagation( | ||
std::shared_ptr<iroha::network::PeerCommunicationService> pcs, | ||
std::shared_ptr<StorageLimit<BatchPtr>> storage_limit, | ||
rxcpp::observable<size_t> propagation_available, | ||
logger::LoggerPtr log) | ||
: log_(std::move(log)), | ||
pcs_(pcs), | ||
pending_batches_(std::move(storage_limit), | ||
std::make_unique<InternalStorage>()), | ||
propagation_available_subscription_( | ||
propagation_available.subscribe([this, pcs](size_t available_txs) { | ||
pending_batches_.extract( | ||
[pcs, &available_txs](InternalStorage &storage) { | ||
std::vector<BatchPtr> extracted; | ||
extracted.reserve(storage.pending_batches.size()); | ||
auto it = storage.pending_batches.begin(); | ||
while (it != storage.pending_batches.end()) { | ||
const auto txs_in_batch = (*it)->transactions().size(); | ||
if (txs_in_batch <= available_txs | ||
and pcs->propagate_batch(*it)) { | ||
available_txs -= txs_in_batch; | ||
extracted.emplace_back(std::move(*it)); | ||
it = storage.pending_batches.erase(it); | ||
} else { | ||
++it; | ||
} | ||
} | ||
return extracted; | ||
}); | ||
})) {} | ||
|
||
MstToPcsPropagation::~MstToPcsPropagation() { | ||
propagation_available_subscription_.unsubscribe(); | ||
} | ||
|
||
void MstToPcsPropagation::notifyCompletedBatch( | ||
std::shared_ptr<MovedBatch> moved_batch) { | ||
if (not pcs_->propagate_batch(moved_batch->get())) { | ||
if (not pending_batches_.insert(std::move(moved_batch))) { | ||
log_->critical( | ||
"Dropped a completed MST batch because no place left in storage: {}", | ||
moved_batch->get()); | ||
assert(false); | ||
} | ||
} | ||
} | ||
|
||
size_t MstToPcsPropagation::pendingBatchesQuantity() const { | ||
return pending_batches_.itemsQuantity(); | ||
} | ||
|
||
bool MstToPcsPropagation::InternalStorage::insert(BatchPtr batch) { | ||
pending_batches.emplace_back(std::move(batch)); | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unconditional return type 🤔 |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, space is used in that context (even if place is more technically correct because it is internals that are not an object of interest for the external interface user).