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

refactor: reuse bank blocked addrs list #10816

Merged
merged 5 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#10612](https://github.com/cosmos/cosmos-sdk/pull/10612) `baseapp.NewBaseApp` constructor function doesn't take the `sdk.TxDecoder` anymore. This logic has been moved into the TxDecoderMiddleware.
* [\#10692](https://github.com/cosmos/cosmos-sdk/pull/10612) `SignerData` takes 2 new fields, `Address` and `PubKey`, which need to get populated when using SIGN_MODE_DIRECT_AUX.
* [\#10748](https://github.com/cosmos/cosmos-sdk/pull/10748) Move legacy `x/gov` api to `v1beta1` directory.
* [\#10816](https://github.com/cosmos/cosmos-sdk/pull/10816) Reuse blocked addresses from the bank module. No need to pass them to distribution.

### Client Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func NewSimApp(
)
app.DistrKeeper = distrkeeper.NewKeeper(
appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, authtypes.FeeCollectorName, app.ModuleAccountAddrs(),
&stakingKeeper, authtypes.FeeCollectorName,
)
app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
Expand Down
7 changes: 2 additions & 5 deletions x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ type Keeper struct {
bankKeeper types.BankKeeper
stakingKeeper types.StakingKeeper

blockedAddrs map[string]bool

feeCollectorName string // name of the FeeCollector ModuleAccount
}

// NewKeeper creates a new distribution Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper,
feeCollectorName string, blockedAddrs map[string]bool,
feeCollectorName string,
) Keeper {

// ensure distribution module account is set
Expand All @@ -52,7 +50,6 @@ func NewKeeper(
bankKeeper: bk,
stakingKeeper: sk,
feeCollectorName: feeCollectorName,
blockedAddrs: blockedAddrs,
}
}

Expand All @@ -63,7 +60,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {

// SetWithdrawAddr sets a new address that will receive the rewards upon withdrawal
func (k Keeper) SetWithdrawAddr(ctx sdk.Context, delegatorAddr sdk.AccAddress, withdrawAddr sdk.AccAddress) error {
if k.blockedAddrs[withdrawAddr.String()] {
if k.bankKeeper.BlockedAddr(withdrawAddr) {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", withdrawAddr)
}

Expand Down
8 changes: 4 additions & 4 deletions x/distribution/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (

// HandleCommunityPoolSpendProposal is a handler for executing a passed community spend proposal
func HandleCommunityPoolSpendProposal(ctx sdk.Context, k Keeper, p *types.CommunityPoolSpendProposal) error {
if k.blockedAddrs[p.Recipient] {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", p.Recipient)
}

recipient, addrErr := sdk.AccAddressFromBech32(p.Recipient)
if addrErr != nil {
return addrErr
}

if k.bankKeeper.BlockedAddr(recipient) {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", p.Recipient)
}

err := k.DistributeFromFeePool(ctx, p.Amount, recipient)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions x/distribution/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type BankKeeper interface {
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error

BlockedAddr(addr sdk.AccAddress) bool
}

// StakingKeeper expected staking keeper (noalias)
Expand Down