Skip to content

Commit

Permalink
Merge pull request #250 from MinterTeam/dev
Browse files Browse the repository at this point in the history
Mainnet!
  • Loading branch information
danil-lashin authored May 14, 2019
2 parents 499f35b + 8aa11ce commit 1ff6ea8
Show file tree
Hide file tree
Showing 30 changed files with 35,852 additions and 71 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ _NOTE: This is alpha software. Please contact us if you intend to run it in prod

You can get official installation instructions in our [docs](https://docs.minter.network/#section/Install-Minter).

1. Download Minter
1. Install LevelDB: https://github.com/google/leveldb

2. Download Minter

Get [latest binary build](https://github.com/MinterTeam/minter-go-node/releases) suitable for your architecture and unpack it to desired folder.

2. Run Minter Node
3. Run Minter Node

```bash
./minter
./minter node
```

3. Use GUI
4. Use GUI

Open http://localhost:3000/ in local browser to see node’s GUI.

Expand Down
7 changes: 4 additions & 3 deletions cmd/make_genesis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func main() {
validators, candidates := makeValidatorsAndCandidates(validatorsPubKeys, big.NewInt(1))

jsonBytes, err := cdc.MarshalJSONIndent(types.AppState{
Note: "Minter, the Internet of Money (IoM)\nBIP Initial Price – $0.32\nSo Long, and Thanks for All the Fish!",
Validators: validators,
Candidates: candidates,
Accounts: bals,
Expand All @@ -158,11 +159,11 @@ func main() {
}

appHash := [32]byte{}
networkId := "minter-test-network-40"
networkId := "minter-mainnet-1"

// Compose Genesis
genesis := tmTypes.GenesisDoc{
GenesisTime: time.Date(2019, time.May, 12, 11, 0, 0, 0, time.UTC),
GenesisTime: time.Date(2019, time.May, 15, 15, 5, 0, 0, time.UTC),
ChainID: networkId,
ConsensusParams: &tmTypes.ConsensusParams{
Block: tmTypes.BlockParams{
Expand All @@ -186,7 +187,7 @@ func main() {
panic(err)
}

if err := genesis.SaveAs("testnet/" + networkId + "/genesis.json"); err != nil {
if err := genesis.SaveAs("mainnet/" + networkId + "/genesis.json"); err != nil {
panic(err)
}
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/minter/cmd/a_cmd-packr.go

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions cmd/minter/cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,13 @@ func getGenesis() (doc *tmTypes.GenesisDoc, e error) {
genesisFile := utils.GetMinterHome() + "/config/genesis.json"

if !common.FileExists(genesisFile) {
box := packr.NewBox("../../../testnet")
err := common.WriteFile(genesisFile, box.Bytes("/"+config.NetworkId+"/genesis.json"), 0644)
box := packr.NewBox("../../../mainnet/")
bytes, err := box.MustBytes(config.NetworkId + "/genesis.json")
if err != nil {
panic(err)
}

if err := common.WriteFile(genesisFile, bytes, 0644); err != nil {
return nil, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (

var (
NetworkId string
DefaultNetworkId = "minter-test-network-40"
DefaultNetworkId = "minter-mainnet-1"

defaultConfigFilePath = filepath.Join(defaultConfigDir, defaultConfigFileName)
defaultGenesisJSONPath = filepath.Join(defaultConfigDir, defaultGenesisJSONName)
Expand Down
16 changes: 7 additions & 9 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/tendermint/tendermint/crypto/encoding/amino"
"github.com/tendermint/tendermint/libs/db"
tmNode "github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/rpc/client"
types2 "github.com/tendermint/tendermint/types"
"math/big"
"sync"
Expand Down Expand Up @@ -142,6 +141,13 @@ func (app *Blockchain) InitChain(req abciTypes.RequestInitChain) abciTypes.Respo

// Signals the beginning of a block.
func (app *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTypes.ResponseBeginBlock {
// Check invariants
if app.height%1 == 0 {
if err := state.NewForCheckFromDeliver(app.stateCheck).CheckForInvariants(); err != nil {
log.With("module", "invariants").Error("Invariants error", "msg", err.Error(), "height", app.height)
}
}

app.wg.Add(1)
if atomic.LoadUint32(&app.stopped) == 1 {
panic("Application stopped")
Expand Down Expand Up @@ -425,14 +431,6 @@ func (app *Blockchain) Commit() abciTypes.ResponseCommit {
// Clear mempool
app.currentMempool = sync.Map{}

// Check invariants
if app.height%720 == 0 && app.tmNode != nil {
genesis, _ := client.NewLocal(app.tmNode).Genesis()
if err := state.NewForCheckFromDeliver(app.stateCheck).CheckForInvariants(genesis.Genesis); err != nil {
log.With("module", "invariants").Error("Invariants error", "msg", err.Error(), "height", app.height)
}
}

// Releasing wg
app.wg.Done()

Expand Down
13 changes: 9 additions & 4 deletions core/minter/minter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestSendTx(t *testing.T) {

tx := transaction.Transaction{
Nonce: nonce,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasPrice: 1,
GasCoin: types.GetBaseCoin(),
Type: transaction.TypeSend,
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestSmallStakeValidator(t *testing.T) {

tx := transaction.Transaction{
Nonce: nonce,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasPrice: 1,
GasCoin: types.GetBaseCoin(),
Type: transaction.TypeDeclareCandidacy,
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestSmallStakeValidator(t *testing.T) {
tx = transaction.Transaction{
Nonce: nonce,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: types.GetBaseCoin(),
Type: transaction.TypeSetCandidateOnline,
Data: encodedData,
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestSmallStakeValidator(t *testing.T) {
tx = transaction.Transaction{
Nonce: nonce,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: types.GetBaseCoin(),
Type: transaction.TypeSetCandidateOnline,
Data: encodedData,
Expand Down Expand Up @@ -421,6 +421,11 @@ func getGenesis() (*types2.GenesisDoc, error) {
return nil, err
}

genesisFile := utils.GetMinterHome() + "/config/genesis.json"
if err := genesisDoc.SaveAs(genesisFile); err != nil {
panic(err)
}

return &genesisDoc, nil
}

Expand Down
21 changes: 19 additions & 2 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import (
"encoding/hex"
"fmt"
"github.com/MinterTeam/go-amino"
"github.com/MinterTeam/minter-go-node/cmd/utils"
"github.com/MinterTeam/minter-go-node/core/rewards"
"github.com/MinterTeam/minter-go-node/core/types"
"github.com/MinterTeam/minter-go-node/core/validators"
"github.com/MinterTeam/minter-go-node/eventsdb"
"github.com/MinterTeam/minter-go-node/eventsdb/events"
"github.com/MinterTeam/minter-go-node/formula"
"github.com/MinterTeam/minter-go-node/helpers"
"github.com/MinterTeam/minter-go-node/log"
"github.com/MinterTeam/minter-go-node/rlp"
dbm "github.com/tendermint/tendermint/libs/db"
tmTypes "github.com/tendermint/tendermint/types"
"math/big"
"os"
"sync"

"bytes"
Expand Down Expand Up @@ -1959,9 +1962,15 @@ func (s *StateDB) Import(appState types.AppState) {
}
}

func (s *StateDB) CheckForInvariants(genesis *tmTypes.GenesisDoc) error {
func (s *StateDB) CheckForInvariants() error {
height := s.height

genesisFile := utils.GetMinterHome() + "/config/genesis.json"
genesis, err := tmTypes.GenesisDocFromFile(genesisFile)
if err != nil {
panic(err)
}

var genesisState types.AppState
_ = amino.UnmarshalJSON(genesis.AppState, &genesisState)

Expand Down Expand Up @@ -2081,9 +2090,17 @@ func (s *StateDB) CheckForInvariants(genesis *tmTypes.GenesisDoc) error {
predictedBasecoinVolume.Add(predictedBasecoinVolume, GenesisAlloc)

delta := big.NewInt(0).Sub(predictedBasecoinVolume, totalBasecoinVolume)

if delta.Cmp(big.NewInt(0)) != 0 {
return fmt.Errorf("smth wrong with total base coins in blockchain. Expected total supply to be %s, got %s",
e := fmt.Errorf("smth wrong with total base coins in blockchain. Expected total supply to be %s, got %s",
predictedBasecoinVolume, totalBasecoinVolume)

if delta.Cmp(helpers.BipToPip(big.NewInt(1000))) == 1 {
println(fmt.Sprintf("CRITICAL INVARIANTS FAILURE: %s", e))
os.Exit(1)
}

return e
}

for coin, volume := range coinSupplies {
Expand Down
2 changes: 1 addition & 1 deletion core/state/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestStateDB_Commit(t *testing.T) {
t.Errorf("Version should be 1, got %d", version)
}

targetHash, _ := hex.DecodeString("c5ffd98054e8ecb08c3f6b64f0c91dc629a664eca07b62782317d4760868f623")
targetHash, _ := hex.DecodeString("466e1c2aca40c0db51e54f6d87224c2eede66b26b96fa1f4c762d66a3d93e637,")
if !bytes.Equal(hash, targetHash) {
t.Errorf("Hash should be %x, got %x", targetHash, hash)
}
Expand Down
18 changes: 9 additions & 9 deletions core/transaction/buy_coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestBuyCoinTx(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: coin,
Type: TypeBuyCoin,
Data: encodedData,
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestBuyCoinTxInsufficientFunds(t *testing.T) {
Nonce: 1,
GasPrice: 1,

ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: coin,
Type: TypeBuyCoin,
Data: encodedData,
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestBuyCoinTxEqualCoins(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: types.GetBaseCoin(),
Type: TypeBuyCoin,
Data: encodedData,
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestBuyCoinTxNotExistsBuyCoin(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: types.GetBaseCoin(),
Type: TypeBuyCoin,
Data: encodedData,
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestBuyCoinTxNotExistsSellCoin(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: types.GetBaseCoin(),
Type: TypeBuyCoin,
Data: encodedData,
Expand Down Expand Up @@ -321,7 +321,7 @@ func TestBuyCoinTxNotExistsGasCoin(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: types.CoinSymbol{},
Type: TypeBuyCoin,
Data: encodedData,
Expand Down Expand Up @@ -371,7 +371,7 @@ func TestBuyCoinTxNotGasCoin(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: getTestCoinSymbol(),
Type: TypeBuyCoin,
Data: encodedData,
Expand All @@ -396,7 +396,7 @@ func TestBuyCoinTxNotGasCoin(t *testing.T) {
}

func TestBuyCoinTxJSON(t *testing.T) {
out := []byte("{\"coin_to_buy\":\"MNT\",\"value_to_buy\":\"1\",\"coin_to_sell\":\"TEST\",\"maximum_value_to_sell\":\"1\"}")
out := []byte("{\"coin_to_buy\":\"BIP\",\"value_to_buy\":\"1\",\"coin_to_sell\":\"TEST\",\"maximum_value_to_sell\":\"1\"}")

buyCoinData := BuyCoinData{
CoinToBuy: types.GetBaseCoin(),
Expand All @@ -412,6 +412,6 @@ func TestBuyCoinTxJSON(t *testing.T) {
}

if !bytes.Equal(out, result) {
t.Fatalf("Error: result is not correct %s", string(result))
t.Fatalf("Error: result is not correct %s, expected %s", string(result), string(out))
}
}
2 changes: 1 addition & 1 deletion core/transaction/create_coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestCreateCoinTx(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: coin,
Type: TypeCreateCoin,
Data: encodedData,
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/create_multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func (data CreateMultisigData) TotalSpend(tx *Transaction, context *state.StateD
}

func (data CreateMultisigData) BasicCheck(tx *Transaction, context *state.StateDB) *Response {
if true {
return &Response{
Code: code.DecodeError,
Log: fmt.Sprintf("multisig transactions are not supported yet")}
}

if len(data.Weights) > 32 {
return &Response{
Code: code.TooLargeOwnersList,
Expand Down
6 changes: 5 additions & 1 deletion core/transaction/create_multisig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
)

func TestCreateMultisigTx(t *testing.T) {
if true {
return
}

cState := getState()

privateKey, _ := crypto.GenerateKey()
Expand Down Expand Up @@ -46,7 +50,7 @@ func TestCreateMultisigTx(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: coin,
Type: TypeCreateMultisig,
Data: encodedData,
Expand Down
2 changes: 1 addition & 1 deletion core/transaction/declare_candidacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestDeclareCandidacyTx(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: coin,
Type: TypeDeclareCandidacy,
Data: encodedData,
Expand Down
4 changes: 4 additions & 0 deletions core/transaction/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (decoder *Decoder) DecodeFromBytes(buf []byte) (*Transaction, error) {
switch tx.SignatureType {
case SigTypeMulti:
{
if true {
return nil, errors.New("multisig transactions are not supported yet")
}

tx.multisig = &SignatureMulti{}
if err := rlp.DecodeBytes(tx.SignatureData, tx.multisig); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion core/transaction/delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestDelegateTx(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: coin,
Type: TypeDelegate,
Data: encodedData,
Expand Down
2 changes: 1 addition & 1 deletion core/transaction/edit_candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestEditCandidateTx(t *testing.T) {
tx := Transaction{
Nonce: 1,
GasPrice: 1,
ChainID: types.ChainTestnet,
ChainID: types.CurrentChainID,
GasCoin: coin,
Type: TypeEditCandidate,
Data: encodedData,
Expand Down
Loading

0 comments on commit 1ff6ea8

Please sign in to comment.