Skip to content

Commit

Permalink
Merge pull request EOSIO#151 from enumivo/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Enumivo authored May 25, 2018
2 parents a7d3fae + 35a5d54 commit 97e026c
Show file tree
Hide file tree
Showing 17 changed files with 557 additions and 212 deletions.
3 changes: 2 additions & 1 deletion Docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM enumivo/builder as builder
ARG branch=master
ARG symbol=SYS

RUN git clone -b $branch https://github.com/enumivo/enumivo.git --recursive \
&& cd enumivo && echo "$branch:$(git rev-parse HEAD)" > /etc/enumivo-version \
&& cmake -H. -B"/tmp/build" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_ROOT=/opt/wasm -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/tmp/build -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true \
-DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/tmp/build -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true -DCORE_SYMBOL_NAME=$symbol \
&& cmake --build /tmp/build --target install && rm /tmp/build/bin/enumivocpp


Expand Down
203 changes: 202 additions & 1 deletion Docker/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,204 @@
# Run in docker

Docker is not available at the moment
Simple and fast setup of Enumivo on Docker is also available.

## Install Dependencies

- [Docker](https://docs.docker.com) Docker 17.05 or higher is required
- [docker-compose](https://docs.docker.com/compose/) version >= 1.10.0

## Docker Requirement

- At least 7GB RAM (Docker -> Preferences -> Advanced -> Memory -> 7GB or above)
- If the build below fails, make sure you've adjusted Docker Memory settings and try again.

## Build Enumivo image

```bash
git clone https://github.com/enumivo/enumivo.git --recursive --depth 1
cd enumivo/Docker
docker build . -t enumivo/enumivo
```

The above will build off the most recent commit to the master branch by default. If you would like to target a specific branch/tag, you may use a build argument. For example, if you wished to generate a docker image based off of the dawn-v4.0.0 tag, you could do the following:

```bash
docker build -t enumivo/enumivo:dawn-v4.0.0 --build-arg branch=dawn-v4.0.0 .
```

By default, the symbol in enumivo.system is set to SYS. You can override this using the symbol argument while building the docker image.

```bash
docker built -t enumivo/enumivo --build-arg symbol=<symbol> .
```

## Start enunode docker container only

```bash
docker run --name enunode -p 8888:8888 -p 9876:9876 -t enumivo/enumivo enunoded.sh arg1 arg2
```

By default, all data is persisted in a docker volume. It can be deleted if the data is outdated or corrupted:

```bash
$ docker inspect --format '{{ range .Mounts }}{{ .Name }} {{ end }}' enunode
fdc265730a4f697346fa8b078c176e315b959e79365fc9cbd11f090ea0cb5cbc
$ docker volume rm fdc265730a4f697346fa8b078c176e315b959e79365fc9cbd11f090ea0cb5cbc
```

Alternately, you can directly mount host directory into the container

```bash
docker run --name enunode -v /path-to-data-dir:/opt/enumivo/bin/data-dir -p 8888:8888 -p 9876:9876 -t enumivo/enumivo enunoded.sh arg1 arg2
```

## Get chain info

```bash
curl http://127.0.0.1:8888/v1/chain/get_info
```

## Start both enunode and enuwallet containers

```bash
docker volume create --name=enunode-data-volume
docker volume create --name=enuwallet-data-volume
docker-compose up -d
```

After `docker-compose up -d`, two services named `enunoded` and `enuwalletd` will be started. enunode service would expose ports 8888 and 9876 to the host. enuwalletd service does not expose any port to the host, it is only accessible to enucli when running enucli is running inside the enuwalletd container as described in "Execute enucli commands" section.

### Execute enulic commands

You can run the `enulic` commands via a bash alias.

```bash
alias enulic='docker-compose exec enuwallet /opt/enumivo/bin/enulic -u http://enunoded:8888 --wallet-url http://localhost:8888'
enulic get info
enulic get account inita
```

Upload sample exchange contract

```bash
enulic set contract exchange contracts/exchange/exchange.wast contracts/exchange/exchange.abi
```

If you don't need enuwallet afterwards, you can stop the enuwallet service using

```bash
docker-compose stop enuwallet
```

### Develop/Build custom contracts

Due to the fact that the enumivo/enumivo image does not contain the required dependencies for contract development (this is by design, to keep the image size small), you will need to utilize the enumivo/enumivo image. This image contains both the required binaries and dependencies to build contracts using enumivocpp.

You can either use the image available on [Docker Hub](https://hub.docker.com/r/enumivo/enumivo/) or navigate into the dev folder and build the image manually.

```bash
cd dev
docker build -t enumivo/enumivo .
```

### Change default configuration

You can use docker compose override file to change the default configurations. For example, create an alternate config file `config2.ini` and a `docker-compose.override.yml` with the following content.

```yaml
version: "2"

services:
enunode:
volumes:
- enunode-data-volume:/opt/enumivo/bin/data-dir
- ./config2.ini:/opt/enumivo/bin/data-dir/config.ini
```
Then restart your docker containers as follows:
```bash
docker-compose down
docker-compose up
```

### Clear data-dir

The data volume created by docker-compose can be deleted as follows:

```bash
docker volume rm enunode-data-volume
docker volume rm enuwallet-data-volume
```

### Docker Hub

Docker Hub image available from [docker hub](https://hub.docker.com/r/enumivo/enumivo/).
Create a new `docker-compose.yaml` file with the content below

```bash
version: "3"

services:
enunoded:
image: enumivo/enumivo:latest
command: /opt/enumivo/bin/enunoded.sh
hostname: enunoded
ports:
- 8888:8888
- 9876:9876
expose:
- "8888"
volumes:
- enunode-data-volume:/opt/enumivo/bin/data-dir

enuwallet:
image: enumivo/enumivo:latest
command: /opt/enumivo/bin/enuwallet
hostname: enuwallet
links:
- enunoded
volumes:
- enuwallet-data-volume:/opt/enumivo/bin/data-dir

volumes:
enunode-data-volume:
enuwallet-data-volume:

```

*NOTE:* the default version is the latest, you can change it to what you want

run `docker pull enumivo/enumivo:latest`

run `docker-compose up`

### Dawn 4.0 Testnet

We can easily set up a Dawn 4.0 local testnet using docker images. Just run the following commands:

Note: if you want to use the mongo db plugin, you have to enable it in your `data-dir/config.ini` first.

```
# pull images
docker pull enumivo/enumivo:latest
docker pull mongo:latest
# create volume
docker volume create --name=enunode-data-volume
docker volume create --name=enuwallet-data-volume
docker volume create --name=mongo-data-volume
# start containers
docker-compose -f docker-compose-dawn4.0.yaml up -d
# get chain info
curl http://127.0.0.1:8888/v1/chain/get_info
# get logs
docker-compose logs enunoded
# stop containers
docker-compose -f docker-compose-dawn4.0.yaml down
```

The `blocks` data are stored under `--data-dir` by default, and the wallet files are stored under `--wallet-dir` by default, of course you can change these as you want.

### About MongoDB Plugin

Currently, the mongodb plugin is disabled in `config.ini` by default, you have to change it manually in `config.ini` or you can mount a `config.ini` file to `/opt/enumivo/bin/data-dir/config.ini` in the docker-compose file.
4 changes: 2 additions & 2 deletions Docker/builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM ubuntu:16.04
FROM ubuntu:18.04

LABEL author="xiaobo <[email protected]>" maintainer="Xiaobo <[email protected]> Huang-Ming Huang <[email protected]>" version="0.1.1" \
description="This is a base image for building enumivo/enumivo"

RUN echo 'APT::Install-Recommends 0;' >> /etc/apt/apt.conf.d/01norecommends \
&& echo 'APT::Install-Suggests 0;' >> /etc/apt/apt.conf.d/01norecommends \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y sudo wget curl net-tools ca-certificates unzip
&& DEBIAN_FRONTEND=noninteractive apt-get install -y sudo wget curl net-tools ca-certificates unzip gnupg

RUN echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main" >> /etc/apt/sources.list.d/llvm.list \
&& wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - \
Expand Down
8 changes: 5 additions & 3 deletions Docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM enumivo/builder
ARG branch=master
ARG symbole=SYS

RUN git clone -b $branch https://github.com/enumivo/enumivo.git --recursive \
&& cd enumivo && echo "$branch:$(git rev-parse HEAD)" > /etc/enumivo-version \
&& cmake -H. -B"/opt/enumivo" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_ROOT=/opt/wasm -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/opt/enumivo -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true \
-DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/opt/enumivo -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true -DCORE_SYMBOL_NAME=$symbol \
&& cmake --build /opt/enumivo --target install \
&& mv /enumivo/Docker/config.ini / && mv /opt/enumivo/contracts /contracts && mv /enumivo/Docker/enunoded.sh /opt/enumivo/bin/enunoded.sh \
&& mv /enumivo/Docker/config.ini / && mv /opt/enumivo/contracts /contracts && mv /enumivo/Docker/enunoded.sh /opt/enumivo/bin/nodeosd.sh && mv tutorials /tutorials \
&& rm -rf /enumivo

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install openssl && rm -rf /var/lib/apt/lists/*
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install openssl vim psmisc python3-pip && rm -rf /var/lib/apt/lists/*
RUN pip3 install numpy
ENV ENUMIVO_ROOT=/opt/enumivo
RUN chmod +x /opt/enumivo/bin/enunoded.sh
ENV LD_LIBRARY_PATH /usr/local/lib
Expand Down
11 changes: 11 additions & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/enumivo/chain/core_symbol.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/enumivo/chain/core_symbol.hpp)

# set the chain id
if (NOT "${CHAIN_ID}" STREQUAL "")
set(enumivo_CHAIN_ID "${CHAIN_ID}")
else()
## sha256("enumivo::chain version 1.0")
set(enumivo_CHAIN_ID "144B6AB7924EA47BAE7A5846B4494A35563AE816E2ED5AFFA7A9C990C2B3CFB3")
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/chain_id.cpp.in ${CMAKE_CURRENT_SOURCE_DIR}/chain_id.cpp)

file(GLOB HEADERS "include/enumivo/chain/*.hpp" "include/enumivo/chain/contracts/*.hpp")

## SORT .cpp by most likely to change / break compile
Expand All @@ -20,6 +30,7 @@ add_library( enumivo_chain
enumivo_contract.cpp
enumivo_contract_abi.cpp
chain_config.cpp
chain_id.cpp

# chain_config.cpp
# block_trace.cpp
Expand Down
14 changes: 11 additions & 3 deletions libraries/chain/abi_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace enumivo { namespace chain {

for( const auto& td : abi.types ) {
FC_ASSERT(is_type(td.type), "invalid type", ("type",td.type));
FC_ASSERT(!is_type(td.new_type_name), "type already exists", ("new_type_name",td.new_type_name));
typedefs[td.new_type_name] = td.type;
}

Expand All @@ -128,6 +129,8 @@ namespace enumivo { namespace chain {
FC_ASSERT( actions.size() == abi.actions.size() );
FC_ASSERT( tables.size() == abi.tables.size() );
FC_ASSERT( error_messages.size() == abi.error_messages.size() );

validate();
}

bool abi_serializer::is_builtin_type(const type_name& type)const {
Expand Down Expand Up @@ -222,10 +225,15 @@ namespace enumivo { namespace chain {
} FC_CAPTURE_AND_RETHROW( (t) ) }
}

type_name abi_serializer::resolve_type(const type_name& type)const {
type_name abi_serializer::resolve_type(const type_name& type)const {
auto itr = typedefs.find(type);
if( itr != typedefs.end() )
return resolve_type(itr->second);
if( itr != typedefs.end() ) {
for( auto i = typedefs.size(); i > 0; --i ) { // avoid infinite recursion
const type_name& t = itr->second;
itr = typedefs.find( t );
if( itr == typedefs.end() ) return t;
}
}
return type;
}

Expand Down
6 changes: 6 additions & 0 deletions libraries/chain/chain_id.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <enumivo/chain/types.hpp>

namespace enumivo { namespace chain {
chain_id_type::chain_id_type( const fc::string& s ) { id = fc::sha256(s); }
chain_id_type::chain_id_type() { id = fc::sha256("${enumivo_CHAIN_ID}"); }
}} // namespace enumivo::chain
2 changes: 1 addition & 1 deletion libraries/chain/genesis_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace enumivo { namespace chain {


chain::chain_id_type genesis_state::compute_chain_id() const {
return initial_chain_id;
return config::chain_id;
}

} } // namespace enumivo::chain
1 change: 0 additions & 1 deletion libraries/chain/include/enumivo/chain/abi_serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct abi_serializer {
map<type_name, pair<unpack_function, pack_function>> built_in_types;
void configure_built_in_types();

bool has_cycle(const vector<pair<string, string>>& sedges)const;
void validate()const;

type_name resolve_type(const type_name& t)const;
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/enumivo/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ const static int irreversible_threshold_percent= 70 * percent_1;

const static uint64_t billable_alignment = 16;

const static chain_id_type chain_id = chain_id_type();

template<typename T>
struct billable_size;

Expand Down
7 changes: 1 addition & 6 deletions libraries/chain/include/enumivo/chain/genesis_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ struct genesis_state {
time_point initial_timestamp = fc::time_point::from_iso_string( "2018-03-02T12:00:00" );
public_key_type initial_key = fc::variant("ENU6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV").as<public_key_type>();

/**
* Temporary, will be moved elsewhere.
*/
chain_id_type initial_chain_id;

/**
* Get the chain_id corresponding to this genesis state.
*
Expand All @@ -58,4 +53,4 @@ struct genesis_state {


FC_REFLECT(enumivo::chain::genesis_state,
(initial_timestamp)(initial_key)(initial_configuration)(initial_chain_id))
(initial_timestamp)(initial_key)(initial_configuration))
Loading

0 comments on commit 97e026c

Please sign in to comment.