public async Task BlockExecutedData_Test() { var genesisBlock = _kernelTestHelper.GenerateBlock(0, Hash.Empty, new List <Transaction>()); var chain = await _blockchainService.CreateChainAsync(genesisBlock, new List <Transaction>()); var blockStateSet = new BlockStateSet { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight }; await _blockStateSetManger.SetBlockStateSetAsync(blockStateSet); var chainKey = GetBlockExecutedDataKey <Chain>(); var dictionary = new Dictionary <string, ByteString> { { chainKey, ByteString.CopyFrom(SerializationHelper.Serialize(chain)) } }; await _blockchainExecutedDataManager.AddBlockExecutedCacheAsync(blockStateSet.BlockHash, dictionary); var isInStore = await CheckExecutedDataInStoreAsync(blockStateSet, chainKey, dictionary[chainKey]); isInStore.ShouldBeFalse(); await _blockchainStateService.MergeBlockStateAsync(chain.BestChainHeight, chain.BestChainHash); isInStore = await CheckExecutedDataInStoreAsync(blockStateSet, chainKey, dictionary[chainKey]); isInStore.ShouldBeTrue(); blockStateSet = await AddBlockStateSetAsync(blockStateSet); isInStore = await CheckExecutedDataInStoreAsync(blockStateSet, chainKey, dictionary[chainKey]); isInStore.ShouldBeTrue(); }
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 && (!_changeHeight.TryGetValue(pair.Key, out var height) || height < blockIndex.BlockHeight)) { _changeHeight[pair.Key] = blockIndex.BlockHeight; } _dictionary.TryRemove(pair.Key, out _); } }
public async Task AddBlockExecutedDataAsync(Hash blockHash, IDictionary <string, ByteString> blockExecutedData) { await _blockchainExecutedDataManager.AddBlockExecutedCacheAsync(blockHash, blockExecutedData); }