anders94 / blockchain-demo

A web-based demonstration of blockchain concepts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blockchain and Distributed Tab Chains Behave Differently

grempe opened this issue · comments

I noticed, when experimenting with your excellent demo, that the chains on the blockchain and distributed tabs behave differently.

For example, on the blockchain tab when you modify the data field on the second block, which breaks the hash signature as expected, the next block in the chain reflects the proper (broken) hash in the Prev field. Also, when you mine the current block again, generating a good signature for the block, the next block in the chain (and all following) reflect the newly generated hashes in the Prev field as well. This works as expected.

However, on the Distributed tab, which to my thinking should behave identically, just with three parallel blockchains, the next and all following blocks do NOT update the Prev value to reflect reality. This means you would need to carry those values forward manually, where I should just be able to kepp clicking mine on successive blocks to get one of the chains to be divergent from all of the others (while still being internally consistent).

After cloning and testing it out I believe changing line 55 in the distributed code with the following diff would fix it:

https://github.com/anders94/blockchain-demo/blob/master/views/distributed.jade#L55

$ git diff
diff --git a/views/distributed.jade b/views/distributed.jade
index 8793610..49cb601 100644
--- a/views/distributed.jade
+++ b/views/distributed.jade
@@ -52,7 +52,7 @@ block content
           var l = Ladda.create(this);
           l.start();
           setTimeout(function() {
-              mine(block, chain);
+              mine(block, chain, true);
               l.stop();
             }, 250); // give UI time to update
         });

I think this also fixes the token page which does not currently break signatures if you modify a value in the data block.

Yeah, that's a good catch. I'll fix that. Thanks!

Great! Thx

Still need this fix pushed out to the demo site I think. :-)