public override async Task <BlockVisitOutcome> VisitBlock(Block block, CancellationToken cancellationToken) { BlockVisitOutcome outcome = await base.VisitBlock(block, cancellationToken); if (_blockTree.IsMainChain(block.Header)) { _receiptStorage.EnsureCanonical(block); } return(outcome); }
private async Task <bool> VisitBlock(IBlockTreeVisitor visitor, Block block, CancellationToken cancellationToken) { BlockVisitOutcome blockVisitOutcome = await visitor.VisitBlock(block, cancellationToken); if ((blockVisitOutcome & BlockVisitOutcome.Suggest) == BlockVisitOutcome.Suggest) { // remnant after previous approach - we want to skip standard suggest processing and just invoke processor BestSuggestedHeader = block.Header; BestSuggestedBody = block; NewBestSuggestedBlock?.Invoke(this, new BlockEventArgs(block)); } if ((blockVisitOutcome & BlockVisitOutcome.StopVisiting) == BlockVisitOutcome.StopVisiting) { return(true); } return(false); }
public async Task Fixer_should_not_suggest_block_with_null_block() { TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(); await testRpc.BlockchainProcessor.StopAsync(); IBlockTree tree = testRpc.BlockTree; SuggestNumberOfBlocks(tree, 1); // simulating restarts - we stopped the old blockchain processor and create the new one BlockchainProcessor newBlockchainProcessor = new(tree, testRpc.BlockProcessor, testRpc.BlockPreprocessorStep, testRpc.StateReader, LimboLogs.Instance, BlockchainProcessor.Options.Default); newBlockchainProcessor.Start(); testRpc.BlockchainProcessor = newBlockchainProcessor; IBlockTreeVisitor fixer = new StartupBlockTreeFixer(new SyncConfig(), tree, testRpc.DbProvider.StateDb, LimboNoErrorLogger.Instance, 5); BlockVisitOutcome result = await fixer.VisitBlock(null, CancellationToken.None); Assert.AreEqual(BlockVisitOutcome.None, result); }
public async Task Fixer_should_not_suggest_block_without_state(int suggestedBlocksAmount) { TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(); await testRpc.BlockchainProcessor.StopAsync(); IBlockTree tree = testRpc.BlockTree; SuggestNumberOfBlocks(tree, suggestedBlocksAmount); // simulating restarts - we stopped the old blockchain processor and create the new one BlockchainProcessor newBlockchainProcessor = new(tree, testRpc.BlockProcessor, testRpc.BlockPreprocessorStep, LimboLogs.Instance, BlockchainProcessor.Options.Default); newBlockchainProcessor.Start(); testRpc.BlockchainProcessor = newBlockchainProcessor; // we create a new empty db for stateDb so we shouldn't suggest new blocks MemDb stateDb = new(); IBlockTreeVisitor fixer = new StartupBlockTreeFixer(new SyncConfig(), tree, stateDb, LimboNoErrorLogger.Instance, 5); BlockVisitOutcome result = await fixer.VisitBlock(tree.Head !, CancellationToken.None); Assert.AreEqual(BlockVisitOutcome.None, result); }