<div dir="ltr">&quot;<span style="font-family:arial,sans-serif;font-size:13px">So my question to the community is, how invasive is this to bitcoin&#39;s</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">source code?&quot;</span><div>
<span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">I&#39;d say not very considering you have regression testing mode.</span></div></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 17, 2014 at 8:25 AM, Jorge Timón <span dir="ltr">&lt;<a href="mailto:jtimon@monetize.io" target="_blank">jtimon@monetize.io</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I&#39;m implementing a new testing mode that produces blocks<br>
periodically. You can get what I have so far here:<br>
<br>
<a href="https://github.com/jtimon/bitcoin/tree/timed" target="_blank">https://github.com/jtimon/bitcoin/tree/timed</a><br>
<br>
It depends on pull request #3824 with some improvements on<br>
CChainParams, but after that the changes required to add this new<br>
mode are very small:<br>
<br>
<a href="https://github.com/jtimon/bitcoin/commit/445321928a143cb9a6f56777cbb7479dd32c3bcd" target="_blank">https://github.com/jtimon/bitcoin/commit/445321928a143cb9a6f56777cbb7479dd32c3bcd</a><br>
<br>
I guess I need a new genesis block, different magic numbers, etc. So<br>
this is definitely not ready.<br>
You can run it like this:<br>
<br>
bitcoind -timedtest -gen=1 blocktime=2000<br>
<br>
blocktime defaults to 1000 milliseconds for timedtest mode and 0 for<br>
the rest of the modes.<br>
<br>
What could this testing mode be useful for?<br>
<br>
Basically, simulations.<br>
For example, you could run several nodes implementing different mining<br>
policies. Let&#39;s say I want to mine 50% of the blocks with standard policy,<br>
25% with policy A and 25% with policy B. I can run 1 one for each of<br>
one with block times 2000, 1000 and 1000 respectively.<br>
<br>
Maybe I want to detect performance bottlenecks by stressing this mode<br>
with as many transaction as can be processed, maybe removing the<br>
block size limits in the simulations.<br>
<br>
But this still doesn&#39;t serve for hardfork or double-spend attacks<br>
simulations without calculating any pow, which would be another<br>
interesting feature for a new testing mode.<br>
I would like to implement the new mode following as the concept of<br>
private chains described in freimarkets:<br>
<br>
<a href="http://freico.in/docs/freimarkets.pdf" target="_blank">http://freico.in/docs/freimarkets.pdf</a><br>
<a href="https://github.com/jtimon/freimarkets/blob/master/doc/freimarkets_specs.org#private-ledgers" target="_blank">https://github.com/jtimon/freimarkets/blob/master/doc/freimarkets_specs.org#private-ledgers</a><br>
<a href="https://github.com/jtimon/freimarkets/blob/master/doc/freimarkets_specs.org#off-chain-transactions" target="_blank">https://github.com/jtimon/freimarkets/blob/master/doc/freimarkets_specs.org#off-chain-transactions</a><br>

<br>
I know this could be considered a &quot;non-bitcoinish&quot; application and<br>
therefore be controversial as discussed in PR 3824, so I want to keep<br>
the conversation focused on testing use cases useful to bitcoin itself<br>
only: additional changes can be implemented elsewhere.<br>
One way I think you could support chain races simulations by using a<br>
private mode could be the following:<br>
<br>
1) The private mode works like the timed mode in how often it<br>
   produces blocks.<br>
<br>
2) In private mode you replace the pow-related fields with a<br>
   blockPubkeyScript and a lastBlockSigScript fields. In the genesis<br>
   block, lastBlockSigScript is empty and the initial<br>
   blockPubkeyScript can be an optional parameter like blocktime. You<br>
   can set any valid script, probably p2sh, maybe with multisig to<br>
   allow different nodes to sign.<br>
<br>
3) In this context, longer chains mean &quot;more work&quot;. Another way to<br>
   see it is that all blocks just contain work==1 in them.<br>
<br>
So let&#39;s say we want to simulate an attack using 50% standard and 50%<br>
attacker blocks. You set up the private mode script to be a 1 of 2<br>
multisig and make each node sign always with the same private key<br>
(maybe an additional parameter).<br>
You make the attacker reject any blocks from height X that he hasn&#39;t<br>
signed himself to get the result you wanted: the standard node will<br>
produce blocks on top of the longest chain while the attacker will<br>
only hash on top of his own blocks.<br>
<br>
So my question to the community is, how invasive is this to bitcoin&#39;s<br>
source code?<br>
In my opinion, done properly could actually result (apart from getting<br>
the new features) in more readable code, not less, since you will<br>
probably need to make sure proof of work functionality is properly<br>
encapsulated during the implementation process (see PR 3839 for a first<br>
step on that direction).<br>
But, should I push a private mode to the core or just the timed one<br>
and implement the private mode elsewhere?<br>
<br>
Of course other comments on the parameters, defaults or any other<br>
design or implementation details are also welcomed.<br>
<br>
--<br>
Jorge Timón<br>
<br>
<a href="http://freico.in/" target="_blank">http://freico.in/</a><br>
<br>
------------------------------------------------------------------------------<br>
Learn Graph Databases - Download FREE O&#39;Reilly Book<br>
&quot;Graph Databases&quot; is the definitive new guide to graph databases and their<br>
applications. Written by three acclaimed leaders in the field,<br>
this first edition is now available. Download your free book today!<br>
<a href="http://p.sf.net/sfu/NeoTech" target="_blank">http://p.sf.net/sfu/NeoTech</a><br>
_______________________________________________<br>
Bitcoin-development mailing list<br>
<a href="mailto:Bitcoin-development@lists.sourceforge.net">Bitcoin-development@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/bitcoin-development" target="_blank">https://lists.sourceforge.net/lists/listinfo/bitcoin-development</a><br>
</blockquote></div><br></div>