diff --git a/go.mod b/go.mod index ff463418a..e11e6bcf5 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,7 @@ require ( github.com/rs/cors v1.9.0 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect github.com/zondax/hid v0.9.1 // indirect - golang.org/x/net v0.22.0 // indirect + golang.org/x/net v0.23.0 // indirect ) require ( diff --git a/go.sum b/go.sum index bb081e135..05e975d6e 100644 --- a/go.sum +++ b/go.sum @@ -1698,6 +1698,8 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= diff --git a/x/assets/types/genesis.go b/x/assets/types/genesis.go index 415517439..7b675b44d 100644 --- a/x/assets/types/genesis.go +++ b/x/assets/types/genesis.go @@ -200,12 +200,13 @@ func (gs GenesisState) Validate() error { assetID, info, ) } - // check that the withdrawable amount is not greater than the total deposit amount. - // since withdrawable amount should be less than or equal to the amount deposited. - if info.WithdrawableAmount.GT(info.TotalDepositAmount) { + // check that the withdrawable amount and the deposited amount are equal. + // this is because this module's genesis only sets up free deposits. + // the delegation module bonds them, thereby altering the withdrawable amount. + if !info.WithdrawableAmount.Equal(info.TotalDepositAmount) { return errorsmod.Wrapf( ErrInvalidGenesisData, - "withdrawable amount exceeds total deposit amount for %s: %+v", + "withdrawable amount is not equal to total deposit amount for %s: %+v", assetID, info, ) } diff --git a/x/assets/types/genesis_test.go b/x/assets/types/genesis_test.go index eb7d3741a..12ab18cfa 100644 --- a/x/assets/types/genesis_test.go +++ b/x/assets/types/genesis_test.go @@ -67,7 +67,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { AssetID: assetID, Info: types.StakerAssetInfo{ TotalDepositAmount: math.NewInt(100), - WithdrawableAmount: math.NewInt(0), + WithdrawableAmount: math.NewInt(100), WaitUnbondingAmount: math.NewInt(0), }, }, @@ -493,9 +493,12 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { malleate: func(gs *types.GenesisState) { gs.Deposits[0].Deposits[0].Info.TotalDepositAmount = stakingInfo.AssetBasicInfo.TotalSupply.Add(math.NewInt(1)) + gs.Deposits[0].Deposits[0].Info.WithdrawableAmount = + stakingInfo.AssetBasicInfo.TotalSupply.Add(math.NewInt(1)) }, unmalleate: func(gs *types.GenesisState) { gs.Deposits[0].Deposits[0].Info.TotalDepositAmount = math.NewInt(100) + gs.Deposits[0].Deposits[0].Info.WithdrawableAmount = math.NewInt(100) }, }, { diff --git a/x/operator/keeper/consensus_keys.go b/x/operator/keeper/consensus_keys.go index 2dd7420a4..2701744e9 100644 --- a/x/operator/keeper/consensus_keys.go +++ b/x/operator/keeper/consensus_keys.go @@ -31,13 +31,26 @@ func (k *Keeper) SetOperatorConsKeyForChainID( chainID string, // should be tm-ed25519 consKey *tmprotocrypto.PublicKey, +) error { + return k.setOperatorConsKeyForChainID(ctx, opAccAddr, chainID, consKey, false) +} + +// setOperatorConsKeyForChainID is the private version of SetOperatorConsKeyForChainID. +// it is used with a boolean flag to indicate that the call is from genesis. +// if so, operator freeze status is not checked and hooks are not called. +func (k *Keeper) setOperatorConsKeyForChainID( + ctx sdk.Context, + opAccAddr sdk.AccAddress, + chainID string, + consKey *tmprotocrypto.PublicKey, + genesis bool, ) error { // check if we are an operator if !k.IsOperator(ctx, opAccAddr) { return delegationtypes.ErrOperatorNotExist } // check for slashing - if k.slashKeeper.IsOperatorFrozen(ctx, opAccAddr) { + if !genesis && k.slashKeeper.IsOperatorFrozen(ctx, opAccAddr) { return delegationtypes.ErrOperatorIsFrozen } // check if the chain id is valid @@ -102,21 +115,23 @@ func (k *Keeper) SetOperatorConsKeyForChainID( } } } - k.setOperatorConsKeyForChainID(ctx, opAccAddr, consAddr, chainID, bz) - if found { - if !alreadyRecorded { - k.Hooks().AfterOperatorKeyReplacement(ctx, opAccAddr, prevKey, consKey, chainID) + k.setOperatorConsKeyForChainIDUnchecked(ctx, opAccAddr, consAddr, chainID, bz) + if !genesis { + if found { + if !alreadyRecorded { + k.Hooks().AfterOperatorKeyReplacement(ctx, opAccAddr, prevKey, consKey, chainID) + } + } else { + k.Hooks().AfterOperatorOptIn(ctx, opAccAddr, chainID, consKey) } - } else { - k.Hooks().AfterOperatorOptIn(ctx, opAccAddr, chainID, consKey) } return nil } -// setOperatorConsKeyForChainID is the internal private version. It performs +// setOperatorConsKeyForChainIDUnchecked is the internal private version. It performs // no error checking of the input. The caller must do the error checking // and then call this function. -func (k Keeper) setOperatorConsKeyForChainID( +func (k Keeper) setOperatorConsKeyForChainIDUnchecked( ctx sdk.Context, opAccAddr sdk.AccAddress, consAddr sdk.ConsAddress, chainID string, bz []byte, ) { diff --git a/x/operator/keeper/genesis.go b/x/operator/keeper/genesis.go index c30f0e424..60319883b 100644 --- a/x/operator/keeper/genesis.go +++ b/x/operator/keeper/genesis.go @@ -26,8 +26,8 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) []abci.Va // #nosec G703 // already validated key, _ := types.HexStringToPubKey(detail.ConsensusKey) // then set pub key - if err := k.SetOperatorConsKeyForChainID( - ctx, operatorAddr, detail.ChainID, key, + if err := k.setOperatorConsKeyForChainID( + ctx, operatorAddr, detail.ChainID, key, true, ); err != nil { panic(err) } diff --git a/x/operator/keeper/operator.go b/x/operator/keeper/operator.go index 9ef38595a..8d366d5e6 100644 --- a/x/operator/keeper/operator.go +++ b/x/operator/keeper/operator.go @@ -25,7 +25,7 @@ func (k *Keeper) SetOperatorInfo(ctx sdk.Context, addr string, info *operatortyp // key := common.HexToAddress(incentive.Contract) bz := k.cdc.MustMarshal(info) - + // TODO: check about client chain registration for earnings addresses provided? store.Set(opAccAddr, bz) return nil }