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); } }
/// <summary> /// Mock a chain with a best branch, and some fork branches /// </summary> /// <returns> /// Mock Chain /// BestChainHeight: 11 /// LIB height: 5 /// /// Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14 /// Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k /// Fork Branch: (e)-> q -> r -> s -> t -> u /// Unlinked Branch: v -> w -> x -> y -> z /// </returns> public async Task MockChainAsync() { await StartNodeAsync(); var chain = await _blockchainService.GetChainAsync(); if (chain.BestChainHeight == 1) { var genesisBlock = await _blockchainService.GetBlockByHashAsync(chain.GenesisBlockHash); BestBranchBlockList.Add(genesisBlock); BestBranchBlockList.AddRange(await AddBestBranch()); ForkBranchBlockList = await AddForkBranch(BestBranchBlockList[4].GetHash(), BestBranchBlockList[4].Height); NotLinkedBlockList = await AddForkBranch(HashHelper.ComputeFrom("UnlinkBlock"), 9); // Set lib chain = await _blockchainService.GetChainAsync(); await _blockchainService.SetIrreversibleBlockAsync(chain, BestBranchBlockList[4].Height, BestBranchBlockList[4].GetHash()); } await _transactionPoolService.UpdateTransactionPoolByBestChainAsync(chain.BestChainHash, chain.BestChainHeight); }
public async Task IterationCleanup() { await _transactionPoolService.CleanByTransactionIdsAsync(_transactions.Select(t => t.GetHash()).ToList()); await _transactionPoolService.UpdateTransactionPoolByBestChainAsync(_chain.BestChainHash, _chain.BestChainHeight); await _transactionManager.RemoveTransactionsAsync(_transactions.Select(t => t.GetHash()).ToList()); }
public async Task IterationCleanup() { await _blockStateSets.RemoveAsync(_block.GetHash().ToStorageKey()); var transactionIds = _transactions.Select(t => t.GetHash()).ToList(); await _transactionManager.RemoveTransactionsAsync(transactionIds); await RemoveTransactionResultsAsync(transactionIds, _block.GetHash()); await _transactionPoolService.CleanByTransactionIdsAsync(_transactions.Select(t => t.GetHash()).ToList()); await _transactionPoolService.UpdateTransactionPoolByBestChainAsync(_chain.BestChainHash, _chain.BestChainHeight); }
public async Task InitializeChainAsync() { await StartNodeAsync(); var chain = await BlockchainService.GetChainAsync(); if (chain.BestChainHeight == 1) { var genesisBlock = await BlockchainService.GetBlockByHashAsync(chain.GenesisBlockHash); chain = await BlockchainService.GetChainAsync(); await BlockchainService.SetIrreversibleBlockAsync(chain, genesisBlock.Height, genesisBlock.GetHash()); } await TransactionPoolService.UpdateTransactionPoolByBestChainAsync(chain.BestChainHash, chain.BestChainHeight); }
public async Task GlobalCleanup() { foreach (var block in _blocks) { await _transactionPoolService.CleanByTransactionIdsAsync(block.TransactionIds); await _transactionManager.RemoveTransactionsAsync(block.Body.TransactionIds); await RemoveTransactionResultsAsync(block.Body.TransactionIds, block.GetHash()); await _chainManager.RemoveChainBlockLinkAsync(block.GetHash()); await _blockManager.RemoveBlockAsync(block.GetHash()); } await _transactionPoolService.UpdateTransactionPoolByBestChainAsync(_chain.BestChainHash, _chain.BestChainHeight); await _chains.SetAsync(_chain.Id.ToStorageKey(), _chain); }
public async Task HandleBestChainFoundTest() { await _transactionPoolService.UpdateTransactionPoolByBestChainAsync(_block.GetHash(), _block.Height); }
public async Task HandleEventAsync(BestChainFoundEventData eventData) { await _transactionPoolService.UpdateTransactionPoolByBestChainAsync(eventData.BlockHash, eventData.BlockHeight); }