0

Lets say I have a private chain with 3 nodes (all mining) A, B and C.

I want to get the latest block of my chain. I connect to node A and get this information with getBlock("latest").

Lets imagine that node A mined the same block as B but did not sync. When it just finished mining, is the mined block already considered as the correct one by the node (without syncing with other nodes)?

Furthermore, if A and B synced and B's block is considered as the correct one, what happens to the block mined by A?

To finish, in a more general way, is it possible to have two different blocks considered as valid blocks on two different nodes at the very same time, or does a block, to be considered as valid by a node (including the one which mined this block), need to synchronize sucessfully with other nodes?

1

Let me try to break this down:

When it just finished mining, is the mined block already considered as the correct one by the node (without syncing with other nodes)?

As soon as a block was mined it is considered to be correct by the node mining it (otherwise it wouldn't have been mined).

Furthermore, if A and B synced and B's block is considered as the correct one, what happens to the block mined by A?

If two blocks are mined at exactly the same time by two different nodes the "longest chain rule" applies. This in short means that the the block that the following blocks are based on is considered to be the real one. The block mined by A in this case would become an "uncle block" and all the transactions that are included in that block and are not included in the chain anymore go back to the transaction pool to be taken up in one of the following blocks.

is it possible to have two different blocks considered as valid blocks on two different nodes at the very same time, or does a block, to be considered as valid by a node (including the one which mined this block), need to synchronize sucessfully with other nodes?

Yes that is possible - both blocks are considered to be valid by the miners that mined those blocks and should also just be accessible through the node in that moment - however only one of those two blocks will remain as a part of the blockchain and the other one will become an "uncle". This is also why a transaction can not be considered as enclosed as soon as it was mined in a block, even though chances are high that it is, there still remains the possiblity that its block will become an "uncle". So to be sure you will need to wait until new blocks are mined upon the block your transaction is in. That's why transactions actually can only be considered valid as soon as some blocks follow on the block they are in and chances become higher with each new block. Also since the possibility that two blocks being mined at exactly the same time more than once in a row is rather small, so as soon as two more blocks have been mined you can be quite certain that everything is fine.

However what I am not quite sure about is, if there is some logic behind getBlock("latest") that only returns the latest block if it is already confirmed by some other blocks or something like that...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.