Example #1
0
 private void PushUpdate(StorageCell cell, byte[] value)
 {
     SetupRegistry(cell);
     IncrementChangePosition();
     _intraBlockCache[cell].Push(_currentPosition);
     _changes[_currentPosition] = new Change(ChangeType.Update, cell, value);
 }
Example #2
0
 private void SetupRegistry(StorageCell cell)
 {
     if (!_intraBlockCache.ContainsKey(cell))
     {
         _intraBlockCache[cell] = new Stack <int>();
     }
 }
Example #3
0
 private void PushToRegistryOnly(StorageCell cell, byte[] value)
 {
     SetupRegistry(cell);
     IncrementChangePosition();
     _intraBlockCache[cell].Push(_currentPosition);
     _originalValues[cell]      = value;
     _changes[_currentPosition] = new Change(ChangeType.JustCache, cell, value);
 }
Example #4
0
        public byte[] GetOriginal(StorageCell storageCell)
        {
            if (!_originalValues.ContainsKey(storageCell))
            {
                throw new InvalidOperationException("Get original should only be called after get within the same caching round");
            }

            return(_originalValues[storageCell]);
        }
Example #5
0
        private byte[] LoadFromTree(StorageCell storageCell)
        {
            StorageTree tree = GetOrCreateStorage(storageCell.Address);

            Metrics.StorageTreeReads++;
            byte[] value = tree.Get(storageCell.Index);
            PushToRegistryOnly(storageCell, value);
            return(value);
        }
Example #6
0
        private byte[] GetCurrentValue(StorageCell storageCell)
        {
            if (_intraBlockCache.ContainsKey(storageCell))
            {
                int lastChangeIndex = _intraBlockCache[storageCell].Peek();
                return(_changes[lastChangeIndex].Value);
            }

            return(LoadFromTree(storageCell));
        }
Example #7
0
//        private Dictionary<Address, (int ChangeIndex, StorageTree Storage)> _destructedStorages = new Dictionary<Address, (int, StorageTree)>();

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

                return(_changes[lastChangeIndex].Value);
            }

            return(LoadFromTree(storageCell));
        }
Example #8
0
 public void SetTransientState(StorageCell storageCell, byte[] newValue)
 {
     _transientStorageProvider.Set(storageCell, newValue);
 }
Example #9
0
 public void Set(StorageCell storageCell, byte[] newValue)
 {
     _persistentStorageProvider.Set(storageCell, newValue);
 }
Example #10
0
 public byte[] GetTransientState(StorageCell storageCell)
 {
     return(_transientStorageProvider.Get(storageCell));
 }
Example #11
0
 public byte[] GetOriginal(StorageCell storageCell)
 {
     return(_persistentStorageProvider.GetOriginal(storageCell));
 }
 public void ReportStorageRead(StorageCell storageCell)
 => throw new InvalidOperationException(ErrorMessage);
Example #13
0
 public Change(ChangeType changeType, StorageCell storageCell, byte[] value)
 {
     StorageCell = storageCell;
     Value       = value;
     ChangeType  = changeType;
 }
Example #14
0
 public byte[] Get(StorageCell storageCell)
 {
     return(GetCurrentValue(storageCell));
 }
 public void ReportStorageChange(StorageCell storageCell, byte[] before, byte[] after)
 => throw new InvalidOperationException(ErrorMessage);
Example #16
0
 public void Set(StorageCell storageCell, byte[] newValue)
 {
     PushUpdate(storageCell, newValue);
 }
 /// <summary>
 /// Get the storage value at the specified storage cell
 /// </summary>
 /// <param name="storageCell">Storage location</param>
 /// <returns>Value at cell</returns>
 protected override byte[] GetCurrentValue(StorageCell storageCell) =>
 TryGetCachedValue(storageCell, out byte[]? bytes) ? bytes ! : _zeroValue;