func (t *TreeMemoryCache) Update(cb func(TreeDatabaseTransaction) error) error {
	return t.underlyingStore.View(func(underlyingTx TreeDatabaseTransaction) error {
		t.lock.Lock()
		defer t.lock.Unlock()

		// we copy and set so that we can easily revert if needed (if the transaction errors)
		dirtyCopy := make(map[chainhash.Hash]Node)
		dirtyKVCopy := make(map[chainhash.Hash]chainhash.Hash)
		toRemoveCopy := make(map[chainhash.Hash]struct{})

		for k, v := range t.dirty {
			dirtyCopy[k] = v
		}

		for k, v := range t.dirtyKV {
			dirtyKVCopy[k] = v
		}

		for k := range t.toRemove {
			toRemoveCopy[k] = struct{}{}
		}

		tx := &TreeMemoryCacheTransaction{
			underlyingTransaction: underlyingTx,
			root:                  t.root,
			dirty:                 dirtyCopy,
			dirtyKV:               dirtyKVCopy,
			toRemove:              toRemoveCopy,
			update:                true,
		}

		err := cb(tx)
		if err != nil {
			return err
		}

		t.root = tx.root
		t.dirty = dirtyCopy
		t.dirtyKV = dirtyKVCopy
		t.toRemove = toRemoveCopy

		return nil
	})
}
// Update creates an update transaction for the cache.
Update creates an update transaction for the cache.
// Update creates an update transaction for the cache .
func (t *TreeMemoryCache) Update(cb func(TreeDatabaseTransaction) error) error {
	return t.underlyingStore.View(func(underlyingTx TreeDatabaseTransaction) error {
		t.lock.Lock()
		defer t.lock.Unlock()
		dirtyCopy := make(map[chainhash.Hash]Node)
		dirtyKVCopy := make(map[chainhash.Hash]chainhash.Hash)
		toRemoveCopy := make(map[chainhash.Hash]struct{})
		for k, v := range t.dirty {
			dirtyCopy[k] = v
		}
		for k, v := range t.dirtyKV {
			dirtyKVCopy[k] = v
		}
		for k := range t.toRemove {
			toRemoveCopy[k] = struct{}{}
		}
		tx := &TreeMemoryCacheTransaction{
			underlyingTransaction: underlyingTx,
			root:                  t.root,
			dirty:                 dirtyCopy,
			dirtyKV:               dirtyKVCopy,
			toRemove:              toRemoveCopy,
			update:                true,
		}
		err := cb(tx)
		if err != nil {
			return err
		}
		t.root = tx.root
		t.dirty = dirtyCopy
		t.dirtyKV = dirtyKVCopy
		t.toRemove = toRemoveCopy
		return nil
	})
}
func ( t * TreeMemoryCache ) Update ( cb func ( TreeDatabaseTransaction ) error ) error { return t . underlyingStore . View ( func ( underlyingTx TreeDatabaseTransaction ) error { t . lock . Lock ( ) defer t . lock . Unlock ( ) dirtyCopy := make ( map [ chainhash . Hash ] Node ) dirtyKVCopy := make ( map [ chainhash . Hash ] chainhash . Hash ) toRemoveCopy := make ( map [ chainhash . Hash ] struct { } ) for k , v := range t . dirty { dirtyCopy [ k ] = v } for k , v := range t . dirtyKV { dirtyKVCopy [ k ] = v } for k := range t . toRemove { toRemoveCopy [ k ] = struct { } { } } tx := & TreeMemoryCacheTransaction { underlyingTransaction : underlyingTx , root : t . root , dirty : dirtyCopy , dirtyKV : dirtyKVCopy , toRemove : toRemoveCopy , update : true , } err := cb ( tx ) if err != nil { return err } t . root = tx . root t . dirty = dirtyCopy t . dirtyKV = dirtyKVCopy t . toRemove = toRemoveCopy return nil } ) }
Update creates an update transaction for the cache.
Update creates an update transaction for the cache .
// we copy and set so that we can easily revert if needed (if the transaction errors)