Skip to content

Commit

Permalink
Merge pull request hyperledger-iroha#445 from hyperledger/feature/int…
Browse files Browse the repository at this point in the history
…egration

[WIP] Feature/integration
  • Loading branch information
MizukiSonoko authored Jul 20, 2017
2 parents 28a9704 + 9d9cc5c commit ad9780f
Show file tree
Hide file tree
Showing 28 changed files with 14 additions and 984 deletions.
6 changes: 3 additions & 3 deletions irohad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ add_subdirectory(ametsuchi)
add_subdirectory(common)
add_subdirectory(consensus)
add_subdirectory(main)
add_subdirectory(ordering)
add_subdirectory(peer_service)
add_subdirectory(validation)
add_subdirectory(torii)
add_subdirectory(network)
add_subdirectory(model)
add_subdirectory(model)
add_subdirectory(ordering)
add_subdirectory(network)
97 changes: 3 additions & 94 deletions irohad/consensus/sumeragi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ namespace consensus {
}

bool unicast(const iroha::protocol::Block &block, size_t peerOrder) {
auto peer =
peer_service::monitor::getActivePeerAt((unsigned int) peerOrder);
auto response = connection::sendBlock(block, peer->ip_);
return response.code() == iroha::protocol::ResponseCode::OK;
return false;
}

bool leaderMulticast(const iroha::protocol::Block &block) {
Expand Down Expand Up @@ -100,34 +97,7 @@ namespace consensus {

Block createSignedBlock(const Block &block,
const std::vector<uint8_t> &merkleRoot) {

// TODO: Use Keypair in peer service.
std::string pkBase64 = peer_service::self_state::getPublicKey();
std::string skBase64 = peer_service::self_state::getPrivateKey();

auto pubkey_ = base64_decode(pkBase64),
privkey_ = base64_decode(skBase64);
auto pubkey =
iroha::to_blob<iroha::ed25519::pubkey_t::size()>(std::string{
pubkey_.begin(), pubkey_.end()});
auto privkey =
iroha::to_blob<iroha::ed25519::privkey_t::size()>(std::string{
privkey_.begin(), privkey_.end()});

auto signature =
iroha::sign(merkleRoot.data(), merkleRoot.size(), pubkey, privkey);

std::string strSigblob;
for (auto e: signature) strSigblob.push_back(e);

Signature newSignature;
*newSignature.mutable_pubkey() = pubkey.to_base64();
*newSignature.mutable_signature() = strSigblob;

Block ret;
ret.CopyFrom(block);
ret.mutable_header()->set_created_time(iroha::time::now64());

return ret;
}

Expand All @@ -143,72 +113,17 @@ namespace consensus {
*/

int getNextOrder() {
thread_local int
currentProxyTail = static_cast<int>(getNumValidatingPeers()) - 1;
if (currentProxyTail >= peer_service::monitor::getActivePeerSize()) {
return -1;
}
return currentProxyTail++;
return 0;
}

size_t countValidSignatures(const Block &block) {
size_t numValidSignatures = 0;
std::set<std::string> usedPubkeys;
/*
auto peerSigs = block.header()..signatures();
for (auto const &sig: peerSigs) {
// FIXME: bytes in proto -> std::string in C++ (null value problem)
if (usedPubkeys.count(sig.pubkey())) continue;
const auto bodyMessage = block.body().SerializeAsString();
// TODO: Use new Keypair class.
const auto hash = iroha::hash::sha3_256_hex(bodyMessage);
if (iroha::signature::verify(sig.signature(), hash, sig.pubkey())) {
numValidSignatures++;
usedPubkeys.insert(sig.pubkey());
}
*/
// }

return numValidSignatures;
}

void processBlock(const Block &block) {

// Stateful Validation
// auto valid = validaton::stateful::validate(block);
// if (!valid) {
// log.info("Stateful validation failed.");
// return;
// }

// Add Signature
auto merkleRoot = appendBlock(block);
auto newBlock = createSignedBlock(block, merkleRoot);

if (peer_service::self_state::isLeader()) {
leaderMulticast(newBlock);
setTimeOutCommit(newBlock);
return;
}

auto numValidSignatures = countValidSignatures(newBlock);

if (numValidSignatures < getNumValidatingPeers()) {
auto next = getNextOrder();
if (next < 0) {
log.error("getNextOrder() < 0 in processBlock");
return;
}
unicast(newBlock, static_cast<size_t>(next));
setTimeOutCommit(newBlock);
} else {
if (numValidSignatures == getNumValidatingPeers()) {
commit(newBlock);
setTimeOutCommit(newBlock);
}
}
}

/**
Expand All @@ -231,13 +146,7 @@ namespace consensus {
*/

void panic(const Block &block) {
auto next = getNextOrder();
if (next < 0) {
log.info("否認");
return;
}
unicast(block, static_cast<size_t>(next));
setTimeOutCommit(block);

}

} // namespace sumeragi
Expand Down
1 change: 0 additions & 1 deletion irohad/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ target_link_libraries(irohad
hash
stateless_validator
processors
torii
crypto
)

Expand Down
22 changes: 0 additions & 22 deletions irohad/main/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,5 @@ Irohad::Irohad():
{}

void Irohad::run(){
// iroha::Irohad irohad;
// iroha::ametsuchi::StorageImpl ametsuchi;

// TODO replace with actual public private keys
auto seed = iroha::create_seed("some passphrase");
auto keypair = iroha::create_keypair(seed);
iroha::model::ModelCryptoProviderImpl crypto_provider(keypair.privkey, keypair.pubkey);

iroha::validation::StatelessValidatorImpl stateless_validator(crypto_provider);
// iroha::validation::StatefulValidatorStub stateful_validator;
iroha::validation::ChainValidatorStub chain_validator;
iroha::ordering::OrderingServiceStub ordering_service;
iroha::consensus::ConsensusServiceStub consensus_service;
iroha::network::PeerCommunicationServiceStub peer_communication_service(
ordering_service,
consensus_service);
iroha::torii::TransactionProcessorImpl tp(peer_communication_service,
ordering_service,
stateless_validator);
// iroha::torii::QueryProcessorStub qp(ametsuchi, ametsuchi);

// iroha::torii::ToriiStub torii(tp, qp);

}
4 changes: 0 additions & 4 deletions irohad/main/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
#define IROHA_APPLICATION_HPP

#include <main/context.hpp>
#include <network/network_api.h>
#include <consensus/connection/service.hpp>
#include <consensus/consensus_service_stub.hpp>
#include <network/peer_communication_stub.hpp>
#include <ordering/ordering_service_stub.hpp>
#include <torii/processor/query_processor_stub.hpp>
#include <torii/processor/transaction_processor_impl.hpp>
#include <torii/torii_stub.hpp>
#include <validation/chain/validator_stub.hpp>
#include <validation/stateless/validator_impl.hpp>

Expand Down
2 changes: 1 addition & 1 deletion irohad/main/server_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void ServerRunner::shutdown() {
commandServiceHandler_->shutdown();
}

bool ServerRunner::waitForServersReady() {
void ServerRunner::waitForServersReady() {
std::unique_lock<std::mutex> lock(waitForServer_);
while (!serverInstance_) serverInstanceCV_.wait(lock);
}
2 changes: 1 addition & 1 deletion irohad/main/server_runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ServerRunner {
~ServerRunner();
void run();
void shutdown();
bool waitForServersReady();
void waitForServersReady();

private:
std::unique_ptr<grpc::Server> serverInstance_;
Expand Down
12 changes: 0 additions & 12 deletions irohad/ordering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#add_subdirectory(connection)

add_library(ordering STATIC queue.cpp observer.cpp)

target_link_libraries(ordering
peer_service
command_service
ordering_service
consensus_service
ordering_connection
)

add_library(ordering_service
ordering_service_stub.cpp
)
Expand Down
22 changes: 0 additions & 22 deletions irohad/ordering/connection/CMakeLists.txt

This file was deleted.

46 changes: 0 additions & 46 deletions irohad/ordering/connection/client.cpp

This file was deleted.

41 changes: 0 additions & 41 deletions irohad/ordering/connection/client.hpp

This file was deleted.

41 changes: 0 additions & 41 deletions irohad/ordering/connection/service.cpp

This file was deleted.

Loading

0 comments on commit ad9780f

Please sign in to comment.