Skip to content

Commit

Permalink
Merge pull request #186 from hyperledger/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
takemiyamakoto committed Mar 4, 2017
2 parents aacade7 + b21b688 commit 67e99c2
Show file tree
Hide file tree
Showing 253 changed files with 25,607 additions and 10,000 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ config/sumeragi.json
cmake-build-debu/*
docker/build/iroha.tar
cmake-build-debug/*
external/*
25 changes: 0 additions & 25 deletions .gitmodules

This file was deleted.

39 changes: 29 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
cmake_minimum_required(VERSION 2.8)
PROJECT(iroha CXX)
PROJECT(iroha C CXX)

ENABLE_LANGUAGE(C)
find_package(Threads)

SET(CMAKE_CXX_FLAGS "-g -Wall -std=c++1y")
SET(CMAKE_CXX_FLAGS "-g -std=c++1y -Wall -fPIC")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
SET(CMAKE_CXX_FLAGS_DEBUG "-Wextra -O0")
SET(CMAKE_SHARED_LINKER_FLAGS "-lpthread -lssl")
SET(CMAKE_CXX_FLAGS_DEBUG "-Wextra -Wno-unused-parameter -O0")
#SET(CMAKE_SHARED_LINKER_FLAGS "-lpthread -lssl")
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

option(BENCHMARKING "Build benchmarks" OFF)
option(TESTING "Build tests" ON)

# set default CMAKE_BUILD_TYPE=Debug
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
message(STATUS "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
message(STATUS "-DTESTING=${TESTING}")
message(STATUS "-DBENCHMARKING=${BENCHMARKING}")

include_directories(${PROJECT_SOURCE_DIR}/core)
include("dependencies.cmake")

add_subdirectory(protos)

add_subdirectory(core)
add_subdirectory(peer)
add_subdirectory(tools)
add_subdirectory(smart_contract)

if(NOT without-test)
if(TESTING)
enable_testing()
include(test/gtest.cmake)
add_subdirectory(test)
endif()
endif()


if(BENCHMARKING)
add_subdirectory(benchmark)
endif()
3 changes: 3 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/benchmark)

add_subdirectory(crypto)
29 changes: 29 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Benchmark

If you want to do benchmarks of some iroha components, put them in this folder.

We use [google benchmark](https://github.com/google/benchmark).

To enable build of benchmarks, specify an option `-DBENCHMARKING=ON` during configure step:

```
$ cmake -DBENCHMARKING=ON ..
```

**Note**: changing `CMAKE_BUILD_TYPE` from `Debug` to `Release` can significantly speedup execution, thus heavily changing benchmark results.

To build iroha and benchmarks in release mode, type:
```
$ cmake -DBENCHMARKING=ON -DCMAKE_BUILD_TYPE=Release ..
```

**Note**: all code inside benchmark function influences on the benchmark results.


# How to write benchmark

1. Include `#include <benchmark/benchmark.h>`.

2. Refer to official [google guilde](https://github.com/google/benchmark#example-usage).

Also, try to preserve namespacing by making directories inside `benchmark` directory.
11 changes: 11 additions & 0 deletions benchmark/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include_directories(
${PROJECT_SOURCE_DIR}/core
)

add_executable(hash_benchmark
hash.cpp
)
target_link_libraries(hash_benchmark
benchmark
hash
)
43 changes: 43 additions & 0 deletions benchmark/crypto/hash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright Soramitsu Co., Ltd. 2016 All Rights Reserved.
* http://soramitsu.co.jp
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <benchmark/benchmark.h>
#include <algorithm>
#include <crypto/hash.hpp>


static void HASH_Sha3_256_with_keccak(benchmark::State& state) {
std::string s = "0123456789"; // length = 10
while (state.KeepRunning()) {
hash::sha3_256_hex(s);
}
}

static void HASH_Sha3_512_with_keccak(benchmark::State& state) {
std::string s = "0123456789"; // length = 10
while (state.KeepRunning()) {
hash::sha3_512_hex(s);
}
}

/**
* These two tests show the number of hashes calculated per sec.
*/
BENCHMARK(HASH_Sha3_256_with_keccak);
BENCHMARK(HASH_Sha3_512_with_keccak);

BENCHMARK_MAIN();
25 changes: 16 additions & 9 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ machine:
java:
version: 'oraclejdk8'

checkout:
post:
- git submodule sync
- git submodule update --init --recursive

dependencies:
cache_directories:
- ~/iroha/core/vendor/
- ~/docker
# to cache external dependencies
- ~/iroha/external
# to cache docker images
- ~/docker
override:
# one way to cache iroha-dev container is to save it to tar image. 2 mins vs 10 mins without caching.
- if [[ -e ~/docker/iroha-dev.tar ]]; then docker load -i ~/docker/iroha-dev.tar; else docker build --rm=false -t hyperledger/iroha-dev ${IROHA_HOME}/docker/dev; fi
# build iroha. Result of this instruction is ${IROHA_HOME}/docker/build/iroha.tar
- docker run -i -v ${IROHA_HOME}/docker/build:/build -v ${IROHA_HOME}:/opt/iroha hyperledger/iroha-dev sh <<< "cd /opt/iroha; /build-iroha.sh || exit 2; /mktar-iroha.sh || exit 3; cp /tmp/iroha.tar /build/iroha.tar || exit 4"
- >
docker run -i \
-v ${IROHA_HOME}/docker/build:/build \
-v ${IROHA_HOME}:/opt/iroha \
hyperledger/iroha-dev \
sh <<< "cd /opt/iroha/docker/dev/scripts; ./build-iroha.sh Release || exit 2; ./mktar-iroha.sh || exit 3; cp /tmp/iroha.tar /build/iroha.tar || exit 4"
# build iroha-docker image
- docker build --rm=false -t hyperledger/iroha-docker ${IROHA_HOME}/docker/build
# cache iroha-dev image. takes 30 sec to save into file
Expand All @@ -34,7 +36,7 @@ test:
# first, run ctest inside a container
- docker run -p 1204:1204 hyperledger/iroha-docker /test.sh
# then, run iroha with dummy config (1 node) and print its output to stdout
- docker logs $(docker run -it -d -p 1204:1204 hyperledger/iroha-docker /run.sh)
- docker run -it -d -p 1204:1204 hyperledger/iroha-docker /run.sh
# put new tests below
- curl -X POST http://127.0.0.1:1204/account/register -d '{"publicKey":"WdvM/DPabapmtA7ISbTYPywbHxk8gWu2221LzmcmAgw=","alias":"yonezu","timestamp":1482053586}'

Expand All @@ -45,3 +47,8 @@ deployment:
commands:
# makes docker login and docker push $1
- ${IROHA_HOME}/deploy.sh hyperledger/iroha-docker

branch: develop
commands:
# makes docker login and docker push $1
- ${IROHA_HOME}/deploy.sh hyperledger/iroha-docker-develop
8 changes: 8 additions & 0 deletions config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Note

Whenever you change `config.json`, don't forget to change according [`config.json`](../docker/build/config/config.json) in `docker` directory.

`config.json` in this folder is used if you use [local build](https://github.com/hyperledger/iroha/blob/master/docs/how_to_build.rst) (without docker),
but `config.json` in `docker/build/config/config.json` is used inside docker images.

The reason behind this is that docker can not use files outside its build scope (which is the directory with Dockerfile).
9 changes: 8 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"database_path":"/tmp/iroha_ledger",
"java_class_path":"java_tests",
"java_class_path_local":"smart_contract/java_tests",
"java_library_path":"lib",
"java_library_path_local":"build/lib",
"java_policy_path":"jvm/java.policy.txt",
"concurrency": 0,
"max_faulty_peers" : 1,
"pool_worker_queue_size": 1024
"pool_worker_queue_size": 1024,
"http_port": 1204,
"grpc_port": 50051
}
5 changes: 1 addition & 4 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
include_directories(".")

add_subdirectory(consensus)
add_subdirectory(model)
add_subdirectory(repository)
add_subdirectory(infra)
add_subdirectory(util)
add_subdirectory(vendor)
add_subdirectory(crypto)
add_subdirectory(validation)
add_subdirectory(transaction_builder)
28 changes: 4 additions & 24 deletions core/consensus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

include_directories(
"${PROJECT_SOURCE_DIR}/core"
"${PROJECT_SOURCE_DIR}/core/vendor/thread_pool_cpp/thread_pool"
)

ADD_LIBRARY(sumeragi STATIC
sumeragi.cpp
)

target_link_libraries(
sumeragi
target_link_libraries(sumeragi
config_manager
connection_with_grpc
signature
event_repository
commands
objects
)

ADD_LIBRARY(consensus_event STATIC
consensus_event.cpp
)

target_link_libraries(consensus_event
config_manager
commands
objects
validator
hash
thread_pool
executor
merkle_transaction_repository
)
3 changes: 0 additions & 3 deletions core/consensus/connection/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
include_directories(
"${PROJECT_SOURCE_DIR}/core"
)
73 changes: 59 additions & 14 deletions core/consensus/connection/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,80 @@ limitations under the License.
#include <memory>
#include <functional>

#include <infra/protobuf/event.grpc.pb.h>
#include <infra/protobuf/api.grpc.pb.h>
#include "../consensus_event.hpp"

namespace connection {

struct Config{
using Api::ConsensusEvent;
using Api::Transaction;
using Api::Query;


struct Config {
std::string name;
std::string ip_addr;
std::string port;
};

void initialize_peer();

bool send(
const std::string& ip,
const Event::ConsensusEvent& msg)
;
namespace iroha {
namespace Sumeragi {

namespace Verify {

bool send(
const std::string &ip,
const ConsensusEvent &msg
);

bool sendAll(const ConsensusEvent &msg);

bool receive(const std::function<void(
const std::string &,
ConsensusEvent &)
> &callback);

void addSubscriber(std::string ip);

};

namespace Torii {

bool receive(const std::function<void(
const std::string &,
Transaction&)
> &callback);

};
};

namespace TransactionRepository {

namespace find {

bool receive(const std::function<void(
const std::string &,
const Query &)
> &callback);

};

}

bool sendAll(
const Event::ConsensusEvent& msg
);
namespace AssetRepository {

bool receive(const std::function<void(
const std::string&,
Event::ConsensusEvent&)
>& callback);
namespace find {

bool receive(const std::function<void(
const std::string &,
const Query &)
> &callback);

void addSubscriber(std::string ip);
};
};
}

int run();

Expand Down

0 comments on commit 67e99c2

Please sign in to comment.