@@ -25,7 +25,7 @@ type Store struct {
2525
2626 traceWriter io.Writer
2727 traceContext types.TraceContext
28- parentStore func (types.StoreKey ) types.CacheWrap
28+ parentStore func (types.StoreKey ) types.CacheWrapper
2929
3030 branched bool
3131}
@@ -61,12 +61,17 @@ func NewStore(
6161 return NewFromKVStore (stores , traceWriter , traceContext )
6262}
6363
64- func newCacheMultiStoreFromCMS (cms Store ) Store {
64+ // NewFromParent constructs a cache multistore with a parent store lazily,
65+ // the parent is usually another cache multistore or the block-stm multiversion store.
66+ func NewFromParent (
67+ parentStore func (types.StoreKey ) types.CacheWrapper ,
68+ traceWriter io.Writer , traceContext types.TraceContext ,
69+ ) Store {
6570 return Store {
6671 stores : make (map [types.StoreKey ]types.CacheWrap ),
67- traceWriter : cms . traceWriter ,
68- traceContext : cms . traceContext ,
69- parentStore : cms . getCacheWrap ,
72+ traceWriter : traceWriter ,
73+ traceContext : traceContext ,
74+ parentStore : parentStore ,
7075 }
7176}
7277
@@ -146,10 +151,10 @@ func (cms Store) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.Cac
146151// CacheMultiStore implements MultiStore, returns a new CacheMultiStore from the
147152// underlying CacheMultiStore.
148153func (cms Store ) CacheMultiStore () types.CacheMultiStore {
149- return newCacheMultiStoreFromCMS (cms )
154+ return NewFromParent (cms . getCacheWrapper , cms . traceWriter , cms . traceContext )
150155}
151156
152- func (cms Store ) getCacheWrap (key types.StoreKey ) types.CacheWrap {
157+ func (cms Store ) getCacheWrapper (key types.StoreKey ) types.CacheWrapper {
153158 store , ok := cms .stores [key ]
154159 if ! ok && cms .parentStore != nil {
155160 // load on demand
@@ -163,7 +168,7 @@ func (cms Store) getCacheWrap(key types.StoreKey) types.CacheWrap {
163168
164169// GetStore returns an underlying Store by key.
165170func (cms Store ) GetStore (key types.StoreKey ) types.Store {
166- store , ok := cms .getCacheWrap (key ).(types.Store )
171+ store , ok := cms .getCacheWrapper (key ).(types.Store )
167172 if ! ok {
168173 panic (fmt .Sprintf ("store with key %v is not Store" , key ))
169174 }
@@ -172,7 +177,7 @@ func (cms Store) GetStore(key types.StoreKey) types.Store {
172177
173178// GetKVStore returns an underlying KVStore by key.
174179func (cms Store ) GetKVStore (key types.StoreKey ) types.KVStore {
175- store , ok := cms .getCacheWrap (key ).(types.KVStore )
180+ store , ok := cms .getCacheWrapper (key ).(types.KVStore )
176181 if ! ok {
177182 panic (fmt .Sprintf ("store with key %v is not KVStore" , key ))
178183 }
@@ -181,7 +186,7 @@ func (cms Store) GetKVStore(key types.StoreKey) types.KVStore {
181186
182187// GetObjKVStore returns an underlying KVStore by key.
183188func (cms Store ) GetObjKVStore (key types.StoreKey ) types.ObjKVStore {
184- store , ok := cms .getCacheWrap (key ).(types.ObjKVStore )
189+ store , ok := cms .getCacheWrapper (key ).(types.ObjKVStore )
185190 if ! ok {
186191 panic (fmt .Sprintf ("store with key %v is not ObjKVStore" , key ))
187192 }
0 commit comments