Skip to content

Commit

Permalink
Merged in coinplugin/go-metadium (pull request #2)
Browse files Browse the repository at this point in the history
Master

Approved-by: Uh Sado <sadoc@metadium.com>
  • Loading branch information
sadoci committed Jul 27, 2018
2 parents f46643b + 3387926 commit e73296e
Show file tree
Hide file tree
Showing 44 changed files with 2,678 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -25,6 +25,8 @@ build/_vendor/pkg
# used by the Makefile
/build/_workspace/
/build/bin/
/build/conf/
/build/*.tar.gz
/geth*.zip

# travis
Expand Down
19 changes: 18 additions & 1 deletion Makefile
Expand Up @@ -11,6 +11,23 @@
GOBIN = $(shell pwd)/build/bin
GO ?= latest

metadium: gmet logrot
@[ -d build/conf ] || mkdir -p build/conf
@cp -p metadium/scripts/gmet.sh build/bin/
@cp -p metadium/scripts/config.json.example \
metadium/scripts/genesis-template.json \
metadium/contracts/MetadiumAdmin-template.sol build/conf/
@(cd build; tar cfz metadium.tar.gz bin conf)
@echo "Done building build/metadium.tar.gz"

gmet:
build/env.sh go run build/ci.go install ./cmd/gmet
@echo "Done building."
@echo "Run \"$(GOBIN)/gmet\" to launch gmet."

logrot:
build/env.sh go run build/ci.go install ./cmd/logrot

geth:
build/env.sh go run build/ci.go install ./cmd/geth
@echo "Done building."
Expand Down Expand Up @@ -41,7 +58,7 @@ lint: ## Run linters.
build/env.sh go run build/ci.go lint

clean:
rm -fr build/_workspace/pkg/ $(GOBIN)/*
rm -fr build/_workspace/pkg/ $(GOBIN)/* build/conf

# The devtools target installs tools required for 'go generate'.
# You need to put $GOBIN (or $GOPATH/bin) in your PATH to use 'go generate'.
Expand Down
122 changes: 122 additions & 0 deletions README.md
Expand Up @@ -2,6 +2,128 @@

Golang implementation of the Metadium project. For now, this is just a forking point. We will release the code as it gets ready for public review. Stay tuned.

## Building

`geth` has been renamed to `gmet`. Building it is the same as go-ethereum.

make gmet

For the convenience of installation, other targets have been added to the default target.

make

will build `logrot` (log rotator) and `metadium.tar.gz` in `build` directory, in addtion. `metadium.tar.gz` has the following files.

bin/gmet
bin/gmet.sh
bin/logrot
conf/MetadiumAdmin-template.sol
conf/genesis-template.json
conf/config.json.example

## Setting Up a Network

One can use `gmet.sh` script to make setup process a little easier. `gmet.sh` assumes metadium data directory to be `/opt/<node-name>`

### Initial Network

First create data directory in `/opt/`, say `/opt/meta1`. Then, unpack metadium.tar.gz in the directory.

mkdir /opt/meta1
cd /opt/meta1
tar xvfz <dir>/metadium.tar.gz

As initial members / accounts and nodes are determined (at least one member / account and node are required), create configuration file using `conf/config.json.example`, say `config.json`. The first account is going to be the governance contract creator, and only the first node is allowed to generate blocks before governance contract is established.

#### Account and Node IDs

One can reuse existing accounts and nodes. Account files are in `keystore` directory, and `geth/nodekey` is node key / id file. Or one can use `gmet` to create accounts and node keys, and copy them to data directory.

To create a new account file, run the following.

bin/gmeth metadium new-account --out <account-file-name>

To create a new node key,

bin/gmeth metadium new-nodekey --out <node-key-file-name>

To get node id, which is the public key of a `nodekey`.

bin/gmeth metadium nodeid <node-key-file-name>

#### First Node & Governance Contract Initialization

If you are to use existing or pre-created node key, copy the file to `geth` directory.

mkdir geth
cp <node-key-file> geth/nodekey

The same for accounts
mkdir keystore
chmod 0600 keystore
cp <account-files> keystore/

Running the following command generates `genesis.json` and `MetadiumAdmin.sol`, and initialize metadium blockchain.

bin/gmeth.sh init config.json <port>

e.g.

bin/gmeth.sh init config.json 10009

Now it's time to compile and load governance contract

bin/solc.sh -p 1 MetadiumAdmin.sol MetadiumAdmin.js

Start the metadium node

bin/gmeth.sh start

Open metadium console and create governance contract

bin/gmeth.sh console
...
> loadScript('MetadiumAdmin.js')
> personal.unlockAccount(<address>, <password>, <duration-in-second>)
> Admin_new()

#### Other Initial Nodes

Copy config.json and MetadiumAdmin.js, then follow the same procedures except governance contract creation.

mkdir /opt/meta2
cd /opt/meta2
mkdir geth
cp <node-key-file> geth/nodekey
mkdir keystore
chmod 0600 keystore
cp <account-files> keystore/
tar xvfz <dir>/metadium.tar.gz
# copy config.json and MetadiumAdmin.js from the first node
bin/gmeth.sh init config.json <port>
bin/gmeth.sh start

Once these node are setup, the first node will automatically connect and chain synchronization will follow.

### Metadium Info

bin/gmeth.sh console
...
> admin.metadiumInfo

### Starting & Stopping Nodes

To start or stop a single node

bin/gmet.sh start
bin/gmet.sh stop

To start or stop multiple nodes

export NODES="<host1> <dir1> <host2> <dir2>"
bin/gmeth.sh start-nodes
bin/gmeth.sh stop-nodes

## Go Ethereum

Official golang implementation of the Ethereum protocol.
Expand Down
4 changes: 4 additions & 0 deletions accounts/keystore/key.go
Expand Up @@ -166,6 +166,10 @@ func newKey(rand io.Reader) (*Key, error) {
return newKeyFromECDSA(privateKeyECDSA), nil
}

func NewKey(rand io.Reader) (*Key, error) {
return newKey(rand)
}

func storeNewKey(ks keyStore, rand io.Reader, auth string) (*Key, accounts.Account, error) {
key, err := newKey(rand)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions cmd/geth/main.go
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
metadium "github.com/ethereum/go-ethereum/metadium"
"gopkg.in/urfave/cli.v1"
)

Expand Down Expand Up @@ -153,6 +154,15 @@ var (
utils.MetricsInfluxDBPasswordFlag,
utils.MetricsInfluxDBHostTagFlag,
}

metadiumFlags = []cli.Flag{
utils.ConsensusMethodFlag,
utils.MetadiumAbiFlag,
utils.FixedDifficultyFlag,
utils.FixedGasLimitFlag,
utils.MaxIdleBlockInterval,
utils.BlocksPerTurn,
}
)

func init() {
Expand Down Expand Up @@ -187,6 +197,7 @@ func init() {
licenseCommand,
// See config.go
dumpConfigCommand,
metadiumCommand,
}
sort.Sort(cli.CommandsByName(app.Commands))

Expand All @@ -196,6 +207,7 @@ func init() {
app.Flags = append(app.Flags, debug.Flags...)
app.Flags = append(app.Flags, whisperFlags...)
app.Flags = append(app.Flags, metricsFlags...)
app.Flags = append(app.Flags, metadiumFlags...)

app.Before = func(ctx *cli.Context) error {
runtime.GOMAXPROCS(runtime.NumCPU())
Expand Down Expand Up @@ -261,6 +273,9 @@ func startNode(ctx *cli.Context, stack *node.Node) {
// Start up the node itself
utils.StartNode(stack)

// Start metadium admin
metadium.StartAdmin(stack, ctx.GlobalString(utils.MetadiumAbiFlag.Name))

// Unlock any account specifically requested
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)

Expand Down

0 comments on commit e73296e

Please sign in to comment.