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

Commit

Permalink
Feature/mst batches (#1642)
Browse files Browse the repository at this point in the history
### Description of the Change
Rework MST with batches;
Update tests and related methods

### Benefits
MST works with batches

### Possible Drawbacks 
Some tests are disabled.
  • Loading branch information
muratovv authored and vdrobnyi committed Aug 27, 2018
1 parent 9f3baae commit c3fd7ab
Show file tree
Hide file tree
Showing 34 changed files with 825 additions and 582 deletions.
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
14 changes: 7 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,22 @@

namespace iroha {

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

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) {
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 =
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());
// 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 batch in network for signing by other
* 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

0 comments on commit c3fd7ab

Please sign in to comment.