Skip to content

Commit

Permalink
Merge pull request #565 from provenance-io/egaxhaj/remove-lock-on-sta…
Browse files Browse the repository at this point in the history
…te-listening

remove listener lock as there is no concurrency
  • Loading branch information
egaxhaj committed Mar 15, 2023
2 parents 1820305 + fd5438c commit 72a21a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
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

0 comments on commit 72a21a6

Please sign in to comment.