Exemple #1
0
 private void PushUpdate(StorageCell cell, byte[] value)
 {
     SetupRegistry(cell);
     IncrementChangePosition();
     _intraBlockCache[cell].Push(_currentPosition);
     _changes[_currentPosition] = new Change(ChangeType.Update, cell, value);
 }
Exemple #2
0
 private void SetupRegistry(StorageCell cell)
 {
     if (!_intraBlockCache.ContainsKey(cell))
     {
         _intraBlockCache[cell] = new Stack <int>();
     }
 }
Exemple #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);
 }
Exemple #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]);
        }
Exemple #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);
        }
Exemple #6
0
        private byte[] GetCurrentValue(StorageCell storageCell)
        {
            if (_intraBlockCache.ContainsKey(storageCell))
            {
                int lastChangeIndex = _intraBlockCache[storageCell].Peek();
                return(_changes[lastChangeIndex].Value);
            }

            return(LoadFromTree(storageCell));
        }
Exemple #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));
        }
Exemple #8
0
 public void SetTransientState(StorageCell storageCell, byte[] newValue)
 {
     _transientStorageProvider.Set(storageCell, newValue);
 }
Exemple #9
0
 public void Set(StorageCell storageCell, byte[] newValue)
 {
     _persistentStorageProvider.Set(storageCell, newValue);
 }
Exemple #10
0
 public byte[] GetTransientState(StorageCell storageCell)
 {
     return(_transientStorageProvider.Get(storageCell));
 }
Exemple #11
0
 public byte[] GetOriginal(StorageCell storageCell)
 {
     return(_persistentStorageProvider.GetOriginal(storageCell));
 }
 public void ReportStorageRead(StorageCell storageCell)
 => throw new InvalidOperationException(ErrorMessage);
Exemple #13
0
 public Change(ChangeType changeType, StorageCell storageCell, byte[] value)
 {
     StorageCell = storageCell;
     Value       = value;
     ChangeType  = changeType;
 }
Exemple #14
0
 public byte[] Get(StorageCell storageCell)
 {
     return(GetCurrentValue(storageCell));
 }
 public void ReportStorageChange(StorageCell storageCell, byte[] before, byte[] after)
 => throw new InvalidOperationException(ErrorMessage);
Exemple #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;