Skip to content

Commit

Permalink
Put data insert log behind verbose flag, nodelist api improvement, ad…
Browse files Browse the repository at this point in the history
…ded npm run start command
  • Loading branch information
jairajdev committed May 8, 2024
1 parent 406b012 commit bff4eba
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"archive-server": "./build/server.js"
},
"scripts": {
"start": "npm run prepare && node build/server.js",
"release": "npm run prepare && np --no-cleanup --no-tests --no-yarn --any-branch",
"test": "echo \"Error: no test specified\" && exit 1",
"check": "gts check",
Expand Down Expand Up @@ -94,4 +95,4 @@
"overrides": {
"axios": "1.6.1"
}
}
}
13 changes: 11 additions & 2 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,18 @@ export function registerRoutes(server: FastifyInstance<Server, IncomingMessage,
const isSignatureValid = Crypto.verify(signedFirstNodeInfo)
if (!isSignatureValid) {
Logger.mainLogger.error('Invalid signature', signedFirstNodeInfo)
reply.send({ success: false, error: 'Invalid signature' })
return
}
} catch (e) {
Logger.mainLogger.error(e)
reply.send({ success: false, error: 'Signature verification failed' })
return
}
if (NodeList.foundFirstNode) {
const res = NodeList.getCachedNodeList()
reply.send(res)
return
}
NodeList.toggleFirstNode()
const ip = signedFirstNodeInfo.nodeInfo.externalIp
Expand All @@ -97,7 +105,9 @@ export function registerRoutes(server: FastifyInstance<Server, IncomingMessage,

// Add first node to NodeList
NodeList.addNodes(NodeList.NodeStatus.SYNCING, [firstNode])

// Setting current time for realUpdatedTimes to refresh the nodelist and full-nodelist cache
NodeList.realUpdatedTimes.set('/nodelist', Date.now())
NodeList.realUpdatedTimes.set('/full-nodelist', Date.now())
// Set first node as dataSender
const firstDataSender: Data.DataSender = {
nodeInfo: firstNode,
Expand All @@ -123,7 +133,6 @@ export function registerRoutes(server: FastifyInstance<Server, IncomingMessage,
data['joinRequest'] = P2P.createArchiverJoinRequest()
data['dataRequestCycle'] = Cycles.getCurrentCycleCounter()
}

res = Crypto.sign<P2P.FirstNodeResponse>(data)
} else {
res = Crypto.sign<P2P.FirstNodeResponse>({
Expand Down
1 change: 1 addition & 0 deletions src/NodeList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,5 @@ export function clearNodeListCache(): void {

export function toggleFirstNode(): void {
foundFirstNode = !foundFirstNode
Logger.mainLogger.debug('foundFirstNode', foundFirstNode)
}
2 changes: 1 addition & 1 deletion src/dbstore/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function bulkInsertAccounts(accounts: AccountCopy[]): Promise<void>
sql = sql + ', (' + placeholders + ')'
}
await db.run(sql, values)
Logger.mainLogger.debug('Successfully inserted Accounts', accounts.length)
if (config.VERBOSE) Logger.mainLogger.debug('Successfully inserted Accounts', accounts.length)
} catch (e) {
Logger.mainLogger.error(e)
Logger.mainLogger.error('Unable to bulk insert Accounts', accounts.length)
Expand Down
2 changes: 1 addition & 1 deletion src/dbstore/cycles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function bulkInsertCycles(cycles: Cycle[]): Promise<void> {
sql = sql + ', (' + placeholders + ')'
}
await db.run(sql, values)
Logger.mainLogger.debug('Successfully inserted Cycles', cycles.length)
if (config.VERBOSE) Logger.mainLogger.debug('Successfully inserted Cycles', cycles.length)
} catch (e) {
Logger.mainLogger.error(e)
Logger.mainLogger.error('Unable to bulk insert Cycles', cycles.length)
Expand Down
3 changes: 2 additions & 1 deletion src/dbstore/originalTxsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export async function bulkInsertOriginalTxsData(originalTxsData: OriginalTxData[
sql = sql + ', (' + placeholders + ')'
}
await db.run(sql, values)
Logger.mainLogger.debug('Successfully inserted OriginalTxsData', originalTxsData.length)
if (config.VERBOSE)
Logger.mainLogger.debug('Successfully inserted OriginalTxsData', originalTxsData.length)
} catch (e) {
Logger.mainLogger.error(e)
Logger.mainLogger.error('Unable to bulk insert OriginalTxsData', originalTxsData.length)
Expand Down
2 changes: 1 addition & 1 deletion src/dbstore/receipts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function bulkInsertReceipts(receipts: Receipt[]): Promise<void> {
sql = sql + ', (' + placeholders + ')'
}
await db.run(sql, values)
Logger.mainLogger.debug('Successfully inserted Receipts', receipts.length)
if (config.VERBOSE) Logger.mainLogger.debug('Successfully inserted Receipts', receipts.length)
} catch (e) {
Logger.mainLogger.error(e)
Logger.mainLogger.error('Unable to bulk insert Receipts', receipts.length)
Expand Down
2 changes: 1 addition & 1 deletion src/dbstore/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function bulkInsertTransactions(transactions: Transaction[]): Promi
sql = sql + ', (' + placeholders + ')'
}
await db.run(sql, values)
Logger.mainLogger.debug('Successfully inserted Transactions', transactions.length)
if (config.VERBOSE) Logger.mainLogger.debug('Successfully inserted Transactions', transactions.length)
} catch (e) {
Logger.mainLogger.error(e)
Logger.mainLogger.error('Unable to bulk insert Transactions', transactions.length)
Expand Down

0 comments on commit bff4eba

Please sign in to comment.