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

chore: Add balance check before inserting MsgWrappedCreateValidator into the epoch message queue #318

Merged
merged 2 commits into from
Feb 23, 2023

Conversation

gitferry
Copy link
Contributor

This PR fixed #317 and added relevant fuzz tests. To support the check of delegator balance, this PR added the BankKeeper to the epoching module

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.

Lgtm! Just some minor comments

@@ -5,6 +5,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/babylonchain/babylon/x/epoching/types"
)

// CheckMsgCreateValidator performs stateless checks on a given `MsgCreateValidator` message
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// CheckMsgCreateValidator performs stateless checks on a given `MsgCreateValidator` message
// CheckMsgCreateValidator performs checks on a given `MsgCreateValidator` message

Now this function does not only perform stateless checks anymore

return err
}

balance := k.bk.GetBalance(ctx, delegatorAddr, msg.Value.GetDenom())
if msg.Value.IsGTE(balance) {
return types.ErrInsufficientBalance
Copy link
Member

Choose a reason for hiding this comment

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

Is there any error that we can reuse from x/bank module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. I suppose it's up to the user of the bank module to determine whether the balance is sufficient or not

@@ -346,7 +350,7 @@ func NewBabylonApp(

// NOTE: the epoching module has to be set before the chekpointing module, as the checkpointing module will have access to the epoching module
epochingKeeper := epochingkeeper.NewKeeper(
appCodec, keys[epochingtypes.StoreKey], keys[epochingtypes.StoreKey], app.GetSubspace(epochingtypes.ModuleName), &app.StakingKeeper,
appCodec, keys[epochingtypes.StoreKey], keys[epochingtypes.StoreKey], app.GetSubspace(epochingtypes.ModuleName), app.BankKeeper, &app.StakingKeeper,
Copy link
Member

Choose a reason for hiding this comment

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

Should this be

Suggested change
appCodec, keys[epochingtypes.StoreKey], keys[epochingtypes.StoreKey], app.GetSubspace(epochingtypes.ModuleName), app.BankKeeper, &app.StakingKeeper,
appCodec, keys[epochingtypes.StoreKey], keys[epochingtypes.StoreKey], app.GetSubspace(epochingtypes.ModuleName), &app.BankKeeper, &app.StakingKeeper,

?

Copy link
Contributor Author

@gitferry gitferry Feb 23, 2023

Choose a reason for hiding this comment

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

I was wondering the same thing that why the staking keeper is passed as a pointer but not the bank keeper, but it turned out it should be as it is in the PR...

@@ -97,6 +98,43 @@ func FuzzWrappedCreateValidator_InsufficientTokens(f *testing.F) {
})
}

// FuzzWrappedCreateValidator_InsufficientBalance tests adding a new validator
// but the delegator has insufficient balance to perform delegating
func FuzzWrappedCreateValidator_InsufficientBalance(f *testing.F) {
Copy link
Member

Choose a reason for hiding this comment

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

Another thing we can do is to move tests on MsgCreateValidator from Cosmos SDK to here. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely agree but I couldn't find any tests in cosmos-sdk that do stateful tests like us 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.

Nice work!

@gitferry gitferry merged commit bdebe17 into dev Feb 23, 2023
@gitferry gitferry deleted the add-balance-check branch February 23, 2023 11:00
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.

Lack of balance check before inserting MsgWrappedCreateValidator into the message queue
3 participants