Skip to content

Commit

Permalink
merge from develop
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Drobny <[email protected]>
  • Loading branch information
vdrobnyi committed Mar 1, 2018
2 parents 8ac1188 + 432276b commit d774a4a
Show file tree
Hide file tree
Showing 65 changed files with 267 additions and 359 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
ccache --show-stats
ccache --zero-stats
# debug/coverage builds produce 2G cache
ccache --max-size=5G
ccache --max-size=2G
- run:
name: cmake
command: >
Expand Down Expand Up @@ -266,7 +266,7 @@ jobs:
- ~/Library/Caches/Homebrew
- run:
name: install dev dependencies
command: brew install cmake boost postgres grpc autoconf automake libtool ccache
command: brew install cmake boost postgres grpc autoconf automake libtool ccache || true
- save_cache:
key: brew-{{ epoch }}
paths:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ cmake-build*
cmake-build*
.gtm
/.gtm/

*.deb
12 changes: 2 additions & 10 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ pipeline {
IROHA_POSTGRES_HOST = "pg-${GIT_COMMIT}-${BUILD_NUMBER}"
IROHA_POSTGRES_USER = "pg-user-${GIT_COMMIT}"
IROHA_POSTGRES_PASSWORD = "${GIT_COMMIT}"
IROHA_REDIS_HOST = "redis-${GIT_COMMIT}-${BUILD_NUMBER}"
IROHA_POSTGRES_PORT = 5432
IROHA_REDIS_PORT = 6379

CTEST_OUTPUT_ON_FAILURE = 1
}
Expand All @@ -58,17 +56,11 @@ pipeline {
+ " --name ${env.IROHA_POSTGRES_HOST}"
+ " --network=${env.IROHA_NETWORK}")

def r_c = docker.image('redis:3.2.8').run(""
+ " --name ${env.IROHA_REDIS_HOST}"
+ " --network=${env.IROHA_NETWORK}")

docker.image("${env.DOCKER_IMAGE}").inside(""
+ " -e IROHA_POSTGRES_HOST=${env.IROHA_POSTGRES_HOST}"
+ " -e IROHA_POSTGRES_PORT=${env.IROHA_POSTGRES_PORT}"
+ " -e IROHA_POSTGRES_USER=${env.IROHA_POSTGRES_USER}"
+ " -e IROHA_POSTGRES_PASSWORD=${env.IROHA_POSTGRES_PASSWORD}"
+ " -e IROHA_REDIS_HOST=${env.IROHA_REDIS_HOST}"
+ " -e IROHA_REDIS_PORT=${env.IROHA_REDIS_PORT}"
+ " --network=${env.IROHA_NETWORK}"
+ " -v /var/jenkins/ccache:${CCACHE_DIR}") {

Expand Down Expand Up @@ -218,8 +210,8 @@ pipeline {
always {
script {
sh """
docker stop $IROHA_POSTGRES_HOST $IROHA_REDIS_HOST
docker rm $IROHA_POSTGRES_HOST $IROHA_REDIS_HOST
docker stop $IROHA_POSTGRES_HOST
docker rm $IROHA_POSTGRES_HOST
docker network rm $IROHA_NETWORK
"""
}
Expand Down
1 change: 0 additions & 1 deletion deploy/ansible/roles/iroha-node/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
postgresName: iroha_postgres
postgresUser: psql
postgresPassword: psql
redisName: iroha_redis
peers:
- 209.250.248.121:10001
- 209.250.248.225:10001
Expand Down
14 changes: 1 addition & 13 deletions deploy/ansible/roles/iroha-node/tasks/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@
networks:
- name: iroha_network

- name: Run redis in docker
docker_container:
name: "{{ redisName }}"
image: redis:3.2.8
state: started
recreate: yes
restart: yes
networks:
- name: iroha_network

- name: Make conf dir
file:
path: '/opt/docker/iroha/conf'
Expand Down Expand Up @@ -81,6 +71,4 @@
POSTGRES_PORT: 5432
POSTGRES_USER: "{{ postgresUser }}"
POSTGRES_PASSWORD: "{{ postgresPassword }}"
REDIS_HOST: "{{ redisName }}"
REDIS_PORT: 6379
KEY: node{{ key }}
KEY: node{{ key }}
2 changes: 0 additions & 2 deletions deploy/ansible/roles/iroha-node/templates/config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"torii_port" : 50051,
"internal_port" : 10001,
"pg_opt" : "host={{ postgresName }} port=5432 user={{ postgresUser }} password='{{ postgresPassword }}'",
"redis_host" : "{{ redisName }}",
"redis_port" : 6379,
"max_proposal_size" : 10,
"proposal_delay" : 5000,
"vote_delay" : 5000,
Expand Down
8 changes: 0 additions & 8 deletions docker/develop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@ RUN git clone https://github.com/jtv/libpqxx /tmp/libpqxx; \
make -C /tmp/libpqxx install; \
rm -rf /tmp/libpqxx

# install cpp_redis 4.3.0
RUN git clone https://github.com/Cylix/cpp_redis /tmp/cpp_redis; \
(cd /tmp/cpp_redis ; git checkout f390eef447a62dcb6da288fb1e91f25f8a9b838c); \
(cd /tmp/cpp_redis ; git submodule update --init --recursive); \
cmake -H/tmp/cpp_redis -B/tmp/cpp_redis/build; \
cmake --build /tmp/cpp_redis/build --target install -- -j${PARALLELISM}; \
rm -rf /tmp/cpp_redis

# install tbb
RUN git clone https://github.com/01org/tbb /tmp/tbb; \
(cd /tmp/tbb ; git checkout eb6336ad29450f2a64af5123ca1b9429ff6bc11d); \
Expand Down
4 changes: 0 additions & 4 deletions docker/docker-compose-swarm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ services:
ports:
- "50051:50051"
depends_on:
- redis
- postgres
tty: true

redis:
image: redis:3.2.8

postgres:
image: postgres:9.5
environment:
Expand Down
5 changes: 0 additions & 5 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ services:
- IROHA_POSTGRES_PORT=5432
- IROHA_POSTGRES_USER=iroha
- IROHA_POSTGRES_PASSWORD=helloworld
- IROHA_REDIS_HOST=${COMPOSE_PROJECT_NAME}_redis_1
- IROHA_REDIS_PORT=6379
- CCACHE_DIR=/tmp/ccache
# export G_ID=$(id -g $(whoami))
# export U_ID=$(id -g $(whoami))
user: ${U_ID:-0}:${G_ID:-0}
depends_on:
- redis
- postgres
tty: true
volumes:
Expand All @@ -27,8 +24,6 @@ services:
working_dir: /opt/iroha
cap_add:
- SYS_PTRACE
redis:
image: redis:3.2.8

postgres:
image: postgres:9.5
Expand Down
Binary file removed docker/release/iroha.deb
Binary file not shown.
36 changes: 8 additions & 28 deletions docs/source/deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,25 @@ Running single instance
Generally, people want to run Iroha locally in order to try out the API and explore the capabilities. This can be done in local or container environment (Docker). We will explore both possible cases, but in order to simplify peer components deployment, *it is advised to have Docker installed on your machine*.

Local environment
----------------
-----------------

By local environment, it is meant to have daemon process and the components (Redis and Postgres) deployed without any containers. This might be helpful in cases when messing up with Docker is not preferred — generally a quick exploration of the features.
By local environment, it is meant to have daemon process and Postgres deployed without any containers. This might be helpful in cases when messing up with Docker is not preferred — generally a quick exploration of the features.

Run postgres server
"""""""""""""""""""

In order to run postgres server locally, you should check postgres `website <https://www.postgresql.org/docs/current/static/server-start.html>`__ and follow their description. Generally, postgres server runs automatically when the system starts, but this should be checked in the configuration of the system.

Run redis server
""""""""""""""""

Redis is known for a simple run process. When it is installed in the system, it is enough to execute `redis-server` binary without arguments. Just in case, check their `website <https://redis.io/topics/quickstart>`__.

Run iroha daemon (irohad)
"""""""""""""""""""""""""

There is a list of preconditions which you should meet before proceeding:

* Postgres server is up and running
* Redis server is up and running
* `irohad` Iroha daemon binary is built and accessible in your system
* The genesis block and configuration files were created
* Config file uses valid postgres and redis connection settings
* Config file uses valid postgres connection settings
* A keypair for the peer is generated
* This is the first time you run the Iroha on this peer and you want to create new chain

Expand All @@ -43,8 +38,8 @@ In case of valid assumptions, the only thing that remains is to launch the daemo
+---------------+-----------------------------------------------------------------+
| Parameter | Meaning |
+---------------+-----------------------------------------------------------------+
| config | configuration file, containing postgres, and redis connection, |
| | and values to tune the system |
| config | configuration file, containing postgres connection and values |
| | to tune the system |
+---------------+-----------------------------------------------------------------+
| genesis_block | initial block in the ledger |
+---------------+-----------------------------------------------------------------+
Expand Down Expand Up @@ -77,23 +72,11 @@ Then, you have to create an enviroment for the image to run without problems:
Create docker network
"""""""""""""""""""""

Containers for Redis, Postgres, and Iroha should run in the same virtual network, in order to be available to each other. Create a network, by typing following command (you can use any name for the network, but in the example, we use *iroha-network* name):
Containers for Postgres and Iroha should run in the same virtual network, in order to be available to each other. Create a network, by typing following command (you can use any name for the network, but in the example, we use *iroha-network* name):

.. code-block:: shell
docker network create iroha-network
Run Redis in a container
""""""""""""""""""""""""

Run redis server, attaching it to the network you have created before, and exposing ports for communication:

.. code-block:: shell
docker run --name some-redis \
-p 6379:6379 \
--network=iroha-network \
-d redis:3.2.8
Run Postgresql in a container
"""""""""""""""""""""""""""""
Expand Down Expand Up @@ -122,7 +105,7 @@ Running iroha daemon in docker container
""""""""""""""""""""""""""""""""""""""""

There is a list of assumptions which you should review before proceeding:
* Postgres and redis servers are running on the same docker network
* Postgres server is running on the same docker network
* There is a folder, containing config file and keypair for a single node
* This is the first time you run the Iroha on this peer and you want to create new chain

Expand All @@ -142,9 +125,6 @@ If they are met, you can move forward with the following command:
-e POSTGRES_PORT='5432' \
-e POSTGRES_PASSWORD='mysecretpassword' \
-e POSTGRES_USER='postgres' \
# Redis settings
-e REDIS_HOST='some-redis' \
-e REDIS_PORT='6379' \
# Node keypair name
-e KEY='node0' \
# Docker network name
Expand Down Expand Up @@ -207,7 +187,7 @@ Step-by-step guide
9. Wait until playbook finishes and then Iroha network is ready and up.

Checking Iroha peer status
""""""""""""""""""""
""""""""""""""""""""""""""

1. SSH into any of your machines

Expand Down
15 changes: 8 additions & 7 deletions irohad/ametsuchi/impl/postgres_block_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ namespace iroha {
execute_{makeExecuteOptional(transaction_, log_)} {}

rxcpp::observable<BlockQuery::wBlock> PostgresBlockQuery::getBlocks(
shared_model::interface::types::HeightType height, uint32_t count) {
shared_model::interface::types::HeightType last_id = block_store_.last_id();
shared_model::interface::types::HeightType height, uint32_t count) {
shared_model::interface::types::HeightType last_id =
block_store_.last_id();
auto to = std::min(last_id, height + count - 1);
if (height > to or count == 0) {
return rxcpp::observable<>::empty<wBlock>();
Expand Down Expand Up @@ -59,7 +60,7 @@ namespace iroha {
}

rxcpp::observable<BlockQuery::wBlock> PostgresBlockQuery::getBlocksFrom(
shared_model::interface::types::HeightType height) {
shared_model::interface::types::HeightType height) {
return getBlocks(height, block_store_.last_id());
}

Expand Down Expand Up @@ -122,8 +123,8 @@ namespace iroha {
return x.at("index").template as<size_t>();
}),
[&](auto x) {
subscriber.on_next(
PostgresBlockQuery::wTransaction(block->transactions().at(x)->copy()));
subscriber.on_next(PostgresBlockQuery::wTransaction(
block->transactions().at(x)->copy()));
});
};
}
Expand Down Expand Up @@ -166,7 +167,6 @@ namespace iroha {
}

for (const auto &block_id : block_ids) {
// create key for querying redis
execute_(
"SELECT DISTINCT index FROM index_by_id_height_asset WHERE id = "
+ transaction_.quote(account_id)
Expand Down Expand Up @@ -215,7 +215,8 @@ namespace iroha {
block.transactions().end(),
[&hash](auto tx) { return tx->hash() == hash; });
if (it != block.transactions().end()) {
result = boost::optional<PostgresBlockQuery::wTransaction>(PostgresBlockQuery::wTransaction((*it)->copy()));
result = boost::optional<PostgresBlockQuery::wTransaction>(
PostgresBlockQuery::wTransaction((*it)->copy()));
}
return result;
};
Expand Down
12 changes: 7 additions & 5 deletions irohad/ametsuchi/impl/postgres_block_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace iroha {
class FlatFile;

/**
* Class which implements BlockQuery with a Redis backend.
* Class which implements BlockQuery with a Postgres backend.
*/
class PostgresBlockQuery : public BlockQuery {
public:
Expand All @@ -55,10 +55,12 @@ namespace iroha {
boost::optional<wTransaction> getTxByHashSync(
const shared_model::crypto::Hash &hash) override;

rxcpp::observable<wBlock> getBlocks(shared_model::interface::types::HeightType height,
uint32_t count) override;
rxcpp::observable<wBlock> getBlocks(
shared_model::interface::types::HeightType height,
uint32_t count) override;

rxcpp::observable<wBlock> getBlocksFrom(shared_model::interface::types::HeightType height) override;
rxcpp::observable<wBlock> getBlocksFrom(
shared_model::interface::types::HeightType height) override;

rxcpp::observable<wBlock> getTopBlocks(uint32_t count) override;

Expand All @@ -80,7 +82,7 @@ namespace iroha {
const shared_model::crypto::Hash &hash);

/**
* creates callback to lrange query to redis to supply result to
* creates callback to lrange query to Postgres to supply result to
* subscriber s
* @param s
* @param block_id
Expand Down
6 changes: 6 additions & 0 deletions irohad/ametsuchi/impl/storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ namespace iroha {
pg_lazy(std::move(pg_lazy)),
pg_nontx(std::move(pg_nontx)) {}

StorageImpl::~StorageImpl() {
wsv_transaction_->commit();
wsv_connection_->disconnect();
log_->info("PostgresQL connection closed");
}

StorageImpl::StorageImpl(
std::string block_store_dir,
std::string postgres_options,
Expand Down
2 changes: 2 additions & 0 deletions irohad/ametsuchi/impl/storage_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ namespace iroha {

std::shared_ptr<BlockQuery> getBlockQuery() const override;

~StorageImpl() override;

protected:
StorageImpl(std::string block_store_dir,
std::string postgres_options,
Expand Down
Loading

0 comments on commit d774a4a

Please sign in to comment.