Skip to content

Commit

Permalink
Merge pull request #243 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v0.20.0
  • Loading branch information
danil-lashin authored Apr 22, 2019
2 parents 3fdad93 + 9fbaf77 commit 1b5df2b
Show file tree
Hide file tree
Showing 14 changed files with 27,517 additions and 93 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Changelog

## 0.19.3
## 0.20.0

BUG FIXES
IMPROVEMENT

- [core] Fix set candidate remainder issue
- [core] Add remainder to total slashed
- [cmd] Add `--network-id` flag

## 0.19.2

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ install:
########################################
### Tools & dependencies

test:
CGO_ENABLED=1 CGO_LDFLAGS="-lsnappy" go test --count 1 --tags "gcc" ./...

check_tools:
@# https://stackoverflow.com/a/25668869
@echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
Expand Down
448 changes: 381 additions & 67 deletions cmd/make_genesis/data.csv

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions cmd/make_genesis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func main() {
return frozenFunds[i].Address.Compare(frozenFunds[j].Address) == -1
})

bals := makeBalances(firstBalances)
bals := makeBalances(firstBalances, secondBalances, bonusBalances, airdropBalances)

sort.SliceStable(bals, func(i, j int) bool {
return bals[i].Address.Compare(bals[j].Address) == -1
Expand All @@ -156,11 +156,11 @@ func main() {
}

appHash := [32]byte{}
networkId := "minter-test-network-38"
networkId := "minter-test-network-39"

// Compose Genesis
genesis := tmTypes.GenesisDoc{
GenesisTime: time.Date(2019, time.April, 17, 17, 0, 0, 0, time.UTC),
GenesisTime: time.Date(2019, time.April, 22, 17, 0, 0, 0, time.UTC),
ChainID: networkId,
ConsensusParams: &tmTypes.ConsensusParams{
Block: tmTypes.BlockParams{
Expand Down Expand Up @@ -231,12 +231,26 @@ func makeValidatorsAndCandidates(pubkeys []string, stake *big.Int) ([]types.Vali
return validators, candidates
}

func makeBalances(balances map[string]*big.Int) []types.Account {
func makeBalances(balances map[string]*big.Int, balances2 map[string]*big.Int, balances3 map[string]*big.Int, balances4 map[string]*big.Int) []types.Account {
totalBalances := big.NewInt(0)
for _, val := range balances {
totalBalances.Add(totalBalances, val)
}

for _, val := range balances2 {
totalBalances.Add(totalBalances, val)
}

for _, val := range balances3 {
totalBalances.Add(totalBalances, val)
}

for _, val := range balances4 {
totalBalances.Add(totalBalances, val)
}

totalBalances.Add(totalBalances, big.NewInt(4)) // first validators' stakes

balances[developers.Address.String()] = big.NewInt(0).Sub(helpers.BipToPip(big.NewInt(200000000)), totalBalances) // Developers account

var result []types.Account
Expand Down
1 change: 1 addition & 0 deletions cmd/minter/cmd/a_cmd-packr.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/minter/cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func getGenesis() (doc *tmTypes.GenesisDoc, e error) {

if !common.FileExists(genesisFile) {
box := packr.NewBox("../../../testnet")
err := common.WriteFile(genesisFile, box.Bytes(config.NetworkId+"/genesis.json"), 0644)
err := common.WriteFile(genesisFile, box.Bytes("/"+config.NetworkId+"/genesis.json"), 0644)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/minter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"github.com/MinterTeam/minter-go-node/cmd/minter/cmd"
"github.com/MinterTeam/minter-go-node/cmd/utils"
"github.com/MinterTeam/minter-go-node/config"
)

func main() {
Expand All @@ -15,6 +16,7 @@ func main() {

rootCmd.PersistentFlags().StringVar(&utils.MinterHome, "home-dir", "", "base dir (default is $HOME/.minter)")
rootCmd.PersistentFlags().StringVar(&utils.MinterConfig, "config", "", "path to config (default is $(home-dir)/config/config.toml)")
rootCmd.PersistentFlags().StringVar(&config.NetworkId, "network-id", config.DefaultNetworkId, "network id")

if err := rootCmd.Execute(); err != nil {
panic(err)
Expand Down
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
)

const (
NetworkId = "minter-test-network-38"

// LogFormatPlain is a format for colored text
LogFormatPlain = "plain"
// LogFormatJSON is a format for json output
Expand All @@ -29,6 +27,9 @@ const (
)

var (
NetworkId string
DefaultNetworkId = "minter-test-network-39"

defaultConfigFilePath = filepath.Join(defaultConfigDir, defaultConfigFileName)
defaultGenesisJSONPath = filepath.Join(defaultConfigDir, defaultGenesisJSONName)
defaultPrivValKeyPath = filepath.Join(defaultConfigDir, defaultPrivValName)
Expand Down
5 changes: 2 additions & 3 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ func (app *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.Respons
vals[i].AccumReward.Add(vals[i].AccumReward, r)
}

// add remainder to last validator
lastValidator := vals[len(vals)-1]
lastValidator.AccumReward.Add(lastValidator.AccumReward, remainder)
// add remainder to total slashed
app.stateDeliver.AddTotalSlashed(remainder)

stateValidators.SetData(vals)
app.stateDeliver.SetStateValidators(stateValidators)
Expand Down
5 changes: 3 additions & 2 deletions core/minter/minter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ func init() {
}

func initNode() {
*utils.MinterHome = os.ExpandEnv(filepath.Join("$HOME", ".minter_test"))
_ = os.RemoveAll(*utils.MinterHome)
utils.MinterHome = os.ExpandEnv(filepath.Join("$HOME", ".minter_test"))
_ = os.RemoveAll(utils.MinterHome)

if err := common.EnsureDir(utils.GetMinterHome()+"/tmdata/blockstore.db", 0777); err != nil {
log.Error(err.Error())
os.Exit(1)
}

minterCfg := config.GetConfig()
log.InitLog(minterCfg)
eventsdb.InitDB(minterCfg)
cfg = config.GetTmConfig(minterCfg)
cfg.Consensus.TimeoutPropose = 0
Expand Down
18 changes: 10 additions & 8 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,12 @@ func (s *StateDB) PayRewards() {
})
}

if s.height < 41556 {
validator.AccumReward.Set(remainder)
vals.data[i].AccumReward = big.NewInt(0)

if remainder.Cmp(big.NewInt(0)) > -1 {
s.AddTotalSlashed(remainder)
} else {
log.With("module", "main").Error("Negative remainder", "remainder", remainder.String())
}
}
}
Expand Down Expand Up @@ -1673,15 +1677,15 @@ func (s *StateDB) deleteCoin(symbol types.CoinSymbol) {
// remove coin from frozen funds
for _, height := range frozenFundsHeights {
frozenFunds := s.GetStateFrozenFunds(height)
var newFrozenFunds []FrozenFund
var newFrozenFundsList []FrozenFund
for _, ff := range frozenFunds.data.List {
if ff.Coin == symbol {
ret := formula.CalculateSaleReturn(coinToDelete.Volume(), coinToDelete.ReserveBalance(), 100, ff.Value)

coinToDelete.SubReserve(ret)
coinToDelete.SubVolume(ff.Value)

newFrozenFunds = append(newFrozenFunds, FrozenFund{
newFrozenFundsList = append(newFrozenFundsList, FrozenFund{
Address: ff.Address,
CandidateKey: ff.CandidateKey,
Coin: types.GetBaseCoin(),
Expand All @@ -1691,10 +1695,10 @@ func (s *StateDB) deleteCoin(symbol types.CoinSymbol) {
continue
}

newFrozenFunds = append(newFrozenFunds, ff)
newFrozenFundsList = append(newFrozenFundsList, ff)
}

frozenFunds.data.List = newFrozenFunds
frozenFunds.data.List = newFrozenFundsList
s.setStateFrozenFunds(frozenFunds)
s.MarkStateFrozenFundsDirty(frozenFunds.blockHeight)
}
Expand All @@ -1715,10 +1719,8 @@ func (s *StateDB) deleteCoin(symbol types.CoinSymbol) {
if stake == nil {
candidate.Stakes[j].Value = ret
candidate.Stakes[j].Coin = types.GetBaseCoin()
candidate.Stakes[j].BipValue = ret
} else {
candidate.Stakes[j].Value = big.NewInt(0)
candidate.Stakes[j].BipValue = big.NewInt(0)
stake.Value.Add(stake.Value, ret)
}
}
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/buy_coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package transaction
import (
"bytes"
"github.com/MinterTeam/go-amino"
"github.com/MinterTeam/minter-go-node/config"
"github.com/MinterTeam/minter-go-node/core/code"
"github.com/MinterTeam/minter-go-node/core/state"
"github.com/MinterTeam/minter-go-node/core/types"
"github.com/MinterTeam/minter-go-node/crypto"
"github.com/MinterTeam/minter-go-node/helpers"
"github.com/MinterTeam/minter-go-node/log"
"github.com/MinterTeam/minter-go-node/rlp"
"github.com/tendermint/tendermint/libs/db"
"math/big"
Expand All @@ -19,6 +21,10 @@ var (
cdc = amino.NewCodec()
)

func init() {
log.InitLog(config.GetConfig())
}

func getState() *state.StateDB {
s, err := state.New(0, db.NewMemDB(), false)

Expand Down
Loading

0 comments on commit 1b5df2b

Please sign in to comment.