Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.21.4.rc #272

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
287 changes: 242 additions & 45 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,83 @@ package app

import (
"fmt"
"path/filepath"

"github.com/cosmos/cosmos-sdk/runtime"
"github.com/rakyll/statik/fs"

"github.com/bitsongofficial/go-bitsong/app/keepers"
"github.com/bitsongofficial/go-bitsong/app/upgrades"
v010 "github.com/bitsongofficial/go-bitsong/app/upgrades/v010"
v011 "github.com/bitsongofficial/go-bitsong/app/upgrades/v011"
v013 "github.com/bitsongofficial/go-bitsong/app/upgrades/v013"
v014 "github.com/bitsongofficial/go-bitsong/app/upgrades/v014"
v015 "github.com/bitsongofficial/go-bitsong/app/upgrades/v015"
v016 "github.com/bitsongofficial/go-bitsong/app/upgrades/v016"
v018 "github.com/bitsongofficial/go-bitsong/app/upgrades/v018"
v020 "github.com/bitsongofficial/go-bitsong/app/upgrades/v020"
v021 "github.com/bitsongofficial/go-bitsong/app/upgrades/v021"

errorsmod "cosmossdk.io/errors"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
"github.com/prometheus/client_golang/prometheus"

"io"
"net/http"
"os"
"path/filepath"
"time"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
storetypes "cosmossdk.io/store/types"
dbm "github.com/cosmos/cosmos-db"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
"cosmossdk.io/log"
"cosmossdk.io/math"
"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
tmos "github.com/cometbft/cometbft/libs/os"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
errorsmod "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

upgradetypes "cosmossdk.io/x/upgrade/types"
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/crisis"

storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ibcwasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"
wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"

"cosmossdk.io/api/cosmos/crypto/ed25519"
"github.com/cosmos/cosmos-sdk/types/bech32"

reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
"github.com/cosmos/cosmos-sdk/codec/types"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto"
"github.com/cometbft/cometbft/libs/bytes"
tmjson "github.com/cometbft/cometbft/libs/json"
tmos "github.com/cometbft/cometbft/libs/os"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
ibcwasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"

"github.com/bitsongofficial/go-bitsong/app/keepers"
"github.com/bitsongofficial/go-bitsong/app/upgrades"
v010 "github.com/bitsongofficial/go-bitsong/app/upgrades/v010"
v011 "github.com/bitsongofficial/go-bitsong/app/upgrades/v011"
v013 "github.com/bitsongofficial/go-bitsong/app/upgrades/v013"
v014 "github.com/bitsongofficial/go-bitsong/app/upgrades/v014"
v015 "github.com/bitsongofficial/go-bitsong/app/upgrades/v015"
v016 "github.com/bitsongofficial/go-bitsong/app/upgrades/v016"
v018 "github.com/bitsongofficial/go-bitsong/app/upgrades/v018"
v020 "github.com/bitsongofficial/go-bitsong/app/upgrades/v020"
v021 "github.com/bitsongofficial/go-bitsong/app/upgrades/v021"
// unnamed import of statik for swagger UI support
// _ "github.com/bitsongofficial/go-bitsong/swagger/statik"
)
Expand Down Expand Up @@ -549,6 +557,12 @@ func (app *BitsongApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.AP
// Register new tendermint queries routes from grpc-gateway.
cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register legacy and grpc-gateway routes for all modules.
module.NewBasicManagerFromManager(app.mm, nil).RegisterGRPCGatewayRoutes(
clientCtx,
apiSvr.GRPCGatewayRouter,
)

// Register new tendermint queries routes from grpc-gateway.
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

Expand Down Expand Up @@ -644,3 +658,186 @@ func getReflectionService() *runtimeservices.ReflectionService {
cachedReflectionService = reflectionSvc
return reflectionSvc
}

// source: https://github.com/osmosis-labs/osmosis/blob/7b1a78d397b632247fe83f51867f319adf3a858c/app/app.go#L786
func InitBitsongAppForTestnet(app *BitsongApp, newValAddr bytes.HexBytes, newValPubKey crypto.PubKey, newOperatorAddress, upgradeToTrigger string) *BitsongApp {

ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
pubkey := &ed25519.PubKey{Key: newValPubKey.Bytes()}
pubkeyAny, err := types.NewAnyWithValue(pubkey)
if err != nil {
tmos.Exit(err.Error())
}

// STAKING

// Create Validator struct for our new validator.
_, bz, err := bech32.DecodeAndConvert(newOperatorAddress)
if err != nil {
tmos.Exit(err.Error())
}
bech32Addr, err := bech32.ConvertAndEncode("bitsongvaloper", bz)
if err != nil {
tmos.Exit(err.Error())
}
newVal := stakingtypes.Validator{
OperatorAddress: bech32Addr,
ConsensusPubkey: pubkeyAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: math.NewInt(900000000000000),
DelegatorShares: math.LegacyMustNewDecFromStr("10000000"),
Description: stakingtypes.Description{
Moniker: "Testnet Validator",
},
Commission: stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates{
Rate: math.LegacyMustNewDecFromStr("0.05"),
MaxRate: math.LegacyMustNewDecFromStr("0.1"),
MaxChangeRate: math.LegacyMustNewDecFromStr("0.05"),
},
},
MinSelfDelegation: math.OneInt(),
}

// Remove all validators from power store
stakingKey := app.GetKey(stakingtypes.ModuleName)
stakingStore := ctx.KVStore(stakingKey)
iterator, err := app.AppKeepers.StakingKeeper.ValidatorsPowerStoreIterator(ctx)
if err != nil {
tmos.Exit(err.Error())
}
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()

// Remove all valdiators from last validators store
iterator, err = app.AppKeepers.StakingKeeper.LastValidatorsIterator(ctx)
if err != nil {
tmos.Exit(err.Error())
}
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()

// Remove all validators from validators store
iterator = storetypes.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorsKey)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()

// Remove all validators from unbonding queue
iterator = storetypes.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorQueueKey)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()

// Add our validator to power and last validators store
err = app.AppKeepers.StakingKeeper.SetValidator(ctx, newVal)
if err != nil {
tmos.Exit(err.Error())
}
err = app.AppKeepers.StakingKeeper.SetValidatorByConsAddr(ctx, newVal)
if err != nil {
tmos.Exit(err.Error())
}
err = app.AppKeepers.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)
if err != nil {
tmos.Exit(err.Error())
}
valAddr, err := sdk.ValAddressFromBech32(newVal.GetOperator())
if err != nil {
tmos.Exit(err.Error())
}
err = app.AppKeepers.StakingKeeper.SetLastValidatorPower(ctx, valAddr, 0)
if err != nil {
tmos.Exit(err.Error())
}
if err := app.AppKeepers.StakingKeeper.Hooks().AfterValidatorCreated(ctx, valAddr); err != nil {
panic(err)
}

// DISTRIBUTION
// Initialize records for this validator across all distribution stores
// Initialize records for this validator across all distribution stores
valAddr, err = sdk.ValAddressFromBech32(newVal.GetOperator())
if err != nil {
tmos.Exit(err.Error())
}
err = app.AppKeepers.DistrKeeper.SetValidatorHistoricalRewards(ctx, valAddr, 0, distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
if err != nil {
tmos.Exit(err.Error())
}
err = app.AppKeepers.DistrKeeper.SetValidatorCurrentRewards(ctx, valAddr, distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1))
if err != nil {
tmos.Exit(err.Error())
}
err = app.AppKeepers.DistrKeeper.SetValidatorAccumulatedCommission(ctx, valAddr, distrtypes.InitialValidatorAccumulatedCommission())
if err != nil {
tmos.Exit(err.Error())
}
err = app.AppKeepers.DistrKeeper.SetValidatorOutstandingRewards(ctx, valAddr, distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}})
if err != nil {
tmos.Exit(err.Error())
}

// SLASHING
// Set validator signing info for our new validator.
newConsAddr := sdk.ConsAddress(newValAddr.Bytes())
newValidatorSigningInfo := slashingtypes.ValidatorSigningInfo{
Address: newConsAddr.String(),
StartHeight: app.LastBlockHeight() - 1,
Tombstoned: false,
}
err = app.AppKeepers.SlashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newValidatorSigningInfo)
if err != nil {
tmos.Exit(err.Error())
}

//
// Optional Changes:
//

// GOV

newExpeditedVotingPeriod := time.Minute
newVotingPeriod := time.Minute * 2

govParams, err := app.AppKeepers.GovKeeper.Params.Get(ctx)
if err != nil {
tmos.Exit(err.Error())
}

govParams.ExpeditedVotingPeriod = &newExpeditedVotingPeriod
govParams.VotingPeriod = &newVotingPeriod
govParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin("ubtsg", 100000000))
govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewInt64Coin("ubtsg", 150000000))
err = app.AppKeepers.GovKeeper.Params.Set(ctx, govParams)
if err != nil {
tmos.Exit(err.Error())
}

// BANK
//

// Fund edgenet faucet

// UPGRADE
//

if upgradeToTrigger != "" {
upgradePlan := upgradetypes.Plan{
Name: upgradeToTrigger,
Height: app.LastBlockHeight() + 10,
}
err = app.AppKeepers.UpgradeKeeper.ScheduleUpgrade(ctx, upgradePlan)
if err != nil {
panic(err)
}
}
return app
}
1 change: 1 addition & 0 deletions cmd/bitsongd/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func ConfigCmd() *cobra.Command {

func runConfigCmd(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

configPath := filepath.Join(clientCtx.HomeDir, "config")

conf, err := getClientConfig(configPath, clientCtx.Viper)
Expand Down
2 changes: 1 addition & 1 deletion cmd/bitsongd/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
genesisFileDownloadFailed = true
chainID = fmt.Sprintf("test-chain-%v", tmrand.Str(6))
} else {
// Set chainID to osmosis-1 in the case of a blank chainID
// Set chainID to bitsong-2b in the case of a blank chainID
chainID = "bitsong-2b"
// We dont print the app state for mainnet nodes because it's massive
fmt.Println("Not printing app state for mainnet node due to verbosity")
Expand Down
Loading
Loading