public async Task TransactionLimitSetAndGet_Test() { var blockIndex = new BlockIndex { BlockHash = HashHelper.ComputeFrom("BlockHash"), BlockHeight = 1 }; await _blockStateSetManger.SetBlockStateSetAsync(new BlockStateSet { BlockHash = blockIndex.BlockHash, BlockHeight = blockIndex.BlockHeight }); var blockTransactionLimit = 50; { var limit = await _blockTransactionLimitProvider.GetLimitAsync( new ChainContext { BlockHash = blockIndex.BlockHash, BlockHeight = blockIndex.BlockHeight }); limit.ShouldBe(int.MaxValue); } { await _blockTransactionLimitProvider.SetLimitAsync(blockIndex, blockTransactionLimit); var limit = await _blockTransactionLimitProvider.GetLimitAsync( new ChainContext { BlockHash = blockIndex.BlockHash, BlockHeight = blockIndex.BlockHeight }); limit.ShouldBe(blockTransactionLimit); } var blockTransactionLimitLessThanSystemTransaction = GetRequiredService <IEnumerable <ISystemTransactionGenerator> >().Count(); await _blockTransactionLimitProvider.SetLimitAsync(blockIndex, blockTransactionLimitLessThanSystemTransaction); var limit2 = await _blockTransactionLimitProvider.GetLimitAsync( new ChainContext { BlockHash = blockIndex.BlockHash, BlockHeight = blockIndex.BlockHeight }); limit2.ShouldBe(blockTransactionLimit); }
public async Task TransactionLimitSetAndGet_Test() { var chain = await _blockchainService.GetChainAsync(); var blockExecutedDataKey = "BlockExecutedData/BlockTransactionLimit"; var blockStateSet = await _blockStateSetManger.GetBlockStateSetAsync(chain.BestChainHash); blockStateSet.BlockExecutedData.ShouldNotContainKey(blockExecutedDataKey); await _blockTransactionLimitProvider.SetLimitAsync(new BlockIndex { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight }, 50); blockStateSet = await _blockStateSetManger.GetBlockStateSetAsync(chain.BestChainHash); blockStateSet.BlockExecutedData.ShouldContainKey(blockExecutedDataKey); var limit = await _blockTransactionLimitProvider.GetLimitAsync( new ChainContext { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight }); limit.ShouldBe(50); }
public async Task ProcessAsync(Block block, TransactionResult transactionResult, LogEvent logEvent) { var configurationSet = new ConfigurationSet(); configurationSet.MergeFrom(logEvent); if (configurationSet.Key != BlockTransactionLimitConfigurationNameProvider.Name) { return; } var limit = new Int32Value(); limit.MergeFrom(configurationSet.Value.ToByteArray()); if (limit.Value < 0) { return; } await _blockTransactionLimitProvider.SetLimitAsync(new BlockIndex { BlockHash = block.GetHash(), BlockHeight = block.Height }, limit.Value); Logger.LogInformation($"BlockTransactionLimit has been changed to {limit.Value}"); }
public async Task Mine_Test() { var chain = await _blockchainService.GetChainAsync(); var blockStateSet = new BlockStateSet { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight, }; await _blockStateSetManger.SetBlockStateSetAsync(blockStateSet); var transactions = _kernelTestHelper.GenerateTransactions(5, chain.BestChainHeight, chain.BestChainHash); await _transactionPoolService.UpdateTransactionPoolByBestChainAsync(chain.BestChainHash, chain.BestChainHeight); await _transactionPoolService.AddTransactionsAsync(transactions); await Task.Delay(200); await _transactionPoolService.UpdateTransactionPoolByBestChainAsync(chain.BestChainHash, chain.BestChainHeight); { await _transactionPackingOptionProvider.SetTransactionPackingOptionAsync(new BlockIndex { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight }, false); var blockTime = TimestampHelper.GetUtcNow(); var result = await _minerService.MineAsync(chain.BestChainHash, chain.BestChainHeight, blockTime, TimestampHelper.DurationFromSeconds(4)); await CheckMiningResultAsync(result, blockTime, 0); } { await _transactionPackingOptionProvider.SetTransactionPackingOptionAsync(new BlockIndex { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight }, true); await _blockTransactionLimitProvider.SetLimitAsync(new BlockIndex { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight }, 3); var blockTime = TimestampHelper.GetUtcNow(); var result = await _minerService.MineAsync(chain.BestChainHash, chain.BestChainHeight, blockTime, TimestampHelper.DurationFromSeconds(4)); await CheckMiningResultAsync(result, blockTime, 2); } }
public async Task ProcessConfigurationAsync(ByteString byteString, BlockIndex blockIndex) { var limit = new Int32Value(); limit.MergeFrom(byteString); if (limit.Value < 0) { return; } await _blockTransactionLimitProvider.SetLimitAsync(blockIndex, limit.Value); }
public async Task ValidateBlockBeforeExecute_Test() { var previousBlockHash = _kernelTestHelper.BestBranchBlockList.Last().GetHash(); var previousBlockHeight = _kernelTestHelper.BestBranchBlockList.Last().Height; var blockWithTransaction2 = GenerateBlock(previousBlockHeight, previousBlockHash, 2); var blockWithTransaction3 = GenerateBlock(previousBlockHeight, previousBlockHash, 3); var blockWithTransaction4 = GenerateBlock(previousBlockHeight, previousBlockHash, 4); await _blockStateSetManger.SetBlockStateSetAsync(new BlockStateSet { BlockHash = previousBlockHash, BlockHeight = previousBlockHeight }); (await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(blockWithTransaction2)).ShouldBeTrue(); (await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(blockWithTransaction3)).ShouldBeTrue(); (await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(blockWithTransaction4)).ShouldBeTrue(); await _blockTransactionLimitProvider.SetLimitAsync(new BlockIndex { BlockHeight = previousBlockHeight, BlockHash = previousBlockHash }, 3); (await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(blockWithTransaction2)).ShouldBeTrue(); (await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(blockWithTransaction3)).ShouldBeTrue(); (await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(blockWithTransaction4)).ShouldBeFalse(); await _blockTransactionLimitProvider.SetLimitAsync(new BlockIndex { BlockHeight = previousBlockHeight, BlockHash = previousBlockHash }, 4); (await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(blockWithTransaction2)).ShouldBeTrue(); (await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(blockWithTransaction3)).ShouldBeTrue(); (await _blockValidationProvider.ValidateBlockBeforeExecuteAsync(blockWithTransaction4)).ShouldBeTrue(); }