Skip to content

Commit

Permalink
Make peer_communication_stub more simple
Browse files Browse the repository at this point in the history
  • Loading branch information
MizukiSonoko committed Jul 10, 2017
1 parent 0b18c57 commit 9719419
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 81 deletions.
8 changes: 3 additions & 5 deletions irohad/main/iroha-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,14 @@ int main(int argc, char *argv[]) {
iroha::ordering::OrderingServiceStub ordering_service;
iroha::consensus::ConsensusServiceStub consensus_service;
iroha::network::PeerCommunicationServiceStub peer_communication_service(
ametsuchi, stateful_validator, chain_validator, ordering_service,
consensus_service, crypto_provider);
ordering_service,
consensus_service);
iroha::torii::TransactionProcessorStub tp(stateless_validator,
peer_communication_service,
crypto_provider);
iroha::torii::QueryProcessorStub qp(ametsuchi, ametsuchi);

iroha::torii::ToriiStub torii(tp, qp);
// shows required order of execution, since callbacks are called synchronously
peer_communication_service.subscribe_on_proposal();
// shows required order of execution, since callbacks are called synchronousl

iroha::model::Transaction transaction;
transaction.commands.push_back(std::make_shared<iroha::model::AddPeer>());
Expand Down
15 changes: 1 addition & 14 deletions irohad/network/network_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,11 @@ namespace iroha {
virtual rxcpp::observable<rxcpp::observable<model::Block>> on_commit() = 0;
};

/**
* Interface for propagating transaction in a network
*/
class TransactionPropagator {
public:
/**
* Method spreads transaction to other members of a network
* @param tx - transaction for propagation
*/
virtual void propagate_transaction(const model::Transaction &tx) = 0;
};

/**
* Public API interface for communication between current peer and other
* peers in a network
*/
class PeerCommunicationService : public TransactionPropagator,
public ConsensusListener {
class PeerCommunicationService : public ConsensusListener {
};
}
}
Expand Down
51 changes: 7 additions & 44 deletions irohad/network/peer_communication_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,16 @@
*/

#include <network/peer_communication_stub.hpp>
#include <ordering/ordering_service_stub.hpp>
#include <consensus/consensus_service_stub.hpp>

namespace iroha {
namespace network {

using ametsuchi::Ametsuchi;
using validation::StatefulValidator;
using validation::ChainValidator;
using ordering::OrderingService;
using consensus::ConsensusService;
using model::Block;

rxcpp::observable<rxcpp::observable<model::Block>>
PeerCommunicationServiceStub::on_commit() {
return consensus_.on_commit().take_while([this](auto commit) {
std::cout << "[PCS] chain validation" << std::endl;
auto storage = storage_.createMutableStorage();
auto result = chain_validator_.validate(commit, *storage);
if (result) {
storage_.commit(*storage);
}
return result;
});
}

void PeerCommunicationServiceStub::propagate_transaction(
const model::Transaction &tx) {
orderer_.propagate_transaction(tx);
}

rxcpp::observable<model::Proposal>
Expand All @@ -51,31 +34,11 @@ namespace iroha {
}

PeerCommunicationServiceStub::PeerCommunicationServiceStub(
Ametsuchi &storage, StatefulValidator &stateful_validator,
ChainValidator &chain_validator, OrderingService &orderer,
ConsensusService &consensus, model::ModelCryptoProvider &crypto_provider)
: storage_(storage),
stateful_validator_(stateful_validator),
chain_validator_(chain_validator),
orderer_(orderer),
consensus_(consensus),
crypto_provider_(crypto_provider) {
}
ordering::OrderingServiceStub &orderer,
consensus::ConsensusServiceStub &consensus
):
orderer_(orderer),
consensus_(consensus) {}

void PeerCommunicationServiceStub::subscribe_on_proposal() {
on_proposal().subscribe([this](auto proposal) {
std::cout << "[PCS] stateful validation" << std::endl;
auto wsv = storage_.createTemporaryWsv();
auto validated_proposal = stateful_validator_.validate(proposal, *wsv);
Block block;
std::for_each(validated_proposal.transactions.begin(),
validated_proposal.transactions.end(),
[&block](const auto &transaction) {
block.transactions.push_back(transaction);
});
// TODO hash and sign
consensus_.vote_block(block);
});
}
}
}
25 changes: 7 additions & 18 deletions irohad/network/peer_communication_stub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,30 @@

#include <network/network_api.h>
#include <ametsuchi/ametsuchi.hpp>
#include <consensus/consensus_service.hpp>
#include <consensus/consensus_service_stub.hpp>
#include <ordering/ordering_service.hpp>
#include <validation/chain/validator.hpp>
#include <validation/stateful/validator.hpp>
#include <model/model_crypto_provider.hpp>
#include <model/model_hash_provider.hpp>
#include <ordering/ordering_service_stub.hpp>

namespace iroha {
namespace network {
class PeerCommunicationServiceStub : public PeerCommunicationService {
public:
PeerCommunicationServiceStub(
ametsuchi::Ametsuchi &storage,
validation::StatefulValidator &stateful_validator,
validation::ChainValidator &chain_validator,
ordering::OrderingService &orderer,
consensus::ConsensusService &consensus,
model::ModelCryptoProvider &crypto_provider);
ordering::OrderingServiceStub &orderer,
consensus::ConsensusServiceStub &consensus
);

rxcpp::observable<model::Proposal> on_proposal() override;

rxcpp::observable<rxcpp::observable<model::Block>> on_commit() override;

void propagate_transaction(const model::Transaction &tx) override;

void subscribe_on_proposal();

private:
ametsuchi::Ametsuchi &storage_;
validation::StatefulValidator &stateful_validator_;
validation::ChainValidator &chain_validator_;
ordering::OrderingService &orderer_;
consensus::ConsensusService &consensus_;
model::ModelCryptoProvider &crypto_provider_;
// TODO add hash provider
ordering::OrderingServiceStub orderer_;
consensus::ConsensusServiceStub consensus_;
};
}
}
Expand Down

0 comments on commit 9719419

Please sign in to comment.