fix: adding check for blocked addresses before escrowing fees#1890
fix: adding check for blocked addresses before escrowing fees#1890crodriguezvega merged 9 commits intomainfrom
Conversation
testing/simapp/app.go
Outdated
| // do not add the following modules to blocked addresses | ||
| // this is only used for testing | ||
| if acc == ibcmock.ModuleName { | ||
| if acc == ibcmock.ModuleName || acc == distrtypes.ModuleName { |
There was a problem hiding this comment.
This is pretty hacky I just left it in for discussion. I'm guessing we don't want to unblock the distribution module?
We have the following test case. We ensure a non-blocked module account can escrow fees.
When I try to use the mock module account I get an AuthKeeper error saying the account doesn't exist. I'm not sure why exactly. I've left the test case as is using the distribution module account for now.
cc: @colin-axner
There was a problem hiding this comment.
I was looking at the test case "refund account is a module account" and trying to use ibcmock.ModuleName instead of disttypes.ModuleName:
"refund account is module account",
func() {
msg.Signer = suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(disttypes.ModuleName).String()
expPacketFee := types.NewPacketFee(fee, msg.Signer, nil)
expFeesInEscrow = []types.PacketFee{expPacketFee}
},
true,
The account does not exist error is being returned from here in escrow.go. And interestingly if we actually use AccountKeeper.GetModuleAccount() we will not encounter that error as it calls directly into GetModuleAccountAndPermissions() which creates and sets the account in x/auth.
This differs from GetModuleAddress which just checks the permAddrs map created on keeper initialisation.
It's definitely pretty ambiguous as to what constitutes a blocked address and what doesn't. Without this logical OR added for distrtypes.ModuleName it is and will be in the blockedAddrs map in x/bank. However, its usage in x/distribution when for example, withdrawing delegation rewards uses SendCoinsFromModuleToAccount which only checks that the recipientAddr is not a blocked address.
When I use the following in the malleate() func, we don't fail on the account not existing but instead fail with an "insufficient funds" error.
moduleAcc := suite.chainA.GetSimApp().AccountKeeper.GetModuleAccount(suite.chainA.GetContext(), ibcmock.ModuleName)
msg.Signer = moduleAcc.GetAddress().String()
expPacketFee := types.NewPacketFee(fee, msg.Signer, nil)
expFeesInEscrow = []types.PacketFee{expPacketFee}
It would be nice to get some more clarity around module accounts in general. We could use the above and also fund the ibcmock.ModuleName module account to get past the error.
There was a problem hiding this comment.
If the blocked address logic gets removed from the SDK, what test case would we want to have? I'd say probably still wise to just use the mock module account since it may not make sense long term to use distr (as community pool might be removed from it)
Maybe we can add the mock module to the list of genAccs in NewTestChainWithValSet?
Also I think you can use GetModuleAddress().String()
Codecov Report
@@ Coverage Diff @@
## main #1890 +/- ##
=======================================
Coverage 80.12% 80.13%
=======================================
Files 167 167
Lines 11750 11770 +20
=======================================
+ Hits 9415 9432 +17
- Misses 1921 1923 +2
- Partials 414 415 +1
|
Not too sure what's going on with the code cov here. I don't have access to the website either. |
crodriguezvega
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks @seantking for fixing the issue so quickly! ⚡
| refundAcc, err := sdk.AccAddressFromBech32(msg.PacketFee.RefundAddress) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if k.bankKeeper.BlockedAddr(refundAcc) { | ||
| return nil, sdkerrors.Wrapf(types.ErrBlockedAddress, "%s", refundAcc) | ||
| } | ||
|
|
||
| if k.IsLocked(ctx) { | ||
| return nil, types.ErrFeeModuleLocked | ||
| } |
There was a problem hiding this comment.
Should we move the check to below k.IsLocked(ctx) for consistency with PayPacketFee rpc?
colin-axner
left a comment
There was a problem hiding this comment.
ACK. Nice work. Would prefer to resolve the testing/simapp/app.go discussion before merging, but I'm ok doing it in a followup
| return nil, err | ||
| } | ||
|
|
||
| if k.bankKeeper.BlockedAddr(refundAcc) { |
There was a problem hiding this comment.
Maybe instead of adding a new error, do something like?
if k.bankKeeper.BlockedAddr(refundAcc) {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc)
}|
@seantking @colin-axner I am wondering if we should also add a check to ensure that the payee address is not blocked in the rpc handler for the |
Yes definitely, nice catch! |
Great idea! Added a check and test for this. |
* fix: adding check for blocked addresses before escrowing fees * refactor: move check below isLocked check * refactor: use sdk error instead of fee error * feat: adding check to RegisterPayee * chore: format import * refactor: remove dist module from unblocked addr (cherry picked from commit 7694903) # Conflicts: # modules/apps/29-fee/keeper/msg_server_test.go
* fix: adding check for blocked addresses before escrowing fees * refactor: move check below isLocked check * refactor: use sdk error instead of fee error * feat: adding check to RegisterPayee * chore: format import * refactor: remove dist module from unblocked addr (cherry picked from commit 7694903)
#1890) (#1950) * fix: adding check for blocked addresses before escrowing fees (#1890) * fix: adding check for blocked addresses before escrowing fees * refactor: move check below isLocked check * refactor: use sdk error instead of fee error * feat: adding check to RegisterPayee * chore: format import * refactor: remove dist module from unblocked addr (cherry picked from commit 7694903) # Conflicts: # modules/apps/29-fee/keeper/msg_server_test.go * fix conflicts Co-authored-by: Sean King <[email protected]> Co-authored-by: Carlos Rodriguez <[email protected]>
#1890) (#1951) * fix: adding check for blocked addresses before escrowing fees (#1890) * fix: adding check for blocked addresses before escrowing fees * refactor: move check below isLocked check * refactor: use sdk error instead of fee error * feat: adding check to RegisterPayee * chore: format import * refactor: remove dist module from unblocked addr (cherry picked from commit 7694903) * fix merge error Co-authored-by: Sean King <[email protected]> Co-authored-by: Carlos Rodriguez <[email protected]>
cosmos#1890) (cosmos#1950) * fix: adding check for blocked addresses before escrowing fees (cosmos#1890) * fix: adding check for blocked addresses before escrowing fees * refactor: move check below isLocked check * refactor: use sdk error instead of fee error * feat: adding check to RegisterPayee * chore: format import * refactor: remove dist module from unblocked addr (cherry picked from commit 7694903) # Conflicts: # modules/apps/29-fee/keeper/msg_server_test.go * fix conflicts Co-authored-by: Sean King <[email protected]> Co-authored-by: Carlos Rodriguez <[email protected]>
cosmos#1890) (cosmos#1950) * fix: adding check for blocked addresses before escrowing fees (cosmos#1890) * fix: adding check for blocked addresses before escrowing fees * refactor: move check below isLocked check * refactor: use sdk error instead of fee error * feat: adding check to RegisterPayee * chore: format import * refactor: remove dist module from unblocked addr (cherry picked from commit 7694903) # Conflicts: # modules/apps/29-fee/keeper/msg_server_test.go * fix conflicts Co-authored-by: Sean King <[email protected]> Co-authored-by: Carlos Rodriguez <[email protected]>
cosmos#1890) (cosmos#1950) * fix: adding check for blocked addresses before escrowing fees (cosmos#1890) * fix: adding check for blocked addresses before escrowing fees * refactor: move check below isLocked check * refactor: use sdk error instead of fee error * feat: adding check to RegisterPayee * chore: format import * refactor: remove dist module from unblocked addr (cherry picked from commit 7694903) # Conflicts: # modules/apps/29-fee/keeper/msg_server_test.go * fix conflicts Co-authored-by: Sean King <[email protected]> Co-authored-by: Carlos Rodriguez <[email protected]>
Description
closes: #1889
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/) or specification (x/<module>/spec/)godoccomments.Unreleasedsection inCHANGELOG.mdFiles changedin the Github PR explorerCodecov Reportin the comment section below once CI passes