-
Notifications
You must be signed in to change notification settings - Fork 296
Conversation
## todo remove schema target, igor-egorov, IR-1512 | ||
## schema is included due to a dependency bug in shared_model_interfaces | ||
schema | ||
shared_model_interfaces |
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.
These two are going from pending_txs_storage
target
const AccountIdType &accountId) const { | ||
std::shared_lock<std::shared_timed_mutex> lock(mutex_); | ||
auto creator_it = storage_.index.find(accountId); | ||
if (storage_.index.end() != creator_it) { |
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.
could you revert the condition, so the code is more linirized, e.g:
if (storage_.index.end() == creator_it) {
return {};
}
...
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.
I prefer leaving it as is because of two reasons:
- Such change will introduce style inconsistency with the following code (line 49)
- For me, it is a matter of taste :)
I can apply the change if you insist on it.
4750870
to
b2a5906
Compare
8c19ddb
to
fe9471b
Compare
fe9471b
to
80a982d
Compare
3469dd9
to
0dd422b
Compare
# | ||
|
||
add_library(pending_txs_storage | ||
impl/pending_txs_storage_impl.cpp |
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.
fix indentation
BatchObservable preparedBatch, | ||
BatchObservable expiredBatch) { | ||
updated_batches_subscription_ = | ||
updatedBatches.subscribe([this](const SharedState &updatedBatches) { |
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.
Confusing naming. updatedBatches variable already exists
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.
Also use snake case for variables' name here and above
|
||
PendingTransactionStorageImpl::SharedTxsCollectionType | ||
PendingTransactionStorageImpl::getPendingTransactions( | ||
const AccountIdType &accountId) const { |
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.
use snake for variables name
void PendingTransactionStorageImpl::removeBatch(const SharedBatch &batch) { | ||
auto creators = batchCreators(*batch); | ||
auto hash = batch->reducedHash(); | ||
{ |
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.
what is the point of making additional scope by parentheses?
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.
Discovered that in this case an additional scope is not needed.
.Times(1); | ||
|
||
validateAndExecute(query); | ||
} |
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.
add empty line at the end
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.
Also, fix this issue in your IDE for automatic endlines
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.
Better to have git hook or any another automated way of checking the presence of trailing newlines rather than automatic "newline completion".
: log_(logger::log("PendingTxsStorageTest")){}; | ||
|
||
std::shared_ptr<PendingTxsStorageFixture::Batch> | ||
PendingTxsStorageFixture::generateSharedBatch( |
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.
please use batch helper's makeTestBatch
method instead
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.
You can use the same approach as from batch test https://github.com/hyperledger/iroha/blob/47c3bfa6c7f3244c76b08efebe819802c5cd1165/test/module/shared_model/backend_proto/proto_batch_test.cpp#L268
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.
or put these functions to batch helper
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.
Discussed offline. If the pr will be merged before the end of the week, then I will add a todo and fix that issue as a separate task.
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.
UPD: now tests are using batch helpers
0dd422b
to
ad2e2df
Compare
|
||
target_link_libraries(pending_txs_storage | ||
mst_state | ||
## todo remove schema target, igor-egorov, IR-1512 |
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.
Seems, that this bug is already fixed in develop:https://github.com/hyperledger/iroha/blob/develop/shared_model/interfaces/CMakeLists.txt
} | ||
|
||
PendingTransactionStorageImpl::SharedTxsCollectionType | ||
PendingTransactionStorageImpl::getPendingTransactions( |
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.
The code in the function looks a bit complicated. Maybe refactor it with functional primitives or separate with different functions.
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.
You are very welcome to propose the better solution.
|
||
std::set<PendingTransactionStorageImpl::AccountIdType> | ||
PendingTransactionStorageImpl::batchCreators( | ||
const TransactionBatch &batch) const { |
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.
Why isn't this function static?
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.
There are no external users. Let's do it static function.
return creators; | ||
} | ||
|
||
void PendingTransactionStorageImpl::updatedBatchesHandler( |
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.
This function, also, seems a bit complicated. Maybe rework it?
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.
You are very welcome to propose the better solution.
The code does nothing more except the required stuff.
}); | ||
prepared_batch_subscription_ = | ||
preparedBatch.subscribe([this](const SharedBatch &preparedBatch) { | ||
this->preparedBatchHandler(preparedBatch); |
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.
What is the point to call wrapper instead of removeBatch
by itself?
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.
The wrapper was removed.
Initially, it was not clear that it will contain the single function call.
}); | ||
expired_batch_subscription_ = | ||
expiredBatch.subscribe([this](const SharedBatch &expiredBatch) { | ||
this->expiredBatchHandler(expiredBatch); |
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.
same as before
std::set<AccountIdType> batchCreators(const TransactionBatch &batch) const; | ||
|
||
/** | ||
* Subscriptions on MST events |
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.
This comment looks related only to one subscription. I think better to use ///
instead.
Or use it with this manner:
// ---------| Subscriptions on MST events |---------
Of course, better to wrap it by 80 symbols for clean-up. Also, you may request me for the python generator of those comments.
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.
Will leave it as is. Subscriptions + comment are separated from the rest of code with empty lines. In my view, it is pretty clear that comment relates to all subscription objects. Even more, comment is written in plural form. Thus, everything here is ok.
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.
I missed a bit with the comment, I imagine using //
as in the example.
*/ | ||
mutable std::shared_timed_mutex mutex_; | ||
|
||
struct { |
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.
This struct and purpose unobvious for me. Pls, add documentation for class(struct) and fields with explanation HOW it works.
.Times(1); | ||
|
||
validateAndExecute(query); | ||
} |
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.
Also, fix this issue in your IDE for automatic endlines
#include <rxcpp/rx.hpp> | ||
#include "module/irohad/pending_txs_storage/pending_txs_storage_fixture.hpp" | ||
|
||
TEST_F(PendingTxsStorageFixture, FixutureSelfCheck) { |
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.
Add given, when, then notation
Requested changes were applied
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov <[email protected]>
c487745
to
fa91693
Compare
Signed-off-by: Fedor Muratov <[email protected]>
There is only one failed test - module_ordering_service_test. This pr will be merged without fixing it - we have a separate task for this https://soramitsu.atlassian.net/browse/IR-1659 . |
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov [email protected]
Description of the Change
The storage listens to MST events and keeps track of semi signed transactions or batches of transactions.
The storage is a backend for "getPendingTransactions" query.
It returns all the transactions or batches of transactions created by query originator (single transactions or transactions from returned batches require more signatories to be processed).
Benefits
Storage for pending transactions is implemented and covered by tests.
Possible Drawbacks
This PR cannot be compiled until corresponding changes will be made in MST.
Usage Examples or Tests
Alternate Designs
Storage is not divided to interface and implementation since having just the implementation is acceptable in that case.
Potentially, internal structures can be replaced with
tbb::concurrent_{vector,hash_map}
. We use two maps as underlying structures and concurrent tbb structures would not solve the problem of simultaneous lock of both maps.