/// import * as ShardusTypes from '../shardus/shardus-types'; import Shardus from '../shardus'; import { StateManager as StateManagerTypes, P2P as P2PTypes } from '@shardeum-foundation/lib-types'; import EventEmitter from 'events'; import Profiler from '../utils/profiler'; import { P2PModuleContext as P2P } from '../p2p/Context'; import Storage from '../storage'; import Crypto from '../crypto'; import Logger from '../logger'; import PartitionStats from './PartitionStats'; import AccountCache from './AccountCache'; import AccountSync from './AccountSync'; import AccountGlobals from './AccountGlobals'; import TransactionQueue from './TransactionQueue'; import TransactionRepair from './TransactionRepair'; import TransactionConsenus from './TransactionConsensus'; import PartitionObjects from './PartitionObjects'; import Deprecated from './Deprecated'; import AccountPatcher from './AccountPatcher'; import CachedAppDataManager from './CachedAppDataManager'; import { CycleShardData, PartitionReceipt, FifoLockObjectMap, QueueEntry, AcceptedTx, GetAccountDataByRangeSmart, MainHashResults, SimpleDistanceObject, WrappedResponses, LocalCachedData, AccountFilter, CycleDebugNotes, QueueCountsResult, SignedReceipt, Proposal } from './state-manager-types'; import { Logger as Log4jsLogger } from 'log4js'; export type Callback = (...args: unknown[]) => void; /** * WrappedEventEmitter just a default extended WrappedEventEmitter * using EventEmitter was causing issues? */ declare class WrappedEventEmitter extends EventEmitter { constructor(); } /** * StateManager */ declare class StateManager { shardus: Shardus; app: ShardusTypes.App; storage: Storage; p2p: P2P; crypto: Crypto; config: ShardusTypes.StrictServerConfiguration; profiler: Profiler; mainLogger: Log4jsLogger; fatalLogger: Log4jsLogger; shardLogger: Log4jsLogger; statsLogger: Log4jsLogger; eventEmitter: WrappedEventEmitter; partitionStats: PartitionStats; accountCache: AccountCache; accountSync: AccountSync; accountGlobals: AccountGlobals; transactionQueue: TransactionQueue; private transactionRepair; transactionConsensus: TransactionConsenus; partitionObjects: PartitionObjects; accountPatcher: AccountPatcher; cachedAppDataManager: CachedAppDataManager; depricated: Deprecated; shardValuesByCycle: Map; currentCycleShardData: CycleShardData | null; globalAccountsSynced: boolean; dataRepairsCompleted: number; dataRepairsStarted: number; useStoredPartitionsForReport: boolean; partitionReceiptsByCycleCounter: { [cycleKey: string]: PartitionReceipt[]; }; ourPartitionReceiptsByCycleCounter: { [cycleKey: string]: PartitionReceipt; }; fifoLocks: FifoLockObjectMap; lastSeenAccountsMap: { [accountId: string]: QueueEntry; }; appFinishedSyncing: boolean; debugNoTxVoting: boolean; debugSkipPatcherRepair: boolean; ignoreRecieptChance: number; ignoreVoteChance: number; loseTxChance: number; failReceiptChance: number; voteFlipChance: number; failNoRepairTxChance: number; syncSettleTime: number; debugTXHistory: { [id: string]: string; }; stateIsGood_txHashsetOld: boolean; stateIsGood_accountPartitions: boolean; stateIsGood_activeRepairs: boolean; stateIsGood: boolean; feature_receiptMapResults: boolean; feature_partitionHashes: boolean; feature_generateStats: boolean; feature_useNewParitionReport: boolean; debugFeature_dumpAccountData: boolean; debugFeature_dumpAccountDataFromSQL: boolean; debugFeatureOld_partitionReciepts: boolean; logger: Logger; extendedRepairLogging: boolean; consensusLog: boolean; lastActiveNodeCount: number; doDataCleanup: boolean; _listeners: Record void]>; queueSitTime: number; dataPhaseTag: string; preTXQueue: AcceptedTx[]; lastShardCalculationTS: number; firstTimeToRuntimeSync: boolean; lastShardReport: string; processCycleSummaries: boolean; cycleDebugNotes: CycleDebugNotes; superLargeNetworkDebugReduction: boolean; lastActiveCount: number; useAccountWritesOnly: boolean; reinjectTxsMap: Map; coverageChangesCopy: { start: number; end: number; }[]; /*** * ###### ####### ## ## ###### ######## ######## ## ## ###### ######## ####### ######## * ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## * ## ## ## #### ## ## ## ## ## ## ## ## ## ## ## ## ## * ## ## ## ## ## ## ###### ## ######## ## ## ## ## ## ## ######## * ## ## ## ## #### ## ## ## ## ## ## ## ## ## ## ## ## * ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## ## ## ## ## * ###### ####### ## ## ###### ## ## ## ####### ###### ## ####### ## ## */ constructor(profiler: Profiler, app: ShardusTypes.App, logger: Logger, storage: Storage, p2p: P2P, crypto: Crypto, config: ShardusTypes.StrictServerConfiguration, shardus: Shardus); renewState(): void; configsInit(): void; /*** * ###### ## ## ### ######## ######## ###### ### ## ###### ###### * ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## * ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## * ###### ######### ## ## ######## ## ## ## ## ## ## ## ###### * ## ## ## ######### ## ## ## ## ## ######### ## ## ## * ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## * ###### ## ## ## ## ## ## ######## ###### ## ## ######## ###### ###### */ updateShardValues(cycleNumber: number, mode: P2PTypes.ModesTypes.Record['mode']): void; calculateChangeInCoverage(): void; getCurrentCycleShardData(): CycleShardData | null; hasCycleShardData(): boolean; waitForShardCalcs(): Promise; /*** * ## ## ######## #### ## ###### * ## ## ## ## ## ## ## * ## ## ## ## ## ## * ## ## ## ## ## ###### * ## ## ## ## ## ## * ## ## ## ## ## ## ## * ####### ## #### ######## ###### */ debugNodeGroup(key: string, key2: number, msg: string, nodes: P2PTypes.P2PTypes.NodeInfo[]): void; getRandomInt(max: number): number; tryGetBoolProperty(parent: Record, propertyName: string, defaultValue: boolean): boolean; /** * test once at the given probability to fail. If it fails, log the message and return true. If it doesnt fail, return false. * @param failChance * @param debugName * @param key * @param message * @param verboseRequired * @returns */ testFailChance(failChance: number, debugName: string, key: string, message: string, verboseRequired: boolean): boolean; startCatchUpQueue(): Promise; recordPotentialBadnode(): void; /** * writeCombinedAccountDataToBackups * @param failedHashes This is a list of hashes that failed and should be ignored in the write operation. */ writeCombinedAccountDataToBackups(goodAccounts: ShardusTypes.WrappedData[], failedHashes: string[]): Promise; getAccountDataByRangeSmart(accountStart: string, accountEnd: string, tsStart: number, maxRecords: number, offset: number, accountOffset: string): Promise; testAccountDataWrapped(accountDataList: ShardusTypes.WrappedData[]): void; checkAndSetAccountData(accountRecords: ShardusTypes.WrappedData[], note: string, processStats: boolean, updatedAccounts?: string[]): Promise; /*** * ######## ## ## ######## ######## ####### #### ## ## ######## ###### * ## ### ## ## ## ## ## ## ## ## ### ## ## ## ## * ## #### ## ## ## ## ## ## ## ## #### ## ## ## * ###### ## ## ## ## ## ######## ## ## ## ## ## ## ## ###### * ## ## #### ## ## ## ## ## ## ## #### ## ## * ## ## ### ## ## ## ## ## ## ## ### ## ## ## * ######## ## ## ######## ## ####### #### ## ## ## ###### */ _registerListener(emitter: EventEmitter, event: string, callback: Callback): void; _unregisterListener(event: string): void; _cleanupListeners(): void; registerEndpoints(): void; _unregisterEndpoints(): void; /*** * ###### ####### ######## ######## * ## ## ## ## ## ## ## * ## ## ## ## ## ## * ## ## ## ######## ###### * ## ## ## ## ## ## * ## ## ## ## ## ## ## * ###### ####### ## ## ######## */ tryStartTransactionProcessingQueue(): void; _firstTimeQueueAwait(): Promise; _sortByIdAsc(first: { id: string; }, second: { id: string; }): number; /** * dumpAccountDebugData2 a temporary version that also uses stats data */ dumpAccountDebugData2(mainHashResults: MainHashResults): Promise; waitForShardData(counterMsg?: string): Promise; getLocalOrRemoteAccountQueueCount(address: string): Promise; getLocalOrRemoteAccount(address: string, opts?: { useRICache: boolean; canThrowException?: boolean; }): Promise; getAccountFailDump(address: string, message: string): void; getRemoteAccount(address: string): Promise; getClosestNodes(hash: string, count?: number, selfExclude?: boolean): ShardusTypes.Node[]; checkCycleShardData(tag: string): boolean; _distanceSortAsc(a: SimpleDistanceObject, b: SimpleDistanceObject): 0 | 1 | -1; getClosestNodesGlobal(hash: string, count: number): string[]; isNodeInDistance(_shardGlobals: StateManagerTypes.shardFunctionTypes.ShardGlobals, _parititionShardDataMap: StateManagerTypes.shardFunctionTypes.ParititionShardDataMap, hash: string, nodeId: string, distance: number): boolean; _clearState(): Promise; _stopQueue(): void; _clearQueue(): void; cleanup(): Promise; isStateGood(): boolean; /*** * ###### ######## ######## ### ###### ###### ####### ## ## ## ## ######## * ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## * ## ## ## ## ## ## ## ## ## ## ## #### ## ## * ###### ###### ## ## ## ## ## ## ## ## ## ## ## ## ## * ## ## ## ######### ## ## ## ## ## ## ## #### ## * ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## * ###### ######## ## ## ## ###### ###### ####### ####### ## ## ## */ setAccount(wrappedStates: WrappedResponses, localCachedData: LocalCachedData, applyResponse: ShardusTypes.ApplyResponse, isGlobalModifyingTX: boolean, accountFilter?: AccountFilter, note?: string): Promise; /** * updateAccountsCopyTable * originally this only recorder results if we were not repairing but it turns out we need to update our copies any time we apply state. * with the update we will calculate the cycle based on timestamp rather than using the last current cycle counter */ updateAccountsCopyTable(accountDataList: ShardusTypes.AccountData[], _repairing: boolean, txTimestamp: number): Promise; /** * _commitAccountCopies * This takes an array of account data and pushes it directly into the system with app.resetAccountData * Account backup copies and in memory global account backups are also updated * you only need to set the true values for the globalAccountKeyMap * @param accountCopies */ _commitAccountCopies(accountCopies: ShardusTypes.AccountsCopy[]): Promise; /*** * ######## #### ######## ####### ## ####### ###### ## ## ###### * ## ## ## ## ## ## ## ## ## ## ## ## ## ## * ## ## ## ## ## ## ## ## ## ## ## ## * ###### ## ###### ## ## ## ## ## ## ##### ###### * ## ## ## ## ## ## ## ## ## ## ## ## * ## ## ## ## ## ## ## ## ## ## ## ## ## ## * ## #### ## ####### ######## ####### ###### ## ## ###### */ fifoLock(fifoName: string): Promise; fifoUnlock(fifoName: string, id: number): void; /** * bulkFifoLockAccounts * @param {string[]} accountIDs */ bulkFifoLockAccounts(accountIDs: string[]): Promise; /** * bulkFifoUnlockAccounts * @param {string[]} accountIDs * @param {number[]} ourLocks */ bulkFifoUnlockAccounts(accountIDs: string[], ourLocks: number[]): void; getLockedFifoAccounts(): FifoLockObjectMap; /** * this funtion will unlock all fifo locks that are currently locked * ideally we should not be calling this, but it is currently needed * as we try to transition to more stable fifo locks. * @param tag * @returns */ forceUnlockAllFifoLocks(tag: string): number; /** * now that we have fixes a but that was stomping fifo locks we could have a problem * where the memory grows forever. This function will clean up old locks that are no longer needed. */ clearStaleFifoLocks(): void; /*** * ###### ## ######## ### ## ## ## ## ######## * ## ## ## ## ## ## ### ## ## ## ## ## * ## ## ## ## ## #### ## ## ## ## ## * ## ## ###### ## ## ## ## ## ## ## ######## * ## ## ## ######### ## #### ## ## ## * ## ## ## ## ## ## ## ### ## ## ## * ###### ######## ######## ## ## ## ## ####### ## */ periodicCycleDataCleanup(oldestCycle: number): void; /*** * ####### ## ####### ####### ## ## ### ## ## ######## ## ######## ######## ###### * ## ## #### ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## * ## ## ## ## ## ## ## ## ## ## #### ## ## ## ## ## ## ## ## * ## ## ## ####### ## ## ####### ######### ## ## ## ## ## ## ## ## ###### ######## ###### * ## ## ## ## ## ## ## ## ## ## ######### ## #### ## ## ## ## ## ## ## * ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## * ##### ## ###### ##### ## ####### ## ## ## ## ## ## ######## ######## ######## ## ## ###### */ startShardCalculations(): void; processPreviousCycleSummaries(): Promise; /** * initApoptosisAndQuitSyncing * stop syncing and init apoptosis */ initApoptosisAndQuitSyncing(logMsg: string, userFriendlyMessage?: string): void; /*** * ######## ######## ###### ######## #### ######## ######## ###### * ## ## ## ## ## ## ## ## ## ## ## ## * ## ## ## ## ## ## ## ## ## ## * ######## ###### ## ###### ## ######## ## ###### * ## ## ## ## ## ## ## ## ## * ## ## ## ## ## ## ## ## ## ## ## * ## ## ######## ###### ######## #### ## ## ###### */ getSignedReceipt(queueEntry: QueueEntry): SignedReceipt; hasReceipt(queueEntry: QueueEntry): boolean; getReceiptResult(queueEntry: QueueEntry): boolean; getReceiptProposal(queueEntry: QueueEntry): Proposal; generateReceiptMapResults(lastCycle: ShardusTypes.Cycle): StateManagerTypes.StateManagerTypes.ReceiptMapResult[]; /*** * ###### ####### ######## ######## * ## ## ## ## ## ## ## * ## ## ## ## ## ## * ## ## ## ######## ###### * ## ## ## ## ## ## * ## ## ## ## ## ## ## ### ### ### * ###### ####### ## ## ######## ### ### ### */ isNodeValidForInternalMessage(nodeId: string, debugMsg: string, checkForNodeDown?: boolean, checkForNodeLost?: boolean, checkIsUpRecent?: boolean, checkNodesRotationBounds?: boolean): boolean; /** * This takes a lists of nodes and test which are safe/smart to send to. * The node list is updated once per cycle but this function can take into nodes that may have been reported down but are * recently up again. * @param nodeList * @param debugMsg * @param checkForNodeDown * @param checkForNodeLost * @param checkIsUpRecent * @returns A list of filtered nodes based on the settings passed in */ filterValidNodesForInternalMessage(nodeList: ShardusTypes.Node[], debugMsg: string, checkForNodeDown?: boolean, checkForNodeLost?: boolean, checkIsUpRecent?: boolean): ShardusTypes.Node[]; /** * * @returns */ getNodesForCycleShard(mode: P2PTypes.ModesTypes.Record['mode']): ShardusTypes.Node[]; getTxRepair(): TransactionRepair; askToRemoveTimestampCache(acceptedTx: QueueEntry['acceptedTx'], signedReceipt: SignedReceipt): Promise; startProcessingCycleSummaries(): void; statemanager_fatal(key: string, log: string): void; } export default StateManager;