-
Notifications
You must be signed in to change notification settings - Fork 175
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
Bump cosmos sdk #173
Conversation
KonradStaniec
commented
Oct 22, 2022
- bumps cosmos-sdk to 0.46.3 (and some transitive deps)
There was a problem hiding this 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 |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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, |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
cmd/babylond/cmd/cmd_test.go
Outdated
@@ -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)) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this 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
app/test_helpers.go
Outdated
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err != nil { | ||
t.Fatalf("Failed to start test") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
app/test_helpers.go
Outdated
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
ksec256k1 "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What "ksec"?
There was a problem hiding this comment.
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
app/test_helpers.go
Outdated
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))), | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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%?
There was a problem hiding this comment.
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
app/test_helpers.go
Outdated
// Setup initializes a new SimApp. A Nop logger is set in SimApp. | ||
func Setup(t *testing.T, isCheckTx bool) *BabylonApp { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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.
There was a problem hiding this comment.
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{})
cmd/babylond/main.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
x/btccheckpoint/types/btcutils.go
Outdated
// r | ||
// / \ | ||
// d1 d2 | ||
// / \ / \ | ||
// l1 l2 l3 l4 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
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 :) |