Skip to content

Commit

Permalink
Upgrade: V0.20.2 (#252)
Browse files Browse the repository at this point in the history
* add stargate queries to wasmOpts

* log upgrade

* move govPropHandlers to modules file, rename AppModuleBasic type, only include impacted delegators in upgrade, ugrade go simulation test layout

* remove printing log file

* e2e localbitsong without state

* add upgrade test for v020

* bump

* clean e2e repo format

---------

Co-authored-by: hard-nett <[email protected]>
Co-authored-by: simi <[email protected]>
  • Loading branch information
3 people authored Dec 27, 2024
1 parent 57cd7be commit e49371a
Show file tree
Hide file tree
Showing 47 changed files with 680 additions and 247 deletions.
36 changes: 6 additions & 30 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import (
"github.com/cosmos/cosmos-sdk/store/streaming"
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"

Expand All @@ -47,7 +45,7 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
fantokenclient "github.com/bitsongofficial/go-bitsong/x/fantoken/client"

"github.com/cosmos/cosmos-sdk/baseapp"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand All @@ -64,7 +62,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

Expand All @@ -88,14 +85,8 @@ var (
EnableSpecificProposals = ""

Upgrades = []upgrades.Upgrade{
v010.Upgrade,
v011.Upgrade,
v013.Upgrade,
v014.Upgrade,
v015.Upgrade,
v016.Upgrade,
v018.Upgrade,
v020.Upgrade,
v010.Upgrade, v011.Upgrade, v013.Upgrade, v014.Upgrade,
v015.Upgrade, v016.Upgrade, v018.Upgrade, v020.Upgrade,
}
)

Expand Down Expand Up @@ -160,21 +151,6 @@ func GetWasmOpts(appOpts servertypes.AppOptions) []wasm.Option {
return wasmOpts
}

func getGovProposalHandlers() []govclient.ProposalHandler {
var govProposalHandlers []govclient.ProposalHandler

govProposalHandlers = append(govProposalHandlers,
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
fantokenclient.ProposalHandler,
)

return govProposalHandlers
}

var (
_ CosmosApp = (*BitsongApp)(nil)
_ servertypes.Application = (*BitsongApp)(nil)
Expand Down Expand Up @@ -496,8 +472,8 @@ func (app *BitsongApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.AP
// Register new tendermint queries routes from grpc-gateway.
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register legacy and grpc-gateway routes for all modules.
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register legacy and grpc-gateway routes for all application modules.
AppModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register new tendermint queries routes from grpc-gateway.
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
Expand Down
2 changes: 1 addition & 1 deletion app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func DefaultConfig() network.Config {
InterfaceRegistry: encCfg.InterfaceRegistry,
AccountRetriever: authtypes.AccountRetriever{},
AppConstructor: NewAppConstructor(encCfg),
GenesisState: ModuleBasics.DefaultGenesis(encCfg.Marshaler),
GenesisState: AppModuleBasics.DefaultGenesis(encCfg.Marshaler),
TimeoutCommit: 1 * time.Second / 2,
ChainID: "bitsong-test-1",
NumValidators: 1,
Expand Down
4 changes: 2 additions & 2 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
AppModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
AppModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
44 changes: 38 additions & 6 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ import (
// object provided to it during init.
type GenesisState map[string]json.RawMessage

// NewDefaultGenesisState generates the default state for bitsong.
func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState {
return ModuleBasics.DefaultGenesis(cdc)
}

func NewDefaultGenesisStateWithCodec(cdc codec.JSONCodec) GenesisState {
gen := ModuleBasics.DefaultGenesis(cdc)
gen := AppModuleBasics.DefaultGenesis(cdc)

// here we override wasm config to make it permissioned by default
wasmGen := wasmtypes.GenesisState{
Expand Down Expand Up @@ -84,3 +79,40 @@ func NewDefaultGenesisStateWithCodec(cdc codec.JSONCodec) GenesisState {
// ),
// }
// }

var defaultGenesisState GenesisState = nil

// NewDefaultGenesisState generates the default state for bitsong.
func NewDefaultGenesisState() GenesisState {
if defaultGenesisState != nil {
return cloneGenesisState(defaultGenesisState)
}
encCfg := MakeEncodingConfig()
gen := AppModuleBasics.DefaultGenesis(encCfg.Marshaler)

// here we override wasm config to make it permissioned by default
wasmGen := wasmtypes.GenesisState{
Params: wasmtypes.Params{
CodeUploadAccess: wasmtypes.AllowNobody,
InstantiateDefaultPermission: wasmtypes.AccessTypeEverybody,
},
}
gen[wasmtypes.ModuleName] = encCfg.Marshaler.MustMarshalJSON(&wasmGen)
return gen
}

// CloneGenesisState creates a deep clone of the provided GenesisState.
func cloneGenesisState(original GenesisState) GenesisState {
clone := make(GenesisState, len(original))
for key, value := range original {
// Make a copy of the json.RawMessage (which is a []byte slice).
copiedValue := make(json.RawMessage, len(value))
copy(copiedValue, value)
if len(copiedValue) == 0 {
// If the value is empty, set it to nil.
copiedValue = nil
}
clone[key] = copiedValue
}
return clone
}
18 changes: 15 additions & 3 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
encparams "github.com/bitsongofficial/go-bitsong/app/params"
"github.com/bitsongofficial/go-bitsong/x/fantoken"
fantokenclient "github.com/bitsongofficial/go-bitsong/x/fantoken/client"
fantokentypes "github.com/bitsongofficial/go-bitsong/x/fantoken/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand All @@ -30,38 +31,49 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
packetforward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
)

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// AppModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
var ModuleBasics = module.NewBasicManager(
var AppModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(getGovProposalHandlers()),
gov.NewAppModuleBasic([]govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
fantokenclient.ProposalHandler,
}),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
Expand Down
68 changes: 41 additions & 27 deletions app/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ const (
// EmptyBaseAppOptions is a stub implementing AppOptions
type EmptyBaseAppOptions struct{}

// EmptyAppOptions is a stub implementing AppOptions
type EmptyAppOptions struct{}

// Get implements AppOptions
func (ao EmptyBaseAppOptions) Get(_ string) interface{} {
return nil
}

// Get implements AppOptions
func (ao EmptyAppOptions) Get(o string) interface{} { return nil }

var DefaultConsensusParams = &tmproto.ConsensusParams{
Block: &tmproto.BlockParams{
MaxBytes: 200000,
Expand Down Expand Up @@ -87,16 +93,10 @@ func Setup(t *testing.T) *BitsongApp {
}

app := SetupWithGenesisAccounts(t, valSet, []authtypes.GenesisAccount{acc}, balance)

return app
}

// EmptyAppOptions is a stub implementing AppOptions
type EmptyAppOptions struct{}

// Get implements AppOptions
func (ao EmptyAppOptions) Get(o string) interface{} { return nil }

// Setup node for testing simulation
func setup(t *testing.T, withGenesis bool, opts ...wasmkeeper.Option) (*BitsongApp, GenesisState) {
db := dbm.NewMemDB()
nodeHome := t.TempDir()
Expand All @@ -111,9 +111,9 @@ func setup(t *testing.T, withGenesis bool, opts ...wasmkeeper.Option) (*BitsongA
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[flags.FlagHome] = nodeHome // ensure unique folder

app := NewBitsongApp(log.NewNopLogger(), db, nil, true, EmptyAppOptions{}, opts, bam.SetChainID("testing"), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2}))
app := NewBitsongApp(log.NewNopLogger(), db, nil, true, appOptions, opts, bam.SetChainID("testing"), bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2}))
if withGenesis {
return app, NewDefaultGenesisState(app.AppCodec())
return app, NewDefaultGenesisState()
}
return app, GenesisState{}
}
Expand All @@ -124,7 +124,8 @@ func SetupWithGenesisAccounts(t *testing.T, valSet *tmtypes.ValidatorSet, genAcc
t.Helper()

btsgApp, genesisState := setup(t, true)
genesisState = genesisStateWithValSet(t, btsgApp, genesisState, valSet, genAccs, balances...)

genesisState = GenesisStateWithValSet(t, btsgApp, genesisState, valSet, genAccs, balances...)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)
Expand Down Expand Up @@ -215,7 +216,7 @@ func CheckBalance(t *testing.T, app *BitsongApp, addr sdk.AccAddress, balances s
require.True(t, balances.IsEqual(app.AppKeepers.BankKeeper.GetAllBalances(ctxCheck, addr)))
}

func genesisStateWithValSet(t *testing.T,
func GenesisStateWithValSet(t *testing.T,
app *BitsongApp, genesisState GenesisState,
valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount,
balances ...banktypes.Balance,
Expand All @@ -230,19 +231,19 @@ func genesisStateWithValSet(t *testing.T,
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))

bondAmt := sdk.DefaultPowerReduction
initValPowers := []abci.ValidatorUpdate{}

for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
require.NoError(t, err)
pkAny, err := codectypes.NewAnyWithValue(pk)
require.NoError(t, err)
pk, _ := cryptocodec.FromTmPubKeyInterface(val.PubKey)
pkAny, _ := codectypes.NewAnyWithValue(pk)
validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: bondAmt,
DelegatorShares: math.LegacyOneDec(),
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: bondAmt,
DelegatorShares: math.LegacyOneDec(),
// DelegatorShares: math.LegacyOneDec().MulTruncate(math.LegacyOneDec().Sub(math.LegacyNewDecWithPrec(1, 3))), // 1 % slash
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Expand All @@ -252,6 +253,13 @@ func genesisStateWithValSet(t *testing.T,
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), math.LegacyOneDec()))

// add initial validator powers so consumer InitGenesis runs correctly
pub, _ := val.ToProto()
initValPowers = append(initValPowers, abci.ValidatorUpdate{
Power: val.VotingPower,
PubKey: pub.PubKey,
})

}

defaultStParams := stakingtypes.DefaultParams()
Expand All @@ -268,21 +276,27 @@ func genesisStateWithValSet(t *testing.T,
stakingGenesis := stakingtypes.NewGenesisState(stParams, validators, delegations)
genesisState[stakingtypes.ModuleName] = codec.MustMarshalJSON(stakingGenesis)

// add bonded amount to bonded pool module account
balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: sdk.Coins{sdk.NewCoin(appparams.DefaultBondDenom, bondAmt.MulRaw(int64(len(valSet.Validators))))},
})

totalSupply := sdk.NewCoins()
for _, b := range balances {
// add genesis acc tokens to total supply
totalSupply = totalSupply.Add(b.Coins...)
}

for range delegations {
// add delegated tokens to total supply
totalSupply = totalSupply.Add(sdk.NewCoin(appparams.DefaultBondDenom, bondAmt))
}

// add bonded amount to bonded pool module account
balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: sdk.Coins{sdk.NewCoin(appparams.DefaultBondDenom, bondAmt.MulRaw(int64(len(valSet.Validators))))},
})

// update total supply
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}, []banktypes.SendEnabled{})
genesisState[banktypes.ModuleName] = codec.MustMarshalJSON(bankGenesis)

// println("genesisStateWithValSet bankState:", string(genesisState[banktypes.ModuleName]))

return genesisState
Expand Down
Loading

0 comments on commit e49371a

Please sign in to comment.