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
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b68adfa
build successful for mst_processor
muratovv Jul 25, 2018
1d7e205
Add one reworked mst test
muratovv Jul 26, 2018
ca717fc
Update MST tests (Needs additional fixes)
Jul 26, 2018
ce2be62
Compiled tests for mst_state
muratovv Aug 3, 2018
891901f
Implement TransactionBatch::addSinature
muratovv Aug 3, 2018
d18366b
Remove redundant logging from hash
muratovv Aug 3, 2018
bc4aba9
Clean up mst state
muratovv Aug 3, 2018
5e13baf
Fix initializer list bug in mst test helpers;
muratovv Aug 3, 2018
3341cc2
Rework 2 mst state tests: compile and pass
muratovv Aug 3, 2018
8378abf
add state tests are passed
muratovv Aug 6, 2018
2423470
* Rework mst transport test with batches;
muratovv Aug 7, 2018
e2b2d75
Remove redundant this from lambda in mst state
muratovv Aug 7, 2018
ac70ae6
Refactor names in mst_processor;
muratovv Aug 7, 2018
65c650a
Add missed logger include for batch helper
muratovv Aug 7, 2018
ecb6821
Add required dependency for gossip propagation strategy
muratovv Aug 7, 2018
f9eb03b
Fix tests for mst processor with batch semantic
muratovv Aug 7, 2018
515d14b
Merge branch 'develop' into feature/mst_batches
muratovv Aug 8, 2018
0faa112
Rework command service :: Torii with batch semantic
muratovv Aug 9, 2018
1448adf
Remove transactionHandle method from TransactionProcessor;
muratovv Aug 9, 2018
dea7819
Fix tests for mst processor with batch semantic
muratovv Aug 11, 2018
5338f46
Remove cli tests from build pipeline
muratovv Aug 11, 2018
982e194
Add explicit instantiation for transactionBatch::create factory
muratovv Aug 11, 2018
1645f54
* fix number of task in todo
muratovv Aug 13, 2018
a4d3b51
Disable tx processor tests
muratovv Aug 13, 2018
01c65d7
Remove redundant cout
muratovv Aug 13, 2018
9606637
Fix review issues:
muratovv Aug 15, 2018
f6a4ef4
Remove redundant todo
muratovv Aug 15, 2018
25d27b3
Fix review issues:
muratovv Aug 17, 2018
cc56c2e
Fix review issues:
muratovv Aug 20, 2018
515ff36
Merge branch 'develop' into feature/mst_batches
muratovv Aug 21, 2018
6af0b69
Fix review issues:
muratovv Aug 23, 2018
7cf5f3f
Merge branch 'develop' into feature/mst_batches
muratovv Aug 23, 2018
10d22da
Fix merge issues;
muratovv Aug 24, 2018
cf87a14
remove redundant universal references
muratovv Aug 24, 2018
68beda7
Fix grammar and remove redundant copy
muratovv Aug 24, 2018
7d050ae
Merge branch 'develop' into feature/mst_batches
muratovv Aug 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions irohad/multi_sig_transactions/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@
namespace iroha {
namespace model {
/**
* Hash calculation factory for transaction
* Hash calculation factory for batch
*/
template <typename Tx>
class PointerTxHasher {
template <typename BatchType>
class PointerBatchHasher {
public:
using TxType = Tx;
size_t operator()(const TxType &tx) const {
auto hash =
string_hasher(shared_model::crypto::toBinaryString(tx->hash()));
return hash;
size_t operator()(const BatchType &batch) const {
return string_hasher(batch->reducedHash().hex());
}

private:
Expand Down
16 changes: 9 additions & 7 deletions irohad/multi_sig_transactions/impl/mst_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}

void MstProcessor::propagateTransaction(const DataType transaction) {
this->propagateTransactionImpl(transaction);
void MstProcessor::propagateBatch(const DataType &batch) {
this->propagateBatchImpl(batch);
}

rxcpp::observable<std::shared_ptr<MstState>> MstProcessor::onStateUpdate()
const {
return this->onStateUpdateImpl();
}

rxcpp::observable<DataType> MstProcessor::onPreparedTransactions() const {
return this->onPreparedTransactionsImpl();
rxcpp::observable<DataType> MstProcessor::onPreparedBatches() const {
return this->onPreparedBatchesImpl();
}

rxcpp::observable<DataType> MstProcessor::onExpiredTransactions() const {
return this->onExpiredTransactionsImpl();
rxcpp::observable<DataType> MstProcessor::onExpiredBatches() const {
return this->onExpiredBatchesImpl();
}
} // namespace iroha
44 changes: 22 additions & 22 deletions irohad/multi_sig_transactions/impl/mst_processor_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ namespace iroha {
template <typename Subject>
void shareState(ConstRefState state, Subject &subject) {
if (not state.isEmpty()) {
auto completed_transactions = state.getTransactions();
std::for_each(
completed_transactions.begin(),
completed_transactions.end(),
[&subject](const auto tx) { subject.get_subscriber().on_next(tx); });
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.

subject.get_subscriber().on_next(batch);
});
}
}

Expand All @@ -53,9 +54,9 @@ namespace iroha {

// -------------------------| MstProcessor override |-------------------------

auto FairMstProcessor::propagateTransactionImpl(const DataType transaction)
-> decltype(propagateTransaction(transaction)) {
shareState(storage_->updateOwnState(transaction), transactions_subject_);
auto FairMstProcessor::propagateBatchImpl(const iroha::DataType &batch)
-> decltype(propagateBatch(batch)) {
shareState(storage_->updateOwnState(batch), batches_subject_);
shareState(
storage_->getExpiredTransactions(time_provider_->getCurrentTime()),
expired_subject_);
Expand All @@ -66,13 +67,13 @@ namespace iroha {
return state_subject_.get_observable();
}

auto FairMstProcessor::onPreparedTransactionsImpl() const
-> decltype(onPreparedTransactions()) {
return transactions_subject_.get_observable();
auto FairMstProcessor::onPreparedBatchesImpl() const
-> decltype(onPreparedBatches()) {
return batches_subject_.get_observable();
}

auto FairMstProcessor::onExpiredTransactionsImpl() const
-> decltype(onExpiredTransactions()) {
auto FairMstProcessor::onExpiredBatchesImpl() const
-> decltype(onExpiredBatches()) {
return expired_subject_.get_observable();
}

Expand All @@ -85,18 +86,17 @@ namespace iroha {
auto current_time = time_provider_->getCurrentTime();

// 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.

std::make_shared<MstState>(storage_->whatsNew(new_state));
state_subject_.get_subscriber().on_next(new_transactions);
state_subject_.get_subscriber().on_next(new_batches);

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.

// completed batches
shareState(storage_->apply(from, new_state), batches_subject_);

// expired transactions
auto expired_transactions = storage_->getDiffState(from, current_time);
shareState(expired_transactions, this->expired_subject_);
// expired batches
auto expired_batches = storage_->getDiffState(from, current_time);
shareState(expired_batches, this->expired_subject_);
}

// -----------------------------| private api |-----------------------------
Expand Down
16 changes: 8 additions & 8 deletions irohad/multi_sig_transactions/impl/mst_processor_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

using namespace iroha;

auto MstProcessorStub::propagateTransactionImpl(const DataType transaction)
-> decltype(propagateTransaction(transaction)) {
log_->error("Multisig transactions are disabled. Skipping transaction: {}",
transaction->toString());
auto MstProcessorStub::propagateBatchImpl(const DataType &batch)
-> decltype(propagateBatch(batch)) {
log_->error("Multisig transactions are disabled. Skipping batch: {}",
batch->reducedHash().toString());
}

auto MstProcessorStub::onStateUpdateImpl() const -> decltype(onStateUpdate()) {
Expand All @@ -20,16 +20,16 @@ auto MstProcessorStub::onStateUpdateImpl() const -> decltype(onStateUpdate()) {
return rxcpp::observable<>::empty<std::shared_ptr<MstState>>();
}

auto MstProcessorStub::onPreparedTransactionsImpl() const
-> decltype(onPreparedTransactions()) {
auto MstProcessorStub::onPreparedBatchesImpl() const
-> decltype(onPreparedBatches()) {
log_->warn(
"Multisig transactions are disabled, so MstProcessor observable won't "
"emit any events");
return rxcpp::observable<>::empty<DataType>();
}

auto MstProcessorStub::onExpiredTransactionsImpl() const
-> decltype(onExpiredTransactions()) {
auto MstProcessorStub::onExpiredBatchesImpl() const
-> decltype(onExpiredBatches()) {
log_->warn(
"Multisig transactions are disabled, so MstProcessor observable won't "
"emit any events");
Expand Down
23 changes: 12 additions & 11 deletions irohad/multi_sig_transactions/mst_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..."

* participants
* @param transaction - transaction for propagation
*/
void propagateTransaction(const DataType transaction);
void propagateBatch(const DataType &batch);

/**
* 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 for further processing in
* system
*/
rxcpp::observable<DataType> onPreparedTransactions() const;
rxcpp::observable<DataType> onPreparedBatches() const;

/**
* Observable emit expired by time transactions
*/
rxcpp::observable<DataType> onExpiredTransactions() const;
rxcpp::observable<DataType> onExpiredBatches() const;

virtual ~MstProcessor() = default;

Expand All @@ -71,8 +72,8 @@ namespace iroha {
/**
* @see propagateTransaction method
*/
virtual auto propagateTransactionImpl(DataType transaction)
-> decltype(propagateTransaction(transaction)) = 0;
virtual auto propagateBatchImpl(const DataType &batch)
-> decltype(propagateBatch(batch)) = 0;

/**
* @see onStateUpdate method
Expand All @@ -82,14 +83,14 @@ namespace iroha {
/**
* @see onPreparedTransactions method
*/
virtual auto onPreparedTransactionsImpl() const
-> decltype(onPreparedTransactions()) = 0;
virtual auto onPreparedBatchesImpl() const
-> decltype(onPreparedBatches()) = 0;

/**
* @see onExpiredTransactions method
*/
virtual auto onExpiredTransactionsImpl() const
-> decltype(onExpiredTransactions()) = 0;
virtual auto onExpiredBatchesImpl() const
-> decltype(onExpiredBatches()) = 0;
};
} // namespace iroha

Expand Down
17 changes: 8 additions & 9 deletions irohad/multi_sig_transactions/mst_processor_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ namespace iroha {

// ------------------------| MstProcessor override |------------------------

auto propagateTransactionImpl(const DataType transaction)
-> decltype(propagateTransaction(transaction)) override;
auto propagateBatchImpl(const DataType &batch)
-> decltype(propagateBatch(batch)) override;

auto onStateUpdateImpl() const -> decltype(onStateUpdate()) override;

auto onPreparedTransactionsImpl() const
-> decltype(onPreparedTransactions()) override;
auto onPreparedBatchesImpl() const
-> decltype(onPreparedBatches()) override;

auto onExpiredTransactionsImpl() const
-> decltype(onExpiredTransactions()) override;
auto onExpiredBatchesImpl() const -> decltype(onExpiredBatches()) override;

// ------------------| MstTransportNotification override |------------------

Expand Down Expand Up @@ -88,10 +87,10 @@ namespace iroha {
/// use for share new states from other peers
rxcpp::subjects::subject<std::shared_ptr<MstState>> state_subject_;

/// use for share completed transactions
rxcpp::subjects::subject<DataType> transactions_subject_;
/// use for share completed batches
rxcpp::subjects::subject<DataType> batches_subject_;

/// use for share expired transactions
/// use for share expired batches
rxcpp::subjects::subject<DataType> expired_subject_;

/// use for tracking the propagation subscription
Expand Down
11 changes: 5 additions & 6 deletions irohad/multi_sig_transactions/mst_processor_stub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@

namespace iroha {
class MstProcessorStub : public MstProcessor {
auto propagateTransactionImpl(const DataType transaction)
-> decltype(propagateTransaction(transaction)) override;
auto propagateBatchImpl(const DataType &batch)
-> decltype(propagateBatch(batch)) override;

auto onStateUpdateImpl() const -> decltype(onStateUpdate()) override;

auto onPreparedTransactionsImpl() const
-> decltype(onPreparedTransactions()) override;
auto onPreparedBatchesImpl() const
-> decltype(onPreparedBatches()) override;

auto onExpiredTransactionsImpl() const
-> decltype(onExpiredTransactions()) override;
auto onExpiredBatchesImpl() const -> decltype(onExpiredBatches()) override;
};

} // namespace iroha
Expand Down
8 changes: 4 additions & 4 deletions irohad/multi_sig_transactions/mst_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#include <memory>
#include "interfaces/common_objects/peer.hpp"
#include "interfaces/common_objects/types.hpp"
#include "interfaces/transaction.hpp"
#include "interfaces/iroha_internal/transaction_batch.hpp"
#include "interfaces/transaction_responses/tx_response.hpp"

namespace iroha {
using SharedTx = std::shared_ptr<shared_model::interface::Transaction>;
using BatchPtr = std::shared_ptr<shared_model::interface::TransactionBatch>;
using ConstPeer = const shared_model::interface::Peer;
using TimeType = shared_model::interface::types::TimestampType;
using TxResponse =
Expand All @@ -34,14 +34,14 @@ namespace iroha {
template <typename T>
using ConstRefT = const T &;

using ConstRefTransaction = ConstRefT<SharedTx>;
using ConstRefBatch = ConstRefT<BatchPtr>;
using ConstRefPeer = ConstRefT<shared_model::interface::Peer>;
using ConstRefTime = ConstRefT<TimeType>;

class MstState;

using ConstRefState = ConstRefT<MstState>;

using DataType = SharedTx;
using DataType = BatchPtr;
} // namespace iroha
#endif // IROHA_MST_TYPES_HPP
Loading