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

Backport #563, #564, #565 to v0.46.x and mark v0.46.10-pio-3 in the changelog. #566

Merged
merged 4 commits into from
Mar 21, 2023
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
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ Ref: https://keepachangelog.com/en/1.0.0/

---

## [v0.46.10-pio-3](https://github.com/provenance-io/cosmos-sdk/releases/tag/v0.46.10-pio-3) - 2023-03-21

### Features

* [PR 563](https://github.com/provenance-io/cosmos-sdk/pull/563) Add support for applying send restrictions before doing a bank send

### Improvements

* [PR 565](https://github.com/provenance-io/cosmos-sdk/pull/565) Removes locks around state listening. There's no concurrency risk.

### Bug Fixes

* [PR 564](https://github.com/provenance-io/cosmos-sdk/pull/564) Fix protobufjs parse error by using object form vs. array for `additional_bindings` rpc tag.

### Full Commit History

* https://github.com/provenance-io/cosmos-sdk/compare/v0.46.10-pio-2...v0.46.10-pio-3
* https://github.com/provenance-io/cosmos-sdk/compare/v0.46.10..v0.46.10-pio-3

---

## [v0.46.10-pio-2](https://github.com/provenance-io/cosmos-sdk/releases/tag/v0.46.10-pio-2) - 2023-02-28

### Bug Fixes
Expand Down
17 changes: 12 additions & 5 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
## [v0.46.10-pio-2](https://github.com/provenance-io/cosmos-sdk/releases/tag/v0.46.10-pio-2) - 2023-02-28
## [v0.46.10-pio-3](https://github.com/provenance-io/cosmos-sdk/releases/tag/v0.46.10-pio-3) - 2023-03-21

### Features

* [PR 563](https://github.com/provenance-io/cosmos-sdk/pull/563) Add support for applying send restrictions before doing a bank send

### Improvements

* [PR 565](https://github.com/provenance-io/cosmos-sdk/pull/565) Removes locks around state listening. There's no concurrency risk.

### Bug Fixes

* [PR 562](https://github.com/provenance-io/cosmos-sdk/pull/562) Fix `stopNodeOnErr` always false in State Listening Plugin system
* [PR 564](https://github.com/provenance-io/cosmos-sdk/pull/564) Fix protobufjs parse error by using object form vs. array for `additional_bindings` rpc tag.

### Full Commit History

* https://github.com/provenance-io/cosmos-sdk/compare/v0.46.10-pio-1...v0.46.10-pio-2
* https://github.com/provenance-io/cosmos-sdk/compare/v0.46.10..v0.46.10-pio-2

* https://github.com/provenance-io/cosmos-sdk/compare/v0.46.10-pio-2...v0.46.10-pio-3
* https://github.com/provenance-io/cosmos-sdk/compare/v0.46.10..v0.46.10-pio-3
14 changes: 9 additions & 5 deletions proto/cosmos/quarantine/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ service Query {
rpc QuarantinedFunds(QueryQuarantinedFundsRequest) returns (QueryQuarantinedFundsResponse) {
option (google.api.http) = {
get: "/cosmos/quarantine/v1beta1/funds"
additional_bindings: [
{get: "/cosmos/quarantine/v1beta1/funds/{to_address}"},
{get: "/cosmos/quarantine/v1beta1/funds/{to_address}/{from_address}"}
]
additional_bindings: {
get: "/cosmos/quarantine/v1beta1/funds/{to_address}"
}
additional_bindings: {
get: "/cosmos/quarantine/v1beta1/funds/{to_address}/{from_address}"
}
};
}

Expand All @@ -38,7 +40,9 @@ service Query {
rpc AutoResponses(QueryAutoResponsesRequest) returns (QueryAutoResponsesResponse) {
option (google.api.http) = {
get: "/cosmos/quarantine/v1beta1/auto/{to_address}"
additional_bindings: [{get: "/cosmos/quarantine/v1beta1/auto/{to_address}/{from_address}"}]
additional_bindings: {
get: "/cosmos/quarantine/v1beta1/auto/{to_address}/{from_address}"
}
};
}
}
Expand Down
1 change: 0 additions & 1 deletion proto/cosmos/tx/v1beta1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ message GetTxsEventRequest {
// pagination defines a pagination for the request.
// Deprecated post v0.46.x: use page and limit instead.
cosmos.base.query.v1beta1.PageRequest pagination = 2 [deprecated = true];
;
OrderBy order_by = 3;
// page is the page number to query, starts at 1. If not provided, will default to first page.
uint64 page = 4;
Expand Down
12 changes: 0 additions & 12 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ type Store struct {
interBlockCache types.MultiStorePersistentCache

listeners map[types.StoreKey]*types.MemoryListener

listenersMx sync.Mutex
}

var (
Expand Down Expand Up @@ -382,8 +380,6 @@ func (rs *Store) TracingEnabled() bool {

// AddListeners adds a listener for the KVStore belonging to the provided StoreKey
func (rs *Store) AddListeners(keys []types.StoreKey) {
rs.listenersMx.Lock()
defer rs.listenersMx.Unlock()
for i := range keys {
listener := rs.listeners[keys[i]]
if listener == nil {
Expand All @@ -405,8 +401,6 @@ func (rs *Store) ListeningEnabled(key types.StoreKey) bool {
// not the state in the store itself. This is a mutating and destructive operation.
// This method has been synchronized.
func (rs *Store) PopStateCache() []*types.StoreKVPair {
rs.listenersMx.Lock()
defer rs.listenersMx.Unlock()
var cache []*types.StoreKVPair
for key := range rs.listeners {
ls := rs.listeners[key]
Expand Down Expand Up @@ -490,8 +484,6 @@ func (rs *Store) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.Cac
// CacheMultiStore creates ephemeral branch of the multi-store and returns a CacheMultiStore.
// It implements the MultiStore interface.
func (rs *Store) CacheMultiStore() types.CacheMultiStore {
rs.listenersMx.Lock()
defer rs.listenersMx.Unlock()
stores := make(map[types.StoreKey]types.CacheWrapper)
for k, v := range rs.stores {
store := types.KVStore(v)
Expand All @@ -510,8 +502,6 @@ func (rs *Store) CacheMultiStore() types.CacheMultiStore {
// any store cannot be loaded. This should only be used for querying and
// iterating at past heights.
func (rs *Store) CacheMultiStoreWithVersion(version int64) (types.CacheMultiStore, error) {
rs.listenersMx.Lock()
defer rs.listenersMx.Unlock()
cachedStores := make(map[types.StoreKey]types.CacheWrapper)
for key, store := range rs.stores {
var cacheStore types.KVStore
Expand Down Expand Up @@ -566,8 +556,6 @@ func (rs *Store) GetStore(key types.StoreKey) types.Store {
// NOTE: The returned KVStore may be wrapped in an inter-block cache if it is
// set on the root store.
func (rs *Store) GetKVStore(key types.StoreKey) types.KVStore {
rs.listenersMx.Lock()
defer rs.listenersMx.Unlock()
s := rs.stores[key]
if s == nil {
panic(fmt.Sprintf("store does not exist for key: %s", key.Name()))
Expand Down
2 changes: 2 additions & 0 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type Keeper interface {

GetAuthority() string

SetSendRestrictionsFunc(sendRestrictionsFunc func(sdk.Context, string, string, string) error)

types.QueryServer
}

Expand Down
1 change: 0 additions & 1 deletion x/bank/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,3 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t

return &types.MsgMultiSendResponse{}, nil
}

44 changes: 43 additions & 1 deletion x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type SendKeeper interface {

IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
EnsureSendRestrictions(ctx sdk.Context, from, to string, coins ...sdk.Coin) error

BlockedAddr(addr sdk.AccAddress) bool
}
Expand All @@ -58,6 +59,8 @@ type BaseSendKeeper struct {

qk types.QuarantineKeeper
sk types.SanctionKeeper

sendRestrictionsFunc func(sdk.Context, string, string, string) error
}

func NewBaseSendKeeper(
Expand Down Expand Up @@ -109,6 +112,15 @@ func (k BaseSendKeeper) GetParams(ctx sdk.Context) (params types.Params) {
return params
}

// SetSendRestrictionsFunc set a function to be called before sends can occur
// if not set, it is a no-op
func (k *BaseSendKeeper) SetSendRestrictionsFunc(sendRestrictionsFunc func(sdk.Context, string, string, string) error) {
if k.sendRestrictionsFunc != nil {
panic("the send restrictions function has already been set")
}
k.sendRestrictionsFunc = sendRestrictionsFunc
}

// SetParams sets the total set of bank parameters.
func (k BaseSendKeeper) SetParams(ctx sdk.Context, params types.Params) {
if len(params.SendEnabled) > 0 {
Expand All @@ -128,6 +140,16 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input,
return err
}

// ensure all inputs and outputs pass any restrictions
for _, input := range inputs {
for _, output := range outputs {
err := k.EnsureSendRestrictions(ctx, input.Address, output.Address, input.Coins...)
if err != nil {
return err
}
}
}

allInputAddrs := make([]sdk.AccAddress, len(inputs))

for i, in := range inputs {
Expand Down Expand Up @@ -229,7 +251,12 @@ func (k BaseSendKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAd
// of possible quarantine on the toAddr.
// An error is returned upon failure.
func (k BaseSendKeeper) SendCoinsBypassQuarantine(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error {
err := k.subUnlockedCoins(ctx, fromAddr, amt)
err := k.EnsureSendRestrictions(ctx, fromAddr.String(), toAddr.String(), amt...)
if err != nil {
return err
}

err = k.subUnlockedCoins(ctx, fromAddr, amt)
if err != nil {
return err
}
Expand Down Expand Up @@ -424,6 +451,21 @@ func (k BaseSendKeeper) IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) e
return nil
}

// EnsureSendRestrictions applies the send restrictions function returns error if send restrictions do not pass
// no-op if the send restrictions function is not set
func (k *BaseSendKeeper) EnsureSendRestrictions(ctx sdk.Context, from, to string, coins ...sdk.Coin) error {
if k.sendRestrictionsFunc == nil {
return nil
}
for _, coin := range coins {
err := k.sendRestrictionsFunc(ctx, from, to, coin.Denom)
if err != nil {
return err
}
}
return nil
}

// IsSendEnabledCoin returns the current SendEnabled status of the provided coin's denom
func (k BaseSendKeeper) IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool {
return k.IsSendEnabledDenom(ctx, coin.Denom)
Expand Down