From eb2aaf967d8bb69c0023a12389ba2bae67fdecd3 Mon Sep 17 00:00:00 2001 From: jairajdev Date: Mon, 5 Aug 2024 20:49:34 +0545 Subject: [PATCH] Revert to the original index applied in the tables --- src/Data/Data.ts | 24 ++++++++++++------------ src/dbstore/index.ts | 19 +++++++------------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/Data/Data.ts b/src/Data/Data.ts index 0a352aa5..d7a44150 100644 --- a/src/Data/Data.ts +++ b/src/Data/Data.ts @@ -529,7 +529,7 @@ async function syncFromNetworkConfig(): Promise { try { // Define the query function to get the network config from a node const queryFn = async (node): Promise => { - const REQUEST_NETCONFIG_TIMEOUT_SECOND = 2 // 2s timeout + const REQUEST_NETCONFIG_TIMEOUT_SECOND = 3 // 3s timeout try { const response = await P2P.getJson( `http://${node.ip}:${node.port}/netconfig`, @@ -566,17 +566,17 @@ async function syncFromNetworkConfig(): Promise { configChangeMaxCyclesToKeep, maxCyclesShardDataToKeep, } = tallyItem.value.config.stateManager - const devPublicKeys = tallyItem.value.config.debug.devPublicKeys - const devPublicKey = - devPublicKeys && - Object.keys(devPublicKeys).length >= 3 && - Object.keys(devPublicKeys).find((key) => devPublicKeys[key] === 3) - if ( - devPublicKey && - typeof devPublicKey === typeof config.DevPublicKey && - devPublicKey !== config.DevPublicKey - ) - updateConfig({ DevPublicKey: devPublicKey }) + // const devPublicKeys = tallyItem.value.config.debug.devPublicKeys + // const devPublicKey = + // devPublicKeys && + // Object.keys(devPublicKeys).length >= 3 && + // Object.keys(devPublicKeys).find((key) => devPublicKeys[key] === 3) + // if ( + // devPublicKey && + // typeof devPublicKey === typeof config.DevPublicKey && + // devPublicKey !== config.DevPublicKey + // ) + // updateConfig({ DevPublicKey: devPublicKey }) if ( !Utils.isUndefined(newPOQReceipt) && typeof newPOQReceipt === typeof config.newPOQReceipt && diff --git a/src/dbstore/index.ts b/src/dbstore/index.ts index 0e5ae727..9870e439 100644 --- a/src/dbstore/index.ts +++ b/src/dbstore/index.ts @@ -7,10 +7,7 @@ export const initializeDB = async (config: Config): Promise => { 'CREATE TABLE if not exists `transactions` (`txId` TEXT NOT NULL UNIQUE PRIMARY KEY, `appReceiptId` TEXT, `timestamp` BIGINT NOT NULL, `cycleNumber` NUMBER NOT NULL, `data` JSON NOT NULL, `originalTxData` JSON NOT NULL)' ) await db.runCreate( - 'CREATE INDEX if not exists `transactions_cycleNumber` ON `transactions` (`cycleNumber` ASC)' - ) - await db.runCreate( - 'CREATE INDEX if not exists `transactions_timestamp` ON `transactions` (`timestamp` ASC)' + 'CREATE INDEX if not exists `transactions_idx` ON `transactions` (`cycleNumber` DESC, `timestamp` DESC)' ) await db.runCreate( 'CREATE INDEX if not exists `transactions_appReceiptId_idx` ON `transactions` (`appReceiptId`)' @@ -22,22 +19,20 @@ export const initializeDB = async (config: Config): Promise => { await db.runCreate( 'CREATE TABLE if not exists `accounts` (`accountId` TEXT NOT NULL UNIQUE PRIMARY KEY, `data` JSON NOT NULL, `timestamp` BIGINT NOT NULL, `hash` TEXT NOT NULL, `cycleNumber` NUMBER NOT NULL, `isGlobal` BOOLEAN NOT NULL)' ) - await db.runCreate('CREATE INDEX if not exists `accounts_cycleNumber` ON `accounts` (`cycleNumber` ASC)') - await db.runCreate('CREATE INDEX if not exists `accounts_timestamp` ON `accounts` (`timestamp` ASC)') + await db.runCreate( + 'CREATE INDEX if not exists `accounts_idx` ON `accounts` (`cycleNumber` DESC, `timestamp` DESC)' + ) await db.runCreate( 'CREATE TABLE if not exists `receipts` (`receiptId` TEXT NOT NULL UNIQUE PRIMARY KEY, `tx` JSON NOT NULL, `cycle` NUMBER NOT NULL, `timestamp` BIGINT NOT NULL, `beforeStateAccounts` JSON, `accounts` JSON NOT NULL, `appliedReceipt` JSON NOT NULL, `appReceiptData` JSON, `executionShardKey` TEXT NOT NULL, `globalModification` BOOLEAN NOT NULL)' ) - await db.runCreate('CREATE INDEX if not exists `receipts_cycle` ON `receipts` (`cycle` ASC)') - await db.runCreate('CREATE INDEX if not exists `receipts_timestamp` ON `receipts` (`timestamp` ASC)') - + await db.runCreate('CREATE INDEX if not exists `receipts_idx` ON `receipts` (`cycle` ASC, `timestamp` ASC)') await db.runCreate( 'CREATE TABLE if not exists `originalTxsData` (`txId` TEXT NOT NULL, `timestamp` BIGINT NOT NULL, `cycle` NUMBER NOT NULL, `originalTxData` JSON NOT NULL, PRIMARY KEY (`txId`, `timestamp`))' ) - await db.runCreate('CREATE INDEX if not exists `originalTxsData_cycle` ON `originalTxsData` (`cycle` ASC)') await db.runCreate( - 'CREATE INDEX if not exists `originalTxsData_timestamp` ON `originalTxsData` (`timestamp` ASC)' + 'CREATE INDEX if not exists `originalTxsData_idx` ON `originalTxsData` (`cycle` ASC, `timestamp` ASC)' ) - await db.runCreate('CREATE INDEX if not exists `originalTxsData_txId` ON `originalTxsData` (`txId`)') + await db.runCreate('CREATE INDEX if not exists `originalTxsData_txId_idx` ON `originalTxsData` (`txId`)') } export const closeDatabase = async (): Promise => {