Exemple #1
0
            private void Node_MessageReceived(Node node, IncomingMessage message)
            {
                // Attempting to find the peers current best chain
                // to be used by the puller to determine if the peer can server blocks
                message.Message.IfPayloadIs <HeadersPayload>(header =>
                {
                    foreach (var blockHeader in header.Headers)
                    {
                        var cahinedBlock = this._Puller.Chain.GetBlock(blockHeader.GetHash());
                        this.TrySetBestKnownTip(cahinedBlock);
                    }
                });

                message.Message.IfPayloadIs <BlockPayload>((block) =>
                {
                    block.Object.Header.CacheHashes();
                    QualityScore = Math.Min(MaxQualityScore, QualityScore + 1);
                    uint256 unused;
                    if (!_PendingDownloads.TryRemove(block.Object.Header.GetHash(), out unused))
                    {
                        //TODO: Add support for unsollicited block
                        // This can be sent by a miner discovering new block
                        // the expected logic:
                        // - partially validate the header
                        // - check if block is a new best chain
                        // - set MerkleChain.Tip (and corresponding ChainBehaviour.PendingTIp for this node)
                        // - push the block to the download dictionary
                        return;
                    }
                    NodesBlockPullerBehavior unused2;
                    if (_Puller._Map.TryRemove(block.Object.Header.GetHash(), out unused2))
                    {
                        foreach (var tx in block.Object.Transactions)
                        {
                            tx.CacheHashes();
                        }
                        _Puller.PushBlock((int)message.Length, block.Object, _Cts.Token);
                        this.AssignPendingVector();
                    }
                });
            }
Exemple #2
0
 private void Node_MessageReceived(Node node, IncomingMessage message)
 {
     message.Message.IfPayloadIs <BlockPayload>((block) =>
     {
         block.Object.Header.CacheHashes();
         QualityScore = Math.Min(MaxQualityScore, QualityScore + 1);
         uint256 unused;
         if (!_PendingDownloads.TryRemove(block.Object.Header.GetHash(), out unused))
         {
             //Unsollicited
             return;
         }
         NodesBlockPullerBehavior unused2;
         if (_Puller._Map.TryRemove(block.Object.Header.GetHash(), out unused2))
         {
             foreach (var tx in block.Object.Transactions)
             {
                 tx.CacheHashes();
             }
             _Puller.PushBlock((int)message.Length, block.Object, _Cts.Token);
             AssignPendingVector();
         }
     });
 }