conradoqg/naivecoin

Simulating mining dispute & using merkle roots for peer validation

eaverdeja opened this issue · 3 comments

Hey Conrado, great improvement from the original naivecoin project, follows smoothly. I had a few questions for my own fork and was hoping you or some other clever guy could help me out.

I was wondering how could I simulate a mining dispute, where 2 or more miners are each trying to validate a block. Is there a mechanism for a miner to stop the mining if another miner broadcasts a valid block? If both miners find a block at almost the same time, is there a mechanism for forking and later on consolidating the chain? If not, how do you think a possible adaption would go on?

Still on peer info validation, how would a merkle root validation process best fit inside the existing codebase? I know how the merkle tree and root construction goes on, but I'm still a bit confused as to what code should be removed and substituted with the merkle steps

Hey!

I was wondering how could I simulate a mining dispute, where 2 or more miners are each trying to validate a block. Is there a mechanism for a miner to stop the mining if another miner broadcasts a valid block? If both miners find a block at almost the same time, is there a mechanism for forking and later on consolidating the chain? If not, how do you think a possible adaption would go on?

I think it's just a matter of implementing that. In this project, the mining is happening in another thread. So the mining thread should check from time to time if its blockchain has received a new block, if it is, it should recreate the block to be mined and then restart all over.

Still on peer info validation, how would a merkle root validation process best fit inside the existing codebase? I know how the merkle tree and root construction goes on, but I'm still a bit confused as to what code should be removed and substituted with the merkle steps

To be honest, I need to study more about the merkle root validation to even try to think about how to implement it.
Without further studying, probably this is something related to the indexing of the blockchain database. So if I'm not wrong (and it's very likely I am) there is no modification in the node, operator and http server side. Just in how to access and get blocks from the blockchain.

Best

Thanks for the fast reply :)

I'll try implementing a successful mining dispute, clear winners and losers.

From what I got from the resources below, the merkle root would be used by participating nodes with no means of checking each and every transaction's signature and structure in a block so that it could be trusted. Instead of looping through every transaction, the node would recreate the block's merkle tree and root, comparing the "expected root" with the "actual root". That leads to O(log(n)) verifications for the node to do, instead of O(n). Makes sense?

merkle roots in js - pt1 Calculating the merkle root
merke roots in js - pt2 Using the merkle root
why does each block store a merkle root?
what is the merkle root?

Oh OK, yes it does make sense. It would be nice to have something like this.

I think this can be done independently of the today's state of naivecoin, what I mean, if one day the blockchain of a node gets large enough, implementing this verification could lead to a speed increase.

Thanks for sharing those links.