Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { BlockHash, EraLike, Hash, Header } from '@dedot/codecs';
import { SignerPayloadJSON } from '@dedot/types';
import { assert, bnMin, hexToNumber, isZeroHex, numberToHex, u8aToHex } from '@dedot/utils';
import { V2Client } from '../../../client/V2Client.js';
import { SignedExtension } from '../SignedExtension.js';

export const MAX_FINALITY_LAG: number = 5;
export const FALLBACK_MAX_HASH_COUNT: number = 250;
export const FALLBACK_PERIOD: number = 6 * 1000;
export const MORTAL_PERIOD: number = 5 * 60 * 1000;
export const MORTAL_PERIOD: number = 12 * 60 * 1000;

interface SigningHeader {
hash: BlockHash;
Expand Down Expand Up @@ -43,7 +42,6 @@ export class CheckMortality extends SignedExtension<EraLike, Hash> {
}

async #getSigningHeaderRpcV2(): Promise<SigningHeader> {
// TODO similar to the legacy, we should account for the case finality is lagging behind
const finalizedBlock = await this.client.block.finalized();

return {
Expand Down
7 changes: 4 additions & 3 deletions packages/api/src/json-rpc/group/ChainHead/ChainHead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,13 @@ export class ChainHead extends JsonRpcGroup<ChainHeadEvent> {

// Build initial pinned blocks
this.#finalizedHash = finalizedBlockHashes.at(-1);
if (!this.#bestHash) {
this.#pinnedBlocks = this.#buildInitialPinnedBlocks(finalizedBlockHashes, this.#finalizedRuntime);

if (!this.#bestHash || (this.#bestHash && !this.findBlock(this.#bestHash))) {
this.#bestHash = this.#finalizedHash;
this.#lastBestBlockNumber = undefined; // Reset to avoid stale gap detection after recovery
}

this.#pinnedBlocks = this.#buildInitialPinnedBlocks(finalizedBlockHashes, this.#finalizedRuntime);

await this.#updateBlockNumbersAndParents(finalizedBlockHashes, prevPinnedBlocks);

// Handle first initialization or reconnection
Expand Down