public static Block?FindParent(this IBlockFinder finder, Block block, BlockTreeLookupOptions options) { if (block.Header.ParentHash is null) { throw new InvalidOperationException( $"Cannot find parent when parent hash is null on block with hash {block.Hash}."); } return(finder.FindBlock(block.Header.ParentHash, options)); }
public BlockHeader FindHeader(Keccak blockHash, BlockTreeLookupOptions options) { if (blockHash == null || blockHash == Keccak.Zero) { // TODO: would be great to check why this is still needed (maybe it is something archaic) return(null); } BlockHeader header = _headerDb.Get(blockHash, _headerDecoder, _headerCache, false); if (header == null) { return(null); } bool totalDifficultyNeeded = (options & BlockTreeLookupOptions.TotalDifficultyNotNeeded) == BlockTreeLookupOptions.None; bool requiresCanonical = (options & BlockTreeLookupOptions.RequireCanonical) == BlockTreeLookupOptions.RequireCanonical; if ((totalDifficultyNeeded && header.TotalDifficulty == null) || requiresCanonical) { (BlockInfo blockInfo, ChainLevelInfo level) = LoadInfo(header.Number, header.Hash); if (level == null || blockInfo == null) { // TODO: this is here because storing block data is not transactional // TODO: would be great to remove it, he? SetTotalDifficulty(header); blockInfo = new BlockInfo(header.Hash, header.TotalDifficulty.Value); UpdateOrCreateLevel(header.Number, blockInfo); (_, level) = LoadInfo(header.Number, header.Hash); } else { header.TotalDifficulty = blockInfo.TotalDifficulty; } if (requiresCanonical) { bool isMain = level.MainChainBlock?.BlockHash.Equals(blockHash) == true; header = isMain ? header : null; } } if (header != null && ShouldCache(header.Number)) { _headerCache.Set(blockHash, header); } return(header); }
public BlockHeader FindHeader(Keccak blockHash, BlockTreeLookupOptions options) => _blockTree.FindHeader(blockHash, options);
public Block FindBlock(long blockNumber, BlockTreeLookupOptions options) => _blockTree.FindBlock(blockNumber, options);
public Block FindBlock(Keccak blockHash, BlockTreeLookupOptions options) => _blockTree.FindBlock(blockHash, options);
public BlockHeader FindHeader(long blockNumber, BlockTreeLookupOptions options) { return(_blockTree.FindHeader(blockNumber, options)); }
public static BlockHeader?FindParentHeader(this IBlockFinder finder, BlockHeader header, BlockTreeLookupOptions options) { if (header.MaybeParent is null) { if (header.ParentHash is null) { throw new InvalidOperationException( $"Cannot find parent when parent hash is null on block with hash {header.Hash}."); } BlockHeader parent = finder.FindHeader(header.ParentHash, options); header.MaybeParent = new WeakReference <BlockHeader>(parent); return(parent); } header.MaybeParent.TryGetTarget(out BlockHeader maybeParent); if (maybeParent is null) { if (header.ParentHash is null) { throw new InvalidOperationException( $"Cannot find parent when parent hash is null on block with hash {header.Hash}."); } BlockHeader parent = finder.FindHeader(header.ParentHash, options); header.MaybeParent.SetTarget(parent); return(parent); } if (maybeParent.TotalDifficulty is null && (options & BlockTreeLookupOptions.TotalDifficultyNotNeeded) == 0) { if (header.ParentHash is null) { throw new InvalidOperationException( $"Cannot find parent when parent hash is null on block with hash {header.Hash}."); } BlockHeader?fromDb = finder.FindHeader(header.ParentHash, options); maybeParent.TotalDifficulty = fromDb?.TotalDifficulty; } return(maybeParent); }
public static Block FindParent(this IBlockFinder finder, BlockHeader blockHeader, BlockTreeLookupOptions options) { return(finder.FindBlock(blockHeader.ParentHash, options)); }
public BlockHeader FindHeader(long blockNumber, BlockTreeLookupOptions options) => _headBlock.Number == blockNumber ? _headBlock.Header : null;
public BlockHeader FindHeader(Keccak blockHash, BlockTreeLookupOptions options) => _headBlock.Hash == blockHash ? _headBlock.Header : null;
public Block FindBlock(long blockNumber, BlockTreeLookupOptions options) => _headBlock.Number == blockNumber ? _headBlock : null;
public Block FindBlock(Keccak blockHash, BlockTreeLookupOptions options) => _headBlock.Hash == blockHash ? _headBlock : null;
public static Block FindParent(this IBlockTree tree, Block block, BlockTreeLookupOptions options) { return(tree.FindBlock(block.Header.ParentHash, options)); }
public static BlockHeader FindParentHeader(this IBlockTree tree, BlockHeader header, BlockTreeLookupOptions options) { return(tree.FindHeader(header.ParentHash, options)); }
public BlockHeader FindHeader(long blockNumber, BlockTreeLookupOptions options) => _blockTree.FindHeader(blockNumber, options);
public Block FindBlock(Keccak blockHash, BlockTreeLookupOptions option) { return(_blockTree.FindBlock(blockHash, option)); }
public static BlockHeader FindParentHeader(this IBlockFinder finder, BlockHeader header, BlockTreeLookupOptions options) { if (header.MaybeParent == null) { BlockHeader parent = finder.FindHeader(header.ParentHash, options); header.MaybeParent = new WeakReference <BlockHeader>(parent); return(parent); } header.MaybeParent.TryGetTarget(out BlockHeader maybeParent); if (maybeParent == null) { BlockHeader parent = finder.FindHeader(header.ParentHash, options); header.MaybeParent.SetTarget(parent); return(parent); } if (maybeParent.TotalDifficulty == null && (options & BlockTreeLookupOptions.TotalDifficultyNotNeeded) == 0) { BlockHeader fromDb = finder.FindHeader(header.ParentHash, options); maybeParent.TotalDifficulty = fromDb.TotalDifficulty; } return(maybeParent); }
public BlockHeader FindHeader(Keccak blockHash, BlockTreeLookupOptions options) { return(_blockTree.FindHeader(blockHash, options)); }
public BlockHeader FindHeader(long number, BlockTreeLookupOptions options) { Keccak blockHash = GetBlockHashOnMainOrBestDifficultyHash(number); return(blockHash == null ? null : FindHeader(blockHash, options)); }
public Block FindBlock(long blockNumber, BlockTreeLookupOptions options) { return(_blockTree.FindBlock(blockNumber, options)); }
public Block FindBlock(long blockNumber, BlockTreeLookupOptions options) { Keccak hash = GetBlockHashOnMainOrBestDifficultyHash(blockNumber); return(FindBlock(hash, options)); }
public Block FindBlock(Keccak blockHash, BlockTreeLookupOptions options) { return(_wrapped.FindBlock(blockHash, options)); }