Ejemplo n.º 1
0
 protected override bool FlushChild(byte[] key, ICachedSource <byte[], byte[]> childCache)
 {
     if (base.FlushChild(key, childCache))
     {
         if (childCache != null)
         {
             StorageCache storageChildCache = (StorageCache)childCache; // praying to the lord this works
             AccountState storageOwnerAcct  = this.parentRepo.accountStateCache.Get(key);
             // need to update account storage root
             storageChildCache.trie.Flush();
             byte[] rootHash = storageChildCache.trie.GetRootHash();
             storageOwnerAcct.StateRoot = rootHash;
             this.parentRepo.accountStateCache.Put(key, storageOwnerAcct);
             return(true);
         }
         else
         {
             // account was deleted
             return(true);
         }
     }
     else
     {
         // no storage changes
         return(false);
     }
 }
        /// <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.º 3
0
        /// <inheritdoc />
        public ISource <byte[], byte[]> Get(byte[] key)
        {
            if (this.cache.ContainsKey(key))
            {
                return(this.cache[key]);
            }

            AccountState  accountState = this.repo.accountStateCache.Get(key);
            IPatriciaTrie storageTrie  = this.repo.GetTrieWithSameCache(accountState?.StateRoot);
            var           newCache     = new StorageCache(storageTrie);

            this.cache[key] = newCache;
            return(newCache);
        }
Ejemplo n.º 4
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);
        }