From 788984fede1b4dff09a8e8ed36e2e625a47ce817 Mon Sep 17 00:00:00 2001 From: Mehdi Sabraoui Date: Sun, 21 Apr 2024 20:17:52 -0400 Subject: [PATCH] rebase and some linting fixes --- src/API.ts | 1 + src/Data/Data.ts | 13 ++----------- src/GlobalAccount.ts | 1 + src/shardeum/calculateAccountHash.ts | 4 +++- src/shardeum/verifyAppReceiptData.ts | 2 +- src/sync-v2/index.ts | 2 +- src/utils/stringify.ts | 1 + 7 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/API.ts b/src/API.ts index b309efa8..b3469729 100644 --- a/src/API.ts +++ b/src/API.ts @@ -1202,6 +1202,7 @@ export const queryFromArchivers = async ( const randomArchivers = Utils.getRandomItemFromArr(filteredArchivers, 0, maxNumberofArchiversToRetry) let retry = 0 while (retry < maxNumberofArchiversToRetry) { + // eslint-disable-next-line security/detect-object-injection let randomArchiver = randomArchivers[retry] if (!randomArchiver) randomArchiver = randomArchivers[0] try { diff --git a/src/Data/Data.ts b/src/Data/Data.ts index 034aaacd..45b8bb14 100644 --- a/src/Data/Data.ts +++ b/src/Data/Data.ts @@ -542,21 +542,12 @@ export function addDataSender(sender: DataSender): void { dataSenders.set(sender.nodeInfo.publicKey, sender) } -interface configConsensusResponse { - config?: { - sharding?: { - nodesPerConsensusGroup?: number - nodesPerEdge?: number - } - } -} - async function getConsensusRadius(): Promise { // If there is no node, return existing currentConsensusRadius if (NodeList.getList().length === 0) return currentConsensusRadius // Define the query function to get the network config from a node - const queryFn = async (node) => { + const queryFn = async (node): Promise => { const REQUEST_NETCONFIG_TIMEOUT_SECOND = 2 // 2s timeout try { const response = await P2P.getJson( @@ -571,7 +562,7 @@ async function getConsensusRadius(): Promise { } // Define the equality function to compare two responses - const equalityFn = (responseA, responseB) => { + const equalityFn = (responseA, responseB): boolean => { return ( responseA.config.sharding.nodesPerConsensusGroup === responseB.config.sharding.nodesPerConsensusGroup ) diff --git a/src/GlobalAccount.ts b/src/GlobalAccount.ts index 0f78d57b..16392078 100644 --- a/src/GlobalAccount.ts +++ b/src/GlobalAccount.ts @@ -60,6 +60,7 @@ export const syncGlobalAccount = async (): Promise => { ) } + // eslint-disable-next-line @typescript-eslint/no-explicit-any const equalFn = (info1: any, info2: any): boolean => { const cm1 = deepCopy(info1) const cm2 = deepCopy(info2) diff --git a/src/shardeum/calculateAccountHash.ts b/src/shardeum/calculateAccountHash.ts index 6f10fa0e..a9d3483e 100644 --- a/src/shardeum/calculateAccountHash.ts +++ b/src/shardeum/calculateAccountHash.ts @@ -21,7 +21,7 @@ export enum AccountType { } export const accountSpecificHash = (account: any): string => { - let hash + let hash: string delete account.hash if ( account.accountType === AccountType.NetworkAccount || @@ -58,6 +58,7 @@ export const accountSpecificHash = (account: any): string => { } // Converting the correct account data format to get the correct hash +// eslint-disable-next-line @typescript-eslint/no-explicit-any export const fixAccountUint8Arrays = (account: any): void => { if (!account) return // if account is null, return if (account.storageRoot) account.storageRoot = Uint8Array.from(Object.values(account.storageRoot)) // Account @@ -93,6 +94,7 @@ export const verifyAccountHash = (receipt: ArchiverReceipt): boolean => { ) return false } + // eslint-disable-next-line security/detect-object-injection const expectedAccountHash = receipt.appliedReceipt.appliedVote.account_state_hash_after[indexOfAccount] if (calculatedAccountHash !== expectedAccountHash) { Logger.mainLogger.error( diff --git a/src/shardeum/verifyAppReceiptData.ts b/src/shardeum/verifyAppReceiptData.ts index ef533617..6f3617ee 100644 --- a/src/shardeum/verifyAppReceiptData.ts +++ b/src/shardeum/verifyAppReceiptData.ts @@ -94,7 +94,7 @@ export const verifyAppReceiptData = async ( } // Converting the correct appReceipt data format to get the correct hash -const calculateAppReceiptDataHash = (appReceiptData: any): string => { +const calculateAppReceiptDataHash = (appReceiptData): string => { try { if (appReceiptData.data && appReceiptData.data.receipt) { if (appReceiptData.data.receipt.bitvector) diff --git a/src/sync-v2/index.ts b/src/sync-v2/index.ts index ce1d43f2..648e9f95 100644 --- a/src/sync-v2/index.ts +++ b/src/sync-v2/index.ts @@ -16,7 +16,7 @@ import { import { ArchiverNodeInfo } from '../State' import { getActiveNodeListFromArchiver } from '../NodeList' import * as NodeList from '../NodeList' -import { verifyCycleRecord, verifyStandbyList, verifyValidatorList } from './verify' +import { verifyCycleRecord, verifyValidatorList } from './verify' import * as Logger from '../Logger' /** diff --git a/src/utils/stringify.ts b/src/utils/stringify.ts index 6e862afc..f226d015 100644 --- a/src/utils/stringify.ts +++ b/src/utils/stringify.ts @@ -17,6 +17,7 @@ const defaultStringifierOptions: stringifierOptions = { bufferEncoding: 'base64', } +// eslint-disable-next-line @typescript-eslint/no-explicit-any export function stringify(val: any, options: stringifierOptions = defaultStringifierOptions): string { const returnVal = stringifier(val, false, options) if (returnVal !== undefined) {