-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix: add extra check in vesting #15373
Changes from all commits
2ae109e
0dc4e29
16ff5b7
2349ebb
c15ae34
dda7318
4ab1005
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package posthandler | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/tx" | ||
"github.com/cosmos/cosmos-sdk/x/auth/types" | ||
|
@@ -47,5 +49,10 @@ func (d tipDecorator) transferTip(ctx sdk.Context, sdkTx sdk.Tx) error { | |
return err | ||
} | ||
|
||
return d.bankKeeper.SendCoins(ctx, tipper, tipTx.FeePayer(), tipTx.GetTip().Amount) | ||
coins := tipTx.GetTip().Amount | ||
if err := d.bankKeeper.IsSendEnabledCoins(ctx, coins...); err != nil { | ||
return fmt.Errorf("cannot tip these coins: %w", err) | ||
} | ||
Comment on lines
+53
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: Why not move the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This made sense to me, however we don't know how people are using our API and expect them to work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would imagine if a coin cannot be sent, as dictated by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree. However, we don't know if module devs made another (even though wrong) assumption. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say that breaks the safety model then and introduces a misuse of the APIs. If such a case exists, then I would introduce a new Just my 2 cents. Not a hill I'll die on, so I'm happy to approve this PR if you really thing this is the ideal approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am more afraid to break, people's code by a change of code behavior. I am going to merge it now, but this is maybe something we need to talk about. Personally, I agree with you, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM |
||
|
||
return d.bankKeeper.SendCoins(ctx, tipper, tipTx.FeePayer(), coins) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,8 +81,7 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre | |
} | ||
}() | ||
|
||
err = bk.SendCoins(ctx, from, to, msg.Amount) | ||
if err != nil { | ||
if err = bk.SendCoins(ctx, from, to, msg.Amount); err != nil { | ||
return nil, err | ||
} | ||
|
||
|
@@ -135,8 +134,7 @@ func (s msgServer) CreatePermanentLockedAccount(goCtx context.Context, msg *type | |
} | ||
}() | ||
|
||
err = bk.SendCoins(ctx, from, to, msg.Amount) | ||
if err != nil { | ||
if err = bk.SendCoins(ctx, from, to, msg.Amount); err != nil { | ||
return nil, err | ||
} | ||
|
||
|
@@ -163,11 +161,14 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type | |
} | ||
|
||
var totalCoins sdk.Coins | ||
|
||
for _, period := range msg.VestingPeriods { | ||
totalCoins = totalCoins.Add(period.Amount...) | ||
} | ||
|
||
if err := bk.IsSendEnabledCoins(ctx, totalCoins...); err != nil { | ||
return nil, err | ||
} | ||
|
||
Comment on lines
+168
to
+171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we update changelog? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but I'll do that in the backport PR, just to have on conflict less to fix in v0.47 :) |
||
baseAccount := authtypes.NewBaseAccountWithAddress(to) | ||
baseAccount = ak.NewAccount(ctx, baseAccount).(*authtypes.BaseAccount) | ||
vestingAccount := types.NewPeriodicVestingAccount(baseAccount, totalCoins.Sort(), msg.StartTime, msg.VestingPeriods) | ||
|
@@ -188,8 +189,7 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type | |
} | ||
}() | ||
|
||
err = bk.SendCoins(ctx, from, to, totalCoins) | ||
if err != nil { | ||
if err = bk.SendCoins(ctx, from, to, totalCoins); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More a question, what is the point in changing these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compacter code but that's it |
||
return nil, err | ||
} | ||
|
||
|
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 will not be backported to v0.46.