-
Notifications
You must be signed in to change notification settings - Fork 170
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
Conversation
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.
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 |
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.
// 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 |
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.
Is there any error that we can reuse from x/bank
module?
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.
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, |
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.
Should this be
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, |
?
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 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) { |
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.
Another thing we can do is to move tests on MsgCreateValidator
from Cosmos SDK to here. Wdyt?
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 definitely agree but I couldn't find any tests in cosmos-sdk that do stateful tests like us 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.
Nice work!
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