summaryrefslogtreecommitdiff
path: root/7b/d5cbd3d90b3b936acf65ebadcbfe4a78a31da7
blob: aeb3f45b22f602654824f92df2669876e860a9ac (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
Return-Path: <bfd@cock.lu>
Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org
	[172.17.192.35])
	by mail.linuxfoundation.org (Postfix) with ESMTPS id 8FF49480
	for <bitcoin-dev@lists.linuxfoundation.org>;
	Wed,  8 Mar 2017 02:02:46 +0000 (UTC)
X-Greylist: from auto-whitelisted by SQLgrey-1.7.6
Received: from cock.li (cock.li [185.100.85.212])
	by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 68C4E17B
	for <bitcoin-dev@lists.linuxfoundation.org>;
	Wed,  8 Mar 2017 02:02:45 +0000 (UTC)
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
	smtp1.linux-foundation.org
X-Spam-Level: 
X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU autolearn=ham version=3.3.1
MIME-Version: 1.0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cock.lu; s=mail;
	t=1488938141; bh=1Q4zEJXg9D88zWSp7/aLMjU9Gr/f2PBBybCj/wzZxvY=;
	h=Date:From:To:Subject:In-Reply-To:References:From;
	b=mJggq7BCk3iqLSenX1b41P6ZartjYYJ1eOW7SgXGs0ZxSVSSizyW9TiN02Jkj7xE0
	gn8lnqARQrI/lP174TLpTWazN9TQ2HP8dB31BM/b/ZbOJd3fyaKafQC11Xtib6U3kJ
	LHwcXKNTTaSL27NoPNTh9YmtheJSer129b6hsLDh1GAeId671AFMG1bWIl58OnbvYT
	rIyVVslJenq4T356K2n1MaD/TZeVAOtXUw8KWi/c58y4Dd/n2SJc8WmYw5ZPG92WW/
	GyAx1+FghuPlLVrjzlygXEBIivrsMSo0P0jmBsAAAK6zaSj9z90+fsBbWoiLlxmqCJ
	98kpvSLYwyY7w==
Content-Type: text/plain; charset=US-ASCII;
 format=flowed
Content-Transfer-Encoding: 7bit
Date: Wed, 08 Mar 2017 12:55:41 +1100
From: bfd@cock.lu
To: bitcoin-dev@lists.linuxfoundation.org
In-Reply-To: <_Z0S6yfN2uS1b0SYoZzU9LMo3QQ967dyn0e12ep_aXJ8cNw8wTovQWED6mKg3PH0hb2yKEG-5Cv0xH3IC2cG5rczP5qo-xLtrjJMXW1uCss=@protonmail.com>
References: <_Z0S6yfN2uS1b0SYoZzU9LMo3QQ967dyn0e12ep_aXJ8cNw8wTovQWED6mKg3PH0hb2yKEG-5Cv0xH3IC2cG5rczP5qo-xLtrjJMXW1uCss=@protonmail.com>
Message-ID: <1a7381ffeceb2209dda11928de10fa12@cock.lu>
X-Sender: bfd@cock.lu
User-Agent: Roundcube Webmail/1.2.3
X-Mailman-Approved-At: Wed, 08 Mar 2017 02:38:16 +0000
Subject: Re: [bitcoin-dev] A Commitment-suitable UTXO set "Balances" file
 data structure
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: Wed, 08 Mar 2017 02:02:46 -0000

Having a commitment to a "balance" of an "address" (I assume you mean
P2SH/P2PKH script) is extremely expensive to create and validate, does
not scale and is not a particularly useful thing for a client to use.
Validating clients should never expect their UTXO to be
inconsistent with that of the network, if something has happened to
cause this loosely committing to the UTXO is of no value.


On 2017-03-08 08:28, praxeology_guy via bitcoin-dev wrote:
> A Commitment-suitable UTXO set "Balances" file data structure
> 
> - Allows pruned nodes to satisfy SPV nodes
> 
> - Allows pruned nodes to trustlessly start synchronizing at a Balances
> file's block height instead of the genesis block
> 
> - Allows all nodes in the network to verify their UTXO set's data
> integrity
> 
> For this to work, Bitcoin would need a new policy:
> 
> - A UTXO commitment is made every "Balances/UTXO Commitment Period"
> (BCP) blocks.  The UTXO commitment is made on the state of the UTXO at
> BCP blocks ago.  For example, if BCP is 5000, and we are creating
> block 20,000, then block 20,000 would contain a commitment on what the
> state of the UTXO was at block 15,000, right before any changes due to
> block 15,001.
> 
> - The commitment is made on the state of the UTXO "BCP blocks ago"
> instead of the UTXO state at the tip because: 1. Such a commitment can
> be made in a background thread and not delay mining/synchronizing node
> operations; 2. The work of creating the commitment doesn't have to be
> redone in the case of a fork.
> 
> - The file/commitment is made in a background thread, starting at
> least BCP/2 blocks after the last block containing a utxo commitment.
> 
> Balances file summary:
> 
> {
> 
> Header: 48 bytes
> 
> {
> 
> File Type: 4 bytes
> 
> File version: 4 bytes
> 
> size of balances: 8 bytes
> 
> root hash: 32 bytes
> 
> }
> 
> balances: "size of balances" bytes
> 
> balance index: "piece count" * (N + 4) bytes, N=4 proposed
> 
> merkle tree hashes: ~ 2 * "piece count" * 32 bytes
> 
> }
> 
> balances: is a list of balances sorted by txid:
> 
> {
> 
> length: 4 bytes
> 
> txid: 32 bytes
> 
> CCoins: variable length, depends on UTXO size
> 
> }
> 
> A "piece" is like in bittorrent's piece.  I propose piece size =
> 32*1024 bytes.  2GB of balance data would then be divided into 65536
> pieces.
> 
> transaction index is an array (with "piece count" elements) of:
> 
> {
> 
> txix: the first N bytes of a txid. I'm proposing N = 4
> 
> piece offset: 4 bytes, location of the first balance in the piece.
> 
> }
> 
> merkle tree hashes:
> 
> - array of "piece count" leaf hashes, hashing the balance pieces
> 
> - array of "(child layer count + 1)/2" node hashes, hashing pairs of
> child hashes, or copying up if only one child
> 
> - repeat ^ until the root hash is written
> 
> ... except reverse the layer order. In other words, it should be
> breadth first.
> 
> ==========
> 
> Data structure design notes:
> 
> - Most of the file's space is used by the balances.  For example,
> given a 32kB piece size and 2GB balances, the non-balances data only
> consumes about 4.5MB.  If N was increased to 32, ~6.5MB.
> 
> - piece size should be small enough that not that much effort is
> wasted when invalid pieces are received.
> 
> - piece size should also be small in the case that this data structure
> is used instead of block history for SPV proof.  Then pruned nodes can
> satisfy SPV clients.
> 
> - The child count = 2 merkle tree structure is only necessary for if
> this data structure is to be used to satisfy SPV clients.  If not used
> for such a purpose, then technically the root hash could have the leaf
> hashes as it's direct children. But practically this doesn't make a
> difference: merkle tree size is nothing compared to sizeof(balances).
> 
> - The only purpose of the balance index is to support SPV clients
> 
> - txix is a truncation of txid to reduce memory usage for a fully
> in-memory index to support SPV nodes.  Maybe this truncation isn't
> worthwhile.
> 
> Other notes:
> 
> - We could make BCP 4383 blocks, which would be 12 times per year,
> given block period was exactly 10 minutes.  But since block period is
> not exactly 10 minutes, and file names generated with period 4283 are
> much less comprehensible than file names generated with period 5000...
>  I propose 5000.
> 
> - Having a shorter BCP period would result in more frequent checks on
> UTXO set integrity, and permit new pruning nodes to start synching
> closer to the tip.  But it may require nodes to keep more copies of
> the balances file to satisfy the same backup period, and require more
> background work of creating more balances files.
> 
> ===========
> 
> Suggested design change to the chainstate "CCoinsViewDB" utxo
> database:
> 
> - As it is designed now, the above proposal would require maintaining
> a duplicate but lagging UTXO database.
> 
> - I propose changing the "CCoins" data structure so that it can keep
> track of spends that shouldn't be included in the commitment. Maybe
> call it "vtipspends".
> 
> Then the process for updating the CCoinsViewDB would be:
> 
> 1. Mark a txo as spent by adding the vout_ix to vtipspends.
> 
> 2. SetNull() and Cleanup() during the background thread that creates
> Balances commitments.  vtipspends would also need to be cleaned.
> 
> - The method for checking whether a txo was spent would need to be
> changed to check vtipspends.
> 
> At the same time, I know there is currently a lot of code complexity
> with handling forks and txo spends.  Let me propose something to
> handle this better too:
> 
> - vtipspends could hold {vout_ix, blockhash } instead of just vout_ix.
> 
> - Checking whether a txo is spent will then require a parameter that
> specifies the "fork tip hash" or "fork chain"
> 
> Then in the case of a fork, no work has to be done to update the utxo
> database... it is immediately ready to handle answering spend
> questions for a different fork.
> 
> Feedback welcome.  FYI I have coded up the creation of such a file
> already... So I am working on the implementation, not just the spec.
> I'd really like to hear what you guys think about my proposed changes
> to CCoins.
> 
> Cheers,
> 
> Praxeology
> _______________________________________________
> bitcoin-dev mailing list
> bitcoin-dev@lists.linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev