public async Task UpdateOneBlockIndexWithoutBestChain() { var previousBlockHeader = _kernelTestHelper.BestBranchBlockList.Last().Header; var block = _kernelTestHelper.GenerateBlock(previousBlockHeader.Height, HashHelper.ComputeFrom("PreBlockHash")); var chain = await _blockchainService.GetChainAsync(); await AddBlockAsync(chain, block); var txId = HashHelper.ComputeFrom("Transaction"); var blockIndex = new BlockIndex { BlockHash = block.GetHash(), BlockHeight = block.Height }; await _transactionBlockIndexService.AddBlockIndexAsync(new List <Hash> { txId }, blockIndex); var actual = await _transactionBlockIndexService.GetTransactionBlockIndexAsync(txId); Assert.Null(actual); var cacheInBestBranch = await _transactionBlockIndexService.GetTransactionBlockIndexAsync(txId); Assert.Null(cacheInBestBranch); var cacheInForkBranch = await _transactionBlockIndexService.ValidateTransactionBlockIndexExistsInBranchAsync(txId, block.GetHash()); Assert.True(cacheInForkBranch); }
public async Task <bool> ValidateBlockBeforeExecuteAsync(IBlock block) { if (block?.Header == null || block.Body == null) { return(false); } if (block.Body.TransactionsCount == 0) { return(false); } // Verify that the transaction has been packaged in the current branch foreach (var transactionId in block.TransactionIds) { var blockIndexExists = await _transactionBlockIndexService.ValidateTransactionBlockIndexExistsInBranchAsync(transactionId, block.Header.PreviousBlockHash); if (!blockIndexExists) { continue; } Logger.LogWarning($"Transaction: {transactionId} repackaged."); return(false); } return(true); }