示例#1
0
 private void SetupRegistry(StorageAddress address)
 {
     if (!_intraBlockCache.ContainsKey(address))
     {
         _intraBlockCache[address] = new Stack <int>();
     }
 }
示例#2
0
 private void SetupCache(StorageAddress address)
 {
     if (!_cache.ContainsKey(address))
     {
         _cache[address] = new Stack <int>();
     }
 }
示例#3
0
 private void PushUpdate(StorageAddress address, byte[] value)
 {
     SetupRegistry(address);
     IncrementPosition();
     _intraBlockCache[address].Push(_currentPosition);
     _changes[_currentPosition] = new Change(ChangeType.Update, address, value);
 }
示例#4
0
 private void PushJustCache(StorageAddress address, byte[] value)
 {
     SetupCache(address);
     IncrementPosition();
     _cache[address].Push(_currentPosition);
     _changes[_currentPosition] = new Change(ChangeType.JustCache, address, value);
 }
示例#5
0
 private void PushToRegistryOnly(StorageAddress address, byte[] value)
 {
     SetupRegistry(address);
     IncrementPosition();
     _intraBlockCache[address].Push(_currentPosition);
     _originalValues[address]   = value;
     _changes[_currentPosition] = new Change(ChangeType.JustCache, address, value);
 }
示例#6
0
        public byte[] GetOriginal(StorageAddress storageAddress)
        {
            if (!_originalValues.ContainsKey(storageAddress))
            {
                throw new InvalidOperationException("Get original should only be called after get within the same caching round");
            }

            return(_originalValues[storageAddress]);
        }
示例#7
0
        private byte[] LoadFromTree(StorageAddress storageAddress)
        {
            StorageTree tree = GetOrCreateStorage(storageAddress.Address);

            Metrics.StorageTreeReads++;
            byte[] value = tree.Get(storageAddress.Index);
            PushToRegistryOnly(storageAddress, value);
            return(value);
        }
示例#8
0
        private byte[] GetThroughCache(StorageAddress storageAddress)
        {
            if (_cache.ContainsKey(storageAddress))
            {
                return(_changes[_cache[storageAddress].Peek()].Value);
            }

            return(GetAndAddToCache(storageAddress));
        }
示例#9
0
        private byte[] GetAndAddToCache(StorageAddress storageAddress)
        {
            //byte[] cached = _storageCache.Get(storageAddress);
            //if (cached != null)
            //{
            //    return cached;
            //}

            StorageTree tree = GetOrCreateStorage(storageAddress.Address);

            Metrics.StorageTreeReads++;
            byte[] value = tree.Get(storageAddress.Index);
            PushJustCache(storageAddress, value);
            //_storageCache.Set(storageAddress, value);
            return(value);
        }
示例#10
0
//        private Dictionary<Address, (int ChangeIndex, StorageTree Storage)> _destructedStorages = new Dictionary<Address, (int, StorageTree)>();

        private byte[] GetCurrentValue(StorageAddress storageAddress)
        {
            if (_intraBlockCache.ContainsKey(storageAddress))
            {
                int lastChangeIndex = _intraBlockCache[storageAddress].Peek();
//                if (_destructedStorages.ContainsKey(storageAddress.Address))
//                {
//                    if (lastChangeIndex < _destructedStorages[storageAddress.Address].ChangeIndex)
//                    {
//                        return new byte[] {0};
//                    }
//                }

                return(_changes[lastChangeIndex].Value);
            }

            return(LoadFromTree(storageAddress));
        }
示例#11
0
 public void Set(StorageAddress storageAddress, byte[] newValue)
 {
     PushUpdate(storageAddress, newValue);
 }
示例#12
0
 public byte[] Get(StorageAddress storageAddress)
 {
     return(GetCurrentValue(storageAddress));
 }
示例#13
0
 public Change(ChangeType changeType, StorageAddress storageAddress, byte[] value)
 {
     StorageAddress = storageAddress;
     Value          = value;
     ChangeType     = changeType;
 }
示例#14
0
 public byte[] Get(StorageAddress storageAddress)
 {
     return(GetThroughCache(storageAddress));
 }