Skip to content

Commit

Permalink
added ajv initialization in archiver scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
devendra-shardeum committed Jan 7, 2025
1 parent a18f4dd commit de4dede
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 2 deletions.
6 changes: 5 additions & 1 deletion scripts/archiver_data_patcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { join } from 'path'
import * as Logger from '../src/Logger'
import { startSaving } from '../src/saveConsoleOutput'
import { Utils as StringUtils } from '@shardus/types'
import { initAjvSchemas } from '../src/types/ajv/Helpers'
import { initializeSerialization } from '../src/utils/serialization/SchemaHelpers'
const {
MAX_RECEIPTS_PER_REQUEST,
MAX_BETWEEN_CYCLES_PER_REQUEST,
Expand Down Expand Up @@ -48,6 +50,8 @@ const archivers: ArchiverNode[] = [
]

const runProgram = async (): Promise<void> => {
initAjvSchemas()
initializeSerialization()
// Override default config params from config file, env vars, and cli args
const file = join(process.cwd(), 'archiver-config.json')
overrideDefaultConfig(file)
Expand Down Expand Up @@ -89,7 +93,7 @@ const runProgram = async (): Promise<void> => {
break
}
const receiptsCountByCycles = await ReceiptDB.queryReceiptCountByCycles(i, nextEnd)
// console.log(receiptsCountByCycles)
console.log(receiptsCountByCycles)
for (let j = i; j <= nextEnd; j++) {
const downloadedReceipts = downloadedReceiptCountByCycles.receipts.filter((d) => d.cycle === j)
const existingReceipts = receiptsCountByCycles.filter((d) => d.cycle === j)
Expand Down
4 changes: 4 additions & 0 deletions scripts/archiver_data_sync_check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { postJson } from '../src/P2P'
import { config, overrideDefaultConfig } from '../src/Config'
import { ArchiverNodeInfo } from '../src/State'
import { Utils as StringUtils } from '@shardus/types'
import { initAjvSchemas } from '../src/types/ajv/Helpers'
import { initializeSerialization } from '../src/utils/serialization/SchemaHelpers'

const configFile = join(process.cwd(), 'archiver-config.json')
overrideDefaultConfig(configFile)
Expand Down Expand Up @@ -36,6 +38,8 @@ const endCycle = 0
const URL = 'receipt'

const runProgram = async (): Promise<void> => {
initAjvSchemas()
initializeSerialization()
for (const archiver of archivers) {
const archiverInfo = archiver.ip + ':' + archiver.port
const responses = {}
Expand Down
4 changes: 4 additions & 0 deletions scripts/create_shut_down_cycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { P2P } from '@shardus/types'
import { addSigListeners } from '../src/State'
import { computeCycleMarker } from '../src/Data/Cycles'
import { Utils as StringUtils } from '@shardus/types'
import { initAjvSchemas } from '../src/types/ajv/Helpers'
import { initializeSerialization } from '../src/utils/serialization/SchemaHelpers'

const archiversAtShutdown = [
{
Expand All @@ -31,6 +33,8 @@ const archiversAtShutdown = [
]

const runProgram = async (): Promise<void> => {
initAjvSchemas()
initializeSerialization()
// Override default config params from config file, env vars, and cli args
const file = join(process.cwd(), 'archiver-config.json')
overrideDefaultConfig(file)
Expand Down
4 changes: 4 additions & 0 deletions scripts/get_tx_receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { join } from 'path'
import { config, overrideDefaultConfig } from '../src/Config'
import { postJson, getJson } from '../src/P2P'
import { isEqual } from 'lodash'
import { initAjvSchemas } from '../src/types/ajv/Helpers'
import { initializeSerialization } from '../src/utils/serialization/SchemaHelpers'

const configFile = join(process.cwd(), 'archiver-config.json')
overrideDefaultConfig(configFile)
Expand All @@ -20,6 +22,8 @@ const timestamp = 0
const full_receipt = false

const runProgram = async (): Promise<void> => {
initAjvSchemas()
initializeSerialization()
const res: any = await getJson(`${ARCHIVER_URL}/full-nodelist?activeOnly=true`)
if (!res || !res.nodeList) throw new Error('No active nodes found')
const nodeList = res.nodeList
Expand Down
5 changes: 4 additions & 1 deletion scripts/ngt_shutdown_repair.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as fs from 'fs'
import * as path from 'path'
import * as crypto from 'crypto'
import { initAjvSchemas } from '../src/types/ajv/Helpers'
import { initializeSerialization } from '../src/utils/serialization/SchemaHelpers'

interface TxData {
nodeId: string
Expand Down Expand Up @@ -118,7 +120,8 @@ async function main() {
console.error('Please provide endCycle and endTime as arguments.')
process.exit(1)
}

initAjvSchemas()
initializeSerialization()
console.log(`Reading data from ${filePath}...`)
const rawData = fs.readFileSync(filePath, 'utf-8')
const transactions: TransactionEntry[] = JSON.parse(rawData)
Expand Down
4 changes: 4 additions & 0 deletions scripts/repair_missing_cycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import * as CycleDB from '../src/dbstore/cycles'
import { startSaving } from '../src/saveConsoleOutput'
import * as Logger from '../src/Logger'
import { Utils as StringUtils } from '@shardus/types'
import { initAjvSchemas } from '../src/types/ajv/Helpers'
import { initializeSerialization } from '../src/utils/serialization/SchemaHelpers'

const patchCycleData = false

const start = async (): Promise<void> => {
initAjvSchemas()
initializeSerialization()
// Override default config params from config file, env vars, and cli args
const file = join(process.cwd(), 'archiver-config.json')
overrideDefaultConfig(file)
Expand Down
5 changes: 5 additions & 0 deletions scripts/update_network_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import * as Logger from '../src/Logger'
import { accountSpecificHash } from '../src/shardeum/calculateAccountHash'
import { addSigListeners } from '../src/State'
import { Utils as StringUtils } from '@shardus/types'
import { initAjvSchemas } from '../src/types/ajv/Helpers'
import { initializeSerialization } from '../src/utils/serialization/SchemaHelpers'


const activeVersion = '1.9.0'
const latestVersion = '1.9.0'
const minVersion = '1.9.0'
// const archiver = { "activeVersion": "3.4.12", "latestVersion": "3.4.12", "minVersion": "3.4.12" }

const runProgram = async (): Promise<void> => {
initAjvSchemas()
initializeSerialization()
// Override default config params from config file, env vars, and cli args
const file = join(process.cwd(), 'archiver-config.json')
overrideDefaultConfig(file)
Expand Down
6 changes: 6 additions & 0 deletions scripts/validate_archiver_receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import * as Utils from '../src/Utils'
import * as Receipt from '../src/dbstore/receipts'
import { AccountType, accountSpecificHash } from '../src/shardeum/calculateAccountHash'
import { ShardeumReceipt } from '../src/shardeum/verifyAppReceiptData'
import { initAjvSchemas } from '../src/types/ajv/Helpers'
import { initializeSerialization } from '../src/utils/serialization/SchemaHelpers'

// Add the full receipt data here
const receipt: any = {}

const runProgram = async (): Promise<void> => {
initAjvSchemas()
initializeSerialization()
// Override default config params from config file, env vars, and cli args
const file = join(process.cwd(), 'archiver-config.json')
overrideDefaultConfig(file)
Expand Down Expand Up @@ -41,6 +45,8 @@ const runProgram = async (): Promise<void> => {

// validating appReceiptData
const validateReceiptData = (receipt: Receipt.ArchiverReceipt): boolean => {


// Add type and field existence check
let err = Utils.validateTypes(receipt, {
tx: 'o',
Expand Down
4 changes: 4 additions & 0 deletions scripts/verify_account_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import * as Logger from '../src/Logger'
import { AccountType, accountSpecificHash } from '../src/shardeum/calculateAccountHash'
import { addSigListeners } from '../src/State'
import { Utils as StringUtils } from '@shardus/types'
import { initAjvSchemas } from '../src/types/ajv/Helpers'
import { initializeSerialization } from '../src/utils/serialization/SchemaHelpers'

const updateHash = false
const runProgram = async (): Promise<void> => {
initAjvSchemas()
initializeSerialization()
// Override default config params from config file, env vars, and cli args
const file = join(process.cwd(), 'archiver-config.json')
overrideDefaultConfig(file)
Expand Down

0 comments on commit de4dede

Please sign in to comment.