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

Bump cosmos sdk #173

Merged
merged 4 commits into from
Oct 24, 2022
Merged

Bump cosmos sdk #173

merged 4 commits into from
Oct 24, 2022

Conversation

KonradStaniec
Copy link
Collaborator

  • bumps cosmos-sdk to 0.46.3 (and some transitive deps)

Copy link
Member

@SebastianElvis SebastianElvis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite challenging to dodge all the weird errors when bumping a dependency with breaking changes! I only have minor comments and it would be good to see others' comments as well.

app/app.go Outdated

// ... other modules keepers
// TODO: Create IBC keeper

// register the proposal types
govRouter := govtypes.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
// Register the proposal types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks duplicated

@@ -241,7 +377,7 @@ func createIncrementalAccounts(accNum int) []sdk.AccAddress {
buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") // base address string

buffer.WriteString(numString) // adding on final two digits to make addresses unique
res, _ := sdk.AccAddressFromHex(buffer.String())
res, _ := sdk.AccAddressFromHexUnsafe(buffer.String())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this function not safe anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from godoc:

// Note, this function is considered unsafe as it may produce an AccAddress from
// otherwise invalid input, such as a transaction hash. Please use
// AccAddressFromBech32.

so presumably it was always unsafe but now it is clear from name, and when accepting addresses from outside we should always use bech32. As this is used only in test it is probably fine here.

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work! Few comments

app/app.go Outdated
@@ -272,7 +276,7 @@ func NewBabylonApp(

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms,
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cosmos (ref). Should we use bbn here?

@@ -489,7 +504,7 @@ func NewBabylonApp(
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we set types.InflationCalculationFn to nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because this inflation calculation to:
ic = types.DefaultInflationCalculationFn

underneath. This should be fine for now as we do not have any tokenomics design yet.

@@ -707,7 +726,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to be using both govv1 and govv1beta1 in this module. Should we use the same version?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's because some parts which were in beta1 has been deprecated but we keep using it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I mostly got that from cosmos-sdk simapp which I treat as kinda blueprint how default wiring should looks like.

My guess simapp not migrated fully to govv1 therefore it is in this half finished state. I will leave some todo here to investigate if there is better way to wire it 👍

@@ -20,5 +20,5 @@ func TestInitCmd(t *testing.T) {
fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json, in case it already exists
})

require.NoError(t, svrcmd.Execute(rootCmd, app.DefaultNodeHome))
require.NoError(t, svrcmd.Execute(rootCmd, "", app.DefaultNodeHome))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we set "" as the envPrefix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from cosmos-sdk 0.46 is possible to have custom prefix for env variables - cosmos/cosmos-sdk#10950, for now we do not have such prefix therefore we can have it as empty string.

I will extract this to separate variable and add comment about it.

@@ -1,13 +1,16 @@
package types_test

import (
sdkmath "cosmossdk.io/math"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use github.com/cosmos-sdk/cosmos/math?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because from 0.46 the old github.com/cosmos-sdk/cosmos/math module was deleted, and separae go module under path "cosmossdk.io/math" was released. Now it is separate library with sperate go.mod file.

Copy link
Contributor

@gitferry gitferry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Thanks for making the bump happen! Only left some tiny comments

// Setup initializes a new BabylonApp. A Nop logger is set in BabylonApp.
func Setup(isCheckTx bool) *BabylonApp {
app, genesisState := setup(!isCheckTx, 5)
// NewSimappWithCustomOptions initializes a new SimApp with custom options.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// NewSimappWithCustomOptions initializes a new SimApp with custom options.
// NewBabyblonAppWithCustomOptions initializes a new BabylonApp with custom options.

@@ -58,7 +59,8 @@ func InitPrivSigner(clientCtx client.Context, nodeDir string, kr keyring.Keyring
}
wrappedPV := privval.LoadOrGenWrappedFilePV(pvKeyFile, pvStateFile)

// setup client context
// TODO this should probably not create separate config, but rahter accept it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice findings! Could you please create an issue for this just in case we forget it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 46 to 48
if err != nil {
t.Fatalf("Failed to start test")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err != nil {
t.Fatalf("Failed to start test")
}
require.NoError(t, err)

@@ -24,7 +24,7 @@ var (
)

func TestDecodeStore(t *testing.T) {
cdc := simapp.MakeTestEncodingConfig().Marshaler
cdc := simapp.MakeTestEncodingConfig().Codec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cdc := simapp.MakeTestEncodingConfig().Codec
cdc := app.MakeTestEncodingConfig().Codec

Making this suggestion is because maybe we should use "github.com/babylonchain/babylon/app" other than simapp

"github.com/cosmos/cosmos-sdk/crypto/keyring"
ksec256k1 "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What "ksec"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was supposed to be abbreviation from keysec256k1 which makes little sense thinking about it now. I will leave import as secp256k1

Comment on lines 95 to 109
privVal := datagen.NewPV()
pubKey, err := privVal.GetPubKey()
require.NoError(t, err)
// create validator set with single validator
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

// generate genesis account
senderPrivKey := ksec256k1.GenPrivKey()

acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs of this method could mention that there will only be a single validator with some hardcoded amount of tokens, explain what the purpose of it all is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will add comment.

It is necessary to create at least one validator here as from cosmos-sdk 0.46, there must be at least one validator in validator set during InitGenesis call (which is called when starting babylonapp)

Jailed: false,
Status: stakingtypes.Bonded,
Tokens: bondAmt,
DelegatorShares: sdk.OneDec(),
Copy link
Contributor

@aakoshh aakoshh Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does everyone has "1 base denom unit"?

I that every validator delegating to themselves? Does it represent 100%?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm from what I understand from godoc:
delegator_shares defines total shares issued to a validator's delegators.
it is not percentage but rather total value of delgated shares.

From what I understand from cosmos-sdk docs this is something which eases up accounting when slashing.

### Delegator Shares

When one Delegates tokens to a Validator they are issued a number of delegator shares based on a
dynamic exchange rate, calculated as follows from the total number of tokens delegated to the
validator and the number of shares issued so far:

`Shares per Token = validator.TotalShares() / validator.Tokens()`

Only the number of shares received is stored on the DelegationEntry. When a delegator then
Undelegates, the token amount they receive is calculated from the number of shares they currently
hold and the inverse exchange rate:

`Tokens per Share = validator.Tokens() / validatorShares()`

These `Shares` are simply an accounting mechanism. They are not a fungible asset. The reason for
this mechanism is to simplify the accounting around slashing. Rather than iteratively slashing the
tokens of every delegation entry, instead the Validators total bonded tokens can be slashed,
effectively reducing the value of each issued delegator share.

From code perspective, it cannot be set to 0 as then InitGenesis will fail with:

ok  	github.com/babylonchain/babylon/x/btclightclient/types	(cached)
--- FAIL: TestInitGenesis (0.01s)
panic: division by zero [recovered]
	panic: division by zero

Comment on lines 207 to 208
// Setup initializes a new SimApp. A Nop logger is set in SimApp.
func Setup(t *testing.T, isCheckTx bool) *BabylonApp {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Setup initializes a new SimApp. A Nop logger is set in SimApp.
func Setup(t *testing.T, isCheckTx bool) *BabylonApp {
// Setup initializes a new BabylonApp. A Nop logger is set in BabylonApp.
func Setup(t *testing.T, isCheckTx bool) *BabylonApp {

I don't see this "Nop logger" in the setup, but the fact a random single validator will be used would be worth mentioning.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea noop logger is used really deep in call stack in setup function.

func setup(withGenesis bool, invCheckPeriod uint) (*BabylonApp, GenesisState) {
	db := dbm.NewMemDB()
	encCdc := MakeTestEncodingConfig()
	privSigner, err := SetupPrivSigner()
	if err != nil {
		panic(err)
	}
	app := NewBabylonApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, privSigner, EmptyAppOptions{})

@@ -15,7 +15,7 @@ func main() {
params.SetAddressPrefixes()
rootCmd, _ := cmd.NewRootCmd()

if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil {
if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of passing these "" around there there could be some const field in the module that makes this readable, like const EmptyWhateverParameter = "" and you could pass that.

Comment on lines 61 to 65
// r
// / \
// d1 d2
// / \ / \
// l1 l2 l3 l4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right.

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're awesome, LGTM!

@KonradStaniec KonradStaniec merged commit ca4f893 into main Oct 24, 2022
@KonradStaniec
Copy link
Collaborator Author

Merged, to avoid blocking repo for too long. If there are other comments or remarks, please leave them here and ping me on slack, I can introduce them in separate pr :)

@KonradStaniec KonradStaniec deleted the bump-cosmos-sdk branch March 17, 2023 10:58
vitsalis pushed a commit that referenced this pull request Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants