Cater for at-genesis best headers (#3264)

This commit is contained in:
Jaco Greeff
2021-03-05 10:28:56 +01:00
committed by GitHub
parent 47f08e9e04
commit a51658ffac
11 changed files with 140 additions and 137 deletions
+8 -5
View File
@@ -35,13 +35,16 @@ function signingHeader (api: ApiInterfaceRx): Observable<Header> {
api.rpc.chain.getHeader(),
api.rpc.chain.getFinalizedHead()
]).pipe(
switchMap(([{ parentHash }, finHash]) =>
switchMap(([bestHeader, finHash]) =>
// retrieve the headers - in the case of the current block, we use the parent
// to minimize (not completely remove) the impact that forks do have on the system
combineLatest([
api.rpc.chain.getHeader(parentHash),
api.rpc.chain.getHeader(finHash)
])
// (when at genesis, just return the current header as the last known)
bestHeader.parentHash.isEmpty
? of([bestHeader, bestHeader])
: combineLatest([
api.rpc.chain.getHeader(bestHeader.parentHash),
api.rpc.chain.getHeader(finHash)
])
),
map(([current, finalized]) =>
// determine the hash to use, current when lag > max, else finalized