示例#1
0
        public void ChangeHeight_Test()
        {
            _blockchainExecutedDataCacheProvider.SetChangeHeight("key1", long.MaxValue);
            _blockchainExecutedDataCacheProvider.TryGetChangeHeight("key1", out var value);
            value.ShouldBe(long.MaxValue);

            _blockchainExecutedDataCacheProvider.CleanChangeHeight(long.MaxValue);
            _blockchainExecutedDataCacheProvider.TryGetChangeHeight("key1", out _).ShouldBeFalse();
        }
        public async Task AddBlockExecutedDataAsync(IBlockIndex blockIndex, IDictionary <string, T> blockExecutedData)
        {
            await _blockchainExecutedDataManager.AddBlockExecutedCacheAsync(blockIndex.BlockHash, blockExecutedData.ToDictionary
                                                                                (pair => pair.Key, pair => Serialize(pair.Value)));

            foreach (var pair in blockExecutedData)
            {
                if (blockIndex.BlockHeight > AElfConstants.GenesisBlockHeight &&
                    (!_blockchainExecutedDataCacheProvider.TryGetChangeHeight(pair.Key, out var height) ||
                     height < blockIndex.BlockHeight))
                {
                    _blockchainExecutedDataCacheProvider.SetChangeHeight(pair.Key, blockIndex.BlockHeight);
                }
                _blockchainExecutedDataCacheProvider.RemoveBlockExecutedData(pair.Key);
            }
        }