I'm writing my own block finder that reads .dat files made and verified by bitcoind, starting from blk00000.dat forwards. As soon as a new block is read I append it to it's parent, thus creating the blockchain. Blocks ofc are not read in the right order so you need to shuffle them on the fly.
Sometimes a block is read that claims a parent that already has a child, so this is a fork (at least in my terms) and one of them has to become an orphan.
How can I resolve this and figure out which one to keep?
Is it a decision based on future block codes or is it an external decision?
For example, I stumbled on a block 000000000000000000E0BBFCB8C89D8A1A68247E9A379E64BF4F6309A2282383 that you won't find on blockchain.info but can see thru bitcoin-cli API, it claims 0000000000000000005f2a78bcf67d01b57c72b3a1c354fad15c18550657b631 as a parent but it was never added to the blockchain.