StoredBlock: if getPrev() called on a genesis block, cut short

Don't try to locate a previous block of the genesis block, using
an arbitrary "previous block hash".
This commit is contained in:
Andreas Schildbach 2025-03-10 11:17:28 +01:00
parent 9e91ae629e
commit 8cbd09438c

View file

@ -129,7 +129,9 @@ public class StoredBlock {
* @return the previous block in the chain or null if it was not found in the store.
*/
public StoredBlock getPrev(BlockStore store) throws BlockStoreException {
return store.get(getHeader().getPrevBlockHash());
return height > 0 ?
store.get(header.getPrevBlockHash()) :
null; // Genesis blocks have no previous block.
}
/**