summaryrefslogtreecommitdiff
path: root/40/823700813cc957c6a90e9513184bd0243f3bee
blob: 76f5a0fde140b0417506c8b77cf140435c33560f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Return-Path: <wordsgalore@gmail.com>
Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org
	[172.17.192.35])
	by mail.linuxfoundation.org (Postfix) with ESMTPS id C98FCD51
	for <bitcoin-dev@lists.linuxfoundation.org>;
	Thu,  2 Nov 2017 23:31:58 +0000 (UTC)
X-Greylist: whitelisted by SQLgrey-1.7.6
Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51])
	by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 7BE1C483
	for <bitcoin-dev@lists.linuxfoundation.org>;
	Thu,  2 Nov 2017 23:31:57 +0000 (UTC)
Received: by mail-wm0-f51.google.com with SMTP id t139so1983421wmt.1
	for <bitcoin-dev@lists.linuxfoundation.org>;
	Thu, 02 Nov 2017 16:31:57 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
	h=mime-version:from:date:message-id:subject:to;
	bh=y/ELpHjZ01vvm/xWfMZsHL97bLpWcHBvxhmxbUOIShM=;
	b=vM/2/2Nr2Fe5SltQPsxYXZosWMLIfQkWbKXIe3twlJFR4TmN+j6qlQJwZWbqg9Zhdp
	AdZJ7RXmncnhV5+VA1Ith0CVr6EqjmelARoZjs1ae53gfWiA9JiShl88s60oSYY2Me5L
	HY/1jTOLPzXjleT4hIhkDiwiVY1sDDR0VeA1kgHHItGYN2w0qpK58JYsYlxkCa55zNwy
	uvmtCBvg23JVrM/raCq5hivo5YtXnQgOunt/8tA89zVOh4s8eq+3vNemL/kisjytVv6b
	JWE1cDLvUtRyUWUbvdKDZlJtQLJ5hYEpKBV6xzb/mv2Amx510DfO6xlNspDOjwvGUFAu
	pqCQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20161025;
	h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
	bh=y/ELpHjZ01vvm/xWfMZsHL97bLpWcHBvxhmxbUOIShM=;
	b=QrSgN+jzVwQCZNFiuC4E1UTt6Ixr68ZTACdD6KCkuNIXhNRPBDiyqtkf+H2+43enVa
	g43KboCS0HloCjszvYt9tEKKdnmXnF+WG+J2O8SQGIHOuAuLMsRPXTGSkFFIKlTkX6fL
	vizND6bTIwQ6jEzgUxHZLrNT7fOU0hXMW4f+SIh8yq/m+RKrABgKtVeiRIkSPYIxkkEg
	sO6DA7u83FBIclUmxSsDK+ihDbi2ufHbszoA5lpM1s5XW/0cCMjQ7Dc+aKqZx8Xymk5j
	dFpsCT6y+wZ12KY9igoE24AjKtVlbbo1mEBlj20E/VpOV8oXoFd8Rs3lxs42oPeW2N7w
	M10Q==
X-Gm-Message-State: AMCzsaUbkd6CCp+D/ZezHeWoMc6Emz3TzIl2MLHbfpxDJLv48B+Uq5Pj
	E6gIjHTWM2yITellK0lgipWwoOqKIBw8vMCtq38d9g==
X-Google-Smtp-Source: ABhQp+Q+c8AAlnikSzlSQpxyOiRqyuCBYCxLgihIhzhgTgHMnl3wDkbv+563uafTVLBxgFlHVgBMQsbiBrXHgqFRI7k=
X-Received: by 10.80.185.68 with SMTP id m62mr6357037ede.239.1509665515797;
	Thu, 02 Nov 2017 16:31:55 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.80.173.10 with HTTP; Thu, 2 Nov 2017 16:31:55 -0700 (PDT)
From: Scott Roberts <wordsgalore@gmail.com>
Date: Thu, 2 Nov 2017 19:31:55 -0400
Message-ID: <CADtTMvn8=uqCwwtvrqjLuN_6ADt+65YpEffSqnBozmWXWO--9A@mail.gmail.com>
To: Bitcoin Protocol Discussion <bitcoin-dev@lists.linuxfoundation.org>
Content-Type: text/plain; charset="UTF-8"
X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID,
	DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM
	autolearn=disabled version=3.3.1
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
	smtp1.linux-foundation.org
X-Mailman-Approved-At: Thu, 02 Nov 2017 23:33:18 +0000
Subject: [bitcoin-dev] Bitcoin Cash's new difficulty algorithm
X-BeenThere: bitcoin-dev@lists.linuxfoundation.org
X-Mailman-Version: 2.1.12
Precedence: list
List-Id: Bitcoin Protocol Discussion <bitcoin-dev.lists.linuxfoundation.org>
List-Unsubscribe: <https://lists.linuxfoundation.org/mailman/options/bitcoin-dev>,
	<mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=unsubscribe>
List-Archive: <http://lists.linuxfoundation.org/pipermail/bitcoin-dev/>
List-Post: <mailto:bitcoin-dev@lists.linuxfoundation.org>
List-Help: <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=help>
List-Subscribe: <https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev>,
	<mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=subscribe>
X-List-Received-Date: Thu, 02 Nov 2017 23:31:58 -0000

Bitcoin cash will hard fork on Nov 13 to implement a new difficulty
algorithm.  Bitcoin itself might need to hard fork to employ a similar
algorithm. It's about as good as they come because it followed the
"simplest is best" route. Their averaging window is probably
significantly too long (N=144). It's:

next_D = sum (past 144 D's) * T / sum(past 144 solvetimes)

They correctly did not use max(timestamp) - min(timestamp) in the
denominator like others do.

They've written the code and they're about to use it live, so Bitcoin
will have a clear, simple, and tested path if it suddenly needs to
hard fork due to having 20x delays for the next 2000 blocks (taking it
a year to get unstuck).

Details on it and the decision process:
https://www.bitcoinabc.org/november

It uses a nice median of 3 for the beginning and end of the window to
help alleviate bad timestamp problems. It's nice, helps a little, but
will also slow its response by 1 block.  They also have 2x and 1/2
limits on the adjustment per block, which is a lot more than they will
ever need.

I recommend bitcoin consider using it and making it N=50 instead of 144.

I have seen that any attempts to modify the above with things like a
low pass filter, starting the window at MTP, or preventing negative
timestamps will only reduce its effectiveness. Bitcoin's +12 and -6
limits on the timestamps are sufficient and well chosen, although
something a bit smaller than the +12 might have been better.

One of the contenders to the above is new and actually better, devised
by Degnr8 and they call it D622 or wt-144.It's a little better than
they realize. It's the only real improvement in difficulty algorithms
since the rolling average.  It gives a linearly higher weight to the
more recent timestamps. Otherwise it is the same. Others have probably
come across it, but there is too much noise in difficulty algorithms
to find the good ones.

# Degnr8's D622 difficulty algorithm
# T=TargetTime, S=Solvetime
# modified by zawy
for i = 1 to N  (from oldest to most recent block)
    t += T[i] / D[i] * i
    j += i
next i
next_D = j / t * T

I believe any modification to the above strict mathematical weighted
average will reduce it's effectiveness. It does not oscillate anymore
than regular algos and rises faster and drops faster, when needed.