Skip to content

Commit

Permalink
Merge pull request #789 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v3.1.1
  • Loading branch information
Klimov Sergey authored Apr 18, 2022
2 parents 8566f58 + 8641711 commit 43f4f18
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 30 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [v3.1.1](https://github.com/MinterTeam/minter-go-node/tree/v3.1.1)

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.1.0...v3.1.1)

### Fixed

- Find coins with last symbol `-`
- Accrual of rewards x3 with `GetAccumReward == 0`

## [v3.1.0](https://github.com/MinterTeam/minter-go-node/tree/v3.1.0)

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.0.3...v3.1.0)
Expand Down
25 changes: 23 additions & 2 deletions api/v2/service/candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ func (s *Service) Candidate(ctx context.Context, req *pb.CandidateRequest) (*pb.
return nil, status.Error(codes.NotFound, err.Error())
}

if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
return nil, timeoutStatus.Err()
}

if req.Height != 0 {
cState.Candidates().LoadCandidates()
cState.Validators().LoadValidators()
}

if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
return nil, timeoutStatus.Err()
}

candidate := cState.Candidates().GetCandidate(pubkey)
Expand All @@ -45,15 +54,23 @@ func (s *Service) Candidate(ctx context.Context, req *pb.CandidateRequest) (*pb.
cState.Candidates().LoadStakesOfCandidate(pubkey)
}

result := makeResponseCandidate(cState, candidate, true, req.NotShowStakes)
if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
return nil, timeoutStatus.Err()
}

result := s.makeResponseCandidate(ctx, cState, candidate, true, req.NotShowStakes)
if cState.Validators().GetByPublicKey(candidate.PubKey) != nil {
result.Validator = true
}

if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
return nil, timeoutStatus.Err()
}

return result, nil
}

func makeResponseCandidate(state *state.CheckState, c *candidates.Candidate, includeStakes, NotShowStakes bool) *pb.CandidateResponse {
func (s *Service) makeResponseCandidate(ctx context.Context, state *state.CheckState, c *candidates.Candidate, includeStakes, NotShowStakes bool) *pb.CandidateResponse {
candidate := &pb.CandidateResponse{
RewardAddress: c.RewardAddress.String(),
OwnerAddress: c.OwnerAddress.String(),
Expand All @@ -75,6 +92,10 @@ func makeResponseCandidate(state *state.CheckState, c *candidates.Candidate, inc
candidate.Stakes = make([]*pb.CandidateResponse_Stake, 0, usedSlots)
}
for i, stake := range stakes {
if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
return candidate
}

if !NotShowStakes {
candidate.Stakes = append(candidate.Stakes, &pb.CandidateResponse_Stake{
Owner: stake.Owner.String(),
Expand Down
15 changes: 14 additions & 1 deletion api/v2/service/candidates.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ func (s *Service) Candidates(ctx context.Context, req *pb.CandidatesRequest) (*p
return nil, status.Error(codes.NotFound, err.Error())
}

if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
return nil, timeoutStatus.Err()
}

if req.Height != 0 {
cState.Candidates().LoadCandidates()
cState.Validators().LoadValidators()
}

if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
return nil, timeoutStatus.Err()
}

candidates := cState.Candidates().GetCandidates()
Expand Down Expand Up @@ -46,9 +55,13 @@ func (s *Service) Candidates(ctx context.Context, req *pb.CandidatesRequest) (*p
cState.Candidates().LoadStakesOfCandidate(candidate.PubKey)
}

responseCandidate := makeResponseCandidate(cState, candidate, req.IncludeStakes, req.NotShowStakes)
responseCandidate := s.makeResponseCandidate(ctx, cState, candidate, req.IncludeStakes, req.NotShowStakes)
responseCandidate.Validator = isValidator

if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
return nil, timeoutStatus.Err()
}

response.Candidates = append(response.Candidates, responseCandidate)
}

Expand Down
3 changes: 3 additions & 0 deletions api/v2/service/coin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func (s *Service) CoinInfo(ctx context.Context, req *pb.CoinInfoRequest) (*pb.Co
return nil, status.Error(codes.NotFound, err.Error())
}

if coinLen := len(req.Symbol); coinLen == 0 || req.Symbol[coinLen-1] == '-' {
return nil, s.createError(status.New(codes.NotFound, "Coin not found"), transaction.EncodeError(code.NewCoinNotExists(req.Symbol, "")))
}
coin := cState.Coins().GetCoinBySymbol(types.StrToCoinBaseSymbol(req.Symbol), types.GetVersionFromSymbol(req.Symbol))
if coin == nil {
return nil, s.createError(status.New(codes.NotFound, "Coin not found"), transaction.EncodeError(code.NewCoinNotExists(req.Symbol, "")))
Expand Down
6 changes: 6 additions & 0 deletions api/v2/service/estimate_coin_buy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func (s *Service) EstimateCoinBuy(ctx context.Context, req *pb.EstimateCoinBuyRe

var coinToBuy types.CoinID
if req.GetCoinToBuy() != "" {
if coinLen := len(req.GetCoinToBuy()); coinLen == 0 || req.GetCoinToBuy()[coinLen-1] == '-' {
return nil, s.createError(status.New(codes.NotFound, "Coin not found"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToBuy(), "")))
}
symbol := cState.Coins().GetCoinBySymbol(types.StrToCoinBaseSymbol(req.GetCoinToBuy()), types.GetVersionFromSymbol(req.GetCoinToBuy()))
if symbol == nil {
return nil, s.createError(status.New(codes.NotFound, "Coin to sell not exists"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToBuy(), "")))
Expand All @@ -50,6 +53,9 @@ func (s *Service) EstimateCoinBuy(ctx context.Context, req *pb.EstimateCoinBuyRe

var coinToSell types.CoinID
if req.GetCoinToSell() != "" {
if coinLen := len(req.GetCoinToSell()); coinLen == 0 || req.GetCoinToSell()[coinLen-1] == '-' {
return nil, s.createError(status.New(codes.NotFound, "Coin not found"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToSell(), "")))
}
symbol := cState.Coins().GetCoinBySymbol(types.StrToCoinBaseSymbol(req.GetCoinToSell()), types.GetVersionFromSymbol(req.GetCoinToSell()))
if symbol == nil {
return nil, s.createError(status.New(codes.NotFound, "Coin to sell not exists"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToSell(), "")))
Expand Down
6 changes: 6 additions & 0 deletions api/v2/service/estimate_coin_sell.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func (s *Service) EstimateCoinSell(ctx context.Context, req *pb.EstimateCoinSell

var coinToBuy types.CoinID
if req.GetCoinToBuy() != "" {
if coinLen := len(req.GetCoinToBuy()); coinLen == 0 || req.GetCoinToBuy()[coinLen-1] == '-' {
return nil, s.createError(status.New(codes.NotFound, "Coin not found"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToBuy(), "")))
}
symbol := cState.Coins().GetCoinBySymbol(types.StrToCoinBaseSymbol(req.GetCoinToBuy()), types.GetVersionFromSymbol(req.GetCoinToBuy()))
if symbol == nil {
return nil, s.createError(status.New(codes.NotFound, "Coin to buy not exists"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToBuy(), "")))
Expand All @@ -49,6 +52,9 @@ func (s *Service) EstimateCoinSell(ctx context.Context, req *pb.EstimateCoinSell

var coinToSell types.CoinID
if req.GetCoinToSell() != "" {
if coinLen := len(req.GetCoinToSell()); coinLen == 0 || req.GetCoinToSell()[coinLen-1] == '-' {
return nil, s.createError(status.New(codes.NotFound, "Coin not found"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToSell(), "")))
}
symbol := cState.Coins().GetCoinBySymbol(types.StrToCoinBaseSymbol(req.GetCoinToSell()), types.GetVersionFromSymbol(req.GetCoinToSell()))
if symbol == nil {
return nil, s.createError(status.New(codes.NotFound, "Coin to sell not exists"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToSell(), "")))
Expand Down
6 changes: 6 additions & 0 deletions api/v2/service/estimate_coin_sell_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func (s *Service) EstimateCoinSellAll(ctx context.Context, req *pb.EstimateCoinS

var coinToBuy types.CoinID
if req.GetCoinToBuy() != "" {
if coinLen := len(req.GetCoinToBuy()); coinLen == 0 || req.GetCoinToBuy()[coinLen-1] == '-' {
return nil, s.createError(status.New(codes.NotFound, "Coin not found"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToBuy(), "")))
}
symbol := cState.Coins().GetCoinBySymbol(types.StrToCoinBaseSymbol(req.GetCoinToBuy()), types.GetVersionFromSymbol(req.GetCoinToBuy()))
if symbol == nil {
return nil, s.createError(status.New(codes.NotFound, "Coin to buy not exists"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToBuy(), "")))
Expand All @@ -46,6 +49,9 @@ func (s *Service) EstimateCoinSellAll(ctx context.Context, req *pb.EstimateCoinS

var coinToSell types.CoinID
if req.GetCoinToSell() != "" {
if coinLen := len(req.GetCoinToSell()); coinLen == 0 || req.GetCoinToSell()[coinLen-1] == '-' {
return nil, s.createError(status.New(codes.NotFound, "Coin not found"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToSell(), "")))
}
symbol := cState.Coins().GetCoinBySymbol(types.StrToCoinBaseSymbol(req.GetCoinToSell()), types.GetVersionFromSymbol(req.GetCoinToSell()))
if symbol == nil {
return nil, s.createError(status.New(codes.NotFound, "Coin to sell not exists"), transaction.EncodeError(code.NewCoinNotExists(req.GetCoinToSell(), "")))
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func DefaultConfig() *Config {
//cfg.StateSync.RPCServers = []string{"sync-test.minter.network:26657", "sync104.minter.su:26657", "state-test.minter.network:26657"}
cfg.StateSync.RPCServers = []string{"state-test.minter.network:26657", "sync-test.minter.network:26657", "sync101.minter.su:26657"}

cfg.StateSync.TrustHeight = 10197600
cfg.StateSync.TrustHash = "BE035F6C00320FBB76D8B3C427891A03D46B3443A9E4309D777ABC4EAB4FDFCC"
cfg.StateSync.TrustHeight = 10309900
cfg.StateSync.TrustHash = "95AB9C70AE7B98F955CB05039A3B2A442F3DA4F95FF82B027A8144AE0E15C6BF"
cfg.StateSync.TrustPeriod = time.Hour * 8760

return cfg
Expand Down
2 changes: 0 additions & 2 deletions coreV2/minter/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ func (blockchain *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTy
blockchain.stateDeliver.App.SetReward(big.NewInt(0), big.NewInt(0))
}

//}

blockchain.StatisticData().PushStartBlock(&statistics.StartRequest{Height: int64(height), Now: time.Now(), HeaderTime: req.Header.Time})

// compute max gas
Expand Down
1 change: 1 addition & 0 deletions coreV2/state/bus/candidates.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Candidates interface {
SetOffline(types.Pubkey)
GetCandidate(types.Pubkey) *Candidate
GetCandidateByTendermintAddress(types.TmAddress) *Candidate
TotalStakes() *big.Int
}

type Stake struct {
Expand Down
4 changes: 4 additions & 0 deletions coreV2/state/candidates/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (b *Bus) SetOffline(pubkey types.Pubkey) {
b.candidates.SetOffline(pubkey)
}

func (b *Bus) TotalStakes() *big.Int {
return b.candidates.TotalStakes()
}

// GetCandidateByTendermintAddress finds and returns candidate with given tendermint-address
func (b *Bus) GetCandidateByTendermintAddress(tmAddress types.TmAddress) *bus.Candidate {
candidate := b.candidates.GetCandidateByTendermintAddress(tmAddress)
Expand Down
74 changes: 52 additions & 22 deletions coreV2/state/validators/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ func (v *Validators) Count() int {
return len(v.list)
}

func (v *Validators) TotalStakes() *big.Int {
vals := v.GetValidators()

v.lock.Lock()
defer v.lock.Unlock()

totalStakes := big.NewInt(0)
for _, validator := range vals {
totalStakes.Add(totalStakes, validator.GetTotalBipStake())
}
return totalStakes
}

func (v *Validators) getOrderedRemoved() []types.Pubkey {
keys := make([]types.Pubkey, 0, len(v.removed))
for k := range v.removed {
Expand Down Expand Up @@ -427,8 +440,16 @@ func (v *Validators) PayRewardsV4(height uint64, period int64) (moreRewards *big
calcReward, safeReward := v.bus.App().Reward()
var totalAccumRewards = big.NewInt(0)
for _, validator := range vals {
totalAccumRewards = big.NewInt(0).Add(totalAccumRewards, validator.GetAccumReward())
totalAccumRewards = totalAccumRewards.Add(totalAccumRewards, validator.GetAccumReward())
}

var totalStakes = big.NewInt(0)
if totalAccumRewards.Sign() != 1 {
for _, validator := range vals {
totalStakes = totalStakes.Add(totalStakes, validator.GetTotalBipStake())
}
}

for _, validator := range vals {
candidate := v.bus.Candidates().GetCandidate(validator.PubKey)

Expand Down Expand Up @@ -505,27 +526,36 @@ func (v *Validators) PayRewardsV4(height uint64, period int64) (moreRewards *big

safeRewardVariable := big.NewInt(0).Set(reward)
if validator.bus.Accounts().IsX3Mining(stake.Owner, height) {

safeRewards := big.NewInt(0).Mul(safeReward, big.NewInt(period))
safeRewards.Mul(safeRewards, stake.BipValue)
safeRewards.Mul(safeRewards, big.NewInt(3))
safeRewards.Mul(safeRewards, validator.GetAccumReward())
safeRewards.Div(safeRewards, validator.GetTotalBipStake())
safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100)))
safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100)))
safeRewards.Div(safeRewards, totalAccumRewards)

calcRewards := big.NewInt(0).Mul(calcReward, big.NewInt(period))
calcRewards.Mul(calcRewards, stake.BipValue)
calcRewards.Mul(calcRewards, validator.GetAccumReward())
calcRewards.Div(calcRewards, validator.GetTotalBipStake())
calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100)))
calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100)))
calcRewards.Div(calcRewards, totalAccumRewards)

feeRewards := big.NewInt(0).Sub(reward, calcRewards)

safeRewardVariable.Set(big.NewInt(0).Add(safeRewards, feeRewards))
if totalAccumRewards.Sign() == 1 && validator.GetAccumReward().Sign() == 1 {
safeRewards := big.NewInt(0).Mul(safeReward, big.NewInt(period))
safeRewards.Mul(safeRewards, stake.BipValue)
safeRewards.Mul(safeRewards, big.NewInt(3))
safeRewards.Mul(safeRewards, validator.GetAccumReward())
safeRewards.Div(safeRewards, validator.GetTotalBipStake())
safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100)))
safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100)))
safeRewards.Div(safeRewards, totalAccumRewards)

calcRewards := big.NewInt(0).Mul(calcReward, big.NewInt(period))
calcRewards.Mul(calcRewards, stake.BipValue)
calcRewards.Mul(calcRewards, validator.GetAccumReward())
calcRewards.Div(calcRewards, validator.GetTotalBipStake())
calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100)))
calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100)))
calcRewards.Div(calcRewards, totalAccumRewards)

feeRewards := big.NewInt(0).Sub(reward, calcRewards)
safeRewardVariable.Set(big.NewInt(0).Add(safeRewards, feeRewards))
} else if totalAccumRewards.Sign() != 1 && validator.GetAccumReward().Sign() != 1 {
safeRewards := big.NewInt(0).Mul(safeReward, big.NewInt(period))
safeRewards.Mul(safeRewards, stake.BipValue)
safeRewards.Mul(safeRewards, big.NewInt(3))
safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100)))
safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100)))
safeRewards.Div(safeRewards, totalStakes)

safeRewardVariable.Set(safeRewards)
}

if safeRewardVariable.Sign() < 1 {
continue
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const (

var (
// Version must be a string because scripts like dist.sh read this file.
Version = "3.1.0"
Version = "3.1.1"

// GitCommit is the current HEAD set using ldflags.
GitCommit string
Expand Down

0 comments on commit 43f4f18

Please sign in to comment.