cosmos-sdk/baseapp/state.go
mergify[bot] 52c3db2eae
fix(baseapp): introduce mutex to state (backport #18846) (#18863)
Co-authored-by: Nikhil Vasan <97126437+nivasan1@users.noreply.github.com>
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
2023-12-22 17:46:17 +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
}