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

remove listener lock as there is no concurrency #565

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

## Unreleased

### 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.
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