refactor: Introduce GetFirstStoredBlock helper function
Summary:
This is a partial backport of core#21726
https://github.com/bitcoin/bitcoin/pull/21726/commits/231fc7b035481f748159968353c1cab81354e843
Depends on D13096
Test Plan: ninja all check-all
Reviewers: #bitcoin_abc, sdulfari
Reviewed By: #bitcoin_abc, sdulfari
Differential Revision: https://reviews.bitcoinabc.org/D13097