Oh P.S, this can be done differently, and I'm actually doing it in a different way in my python code.
Share, plz.
I think it's ok for me to do, when analyzing data, but I'm not sure it it'd be ok for official client.
Basically when getting blocks, I think (but I might be wrong here) there are only two options:
- our tail is ok
- either our current tail is wrong and we must fix it
First case is clear, just append new blocks.
In second case:
our_1 .. our_2 .. our_n
/
id_1 . id_2 ... commonBlockId
\
recv_1 .. recv_2 .. recv_3 .. recv_m
(I'm doing check if recv chain makes any sense at all and)
I'm relying solely on length of chain, if recv is longer than mine, I'm dropping my chain.
I think that might be inacceptable for official client, as with number of *evil* nodes, bad things could happen.
The difference is NRS to "rollback", does re-load of blocks and TXes from file (which will be more and more costly, when chain will get longer and longer).
With the cost of complicating code a bit, I think that "applying changes & rollback" could be done in more lightway way