We don't want to copy all the block hashes starting at the genesis when most of them will just be ignored because their hashes are already cached.
This diff is a performance optimization.
There are 4 cases to consider:
- the cache is empty, so we pass all blockhashes starting at the genesis block (height 0)
- the cache has already some of the value it needs, so we pass a shorter range of blockhashes (omitting the lower heights)
- the cache has more values than it needs, so we don't pass any hashes (empty vector)
- the cache has enough values, but we are requesting the merkle data for an odd number of blockhashes, so we need to pass the last hash so it can be duplicated.
In any case, we pass the blockhash that is the first hash in branch as a parameter to the merkle_root_and_branch method, because now the merkle tree cache may no longer have access to it.