Cleanup author extraction (#4296)
This commit is contained in:
@@ -4,43 +4,34 @@
|
||||
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');
|
||||
|
||||
const [citem] = digest.logs.filter((e) => e.isConsensus);
|
||||
const [pitem] = digest.logs.filter((e) => e.isPreRuntime);
|
||||
const [sitem] = digest.logs.filter((e) => e.isSeal);
|
||||
let accountId: AccountId | undefined;
|
||||
|
||||
// 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 {
|
||||
try {
|
||||
// This is critical to be first for BABE (before Consensus)
|
||||
// If not first, we end up dropping the author at session-end
|
||||
if (pitem) {
|
||||
const [engine, data] = pitem.asPreRuntime;
|
||||
|
||||
accountId = engine.extractAuthor(data, sessionValidators);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (!accountId && citem) {
|
||||
try {
|
||||
if (!accountId && citem) {
|
||||
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 {
|
||||
// SEAL, still used in e.g. Kulupu for pow
|
||||
if (!accountId && sitem) {
|
||||
const [engine, data] = sitem.asSeal;
|
||||
|
||||
accountId = engine.extractAuthor(data, sessionValidators);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return accountId;
|
||||
|
||||
Reference in New Issue
Block a user