Skip to content

Commit

Permalink
rename blacklist to blocked (cosmos#6455)
Browse files Browse the repository at this point in the history
* rename blacklisted to cannotSendTo

* add changelog

* rename to blockedAddrs

Co-authored-by: Federico Kunze <[email protected]>
  • Loading branch information
colin-axner and fedekunze authored Jun 17, 2020
1 parent d82114d commit eb3f7e6
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposa
* (modules) [\#6336](https://github.com/cosmos/cosmos-sdk/pull/6336) `AppModuleBasic.RegisterQueryService` method was added to support gRPC queries, and `QuerierRoute` and `NewQuerierHandler` were deprecated.
* (modules) [\#6311](https://github.com/cosmos/cosmos-sdk/issues/6311) Remove `alias.go` usage
* (x/auth) [\#6443](https://github.com/cosmos/cosmos-sdk/issues/6443) Move `FeeTx` and `TxWithMemo` interfaces from `x/auth/ante` to `types`.
* (modules) [\#6447](https://github.com/cosmos/cosmos-sdk/issues/6447) Rename `blacklistedAddrs` to `blockedAddrs`.

Migration guide:

Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/adr-023-protobuf-naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ or `.v3`.
[Buf's recommended version suffix](https://buf.build/docs/lint-checkers#package_version_suffix)
(ex. `v1alpha1`) _should_ be used for non-stable packages. These packages should
likely be excluded from breaking change detection and _should_ generally
be blacklisted from usage by smart contracts/persistent scripts to prevent them
be blocked from usage by smart contracts/persistent scripts to prevent them
from breaking. The SDK _should_ mark any packages as alpha or beta where the
API is likely to change significantly in the near future.

Expand Down
13 changes: 7 additions & 6 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func NewSimApp(
appCodec, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, maccPerms,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.subspaces[banktypes.ModuleName], app.BlacklistedAccAddrs(),
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.subspaces[banktypes.ModuleName], app.BlockedAddrs(),
)
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.subspaces[stakingtypes.ModuleName],
Expand Down Expand Up @@ -443,14 +443,15 @@ func (app *SimApp) ModuleAccountAddrs() map[string]bool {
return modAccAddrs
}

// BlacklistedAccAddrs returns all the app's module account addresses black listed for receiving tokens.
func (app *SimApp) BlacklistedAccAddrs() map[string]bool {
blacklistedAddrs := make(map[string]bool)
// BlockedAddrs returns all the app's module account addresses that are not
// allowed to receive external tokens.
func (app *SimApp) BlockedAddrs() map[string]bool {
blockedAddrs := make(map[string]bool)
for acc := range maccPerms {
blacklistedAddrs[auth.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc]
blockedAddrs[auth.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc]
}

return blacklistedAddrs
return blockedAddrs
}

// Codec returns SimApp's codec.
Expand Down
6 changes: 3 additions & 3 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func TestSimAppExport(t *testing.T) {
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

// ensure that black listed addresses are properly set in bank keeper
func TestBlackListedAddrs(t *testing.T) {
// ensure that blocked addresses are properly set in bank keeper
func TestBlockedAddrs(t *testing.T) {
db := dbm.NewMemDB()
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0)

for acc := range maccPerms {
require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlacklistedAddr(app.AccountKeeper.GetModuleAddress(acc)))
require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlockedAddr(app.AccountKeeper.GetModuleAddress(acc)))
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/bank/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func handleMsgSend(ctx sdk.Context, k keeper.Keeper, msg *types.MsgSend) (*sdk.R
return nil, types.ErrSendDisabled
}

if k.BlacklistedAddr(msg.ToAddress) {
if k.BlockedAddr(msg.ToAddress) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive transactions", msg.ToAddress)
}

Expand All @@ -58,7 +58,7 @@ func handleMsgMultiSend(ctx sdk.Context, k keeper.Keeper, msg *types.MsgMultiSen
}

for _, out := range msg.Outputs {
if k.BlacklistedAddr(out.Address) {
if k.BlockedAddr(out.Address) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive transactions", out.Address)
}
}
Expand Down
4 changes: 2 additions & 2 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type BaseKeeper struct {

func NewBaseKeeper(
cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace,
blacklistedAddrs map[string]bool,
blockedAddrs map[string]bool,
) BaseKeeper {

// set KeyTable if it has not already been set
Expand All @@ -66,7 +66,7 @@ func NewBaseKeeper(
}

return BaseKeeper{
BaseSendKeeper: NewBaseSendKeeper(cdc, storeKey, ak, paramSpace, blacklistedAddrs),
BaseSendKeeper: NewBaseSendKeeper(cdc, storeKey, ak, paramSpace, blockedAddrs),
ak: ak,
cdc: cdc,
storeKey: storeKey,
Expand Down
26 changes: 13 additions & 13 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type SendKeeper interface {
GetSendEnabled(ctx sdk.Context) bool
SetSendEnabled(ctx sdk.Context, enabled bool)

BlacklistedAddr(addr sdk.AccAddress) bool
BlockedAddr(addr sdk.AccAddress) bool
}

var _ SendKeeper = (*BaseSendKeeper)(nil)
Expand All @@ -42,20 +42,20 @@ type BaseSendKeeper struct {
paramSpace paramtypes.Subspace

// list of addresses that are restricted from receiving transactions
blacklistedAddrs map[string]bool
blockedAddrs map[string]bool
}

func NewBaseSendKeeper(
cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blacklistedAddrs map[string]bool,
cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blockedAddrs map[string]bool,
) BaseSendKeeper {

return BaseSendKeeper{
BaseViewKeeper: NewBaseViewKeeper(cdc, storeKey, ak),
cdc: cdc,
ak: ak,
storeKey: storeKey,
paramSpace: paramSpace,
blacklistedAddrs: blacklistedAddrs,
BaseViewKeeper: NewBaseViewKeeper(cdc, storeKey, ak),
cdc: cdc,
ak: ak,
storeKey: storeKey,
paramSpace: paramSpace,
blockedAddrs: blockedAddrs,
}
}

Expand Down Expand Up @@ -264,8 +264,8 @@ func (k BaseSendKeeper) SetSendEnabled(ctx sdk.Context, enabled bool) {
k.paramSpace.Set(ctx, types.ParamStoreKeySendEnabled, &enabled)
}

// BlacklistedAddr checks if a given address is blacklisted (i.e restricted from
// receiving funds)
func (k BaseSendKeeper) BlacklistedAddr(addr sdk.AccAddress) bool {
return k.blacklistedAddrs[addr.String()]
// BlockedAddr checks if a given address is restricted from
// receiving funds.
func (k BaseSendKeeper) BlockedAddr(addr sdk.AccAddress) bool {
return k.blockedAddrs[addr.String()]
}
10 changes: 5 additions & 5 deletions x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Keeper struct {
bankKeeper types.BankKeeper
stakingKeeper types.StakingKeeper

blacklistedAddrs map[string]bool
blockedAddrs map[string]bool

feeCollectorName string // name of the FeeCollector ModuleAccount
}
Expand All @@ -30,7 +30,7 @@ type Keeper struct {
func NewKeeper(
cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace,
ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper,
feeCollectorName string, blacklistedAddrs map[string]bool,
feeCollectorName string, blockedAddrs map[string]bool,
) Keeper {

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

Expand All @@ -62,8 +62,8 @@ 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.blacklistedAddrs[withdrawAddr.String()] {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is blacklisted from receiving external funds", withdrawAddr)
if k.blockedAddrs[withdrawAddr.String()] {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", withdrawAddr)
}

if !k.GetWithdrawAddrEnabled(ctx) {
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ 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.blacklistedAddrs[p.Recipient.String()] {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is blacklisted from receiving external funds", p.Recipient)
if k.blockedAddrs[p.Recipient.String()] {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", p.Recipient)
}

err := k.DistributeFromFeePool(ctx, p.Amount, p.Recipient)
Expand Down

0 comments on commit eb3f7e6

Please sign in to comment.