{"action":"created","comment":{"url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/comments/197722019","pull_request_review_id":131518726,"id":197722019,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NzcyMjAxOQ==","diff_hunk":"@@ -0,0 +1,118 @@\n+﻿using System;\n+using Moq;\n+using Stratis.Bitcoin.BlockPulling2;\n+using Stratis.Bitcoin.Configuration.Logging;\n+using Stratis.Bitcoin.Interfaces;\n+using Xunit;\n+\n+namespace Stratis.Bitcoin.Tests.BlockPulling2\n+{\n+    public class BlockPullerBehaviorTests\n+    {\n+        private readonly BlockPullerBehavior behavior;\n+\n+        public BlockPullerBehaviorTests()\n+        {\n+            var puller = new Mock<IBlockPuller>();\n+\n+            var ibdState = new Mock<IInitialBlockDownloadState>();\n+            ibdState.Setup(x => x.IsInitialBlockDownload()).Returns(() => true);\n+\n+            var loggerFactory = new ExtendedLoggerFactory();\n+            loggerFactory.AddConsoleWithFilters();\n+\n+            this.behavior = new BlockPullerBehavior(puller.Object, ibdState.Object, loggerFactory);\n+        }\n+\n+        [Fact]\n+        public void InitializesWithDefaultValues()\n+        {\n+            Assert.Equal(BlockPullerBehavior.SamplelessQualityScore, this.behavior.QualityScore);\n+            Assert.Equal(0, this.behavior.SpeedBytesPerSecond);\n+            Assert.Null(this.behavior.Tip);\n+        }\n+\n+        [Fact]\n+        public void QualityScoreCanGoToMinimum()\n+        {\n+            this.behavior.Penalize(10, 10);\n+            this.behavior.RecalculateQualityScore(1000);\n+\n+            Assert.Equal(BlockPullerBehavior.MinQualityScore, this.behavior.QualityScore);\n+        }\n+\n+        [Fact]\n+        public void QualityScoreCanGoToMaximum()\n+        {\n+            this.behavior.AddSample(1000, 1);\n+            this.behavior.RecalculateQualityScore(1);\n+\n+            Assert.Equal(BlockPullerBehavior.MaxQualityScore, this.behavior.QualityScore);\n+        }\n+\n+        [Fact]\n+        public void QualityScoreIsRelativeToBestSpeed()\n+        {\n+            this.behavior.AddSample(1000, 1);\n+            this.behavior.RecalculateQualityScore(this.behavior.SpeedBytesPerSecond * 2);\n+\n+            Assert.True(this.DoubleEqual(0.5, this.behavior.QualityScore));\n+        }\n+\n+        [Fact]\n+        public void SpeedBytesPerSecondCalculatedCorrectly()\n+        {\n+            this.behavior.AddSample(1000, 1);\n+            this.behavior.AddSample(2000, 1);\n+            this.behavior.AddSample(1000, 10);\n+            this.behavior.AddSample(500, 2);\n+\n+            // (500+1000+2000+1000) / (1+ 1 + 10 + 2) == 321.428\n+            Assert.Equal(321, this.behavior.SpeedBytesPerSecond);\n+        }\n+\n+        [Fact]\n+        public void WhenIBDStateChangesMaxSamplesNuberIsRecalculated()","path":"src/Stratis.Bitcoin.Tests/BlockPulling2/BlockPullerBehaviorTests.cs","position":75,"original_position":75,"commit_id":"a9bb58b993752bb785dbfae923ae3469ff7e59e5","original_commit_id":"a9bb58b993752bb785dbfae923ae3469ff7e59e5","user":{"login":"Aprogiena","id":30052221,"node_id":"MDQ6VXNlcjMwMDUyMjIx","avatar_url":"https://avatars0.githubusercontent.com/u/30052221?v=4","gravatar_id":"","url":"https://api.github.com/users/Aprogiena","html_url":"https://github.com/Aprogiena","followers_url":"https://api.github.com/users/Aprogiena/followers","following_url":"https://api.github.com/users/Aprogiena/following{/other_user}","gists_url":"https://api.github.com/users/Aprogiena/gists{/gist_id}","starred_url":"https://api.github.com/users/Aprogiena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aprogiena/subscriptions","organizations_url":"https://api.github.com/users/Aprogiena/orgs","repos_url":"https://api.github.com/users/Aprogiena/repos","events_url":"https://api.github.com/users/Aprogiena/events{/privacy}","received_events_url":"https://api.github.com/users/Aprogiena/received_events","type":"User","site_admin":false},"body":"Also should check whether the new average is correctly calculated","created_at":"2018-06-25T08:53:08Z","updated_at":"2018-06-25T08:53:08Z","html_url":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/1530#discussion_r197722019","pull_request_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/1530","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/comments/197722019"},"html":{"href":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/1530#discussion_r197722019"},"pull_request":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/1530"}},"in_reply_to_id":197721738},"pull_request":{"url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/1530","id":195333583,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk1MzMzNTgz","html_url":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/1530","diff_url":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/1530.diff","patch_url":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/1530.patch","issue_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues/1530","number":1530,"state":"open","locked":false,"title":"Created new block puller","user":{"login":"noescape00","id":10259355,"node_id":"MDQ6VXNlcjEwMjU5MzU1","avatar_url":"https://avatars0.githubusercontent.com/u/10259355?v=4","gravatar_id":"","url":"https://api.github.com/users/noescape00","html_url":"https://github.com/noescape00","followers_url":"https://api.github.com/users/noescape00/followers","following_url":"https://api.github.com/users/noescape00/following{/other_user}","gists_url":"https://api.github.com/users/noescape00/gists{/gist_id}","starred_url":"https://api.github.com/users/noescape00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noescape00/subscriptions","organizations_url":"https://api.github.com/users/noescape00/orgs","repos_url":"https://api.github.com/users/noescape00/repos","events_url":"https://api.github.com/users/noescape00/events{/privacy}","received_events_url":"https://api.github.com/users/noescape00/received_events","type":"User","site_admin":false},"body":"Block puller that allows syncing from different chain, threadsafe and quicker than prev one. It also implements relative quality score. \r\n\r\nThis PR is the 1st one. 2nd will connect it to the ConsensusManager and probably activate it. ","created_at":"2018-06-16T14:02:03Z","updated_at":"2018-06-25T08:53:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"69fca7549a979b9ee5e1316b7eed0b09c1190997","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/1530/commits","review_comments_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/1530/comments","review_comment_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues/1530/comments","statuses_url":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/statuses/a9bb58b993752bb785dbfae923ae3469ff7e59e5","head":{"label":"noescape00:BlockPuller","ref":"BlockPuller","sha":"a9bb58b993752bb785dbfae923ae3469ff7e59e5","user":{"login":"noescape00","id":10259355,"node_id":"MDQ6VXNlcjEwMjU5MzU1","avatar_url":"https://avatars0.githubusercontent.com/u/10259355?v=4","gravatar_id":"","url":"https://api.github.com/users/noescape00","html_url":"https://github.com/noescape00","followers_url":"https://api.github.com/users/noescape00/followers","following_url":"https://api.github.com/users/noescape00/following{/other_user}","gists_url":"https://api.github.com/users/noescape00/gists{/gist_id}","starred_url":"https://api.github.com/users/noescape00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noescape00/subscriptions","organizations_url":"https://api.github.com/users/noescape00/orgs","repos_url":"https://api.github.com/users/noescape00/repos","events_url":"https://api.github.com/users/noescape00/events{/privacy}","received_events_url":"https://api.github.com/users/noescape00/received_events","type":"User","site_admin":false},"repo":{"id":109851531,"node_id":"MDEwOlJlcG9zaXRvcnkxMDk4NTE1MzE=","name":"StratisBitcoinFullNode","full_name":"noescape00/StratisBitcoinFullNode","owner":{"login":"noescape00","id":10259355,"node_id":"MDQ6VXNlcjEwMjU5MzU1","avatar_url":"https://avatars0.githubusercontent.com/u/10259355?v=4","gravatar_id":"","url":"https://api.github.com/users/noescape00","html_url":"https://github.com/noescape00","followers_url":"https://api.github.com/users/noescape00/followers","following_url":"https://api.github.com/users/noescape00/following{/other_user}","gists_url":"https://api.github.com/users/noescape00/gists{/gist_id}","starred_url":"https://api.github.com/users/noescape00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noescape00/subscriptions","organizations_url":"https://api.github.com/users/noescape00/orgs","repos_url":"https://api.github.com/users/noescape00/repos","events_url":"https://api.github.com/users/noescape00/events{/privacy}","received_events_url":"https://api.github.com/users/noescape00/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/noescape00/StratisBitcoinFullNode","description":"Bitcoin full node in C#","fork":true,"url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode","forks_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/forks","keys_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/keys{/key_id}","collaborators_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/teams","hooks_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/hooks","issue_events_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/issues/events{/number}","events_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/events","assignees_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/assignees{/user}","branches_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/branches{/branch}","tags_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/tags","blobs_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/git/refs{/sha}","trees_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/git/trees{/sha}","statuses_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/statuses/{sha}","languages_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/languages","stargazers_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/stargazers","contributors_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/contributors","subscribers_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/subscribers","subscription_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/subscription","commits_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/commits{/sha}","git_commits_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/git/commits{/sha}","comments_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/comments{/number}","issue_comment_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/issues/comments{/number}","contents_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/contents/{+path}","compare_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/compare/{base}...{head}","merges_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/merges","archive_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/downloads","issues_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/issues{/number}","pulls_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/pulls{/number}","milestones_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/milestones{/number}","notifications_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/labels{/name}","releases_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/releases{/id}","deployments_url":"https://api.github.com/repos/noescape00/StratisBitcoinFullNode/deployments","created_at":"2017-11-07T15:09:59Z","updated_at":"2018-06-22T09:48:00Z","pushed_at":"2018-06-24T21:45:59Z","git_url":"git://github.com/noescape00/StratisBitcoinFullNode.git","ssh_url":"git@github.com:noescape00/StratisBitcoinFullNode.git","clone_url":"https://github.com/noescape00/StratisBitcoinFullNode.git","svn_url":"https://github.com/noescape00/StratisBitcoinFullNode","homepage":"https://stratisplatform.com","size":29111,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"stratisproject:master","ref":"master","sha":"2179c5d80b3174f128d99b1a7ebc2c0c9305fae6","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","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},"private":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-06-24T06:37:40Z","pushed_at":"2018-06-24T21:46:00Z","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":30493,"stargazers_count":496,"watchers_count":496,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":218,"mirror_url":null,"archived":false,"open_issues_count":109,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":218,"open_issues":109,"watchers":496,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/1530"},"html":{"href":"https://github.com/stratisproject/StratisBitcoinFullNode/pull/1530"},"issue":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues/1530"},"comments":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/issues/1530/comments"},"review_comments":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/1530/comments"},"review_comment":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/pulls/1530/commits"},"statuses":{"href":"https://api.github.com/repos/stratisproject/StratisBitcoinFullNode/statuses/a9bb58b993752bb785dbfae923ae3469ff7e59e5"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"Aprogiena"}}