示例#1
0
        private bool CanUseBloomDatabase(BlockHeader toBlock, BlockHeader fromBlock)
        {
            // method is designed for convenient debugging

            bool containsRange = _bloomStorage.ContainsRange(fromBlock.Number, toBlock.Number);

            if (!containsRange)
            {
                return(false);
            }

            bool toIsOnMainChain = _blockFinder.IsMainChain(toBlock);

            if (!toIsOnMainChain)
            {
                return(false);
            }

            bool fromIsOnMainChain = _blockFinder.IsMainChain(fromBlock);

            if (!fromIsOnMainChain)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public static IEnumerable <SearchResult <Block> > SearchForBlocksOnMainChain(this IBlockFinder blockFinder, BlockParameter fromBlock, BlockParameter toBlock)
        {
            SearchResult <Block> startingBlock = SearchForBlock(blockFinder, fromBlock);

            if (startingBlock.IsError || startingBlock.Object == null)
            {
                yield return(startingBlock);
            }
            else
            {
                SearchResult <BlockHeader> finalBlockHeader = SearchForHeader(blockFinder, toBlock);
                if (finalBlockHeader.IsError || finalBlockHeader.Object == null)
                {
                    yield return(new SearchResult <Block>(finalBlockHeader.Error ?? string.Empty, finalBlockHeader.ErrorCode));
                }
                bool isFinalBlockOnMainChain    = blockFinder.IsMainChain(finalBlockHeader.Object !);
                bool isStartingBlockOnMainChain = blockFinder.IsMainChain(startingBlock.Object.Header);
                if (!isFinalBlockOnMainChain || !isStartingBlockOnMainChain)
                {
                    Keccak?notCanonicalBlockHash = isFinalBlockOnMainChain
                        ? startingBlock.Object.Hash
                        : finalBlockHeader.Object.Hash;
                    yield return(new SearchResult <Block>($"{notCanonicalBlockHash} block is not canonical", ErrorCodes.InvalidInput));
                }
                else
                {
                    yield return(startingBlock);

                    long startingBlockNumber = startingBlock.Object.Number;
                    long finalBlockNumber    = finalBlockHeader.Object.Number;
                    if (startingBlockNumber > finalBlockNumber)
                    {
                        yield return(new SearchResult <Block>($"From block number: {startingBlockNumber} is greater than to block number {finalBlockNumber}", ErrorCodes.InvalidInput));
                    }

                    for (long i = startingBlock.Object.Number + 1; i <= finalBlockHeader.Object.Number; ++i)
                    {
                        yield return(SearchForBlock(blockFinder, new BlockParameter(i)));
                    }
                }
            }
        }
示例#3
0
 private bool CanUseBloomDatabase(BlockHeader toBlock, BlockHeader fromBlock) => _bloomStorage.ContainsRange(fromBlock.Number, toBlock.Number) && _blockFinder.IsMainChain(toBlock) && _blockFinder.IsMainChain(fromBlock);