Skip to content

Commit

Permalink
Remove inter-block cache from Context
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez committed Aug 26, 2019
1 parent a635ca5 commit 4ee169b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 46 deletions.
14 changes: 14 additions & 0 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ type CommitMultiStore interface {
// must be idempotent (return the same commit id). Otherwise the behavior is
// undefined.
LoadVersion(ver int64) error

// Set an inter-block (persistent) cache that maintains a mapping from
// StoreKeys to CommitKVStores.
SetInterBlockCache(MultiStorePersistentCache)
}

//---------subsp-------------------------------
Expand Down Expand Up @@ -328,3 +332,13 @@ type KVPair cmn.KVPair
// TraceContext contains TraceKVStore context data. It will be written with
// every trace operation.
type TraceContext map[string]interface{}

// MultiStorePersistentCache defines an interface which provides inter-block
// (persistent) caching capabilities for multiple CommitKVStores based on StoreKeys.
type MultiStorePersistentCache interface {
// Wrap and return the provided CommitKVStore with an inter-block (persistent)
// cache.
GetStoreCache(key StoreKey, store CommitKVStore) CommitKVStore
// Reset the entire set of internal caches.
Reset()
}
52 changes: 15 additions & 37 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ but please do not over-use it. We try to keep all data structured
and standard additions here would be better just to add to the Context struct
*/
type Context struct {
ctx context.Context
ms MultiStore
interBlockCache *KVStoreCacheManager
header abci.Header
chainID string
txBytes []byte
logger log.Logger
voteInfo []abci.VoteInfo
gasMeter GasMeter
blockGasMeter GasMeter
checkTx bool
minGasPrice DecCoins
consParams *abci.ConsensusParams
eventManager *EventManager
ctx context.Context
ms MultiStore
header abci.Header
chainID string
txBytes []byte
logger log.Logger
voteInfo []abci.VoteInfo
gasMeter GasMeter
blockGasMeter GasMeter
checkTx bool
minGasPrice DecCoins
consParams *abci.ConsensusParams
eventManager *EventManager
}

// Proposed rename, not done to avoid API breakage
Expand Down Expand Up @@ -92,15 +91,6 @@ func (c Context) WithMultiStore(ms MultiStore) Context {
return c
}

// WithInterBlockCache returns the Context with an inter-block write-through
// cache.
//
// NOTE: This cache is persistent and should only be set on the DeliverTx state.
func (c Context) WithInterBlockCache(cacheMngr *KVStoreCacheManager) Context {
c.interBlockCache = cacheMngr
return c
}

func (c Context) WithBlockHeader(header abci.Header) Context {
// https://github.com/gogo/protobuf/issues/519
header.Time = header.Time.UTC()
Expand Down Expand Up @@ -207,24 +197,12 @@ func (c Context) Value(key interface{}) interface{} {

// KVStore fetches a KVStore from the MultiStore.
func (c Context) KVStore(key StoreKey) KVStore {
kvStore := c.MultiStore().GetKVStore(key)
if c.interBlockCache != nil {
// wrap the KVStore in an inter-block write-through cache
kvStore = c.interBlockCache.GetKVStoreCache(key, kvStore)
}

return gaskv.NewStore(kvStore, c.GasMeter(), stypes.KVGasConfig())
return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), stypes.KVGasConfig())
}

// TransientStore fetches a TransientStore from the MultiStore.
func (c Context) TransientStore(key StoreKey) KVStore {
kvStore := c.MultiStore().GetKVStore(key)
if c.interBlockCache != nil {
// wrap the KVStore in an inter-block write-through cache
kvStore = c.interBlockCache.GetKVStoreCache(key, kvStore)
}

return gaskv.NewStore(kvStore, c.GasMeter(), stypes.TransientGasConfig())
return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), stypes.TransientGasConfig())
}

// CacheContext returns a new Context with the multi-store cached and a new
Expand Down
19 changes: 10 additions & 9 deletions types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ type (

// nolint - reexport
type (
Store = types.Store
Committer = types.Committer
CommitStore = types.CommitStore
Queryable = types.Queryable
MultiStore = types.MultiStore
CacheMultiStore = types.CacheMultiStore
CommitMultiStore = types.CommitMultiStore
KVStore = types.KVStore
Iterator = types.Iterator
Store = types.Store
Committer = types.Committer
CommitStore = types.CommitStore
Queryable = types.Queryable
MultiStore = types.MultiStore
CacheMultiStore = types.CacheMultiStore
CommitMultiStore = types.CommitMultiStore
MultiStorePersistentCache = types.MultiStorePersistentCache
KVStore = types.KVStore
Iterator = types.Iterator
)

// StoreDecoderRegistry defines each of the modules store decoders. Used for ImportExport
Expand Down
2 changes: 2 additions & 0 deletions x/params/subspace/subspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ func (s Subspace) Update(ctx sdk.Context, key []byte, param []byte) error {
}

s.Set(ctx, key, dest)

// TODO: Remove; seems redundant as Set already does this.
tStore := s.transientStore(ctx)
tStore.Set(key, []byte{})

Expand Down

0 comments on commit 4ee169b

Please sign in to comment.