{"action":"created","comment":{"url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/comments/226351792","pull_request_review_id":166154363,"id":226351792,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNjM1MTc5Mg==","diff_hunk":"@@ -0,0 +1,111 @@\n+﻿using System.Collections.Generic;\n+using System.Linq;\n+using System.Threading.Tasks;\n+using Microsoft.Extensions.Logging;\n+using Stratis.Bitcoin.Connection;\n+using Stratis.Bitcoin.P2P;\n+using Stratis.Bitcoin.P2P.Peer;\n+using Stratis.Bitcoin.P2P.Protocol;\n+using Stratis.Bitcoin.P2P.Protocol.Behaviors;\n+using Stratis.Bitcoin.P2P.Protocol.Payloads;\n+using Stratis.Bitcoin.Utilities;\n+\n+namespace Stratis.Bitcoin.Features.Consensus.Behaviors\n+{\n+    public class ProvenHeadersReservedSlotsBehavior : NetworkPeerBehavior\n+    {\n+        private readonly IConnectionManager connectionManager;\n+        private readonly ILoggerFactory loggerFactory;\n+\n+        /// <summary>Instance logger.</summary>\n+        private readonly ILogger logger;\n+\n+        public ProvenHeadersReservedSlotsBehavior(\n+            IConnectionManager connectionManager,\n+            ILoggerFactory loggerFactory)\n+        {\n+            this.connectionManager = connectionManager;\n+            this.loggerFactory = loggerFactory;\n+            this.logger = loggerFactory.CreateLogger(this.GetType().FullName, $\"[{this.GetHashCode():x}] \");\n+        }\n+\n+        /// <summary>\n+        /// Processes and incoming message from the peer.\n+        /// </summary>\n+        /// <param name=\"peer\">Peer from which the message was received.</param>\n+        /// <param name=\"message\">Received message to process.</param>\n+        protected async Task OnMessageReceivedAsync(INetworkPeer peer, IncomingMessage message)\n+        {\n+            switch (message.Message.Payload)\n+            {\n+                case VersionPayload version:\n+                    await this.ProcessVersionAsync(peer, version).ConfigureAwait(false);\n+                    break;\n+            }\n+        }\n+\n+        /// <summary>\n+        /// Processes \"version\" message received from the peer.\n+        /// Ensures we leave some available connection slots to nodes that are enabled to serve Proven Headers, if the number of minimum PH enabled nodes connected isn't met.\n+        /// </summary>\n+        /// <param name=\"peer\">Peer from which the message was received.</param>\n+        /// <param name=\"version\">Payload of \"version\" message to process.</param>\n+        private Task ProcessVersionAsync(INetworkPeer peer, VersionPayload version)\n+        {\n+            PeerConnectorDiscovery connector = this.connectionManager.PeerConnectors.OfType<PeerConnectorDiscovery>().FirstOrDefault();\n+            // If PeerConnectorDiscovery is not found means we are using other ways to connect peers (like -connect) and thus we don't enforce the rule.\n+            if (connector != null)\n+            {\n+                int freeSlots = connector.MaxOutboundConnections - connector.ConnectorPeers.Count;\n+                if (freeSlots >= 1)\n+                {\n+                    // There is at least one free slot, so we don't enforce this peer to be PH enabled.\n+                    return Task.CompletedTask;\n+                }\n+\n+                bool peerSupportsPH = peer.Version >= NBitcoin.Protocol.ProtocolVersion.PROVEN_HEADER_VERSION;\n+                if (peerSupportsPH)\n+                {\n+                    INetworkPeer nodeToDisconnect = GetConnectedLegacyPeersSortedByTip(connector.ConnectorPeers).FirstOrDefault();\n+                    if (nodeToDisconnect != null)","path":"src/Stratis.Bitcoin.Features.Consensus/Behaviors/ProvenHeadersReservedSlotsBehavior.cs","position":71,"original_position":70,"commit_id":"06eb9a2cc90ae30660d454a7b937d1e5a7df2ea6","original_commit_id":"f94b1a887ee49a65d621b9b0bd965f1a063721de","user":{"login":"dangershony","id":7487930,"node_id":"MDQ6VXNlcjc0ODc5MzA=","avatar_url":"https://avatars2.githubusercontent.com/u/7487930?v=4","gravatar_id":"","url":"https://api.github.com/users/dangershony","html_url":"https://github.com/dangershony","followers_url":"https://api.github.com/users/dangershony/followers","following_url":"https://api.github.com/users/dangershony/following{/other_user}","gists_url":"https://api.github.com/users/dangershony/gists{/gist_id}","starred_url":"https://api.github.com/users/dangershony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dangershony/subscriptions","organizations_url":"https://api.github.com/users/dangershony/orgs","repos_url":"https://api.github.com/users/dangershony/repos","events_url":"https://api.github.com/users/dangershony/events{/privacy}","received_events_url":"https://api.github.com/users/dangershony/received_events","type":"User","site_admin":false},"body":"yes its fine, this is dev preference so no problem","created_at":"2018-10-18T15:24:40Z","updated_at":"2018-10-18T15:24:40Z","html_url":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/2469#discussion_r226351792","pull_request_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/2469","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/comments/226351792"},"html":{"href":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/2469#discussion_r226351792"},"pull_request":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/2469"}},"in_reply_to_id":226297760},"pull_request":{"url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/2469","id":222220537,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIyMjIwNTM3","html_url":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/2469","diff_url":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/2469.diff","patch_url":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/2469.patch","issue_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues/2469","number":2469,"state":"open","locked":false,"title":"[PH] Disconnect peers when node can't advance","user":{"login":"MithrilMan","id":5107375,"node_id":"MDQ6VXNlcjUxMDczNzU=","avatar_url":"https://avatars3.githubusercontent.com/u/5107375?v=4","gravatar_id":"","url":"https://api.github.com/users/MithrilMan","html_url":"https://github.com/MithrilMan","followers_url":"https://api.github.com/users/MithrilMan/followers","following_url":"https://api.github.com/users/MithrilMan/following{/other_user}","gists_url":"https://api.github.com/users/MithrilMan/gists{/gist_id}","starred_url":"https://api.github.com/users/MithrilMan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MithrilMan/subscriptions","organizations_url":"https://api.github.com/users/MithrilMan/orgs","repos_url":"https://api.github.com/users/MithrilMan/repos","events_url":"https://api.github.com/users/MithrilMan/events{/privacy}","received_events_url":"https://api.github.com/users/MithrilMan/received_events","type":"User","site_admin":false},"body":"implementation of #2146 \r\n\r\nEnsures we leave some available connection slots to nodes that are enabled to serve Proven Headers, if the number of minimum PH enabled nodes connected isn't met.\r\n\r\nDuring IBD, all nodes are allowed.","created_at":"2018-10-11T17:34:32Z","updated_at":"2018-10-18T15:24:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"69c3b2aa1b4cd28e43c04f845baaafe6c97e8ad3","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/2469/commits","review_comments_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/2469/comments","review_comment_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues/2469/comments","statuses_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/statuses/06eb9a2cc90ae30660d454a7b937d1e5a7df2ea6","head":{"label":"MithrilMan:ph/disconnect-legacy-nodes","ref":"ph/disconnect-legacy-nodes","sha":"06eb9a2cc90ae30660d454a7b937d1e5a7df2ea6","user":{"login":"MithrilMan","id":5107375,"node_id":"MDQ6VXNlcjUxMDczNzU=","avatar_url":"https://avatars3.githubusercontent.com/u/5107375?v=4","gravatar_id":"","url":"https://api.github.com/users/MithrilMan","html_url":"https://github.com/MithrilMan","followers_url":"https://api.github.com/users/MithrilMan/followers","following_url":"https://api.github.com/users/MithrilMan/following{/other_user}","gists_url":"https://api.github.com/users/MithrilMan/gists{/gist_id}","starred_url":"https://api.github.com/users/MithrilMan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MithrilMan/subscriptions","organizations_url":"https://api.github.com/users/MithrilMan/orgs","repos_url":"https://api.github.com/users/MithrilMan/repos","events_url":"https://api.github.com/users/MithrilMan/events{/privacy}","received_events_url":"https://api.github.com/users/MithrilMan/received_events","type":"User","site_admin":false},"repo":{"id":82193635,"node_id":"MDEwOlJlcG9zaXRvcnk4MjE5MzYzNQ==","name":"StratisBitcoinFullNode","full_name":"MithrilMan/StratisBitcoinFullNode","private":false,"owner":{"login":"MithrilMan","id":5107375,"node_id":"MDQ6VXNlcjUxMDczNzU=","avatar_url":"https://avatars3.githubusercontent.com/u/5107375?v=4","gravatar_id":"","url":"https://api.github.com/users/MithrilMan","html_url":"https://github.com/MithrilMan","followers_url":"https://api.github.com/users/MithrilMan/followers","following_url":"https://api.github.com/users/MithrilMan/following{/other_user}","gists_url":"https://api.github.com/users/MithrilMan/gists{/gist_id}","starred_url":"https://api.github.com/users/MithrilMan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MithrilMan/subscriptions","organizations_url":"https://api.github.com/users/MithrilMan/orgs","repos_url":"https://api.github.com/users/MithrilMan/repos","events_url":"https://api.github.com/users/MithrilMan/events{/privacy}","received_events_url":"https://api.github.com/users/MithrilMan/received_events","type":"User","site_admin":false},"html_url":"https://github.com/MithrilMan/StratisBitcoinFullNode","description":null,"fork":true,"url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode","forks_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/forks","keys_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/teams","hooks_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/hooks","issue_events_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/issues/events{/number}","events_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/events","assignees_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/assignees{/user}","branches_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/branches{/branch}","tags_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/tags","blobs_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/git/refs{/sha}","trees_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/statuses/{sha}","languages_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/languages","stargazers_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/stargazers","contributors_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/contributors","subscribers_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/subscribers","subscription_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/subscription","commits_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/commits{/sha}","git_commits_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/git/commits{/sha}","comments_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/comments{/number}","issue_comment_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/issues/comments{/number}","contents_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/contents/{+path}","compare_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/merges","archive_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/downloads","issues_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/issues{/number}","pulls_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/pulls{/number}","milestones_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/milestones{/number}","notifications_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/labels{/name}","releases_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/releases{/id}","deployments_url":"https://api.github.com/repos/MithrilMan/StratisBitcoinFullNode/deployments","created_at":"2017-02-16T15:12:31Z","updated_at":"2018-10-18T13:27:02Z","pushed_at":"2018-10-18T13:53:08Z","git_url":"git://github.com/MithrilMan/StratisBitcoinFullNode.git","ssh_url":"git@github.com:MithrilMan/StratisBitcoinFullNode.git","clone_url":"https://github.com/MithrilMan/StratisBitcoinFullNode.git","svn_url":"https://github.com/MithrilMan/StratisBitcoinFullNode","homepage":null,"size":38013,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"stratisproject:master","ref":"master","sha":"452ac0760d8c3317a74cf90add35bcf60a73cb1b","user":{"login":"stratisproject","id":15229748,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1MjI5NzQ4","avatar_url":"https://avatars0.githubusercontent.com/u/15229748?v=4","gravatar_id":"","url":"https://api.github.com/users/stratisproject","html_url":"https://github.com/stratisproject","followers_url":"https://api.github.com/users/stratisproject/followers","following_url":"https://api.github.com/users/stratisproject/following{/other_user}","gists_url":"https://api.github.com/users/stratisproject/gists{/gist_id}","starred_url":"https://api.github.com/users/stratisproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stratisproject/subscriptions","organizations_url":"https://api.github.com/users/stratisproject/orgs","repos_url":"https://api.github.com/users/stratisproject/repos","events_url":"https://api.github.com/users/stratisproject/events{/privacy}","received_events_url":"https://api.github.com/users/stratisproject/received_events","type":"Organization","site_admin":false},"repo":{"id":67271290,"node_id":"MDEwOlJlcG9zaXRvcnk2NzI3MTI5MA==","name":"StratisBitcoinFullNode","full_name":"stratisproject/StratisBitcoinFullNode","private":false,"owner":{"login":"stratisproject","id":15229748,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1MjI5NzQ4","avatar_url":"https://avatars0.githubusercontent.com/u/15229748?v=4","gravatar_id":"","url":"https://api.github.com/users/stratisproject","html_url":"https://github.com/stratisproject","followers_url":"https://api.github.com/users/stratisproject/followers","following_url":"https://api.github.com/users/stratisproject/following{/other_user}","gists_url":"https://api.github.com/users/stratisproject/gists{/gist_id}","starred_url":"https://api.github.com/users/stratisproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stratisproject/subscriptions","organizations_url":"https://api.github.com/users/stratisproject/orgs","repos_url":"https://api.github.com/users/stratisproject/repos","events_url":"https://api.github.com/users/stratisproject/events{/privacy}","received_events_url":"https://api.github.com/users/stratisproject/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/stratisproject/StratisBitcoinFullNode","description":"Bitcoin full node in C#","fork":false,"url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode","forks_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/forks","keys_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/teams","hooks_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/hooks","issue_events_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues/events{/number}","events_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/events","assignees_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/assignees{/user}","branches_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/branches{/branch}","tags_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/tags","blobs_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/git/refs{/sha}","trees_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/statuses/{sha}","languages_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/languages","stargazers_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/stargazers","contributors_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/contributors","subscribers_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/subscribers","subscription_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/subscription","commits_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/commits{/sha}","git_commits_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/git/commits{/sha}","comments_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/comments{/number}","issue_comment_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues/comments{/number}","contents_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/contents/{+path}","compare_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/merges","archive_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/downloads","issues_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues{/number}","pulls_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls{/number}","milestones_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/milestones{/number}","notifications_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/labels{/name}","releases_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/releases{/id}","deployments_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/deployments","created_at":"2016-09-03T04:32:51Z","updated_at":"2018-10-18T13:50:10Z","pushed_at":"2018-10-18T14:00:07Z","git_url":"git://github.com/stratisproject/StratisBitcoinFullNode.git","ssh_url":"git@github.com:stratisproject/StratisBitcoinFullNode.git","clone_url":"https://github.com/stratisproject/StratisBitcoinFullNode.git","svn_url":"https://github.com/stratisproject/StratisBitcoinFullNode","homepage":"https://stratisplatform.com","size":34761,"stargazers_count":585,"watchers_count":585,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":256,"mirror_url":null,"archived":false,"open_issues_count":197,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":256,"open_issues":197,"watchers":585,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/2469"},"html":{"href":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/2469"},"issue":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues/2469"},"comments":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues/2469/comments"},"review_comments":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/2469/comments"},"review_comment":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/2469/commits"},"statuses":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/statuses/06eb9a2cc90ae30660d454a7b937d1e5a7df2ea6"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"dangershony"}}