Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Feature/mst batches #1642

Merged
merged 36 commits into from
Aug 24, 2018
Merged

Feature/mst batches #1642

merged 36 commits into from
Aug 24, 2018

Conversation

muratovv
Copy link
Contributor

Description of the Change

Rework MST with batches;
Update tests and related methods

Benefits

MST works with batches

Possible Drawbacks

Some tests are disabled.

muratovv and others added 23 commits August 3, 2018 13:13
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Tests logic needs to be verified.
Need txBuilder that operates with signatures.

Signed-off-by: Igor Egorov <igor@soramitsu.co.jp>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
clean up a little bit

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
* fix ub with conditional variable
* add test generator fo batches with keypair
* fix operator == in transaction batch
* extend delay on cv in test
* mst state: fix operator ==, add sorting order to getBatches method

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
also fix comments a little bit

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Rework mst mocks with refactored interfaces;

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Rework txProcessor with batch semantic

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Rework mst mocks with refactored interfaces;

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
* remove redundant logs

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
@muratovv muratovv changed the base branch from master to trunk/mst_batch August 14, 2018 07:18
Copy link
Contributor

@igor-egorov igor-egorov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update MstStorage too. It contains the method named getExpiredTransactions. Actualize its naming and contents if needed.

@@ -86,17 +87,17 @@ namespace iroha {

// update state
// todo wrap in method
auto new_transactions =
auto new_batches =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[required]
Please specify task id along with todo either remove the comment.

log_->info("New txes size: {}", new_transactions->getTransactions().size());
// completed transactions
shareState(storage_->apply(from, new_state), transactions_subject_);
log_->info("New batches size: {}", new_batches->getBatches().size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional]
I suggest logging "new amount of batches" instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rephrasing. amount of batches is not the same as their size.


/**
* Prove updating of state for handling status of signing
*/
rxcpp::observable<std::shared_ptr<MstState>> onStateUpdate() const;

/**
* Observable emit transactions that prepared to processing in system
* Observable emit batches which are prepared to processing in system
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional]
Observable that emits batches which are prepared for processing

or for further processing
or to be processed

rhs_batches.begin(),
rhs_batches.end(),
[](const auto &l, const auto &r) {
return *l == *r;;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[required]
Extra ; at the end of the line.

std::sort(
result.begin(), result.end(), [](const auto &left, const auto &right) {
return left->reducedHash().hex() < right->reducedHash().hex();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[required]
Please leave a comment in code why that sorting is needed.

* Merge signatures in batches
* @param target - batch for inserting
* @param donor - batch with interested transactions
* @return false if hashes of transactions don't satisfy each other
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[hashes satisfaction]
return false when sequences of transactions inside input batches are different

note that reduced hash of batch does not take into account batch type.

signature.publicKey());
});
} else {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[required]
Depending on the result of DataType->reducedHash(), now it is possible to have several signatures being merged to the target batch and then false will be returned as the result of evaluation of if (target_tx->hash() == donor_tx->hash()).

A possible solution is to perform the check of transaction hashes equality before the act of signatures merging.

The point is avoiding an appearance of semi-merged batches.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there is a bug. In a best case, signatures will be merged only for one pair of transactions.

}
};

/**
* Class provide default behaviour for transaction completer
*/
class DefaultCompleter : public Completer {
bool operator()(const DataType transaction) const override {
return boost::size(transaction->signatures()) >= transaction->quorum();
bool operator()(const DataType &batch) const override {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional]
The docstring might need to be updated.

bool operator()(const DataType transaction) const override {
return boost::size(transaction->signatures()) >= transaction->quorum();
bool operator()(const DataType &batch) const override {
return std::accumulate(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!


shared_model::interface::types::SharedTxsCollectionType collection;

for (const auto &proto_tx : request->transactions()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[required]
Please specify task id for todo below either remove the comment.

* cleanup documentation
* fix bug in mst state on merge signatures in batches
* add equalByValue method to signable

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
@muratovv muratovv requested a review from lebdron August 20, 2018 07:49
add missed comments for batch helper and state test

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
@igor-egorov
Copy link
Contributor

Please update the branch and resolve conflicts

return framework::batch::makeTestBatch(builders...);
}

template <typename Batch, typename... Signatures>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rework variadic templates with variadic agruments with type Signature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems, that this is not possible, because we don't not the real type of signature here.

return batch;
}

template <typename Batch, typename... KeyPairs>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, KeyPairs can be passed using variadic arguments, not templates

Copy link
Contributor Author

@muratovv muratovv Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems, there is, also, not possible to fix your issue because we know a type, but don't know modifiers of the type.

KeyPairs... keypairs) {
auto create_signature = [&](auto &&key_pair) {
auto &payload = batch->transactions().at(tx_number)->payload();
auto signedBlob = shared_model::crypto::CryptoSigner<>::sign(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use snake

batch->addSignature(tx_number, signedBlob, key_pair.publicKey());
};

int temp[] = {(create_signature(std::forward<KeyPairs>(keypairs)), 0)...};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a comment explaining that construction

@@ -19,22 +19,24 @@

namespace iroha {

MstProcessor::MstProcessor() { log_ = logger::log("MstProcessor"); }
MstProcessor::MstProcessor() {
log_ = logger::log("MstProcessor");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c49-prefer-initialization-to-assignment-in-constructors

An initialization explicitly states that initialization, rather than assignment, is done and can be more elegant and efficient.

auto completed_batches = state.getBatches();
std::for_each(completed_batches.begin(),
completed_batches.end(),
[&subject](const auto batch) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use const auto & to avoid two copies - when lambda is called, and when on_next() is called in lambda.

@@ -37,26 +37,27 @@ namespace iroha {
// ---------------------------| user interface |----------------------------

/**
* Propagate in network multi-signature transaction for signing by other
* Propagate in network batch for signing by other
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider rephrasing, because it means 'network batch' now.
"Propagate batch in network ..."

}
return false;
});
auto &&lhs_batches = getBatches();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getBatches returns a value, maybe use const auto & instead?

std::for_each(internal_state_.begin(),
internal_state_.end(),
[&result](const auto &val) {
val->transactions();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this statement? Please remove or add a comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why the previous version was changed? It can be something like:

std::vector<DataType> result(internal_state_.begin(), internal_state_.end());
std::sort(...);
return result;

}
};

/**
* @given state with one transaction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> given a timepoint AND a state with an expired transaction
when erase by time is called
then the resulting state contains the expired transaction

}

/**
* @given init two states
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> given two states with expired transactions
when the states are merged
then the resulting state does not contain any transactions

Copy link
Contributor Author

@muratovv muratovv Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given two states with expired transactions

Batches are not expired at this time.


auto completed_state = state1 += state2;
ASSERT_EQ(0, completed_state.getTransactions().size());
ASSERT_EQ(0, completed_state.getBatches().size());

auto expired_state = state1.eraseByTime(time + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if this case is already covered in TimeIndexInsertionByTx

}

/**
* @given first state with two batches, seconds is empty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> given a state with two expired batches AND an empty state
when the second state is removed from the first state
AND erase by time is called
then the resulting state does not contain any transactions


transport->sendState(*peer, state);
std::unique_lock<std::mutex> lock(mtx);
cv.wait_for(lock, std::chrono::milliseconds(100));
cv.wait_for(lock, std::chrono::milliseconds(5000));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a task to rewrite this with gRPC mocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we created it already?

# Conflicts:
#	irohad/multi_sig_transactions/transport/impl/mst_transport_grpc.cpp
#	shared_model/interfaces/iroha_internal/transaction_batch.cpp
#	test/framework/batch_helper.hpp
* rework many grammar issues
* code clean ups
* fix merge issues in mst grpc
* rework state test with transaction content checks

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
# Conflicts:
#	irohad/torii/processor/impl/transaction_processor_impl.cpp
Add transaction batch ctor to explicit area;
Clean up batch helper with batch ctor;
Fix empty sequence test

Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
Signed-off-by: Fedor Muratov <muratovfyodor@yandex.ru>
@muratovv muratovv changed the base branch from trunk/mst_batch to develop August 24, 2018 14:33
@@ -113,7 +112,7 @@ namespace iroha {
MstState operator-(const MstState &rhs) const;

/**
* @return true, if there is no transactions inside
* @return true, if there is no bathes inside
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> batches

// TODO (@l4l) 04/03/18 simplify with IR-1040
new (addtxs) protocol::Transaction(
*protoState.add_transactions() = protocol::Transaction(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for additional protocol::Transaction(), as it will make a copy anyway.

@@ -46,8 +46,12 @@ auto addSignatures(Batch &&batch, int tx_number, Signatures... signatures) {
batch->addSignature(tx_number, sig_pair.first, sig_pair.second);
};

// pack expansion trick:
// generate array with zeros. Operator , express left lambda and return right
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> an ellipsis applies insert_signatures to each signature, operator comma returns the rightmost argument, which is 0

};

// pack expansion trick:
// generate array with zeros. Operator , express left lambda and return right
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

* @given state with one transaction
* @when call erase by time, where batch will be already expired
* @then checks that expired state contains batch and initial doesn't conitain
* @given given a timepoint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One "given" can be removed

@neewy
Copy link
Contributor

neewy commented Aug 24, 2018

👍

@sorabot
Copy link

sorabot commented Aug 24, 2018

SonarQube analysis reported 4 issues

  1. MINOR mst_storage_impl.cpp#L12: Function parameter 'target_peer' should be passed by reference. rule
  2. MINOR transport_builder_test.cpp#L64: The function 'createUnbuildTransaction' is never used. rule
  3. MINOR transport_builder_test.cpp#L163: The function 'createInvalidProposal' is never used. rule
  4. MINOR transport_builder_test.cpp#L462: Function parameter 'tx' should be passed by reference. rule

@muratovv muratovv merged commit 8bb678d into develop Aug 24, 2018
@muratovv muratovv mentioned this pull request Aug 27, 2018
neewy pushed a commit that referenced this pull request Aug 29, 2018
### Description of the Change
Rework MST with batches;
Update tests and related methods

### Benefits
MST works with batches

### Possible Drawbacks 
Some tests are disabled.
vdrobnyi pushed a commit that referenced this pull request Aug 31, 2018
### Description of the Change
Rework MST with batches;
Update tests and related methods

### Benefits
MST works with batches

### Possible Drawbacks 
Some tests are disabled.
nickaleks pushed a commit that referenced this pull request Sep 10, 2018
### Description of the Change
Rework MST with batches;
Update tests and related methods

### Benefits
MST works with batches

### Possible Drawbacks 
Some tests are disabled.
nickaleks pushed a commit that referenced this pull request Sep 10, 2018
### Description of the Change
Rework MST with batches;
Update tests and related methods

### Benefits
MST works with batches

### Possible Drawbacks 
Some tests are disabled.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants