Skip to content

Commit

Permalink
Configure Distillery for deployment
Browse files Browse the repository at this point in the history
Other Changes:

* Update README with installation instructions
  • Loading branch information
masonforest committed Dec 11, 2018
1 parent 3b132b9 commit 10190d3
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 34 deletions.
69 changes: 62 additions & 7 deletions README.md
@@ -1,10 +1,65 @@
Elipticoin Blacksmith Node
Ellipticoin Blacksmith Node
==========

Elipticoin is a Ethereum-like blockchain that's optimized for sustainability and
developer happiness. [Stakers](https://en.wikipedia.org/wiki/Proof-of-stake) run
blacksmith nodes to form consensus on transactions on the network in return for
staking rewards. This is the reference implementation of a
blacksmith node written in Elixir and Rust.
Ellipticoin is a developer friendly scalable Ethereum side-chain. Blacksmith
nodes forge transactions to keep the network secure. They are authenticated via [proof
of
burn](https://www.masonforest.com/blockchain/ethereum/ellipticoin/2018/05/29/the-ellipticoin-proof-of-burn-algorithm.html)
which has similar economic incentives to proof of work except instead of
burning energy they burn tokens on the parent chain.

You can access the Elipticoin network using the [reference wallet](https://www.npmjs.com/package/ec-wallet).
You can install the [reference wallet](https://www.npmjs.com/package/ec-wallet) to use the Ellipticoin network itself.


Running a Blacksmith Node:
==========================

Using docker-compose
-----
1. Clone the repo: `git clone https://github.com/ellipticoin/ellipticoin-blacksmith-node && cd ellipticoin-blacksmith-node`
2. Install Docker
2. Update `ETHEREUM_PRIVATE_KEY` in `config/docker.env`
3. Run `docker-compose up`

From a binary release
-----

1. Create an `Ubuntu 18.04` VPS/Droplet (or another type of VPS and create a
PR!)
2. Download the appropriate release for your system and extract it:
````
$ cd /usr/local
$ wget blacksmith.tar.gz
$ tar -xf blacksmith.tar.gz
$ rm blacksmith.tar.gz
````
3. Run `sh ./releases/0.1.0/commands/install_deps.sh` to install the required dependencies.
4. Allow all postgres connections from localhost:

Edit: /etc/postgresql/10/main/pg_hba.conf

Change the line:
````
local all postgres peer
````
to
````
local all postgres trust
````
5. Restart postgres: `sudo service postgresql restart`

6. Create the blacksmith's db: `createdb -U postgres blacksmith`
7. Update `ETHEREUM_PRIVATE_KEY` and anything else you'd like to customize in
`/usr/local/etc/config.exs`

9. Run the blacksmith node in the forground to check if everything is set up correctly: `blacksmith foreground`

10. If everything looks to be working you can kill the node and start it again in the background: `blacksmith start`

From Source
-----
1. Clone the repo: `git clone https://github.com/ellipticoin/ellipticoin-blacksmith-node && cd ellipticoin-blacksmith-node`
2. Update `ETHEREUM_PRIVATE_KEY` and anything else you'd like to customize in
`config/dev.secret.exs` and `config/dev.exs`
3. Run: `mix dep.get`
4. Run: `mix run --no-halt`
60 changes: 60 additions & 0 deletions lib/blacksmith/release_tasks.ex
@@ -0,0 +1,60 @@
defmodule Blacksmith.ReleaseTasks do
@start_apps [
:crypto,
:ssl,
:postgrex,
:ecto,
:ecto_sql
]

@repos Application.get_env(:blacksmith, :ecto_repos, [])

def migrate(_argv) do
start_services()

run_migrations()

stop_services()
end

defp start_services do
IO.puts("Starting dependencies..")
# Start apps necessary for executing migrations
Enum.each(@start_apps, &Application.ensure_all_started/1)

# Start the Repo(s) for app
IO.puts("Starting repos..")

Enum.each(@repos, & &1.start_link(pool_size: 2))
end

defp stop_services do
IO.puts("Success!")
:init.stop()
end

defp run_migrations do
Enum.each(@repos, &run_migrations_for/1)
end

defp run_migrations_for(repo) do
app = Keyword.get(repo.config, :otp_app)
IO.puts("Running migrations for #{app}")
migrations_path = priv_path_for(repo, "migrations")
Ecto.Migrator.run(repo, migrations_path, :up, all: true)
end

defp priv_path_for(repo, filename) do
app = Keyword.get(repo.config, :otp_app)

repo_underscore =
repo
|> Module.split()
|> List.last()
|> Macro.underscore()

priv_dir = "#{:code.priv_dir(app)}"

Path.join([priv_dir, repo_underscore, filename])
end
end
1 change: 0 additions & 1 deletion lib/staking_contract_monitor.ex
Expand Up @@ -57,7 +57,6 @@ defmodule StakingContractMonitor do
|> Ethereum.Helpers.bytes_to_hex()
last_signature = EllipticoinStakingContract.last_signature()
|> ok
IO.inspect (last_signature |> Base.encode16(case: :lower)), label: "last signature"
{:ok, signature} = EllipticoinStakingContract.last_signature()
|> ok
|> Ethereum.Helpers.sign(ethereum_private_key)
Expand Down
4 changes: 1 addition & 3 deletions mix.exs
Expand Up @@ -6,10 +6,8 @@ defmodule Blacksmith.Mixfile do
app: :blacksmith,
version: "0.1.0",
elixir: "~> 1.7",
build_embedded: false,
start_permanent: Mix.env() == :prod,
compilers: [:rustler] ++ Mix.compilers(),
compilers: Mix.compilers(),
rustler_crates: rustler_crates(),
deps: deps(),
elixirc_paths: elixirc_paths(Mix.env())
Expand Down Expand Up @@ -58,7 +56,7 @@ defmodule Blacksmith.Mixfile do
{:ecto, "~> 3.0"},
{:ecto_sql, "~> 3.0-rc.1"},
{:ethereumex,
[github: "masonforest/ethereumex", branch: "websocket-client", override: true]},
[github: "masonforest/ethereumex", branch: "websocket-client", override: true]},
{:ex_machina, "~> 2.2"},
{:exth_crypto, "~> 0.1.4", override: true},
{:exw3, github: "masonforest/exw3", branch: "websocket-client"},
Expand Down
1 change: 0 additions & 1 deletion native/transaction_processor/src/main.rs
Expand Up @@ -27,7 +27,6 @@ impl Ctx {
fn new() -> Ctx {
let args: Vec<String> = env::args().collect();
let connection_string: &str = &args[1];
println!("Connection string: {:?}", connection_string);
let client = Client::open(connection_string).unwrap();
Ctx {
client: Arc::new(client),
Expand Down
51 changes: 51 additions & 0 deletions rel/commands/install_deps.sh
@@ -0,0 +1,51 @@
#!/bin/env sh

LINUX_DEPS="build-essential automake autoconf autogen libncurses-dev libgmp-dev libtinfo-dev libncursesw5-dev libncurses5-dev libtool gcc curl postgresql redis-server openssl"
DARWIN_DEPS="automake autoconf autogen libgmp-dev postgresql redis"

fancy_echo() {
local fmt="$1"; shift

# shellcheck disable=SC2059
printf "\\n$fmt\\n" "$@"
}

install_linux_deps() {
local flavor=`grep "^ID=" /etc/os-release | cut -d"=" -f 2`
case $flavor in
debian|ubuntu)
sudo apt-get update && sudo apt-get update && sudo apt-get install -y $LINUX_DEPS libgmp-dev erlang-dev
;;
fedora|centos)
sudo yum install $LINUX_DEPS gmp-devel
;;
*)
fancy_echo "Unrecognized distribution $flavor"
exit 1
;;
esac
}

install_darwin_deps(){
fancy_echo "Installing dependencies via brew"
brew install $DARWIN_DEPS
}

install_deps() {
local sys=`uname -s`
echo $sys
case $sys in
Linux*)
install_linux_deps
;;
Darwin*)
install_darwin_deps
;;
*)
fancy_echo "Unknown system"
exit 1
;;
esac
}
set -e
install_deps
3 changes: 3 additions & 0 deletions rel/commands/migrate.sh
@@ -0,0 +1,3 @@
#!/bin/sh

release_ctl eval --mfa "Blacksmith.ReleaseTasks.migrate/1" --argv -- "$@"
20 changes: 13 additions & 7 deletions rel/config.exs
Expand Up @@ -39,7 +39,16 @@ environment :prod do
set include_src: false
set cookie: :"|X^}BrYC6%BQYK;Y3o?jWJ]^hXR>0/zz)euGL&qq.V`tTE|HD6EZxr_CtEdPlfsF"
set vm_args: "rel/vm.args"
set pre_start_hooks: "rel/hooks/pre_start"
set config_providers: [
{Mix.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/etc/config.exs"]}
]
set commands: [
install_deps: "rel/commands/install_deps.sh",
migrate: "rel/commands/migrate.sh",
]
set overlays: [
{:copy, "rel/config/config.exs", "etc/config.exs"}
]
end

# You may define one or more releases in this file.
Expand All @@ -52,13 +61,10 @@ release :blacksmith do
set applications: [
:crypto,
:libsecp256k1,
:ethereumex,
:evm,
:blockchain,
:runtime_tools
]
set config_providers: [
{Mix.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/etc/config.exs"]}
]
set overlays: [
{:copy, "rel/config/config.exs", "etc/config.exs"}
]
end

19 changes: 10 additions & 9 deletions rel/config/config.exs
@@ -1,20 +1,21 @@
use Mix.Config

config :blacksmith, :ethereum_private_key, "wss://rinkeby.infura.io/ws"
config :blacksmith, base_contracts_path: "./base_contracts"
config :blacksmith, port: String.to_integer(System.get_env("PORT") || "4045")
config :blacksmith, port: 4045

config :blacksmith,
staking_contract_address:
(System.get_env("STAKING_CONTRACT_ADDRESS") || "") |> Base.decode16!(case: :mixed)
"756d0ABF6235AB135126fe772CDaE195C3DECc0e" |> Base.decode16!(case: :mixed)

config :ethereumex, :web3_url, System.get_env("WEB3_URL")
config :ethereumex, :web3_url, "wss://rinkeby.infura.io/ws"
config :ethereumex, :client_type, :websocket
config :blacksmith, private_key: (System.get_env("ETHEREUM_PRIVATE_KEY") || "") |> Base.decode16!()
config :blacksmith, ethereum_private_key: "1274EA29DC71B4B2E6439FDD109545E8C1585E2B16BCD45236FE20FBF919A70D" |> Base.decode16!()

config :blacksmith, :redis_url, System.get_env("REDIS_URL")
config :blacksmith, :redis_url, "redis://localhost:6379/"
config :blacksmith, Blacksmith.Repo,
username: System.get_env("POSTGRES_USER"),
password: System.get_env("POSTGRES_PASS"),
database: System.get_env("POSTGRES_DB"),
hostname: System.get_env("POSTGRES_HOST"),
username: "postgres",
password: "",
database: "blacksmith",
hostname: "localhost",
pool_size: 15
1 change: 0 additions & 1 deletion rel/hooks/pre_start/echo.sh

This file was deleted.

5 changes: 0 additions & 5 deletions rel/hooks/pre_start/wait_for_postgres

This file was deleted.

0 comments on commit 10190d3

Please sign in to comment.