import { Transaction } from '@subql/x-sequelize'; import { GlobalData, GlobalDataRepo } from '../../entities'; export interface IGlobalData { getChainRewindInfo(): Promise; acquireGlobalRewindLock(rewindTimestamp: Date): Promise<{ lockTimestamp: Date; }>; /** * Check if the height is consistent before unlocking. * @param tx * @param rewindTimestamp The timestamp to roll back to, in milliseconds. * @param allowRewindTimestamp Set a rewind-allowed height; only heights greater than or equal this can be released. * @returns the number of remaining rewind chains */ releaseChainRewindLock(tx: Transaction, rewindTimestamp: Date, allowRewindTimestamp?: Date): Promise; } export declare class PlainGlobalModel implements IGlobalData { private readonly dbSchema; private readonly chainId; private readonly model; constructor(dbSchema: string, chainId: string, model: GlobalDataRepo); private get sequelize(); getChainRewindInfo(): Promise; /** * If the set rewindTimestamp is greater than or equal to the current blockHeight, we do nothing because we will roll back to an earlier time. * If the set rewindTimestamp is less than the current blockHeight, we should roll back to the earlier rewindTimestamp. * The reason for not using the external tx variable here is to complete the locking task as soon as possible and promptly send a notification to allow other chains to rewind. * @param rewindTimestamp * @param tx * @returns */ acquireGlobalRewindLock(rewindTimestamp: Date): Promise<{ lockTimestamp: Date; }>; /** * The following special cases may exist: * 1. A table lock needs to be added before release to prevent multiple chains from releasing simultaneously, causing a deadlock. If one chain is setting setGlobalRewindLock, others need to queue (so it’s necessary to check if it’s the lock for the current timestamp; if not, the release fails, and the rollback fails). * 2. There may be a case where lastProcessBlock < rewindTime, in which case the lock should be released directly (force = true). * @param rewindTimestamp * * @returns */ releaseChainRewindLock(tx: Transaction, rewindTimestamp: Date, allowRewindTimestamp?: Date): Promise; private getChainsInfo; getChainIdsFromMetadata(tx: Transaction): Promise; }