Fix author extraction (both POW & BABE) (#3299)

* Fix author extaction for Babeb session-end

* Fix extraction from Seal
This commit is contained in:
Jaco Greeff
2021-03-10 16:55:59 +01:00
committed by GitHub
parent cf0d9a2d3f
commit 2b270a3c9f
+32 -9
View File
@@ -5,20 +5,43 @@ import type { AccountId, Digest } from '@polkadot/types/interfaces';
export function extractAuthor (digest: Digest, sessionValidators: AccountId[] = []): AccountId | undefined {
const [citem] = digest.logs.filter(({ type }) => type === 'Consensus');
const [pitem] = digest.logs.filter(({ type }) => type === 'PreRuntime');
const [sitem] = digest.logs.filter(({ type }) => type === 'Seal');
if (citem) {
const [engine, data] = citem.asConsensus;
let accountId: AccountId | undefined;
return engine.extractAuthor(data, sessionValidators);
} else {
const [pitem] = digest.logs.filter(({ type }) => type === 'PreRuntime');
if (pitem) {
// This is critical to be first for BABE (before Consensus)
// If not first, we end up dropping the author at session-end
if (pitem) {
try {
const [engine, data] = pitem.asPreRuntime;
return engine.extractAuthor(data, sessionValidators);
accountId = engine.extractAuthor(data, sessionValidators);
} catch {
// ignore
}
}
return undefined;
if (!accountId && citem) {
try {
const [engine, data] = citem.asConsensus;
accountId = engine.extractAuthor(data, sessionValidators);
} catch {
// ignore
}
}
// SEAL, still used in e.g. Kulupu for pow
if (!accountId && sitem) {
try {
const [engine, data] = sitem.asSeal;
accountId = engine.extractAuthor(data, sessionValidators);
} catch {
// ignore
}
}
return accountId;
}