core: move write caching layer into MemCacheStore

Simplify Blockchain and associated functions, deduplicate code, fix Get() and
Seek() implementations.
This commit is contained in:
Roman Khimov 2019-10-16 16:41:50 +03:00
parent 4822c736bb
commit fc0031e5aa
10 changed files with 283 additions and 197 deletions

View file

@ -16,24 +16,18 @@ type UnspentCoins map[util.Uint256]*UnspentCoinState
// getAndUpdate retreives UnspentCoinState from temporary or persistent Store
// and return it. If it's not present in both stores, returns a new
// UnspentCoinState.
func (u UnspentCoins) getAndUpdate(ts storage.Store, ps storage.Store, hash util.Uint256) (*UnspentCoinState, error) {
func (u UnspentCoins) getAndUpdate(s storage.Store, hash util.Uint256) (*UnspentCoinState, error) {
if unspent, ok := u[hash]; ok {
return unspent, nil
}
unspent, err := getUnspentCoinStateFromStore(ts, hash)
unspent, err := getUnspentCoinStateFromStore(s, hash)
if err != nil {
if err != storage.ErrKeyNotFound {
return nil, err
}
unspent, err = getUnspentCoinStateFromStore(ps, hash)
if err != nil {
if err != storage.ErrKeyNotFound {
return nil, err
}
unspent = &UnspentCoinState{
states: []CoinState{},
}
unspent = &UnspentCoinState{
states: []CoinState{},
}
}