Cache updates to state.store in readCache
This commit is contained in:
parent
c1c79d1e3d
commit
88fd1b752e
|
@ -131,6 +131,9 @@ func (app *Basecoin) Commit() (res tmsp.Result) {
|
|||
// Commit eyes.
|
||||
res = app.eyesCli.CommitSync()
|
||||
|
||||
// Wrap the committed state in cache for CheckTx
|
||||
app.cacheState = app.state.CacheWrap()
|
||||
|
||||
if res.IsErr() {
|
||||
PanicSanity("Error getting hash: " + res.Error())
|
||||
}
|
||||
|
@ -149,7 +152,6 @@ func (app *Basecoin) BeginBlock(height uint64) {
|
|||
for _, plugin := range app.plugins.GetList() {
|
||||
plugin.Plugin.BeginBlock(app.state, height)
|
||||
}
|
||||
app.cacheState = app.state.CacheWrap()
|
||||
}
|
||||
|
||||
// TMSP::EndBlock
|
||||
|
|
|
@ -11,13 +11,16 @@ import (
|
|||
type State struct {
|
||||
chainID string
|
||||
store types.KVStore
|
||||
cache *types.KVCache // optional
|
||||
readCache map[string][]byte // optional, for caching writes to store
|
||||
writeCache *types.KVCache // optional, for caching writes w/o writing to store
|
||||
}
|
||||
|
||||
func NewState(store types.KVStore) *State {
|
||||
return &State{
|
||||
chainID: "",
|
||||
store: store,
|
||||
readCache: make(map[string][]byte),
|
||||
writeCache: nil,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,33 +36,43 @@ func (s *State) GetChainID() string {
|
|||
}
|
||||
|
||||
func (s *State) Get(key []byte) (value []byte) {
|
||||
if s.readCache != nil {
|
||||
value, ok := s.readCache[string(key)]
|
||||
if ok {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return s.store.Get(key)
|
||||
}
|
||||
|
||||
func (s *State) Set(key []byte, value []byte) {
|
||||
if s.readCache != nil {
|
||||
s.readCache[string(key)] = value
|
||||
}
|
||||
s.store.Set(key, value)
|
||||
}
|
||||
|
||||
func (s *State) GetAccount(addr []byte) *types.Account {
|
||||
return GetAccount(s.store, addr)
|
||||
return GetAccount(s, addr)
|
||||
}
|
||||
|
||||
func (s *State) SetAccount(addr []byte, acc *types.Account) {
|
||||
SetAccount(s.store, addr, acc)
|
||||
SetAccount(s, addr, acc)
|
||||
}
|
||||
|
||||
func (s *State) CacheWrap() *State {
|
||||
cache := types.NewKVCache(s.store)
|
||||
cache := types.NewKVCache(s)
|
||||
return &State{
|
||||
chainID: s.chainID,
|
||||
store: cache,
|
||||
cache: cache,
|
||||
readCache: nil,
|
||||
writeCache: cache,
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: errors if s is not from CacheWrap()
|
||||
func (s *State) CacheSync() {
|
||||
s.cache.Sync()
|
||||
s.writeCache.Sync()
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
|
Loading…
Reference in New Issue