cosmos-sdk/baseapp/state.go
Nikhil Vasan c5191041a2
fix(baseapp): introduce mutex to state (#18846)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
2023-12-21 19:05:40 +00:00

37 lines
721 B
Go

package baseapp
import (
"sync"
storetypes "cosmossdk.io/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
type state struct {
ms storetypes.CacheMultiStore
mtx sync.RWMutex
ctx sdk.Context
}
// CacheMultiStore calls and returns a CacheMultiStore on the state's underling
// CacheMultiStore.
func (st *state) CacheMultiStore() storetypes.CacheMultiStore {
return st.ms.CacheMultiStore()
}
// SetContext updates the state's context to the context provided.
func (st *state) SetContext(ctx sdk.Context) {
st.mtx.Lock()
defer st.mtx.Unlock()
st.ctx = ctx
}
// Context returns the Context of the state.
func (st *state) Context() sdk.Context {
st.mtx.RLock()
defer st.mtx.RUnlock()
return st.ctx
}