private void PushUpdate(StorageCell cell, byte[] value) { SetupRegistry(cell); IncrementChangePosition(); _intraBlockCache[cell].Push(_currentPosition); _changes[_currentPosition] = new Change(ChangeType.Update, cell, value); }
private void SetupRegistry(StorageCell cell) { if (!_intraBlockCache.ContainsKey(cell)) { _intraBlockCache[cell] = new Stack <int>(); } }
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); }
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]); }
private byte[] LoadFromTree(StorageCell storageCell) { StorageTree tree = GetOrCreateStorage(storageCell.Address); Metrics.StorageTreeReads++; byte[] value = tree.Get(storageCell.Index); PushToRegistryOnly(storageCell, value); return(value); }
private byte[] GetCurrentValue(StorageCell storageCell) { if (_intraBlockCache.ContainsKey(storageCell)) { int lastChangeIndex = _intraBlockCache[storageCell].Peek(); return(_changes[lastChangeIndex].Value); } return(LoadFromTree(storageCell)); }
// 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)); }
public void SetTransientState(StorageCell storageCell, byte[] newValue) { _transientStorageProvider.Set(storageCell, newValue); }
public void Set(StorageCell storageCell, byte[] newValue) { _persistentStorageProvider.Set(storageCell, newValue); }
public byte[] GetTransientState(StorageCell storageCell) { return(_transientStorageProvider.Get(storageCell)); }
public byte[] GetOriginal(StorageCell storageCell) { return(_persistentStorageProvider.GetOriginal(storageCell)); }
public void ReportStorageRead(StorageCell storageCell) => throw new InvalidOperationException(ErrorMessage);
public Change(ChangeType changeType, StorageCell storageCell, byte[] value) { StorageCell = storageCell; Value = value; ChangeType = changeType; }
public byte[] Get(StorageCell storageCell) { return(GetCurrentValue(storageCell)); }
public void ReportStorageChange(StorageCell storageCell, byte[] before, byte[] after) => throw new InvalidOperationException(ErrorMessage);
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;