Exemplo n.º 1
0
 public bool TryGetAtHeight(int height, [MaybeNullWhen(false)] out HeaderNode?headerNode)
 {
     using (GlobalLocks.ReadOnMainAsync().GetAwaiter().GetResult())
     {
         return(HeadersTree.TryGetNodeOnBestChain(height, out headerNode));
     }
 }
Exemplo n.º 2
0
        public HeaderNode AddToBlockIndex(BlockHeader header)
        {
            using (GlobalLocks.WriteOnMainAsync().GetAwaiter().GetResult())
            {
                // Check for duplicate
                if (TryGetKnownHeaderNode(header.Hash, out HeaderNode? headerNode))
                {
                    return(headerNode);
                }

                if (!TryGetKnownHeaderNode(header.PreviousBlockHash, out HeaderNode? previousHeader))
                {
                    ThrowHelper.ThrowNotSupportedException("Previous hash not found (shouldn't happen).");
                }

                headerNode = new HeaderNode(header, previousHeader);

                if (BestHeader == null || BestHeader.ChainWork < headerNode.ChainWork)
                {
                    BestHeader = headerNode;
                }

                HeadersTree.Add(headerNode);
                _blockHeaderRepository.TryAdd(header);

                return(headerNode);
            }
        }
Exemplo n.º 3
0
        public bool TryGetNext(HeaderNode headerNode, [MaybeNullWhen(false)] out HeaderNode nextHeaderNode)
        {
            using (GlobalLocks.ReadOnMainAsync().GetAwaiter().GetResult())
            {
                if (IsInBestChain(headerNode) && HeadersTree.TryGetNodeOnBestChain(headerNode.Height + 1, out nextHeaderNode))
                {
                    return(true);
                }

                nextHeaderNode = null;
                return(false);
            }
        }
Exemplo n.º 4
0
 public bool IsInBestChain(HeaderNode headerNode)
 {
     return(HeadersTree.IsInBestChain(headerNode));
 }
Exemplo n.º 5
0
 public BlockLocator?GetLocator(HeaderNode headerNode)
 {
     using Microsoft.VisualStudio.Threading.AsyncReaderWriterLock.Releaser readMainLock = GlobalLocks.ReadOnMainAsync().GetAwaiter().GetResult();
     return(HeadersTree.GetLocator(headerNode));
 }
Exemplo n.º 6
0
 public bool TryGetKnownHeaderNode(UInt256?blockHash, [MaybeNullWhen(false)] out HeaderNode node)
 {
     //using var readLock = new ReadLock(this.theLock);
     using Microsoft.VisualStudio.Threading.AsyncReaderWriterLock.Releaser readMainLock = GlobalLocks.ReadOnMainAsync().GetAwaiter().GetResult();
     return(HeadersTree.TryGetNode(blockHash, false, out node));
 }
Exemplo n.º 7
0
 public bool TryGetBestChainHeaderNode(UInt256 blockHash, [MaybeNullWhen(false)] out HeaderNode node)
 {
     using Microsoft.VisualStudio.Threading.AsyncReaderWriterLock.Releaser readMainLock = GlobalLocks.ReadOnMainAsync().GetAwaiter().GetResult();
     return(HeadersTree.TryGetNode(blockHash, true, out node));
 }