Skip to content

Commit

Permalink
Merge pull request #1110 from irisnet/upgrade/class2
Browse files Browse the repository at this point in the history
R4R: Release version 0.10.2 for the class2 (smooth) upgrade
  • Loading branch information
wukongcheng authored Jan 17, 2019
2 parents ecd7a59 + 4fccdb5 commit 7f83970
Show file tree
Hide file tree
Showing 36 changed files with 5,154 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.10.2

*January 17th, 2019*

- [iris] The proposer must deposit 30% of the mindeposit when submitting the proposal


## 0.10.1

*January 17th, 2019*
Expand Down
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/irisnet/irishub/app/protocol"
"github.com/irisnet/irishub/app/v0"
"github.com/irisnet/irishub/app/v1"
"github.com/irisnet/irishub/codec"
"github.com/irisnet/irishub/modules/auth"
sdk "github.com/irisnet/irishub/types"
Expand Down Expand Up @@ -67,7 +68,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
}

engine.Add(v0.NewProtocolV0(0, logger, protocolKeeper, sdk.InvariantLevel))
// engine.Add(v1.NewProtocolV1(1, ...))
engine.Add(v1.NewProtocolV1(1, logger, protocolKeeper, sdk.InvariantLevel))
// engine.Add(v2.NewProtocolV1(2, ...))

loaded, current := engine.LoadCurrentProtocol(app.GetKVStore(protocol.KeyMain))
Expand All @@ -81,7 +82,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio

// latest version of codec
func MakeLatestCodec() *codec.Codec {
var cdc = v0.MakeCodec() // replace with latest protocol version
var cdc = v1.MakeCodec() // replace with latest protocol version
return cdc
}

Expand Down
2 changes: 2 additions & 0 deletions app/protocol/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package protocol
import (
sdk "github.com/irisnet/irishub/types"
"fmt"
"github.com/irisnet/irishub/modules/params"
)

type ProtocolEngine struct {
Expand Down Expand Up @@ -37,6 +38,7 @@ func (pe *ProtocolEngine) LoadCurrentProtocol(kvStore sdk.KVStore) (bool, uint64
func (pe *ProtocolEngine) Activate(version uint64) bool {
p, flag := pe.protocols[version]
if flag == true {
params.ParamSetMapping = make(map[string]params.ParamSet)
p.Load()
p.Init()
pe.current = version
Expand Down
191 changes: 191 additions & 0 deletions app/v1/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
package v1

import (
"encoding/json"
"fmt"

"github.com/irisnet/irishub/app/protocol"
"github.com/irisnet/irishub/codec"
"github.com/irisnet/irishub/modules/auth"
distr "github.com/irisnet/irishub/modules/distribution"
"github.com/irisnet/irishub/app/v1/gov"
"github.com/irisnet/irishub/modules/guardian"
"github.com/irisnet/irishub/modules/mint"
"github.com/irisnet/irishub/modules/service"
"github.com/irisnet/irishub/modules/slashing"
stake "github.com/irisnet/irishub/modules/stake"
"github.com/irisnet/irishub/modules/upgrade"
sdk "github.com/irisnet/irishub/types"
tmtypes "github.com/tendermint/tendermint/types"
)

// export the state of iris for a genesis file
func (p *ProtocolV1) ExportAppStateAndValidators(ctx sdk.Context, forZeroHeight bool) (
appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {

if forZeroHeight {
p.prepForZeroHeightGenesis(ctx)
}

// iterate to get the accounts
accounts := []GenesisAccount{}
appendAccount := func(acc auth.Account) (stop bool) {
account := NewGenesisAccountI(acc)
accounts = append(accounts, account)
return false
}
p.accountMapper.IterateAccounts(ctx, appendAccount)
fileAccounts := []GenesisFileAccount{}
for _, acc := range accounts {
if acc.Coins == nil {
continue
}
var coinsString []string
for _, coin := range acc.Coins {
coinsString = append(coinsString, coin.String())
}
fileAccounts = append(fileAccounts,
GenesisFileAccount{
Address: acc.Address,
Coins: coinsString,
Sequence: acc.Sequence,
AccountNumber: acc.AccountNumber,
})
}

genState := NewGenesisFileState(
fileAccounts,
auth.ExportGenesis(ctx, p.feeKeeper),
stake.ExportGenesis(ctx, p.StakeKeeper),
mint.ExportGenesis(ctx, p.mintKeeper),
distr.ExportGenesis(ctx, p.distrKeeper),
gov.ExportGenesis(ctx, p.govKeeper),
upgrade.ExportGenesis(ctx),
service.ExportGenesis(ctx, p.serviceKeeper),
guardian.ExportGenesis(ctx, p.guardianKeeper),
slashing.ExportGenesis(ctx, p.slashingKeeper),
)
appState, err = codec.MarshalJSONIndent(p.cdc, genState)
if err != nil {
return nil, nil, err
}
sdk.MustSortJSON(appState)
validators = stake.WriteValidators(ctx, p.StakeKeeper)
return appState, validators, nil
}

// prepare for fresh start at zero height
func (p *ProtocolV1) prepForZeroHeightGenesis(ctx sdk.Context) {

/* Handle fee distribution state. */

// withdraw all delegator & validator rewards
vdiIter := func(_ int64, valInfo distr.ValidatorDistInfo) (stop bool) {
_, _, err := p.distrKeeper.WithdrawValidatorRewardsAll(ctx, valInfo.OperatorAddr)
if err != nil {
panic(err)
}
return false
}
p.distrKeeper.IterateValidatorDistInfos(ctx, vdiIter)

ddiIter := func(_ int64, distInfo distr.DelegationDistInfo) (stop bool) {
_, err := p.distrKeeper.WithdrawDelegationReward(
ctx, distInfo.DelegatorAddr, distInfo.ValOperatorAddr)
if err != nil {
panic(err)
}
return false
}
p.distrKeeper.IterateDelegationDistInfos(ctx, ddiIter)

// set distribution info withdrawal heights to 0
p.distrKeeper.IterateDelegationDistInfos(ctx, func(_ int64, delInfo distr.DelegationDistInfo) (stop bool) {
delInfo.DelPoolWithdrawalHeight = 0
p.distrKeeper.SetDelegationDistInfo(ctx, delInfo)
return false
})
p.distrKeeper.IterateValidatorDistInfos(ctx, func(_ int64, valInfo distr.ValidatorDistInfo) (stop bool) {
valInfo.FeePoolWithdrawalHeight = 0
valInfo.DelAccum.UpdateHeight = 0
p.distrKeeper.SetValidatorDistInfo(ctx, valInfo)
return false
})

// assert that the fee pool is empty
feePool := p.distrKeeper.GetFeePool(ctx)
if !feePool.TotalValAccum.Accum.IsZero() {
panic("unexpected leftover validator accum")
}
bondDenom := p.StakeKeeper.BondDenom()
if !feePool.ValPool.AmountOf(bondDenom).IsZero() {
panic(fmt.Sprintf("unexpected leftover validator pool coins: %v",
feePool.ValPool.AmountOf(bondDenom).String()))
}

// reset fee pool height, save fee pool
feePool.TotalValAccum = distr.NewTotalAccum(0)
p.distrKeeper.SetFeePool(ctx, feePool)

/* Handle stake state. */

// iterate through redelegations, reset creation height
p.StakeKeeper.IterateRedelegations(ctx, func(_ int64, red stake.Redelegation) (stop bool) {
red.CreationHeight = 0
p.StakeKeeper.SetRedelegation(ctx, red)
return false
})

// iterate through unbonding delegations, reset creation height
p.StakeKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stake.UnbondingDelegation) (stop bool) {
ubd.CreationHeight = 0
p.StakeKeeper.SetUnbondingDelegation(ctx, ubd)
return false
})
// Iterate through validators by power descending, reset bond and unbonding heights
store := ctx.KVStore(protocol.KeyStake)
iter := sdk.KVStoreReversePrefixIterator(store, stake.ValidatorsKey)
defer iter.Close()
counter := int16(0)
var valConsAddrs []sdk.ConsAddress
for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := p.StakeKeeper.GetValidator(ctx, addr)
if !found {
panic("expected validator, not found")
}
validator.BondHeight = 0
validator.UnbondingHeight = 0
valConsAddrs = append(valConsAddrs, validator.ConsAddress())
p.StakeKeeper.SetValidator(ctx, validator)
counter++
}

/* Handle slashing state. */

// remove all existing slashing periods and recreate one for each validator
p.slashingKeeper.DeleteValidatorSlashingPeriods(ctx)
for _, valConsAddr := range valConsAddrs {
sp := slashing.ValidatorSlashingPeriod{
ValidatorAddr: valConsAddr,
StartHeight: 0,
EndHeight: 0,
SlashedSoFar: sdk.ZeroDec(),
}
p.slashingKeeper.SetValidatorSlashingPeriod(ctx, sp)
}

// reset start height on signing infos
p.slashingKeeper.IterateValidatorSigningInfos(ctx, func(addr sdk.ConsAddress, info slashing.ValidatorSigningInfo) (stop bool) {
info.StartHeight = 0
p.slashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
return false
})

/* Handle gov state. */

gov.PrepForZeroHeightGenesis(ctx, p.govKeeper)

/* Handle service state. */
service.PrepForZeroHeightGenesis(ctx, p.serviceKeeper)
}
Loading

0 comments on commit 7f83970

Please sign in to comment.