コード例 #1
0
        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();
        }
コード例 #2
0
        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 _);
            }
        }
コード例 #3
0
 public async Task AddBlockExecutedDataAsync(Hash blockHash, IDictionary <string, ByteString> blockExecutedData)
 {
     await _blockchainExecutedDataManager.AddBlockExecutedCacheAsync(blockHash, blockExecutedData);
 }