Skip to content

Commit

Permalink
Merge pull request #48 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v0.0.4
  • Loading branch information
danil-lashin authored Jun 26, 2018
2 parents 8e95058 + 8695c5f commit b26bc0f
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 59 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# Changelog

## 0.0.4

*June 24th, 2018*

BREAKING CHANGES

- [validators] Reward now is payed each 12 blocks
- [validators] Change total "validators' power" to 100 mln
- [tendermint] Switched to v0.21.0
- [testnet] New testnet chain id
- [api] Changed */api/block* response format

IMPROVEMENT

- [docs] Updated docs

BUG FIXES

- [validators] Fixed issue with incorrect pubkey length
10 changes: 5 additions & 5 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,9 @@
branch = "master"
name = "github.com/syndtr/goleveldb"

[[constraint]]
name = "github.com/tendermint/abci"
version = "0.11.0"

[[constraint]]
name = "github.com/tendermint/tendermint"
version = "0.20.0"

[[constraint]]
name = "github.com/tendermint/tmlibs"
version = "0.8.4"
version = "0.21.0"

[[constraint]]
branch = "v2"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $ docker-compose up
You'll need **go** [installed](https://golang.org/doc/install) and the required
[environment variables set](https://github.com/tendermint/tendermint/wiki/Setting-GOPATH)

1. Install [Tendermint 0.20](https://github.com/tendermint/tendermint/blob/master/docs/install.rst)
1. Install [Tendermint 0.21.0](https://github.com/tendermint/tendermint/blob/master/docs/install.rst)

2. Clone Minter to your machine
```bash
Expand Down
57 changes: 56 additions & 1 deletion api/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,39 @@ package api

import (
"encoding/json"
"fmt"
"github.com/MinterTeam/minter-go-node/core/transaction"
"github.com/gorilla/mux"
"github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/common"
"math/big"
"net/http"
"strconv"
"time"
)

type BlockResponse struct {
Hash common.HexBytes `json:"hash"`
Height int64 `json:"height"`
Time time.Time `json:"time"`
NumTxs int64 `json:"num_txs"`
TotalTxs int64 `json:"total_txs"`
Transactions []BlockTransactionResponse `json:"transactions"`
Precommits []*types.Vote `json:"precommits"`
}

type BlockTransactionResponse struct {
Hash string `json:"hash"`
From string `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *big.Int `json:"gasPrice"`
Type byte `json:"type"`
Data transaction.Data `json:"data"`
Payload []byte `json:"payload"`
ServiceData []byte `json:"serviceData"`
}

func Block(w http.ResponseWriter, r *http.Request) {

vars := mux.Vars(r)
Expand All @@ -31,9 +58,37 @@ func Block(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(http.StatusOK)

txs := make([]BlockTransactionResponse, len(result.Block.Data.Txs))

for i, rawTx := range result.Block.Data.Txs {
tx, _ := transaction.DecodeFromBytes(rawTx)
sender, _ := tx.Sender()

txs[i] = BlockTransactionResponse{
Hash: fmt.Sprintf("Mt%x", types.Tx(rawTx).Hash()),
From: sender.String(),
Nonce: tx.Nonce,
GasPrice: tx.GasPrice,
Type: tx.Type,
Data: tx.GetDecodedData(),
Payload: tx.Payload,
ServiceData: tx.ServiceData,
}
}

response := BlockResponse{
Hash: result.Block.Hash(),
Height: result.Block.Height,
Time: result.Block.Time,
NumTxs: result.Block.NumTxs,
TotalTxs: result.Block.TotalTxs,
Precommits: result.Block.LastCommit.Precommits,
Transactions: txs,
}

err = json.NewEncoder(w).Encode(Response{
Code: 0,
Result: result,
Result: response,
})

if err != nil {
Expand Down
13 changes: 1 addition & 12 deletions api/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,18 @@ import (
"encoding/hex"
"encoding/json"
"github.com/gorilla/mux"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/common"
"net/http"
"strings"
)

type ResTx struct {
Hash common.HexBytes `json:"hash"`
Height int64 `json:"height"`
Index uint32 `json:"index"`
TxResult abci.ResponseDeliverTx `json:"tx_result"`
Tx types.Tx `json:"tx"`
Proof types.TxProof `json:"proof,omitempty"`
}

func Transaction(w http.ResponseWriter, r *http.Request) {

vars := mux.Vars(r)
hash := strings.TrimRight(vars["hash"], "Mt")
decoded, err := hex.DecodeString(hash)

result := new(ResTx)
result := new(types.TxResult)
_, err = client.Call("tx", map[string]interface{}{
"hash": decoded,
}, result)
Expand Down
3 changes: 1 addition & 2 deletions api/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func Transactions(w http.ResponseWriter, r *http.Request) {

result := make([]TransactionResponse, len(rpcResult.Txs))

for i := range rpcResult.Txs {
tx := rpcResult.Txs[i]
for i, tx := range rpcResult.Txs {
decodedTx, _ := transaction.DecodeFromBytes(tx.Tx)
sender, _ := decodedTx.Sender()

Expand Down
43 changes: 25 additions & 18 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@ import (
type Blockchain struct {
abciTypes.BaseApplication

db *mintdb.LDBDatabase
stateDeliver *state.StateDB
stateCheck *state.StateDB
rootHash types.Hash
height uint64
rewards *big.Int
activeValidators abciTypes.Validators
absentCandidates map[string]bool
db *mintdb.LDBDatabase
stateDeliver *state.StateDB
stateCheck *state.StateDB
rootHash types.Hash
height uint64
rewards *big.Int
activeValidators abciTypes.Validators
validatorsStatuses map[string]int8

BaseCoin types.CoinSymbol
}

const (
ValidatorPresent = 1
ValidatorAbsent = 2
)

var (
blockchain *Blockchain

Expand Down Expand Up @@ -101,15 +106,18 @@ func (app *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTypes.Res
app.rewards = big.NewInt(0)

// clear absent candidates
app.absentCandidates = make(map[string]bool)
app.validatorsStatuses = map[string]int8{}

// give penalty to absent validators
for _, v := range req.Validators {
pubkey := types.Pubkey(v.Validator.PubKey.Data)

if v.SignedLastBlock {
app.stateDeliver.SetValidatorPresent(v.Validator.PubKey.Data)
app.stateDeliver.SetValidatorPresent(pubkey)
app.validatorsStatuses[pubkey.String()] = ValidatorPresent
} else {
app.stateDeliver.SetValidatorAbsent(v.Validator.PubKey.Data)
app.absentCandidates[v.Validator.PubKey.String()] = true
app.stateDeliver.SetValidatorAbsent(pubkey)
app.validatorsStatuses[pubkey.String()] = ValidatorAbsent
}
}

Expand Down Expand Up @@ -154,9 +162,8 @@ func (app *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.Respons
// calculate total power of validators
totalPower := big.NewInt(0)
for _, candidate := range newCandidates {

// skip if candidate is absent
if app.absentCandidates[candidate.PubKey.String()] {
// skip if candidate is not present
if app.validatorsStatuses[candidate.PubKey.String()] != ValidatorPresent {
continue
}

Expand All @@ -166,8 +173,8 @@ func (app *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.Respons
// accumulate rewards
for _, candidate := range newCandidates {

// skip if candidate is absent
if app.absentCandidates[candidate.PubKey.String()] {
// skip if candidate is not present
if app.validatorsStatuses[candidate.PubKey.String()] != ValidatorPresent {
continue
}

Expand All @@ -182,7 +189,7 @@ func (app *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.Respons
}

// pay rewards
if app.height%5 == 0 {
if app.height%12 == 0 {
app.stateDeliver.PayRewards()
}

Expand Down
2 changes: 1 addition & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func (s *StateDB) GetValidators(count int) ([]abci.Validator, []Candidate) {
}

for i := range activeCandidates[:count] {
power := big.NewInt(0).Div(big.NewInt(0).Mul(activeCandidates[i].TotalBipStake, big.NewInt(10000)), totalPower)
power := big.NewInt(0).Div(big.NewInt(0).Mul(activeCandidates[i].TotalBipStake, big.NewInt(100000000)), totalPower)
validators[i] = abci.Ed25519Validator(activeCandidates[i].PubKey, power.Int64())
}

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.4"
services:
minter:
image: minterteam/minter:latest
image: minterteam/minter:0.0.4
command: --tendermint_addr=tcp://tendermint:46657
volumes:
- ~/.minter:/minter
Expand All @@ -15,7 +15,7 @@ services:
retries: 3
start_period: 30s
tendermint:
image: tendermint/tendermint:0.20.0
image: tendermint/tendermint:0.21.0
command: node --proxy_app=tcp://minter:46658
volumes:
- ~/.tendermint:/tendermint
Expand Down
Binary file added docs/assets/vault-candidate-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/vault-declare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 15 additions & 3 deletions docs/install.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.. _install-minter:

Install Minter
==============

There are several ways you can install Minter Blockchain node on your machine:
There are several ways you can install Minter Blockchain Testnet node on your machine:

Using Docker
------------
Expand Down Expand Up @@ -47,8 +49,8 @@ From Source
You'll need ``go`` `installed <https://golang.org/doc/install>`__ and the required
`environment variables set <https://github.com/tendermint/tendermint/wiki/Setting-GOPATH>`__

Install Tendermint 0.20
^^^^^^^^^^^^^^^^^^^^^^^
Install Tendermint 0.21.0
^^^^^^^^^^^^^^^^^^^^^^^^^
`Read official instructions <https://tendermint.readthedocs.io/en/master/install.html>`__

Clone Minter source code to your machine
Expand Down Expand Up @@ -122,3 +124,13 @@ Run Minter
:lineno-start: 13
minter
Troubleshooting
---------------

Too many open files (24)
^^^^^^^^^^^^^^^^^^^^^^^^

Tendermint sometimes is very resource-demanding in terms of "max open files limit". If your
instance is constantly shutting down after working couple minutes - try to increase open files limit:
`<https://easyengine.io/tutorials/linux/increase-open-files-limit/>`__
2 changes: 1 addition & 1 deletion docs/running-in-production.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Minimal requirements are:

- 2GB RAM
- 100GB of disk space
- 1.4 GHz CPU
- 1.4 GHz 2v CPU

SSD disks are preferable for high transaction throughput.

Expand Down
Loading

0 comments on commit b26bc0f

Please sign in to comment.