/// <inheritdoc />
        public bool Flush()
        {
            // Theoretically the cache dictionary could be updated while a flush is attempted,
            // causing enumeration of the loop to fail.
            lock (this.cacheLock)
            {
                bool ret = false;
                foreach (KeyValuePair <byte[], StorageCache> kvp in this.cache)
                {
                    StorageCache childCache = kvp.Value;
                    ret |= childCache.Flush();
                    AccountState storageOwnerAcct = this.repo.accountStateCache.Get(kvp.Key);
                    // need to update account storage root
                    if (storageOwnerAcct != null)
                    {
                        childCache.trie.Flush();
                        byte[] rootHash = childCache.trie.GetRootHash();
                        storageOwnerAcct.StateRoot = rootHash;
                        this.repo.accountStateCache.Put(kvp.Key, storageOwnerAcct);
                    }
                }

                this.cache.Clear();

                return(ret);
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public bool Flush()
        {
            bool ret = false;

            foreach (KeyValuePair <byte[], StorageCache> kvp in this.cache)
            {
                StorageCache childCache = kvp.Value;
                ret |= childCache.Flush();
                AccountState storageOwnerAcct = this.repo.accountStateCache.Get(kvp.Key);
                // need to update account storage root
                if (storageOwnerAcct != null)
                {
                    childCache.trie.Flush();
                    byte[] rootHash = childCache.trie.GetRootHash();
                    storageOwnerAcct.StateRoot = rootHash;
                    this.repo.accountStateCache.Put(kvp.Key, storageOwnerAcct);
                }
            }

            this.cache.Clear();

            return(ret);
        }