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
+4 -4
View File
@@ -20,13 +20,13 @@
"@polkadot/api": "4.0.1-8",
"@polkadot/rpc-core": "4.0.1-8",
"@polkadot/types": "4.0.1-8",
"@polkadot/util": "^6.0.1-5",
"@polkadot/util-crypto": "^6.0.1-5",
"@polkadot/x-rxjs": "^6.0.1-5",
"@polkadot/util": "^6.0.1-9",
"@polkadot/util-crypto": "^6.0.1-9",
"@polkadot/x-rxjs": "^6.0.1-9",
"bn.js": "^4.11.9"
},
"devDependencies": {
"@polkadot/keyring": "^6.0.1-5",
"@polkadot/keyring": "^6.0.1-9",
"@polkadot/rpc-provider": "4.0.1-8"
}
}
+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