Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cycle debug log #18

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 3 additions & 6 deletions src/Data/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,7 @@
saved: false,
senderNodes: [senderInfo],
}
// Logger.mainLogger.debug(
// 'Different Cycle Record received',
// cycle.counter,
// receivedCycleTracker[cycle.counter]
// )
if (config.VERBOSE) Logger.mainLogger.debug('Different Cycle Record received', cycle.counter)

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.
}
} else {
if (!validateCycleData(cycle)) continue
Expand All @@ -376,7 +372,8 @@
},
}
}
// Logger.mainLogger.debug('Cycle received', cycle.counter, receivedCycleTracker)
if (config.VERBOSE)
Logger.mainLogger.debug('Cycle received', cycle.counter, receivedCycleTracker[cycle.counter])

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.
const minCycleConfirmations =
Math.min(Math.ceil(NodeList.getActiveNodeCount() / currentConsensusRadius), 5) || 1

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
Loading