Skip to content

Commit

Permalink
Set request retries dynamically by getting rotationEdgeToAvoid config…
Browse files Browse the repository at this point in the history
… from a node
  • Loading branch information
urnotsam committed May 2, 2024
1 parent ed499a5 commit fc06509
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
sleep,
cleanBadNodes,
initSyncTime,
updateEdgeNodeConfig,
updateRequestRetries,
} from './utils'
import { router as logRoute } from './routes/log'
import { router as authenticate } from './routes/authenticate'
Expand Down Expand Up @@ -208,12 +208,12 @@ setupArchiverDiscovery({
debug_info.txRecordingStartTime = config.recordTxStatus ? Date.now() : 0
setConsensorNode()
initSyncTime()
updateEdgeNodeConfig()
updateRequestRetries()
setInterval(updateNodeList, config.nodelistRefreshInterval)
setInterval(saveTxStatus, 5000)
setInterval(checkArchiverHealth, 60000)
setInterval(cleanBadNodes, 60000)
setInterval(updateEdgeNodeConfig, 60000 * 5)
setInterval(updateRequestRetries, 60000 * 5)
extendedServer.listen(port, function () {
console.log(`JSON RPC Server listening on port ${port} and chainId is ${chainId}.`)
setupDatabase()
Expand Down
12 changes: 6 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export const node = {
port: 9001,
}

let rotationEdgeToAvoid = 0

const badNodesMap: Map<string, number> = new Map()

const verbose = config.verbose
Expand Down Expand Up @@ -151,18 +149,20 @@ export async function updateNodeList(tryInfinate = false): Promise<void> {
}

export function removeFromNodeList(ip: string, port: string): void {
console.log(`Removing node ${ip}:${port} from nodeList`)
nodeList = nodeList.filter((node) => node.ip !== ip || node.port !== Number(port))
console.log(nodeList.map((node) => `${node.port}`))
}

export async function updateEdgeNodeConfig(): Promise<void> {
console.log(`Updating rotationEdgeToAvoid configuration`)
export async function updateRequestRetries(): Promise<void> {
console.log(`Updating defaultRequestRetry configuration`)

const res = await requestWithRetry(RequestMethod.Get, `/netconfig`)

if (res.data && res.data.config) {
const newRotationEdgeToAvoid = res.data.config.p2p.rotationEdgeToAvoid
rotationEdgeToAvoid = newRotationEdgeToAvoid
console.log(`Setting rotationEdgeToAvoid to ${newRotationEdgeToAvoid}`)
config.defaultRequestRetry = newRotationEdgeToAvoid * 2
console.log(`Setting request retries to ${config.defaultRequestRetry}`)
} else if (res.data && res.data.error) {
console.log(`Error getting rotationEdgeToAvoid configuration: ${res.data.error}`)
}
Expand Down

0 comments on commit fc06509

Please sign in to comment.