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

RED-90: Improve node rotation handling #21

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 14 additions & 9 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ async function injectWithRetries(txHash: string, tx: any, args: any, retries = c
result = await injectAndRecordTx(txHash, tx, args)
if (result.success) {
return result
} else if (result.reason === 'Node is too close to rotation edges. Inject to another node') {
console.log('Node is close to rotation edges. Rotating node...')
} else if (result.status === 503) {
if (result?.reason) console.log(result.reason)
if (result.nodeUrl) {
const urlParts = result.nodeUrl.split(':')
removeFromNodeList(urlParts[0], urlParts[1])
Expand Down Expand Up @@ -651,7 +651,7 @@ async function injectAndRecordTx(
nodeUrl: baseUrl,
success: injectResult ? injectResult.success : false,
reason: injectResult.reason,
status: injectResult.status,
status: injectResult.status
})
}

Expand All @@ -670,7 +670,7 @@ async function injectAndRecordTx(
nodeUrl: baseUrl,
success: injectResult ? injectResult.success : false,
reason: injectResult.reason,
status: injectResult.status,
status: injectResult.status
})
} else {
countInjectTxRejections('No injection result')
Expand All @@ -687,9 +687,9 @@ async function injectAndRecordTx(
reject({ nodeUrl: baseUrl, error: 'Unable inject transaction to the network' })
}
})
.catch((e: Error) => {
if (config.verbose) console.log('injectAndRecordTx: Caught Exception: ' + e.message)
countInjectTxRejections('Caught Exception: ' + trimInjectRejection(e.message))
.catch((error) => {
if (config.verbose) console.log('injectAndRecordTx: Caught Exception: ' + error?.message)
countInjectTxRejections('Caught Exception: ' + trimInjectRejection(error?.message))

if (config.recordTxStatus)
recordTxStatus({
Expand All @@ -702,7 +702,12 @@ async function injectAndRecordTx(
ip: args[1000], // this index slot is reserved for ip, check injectIP middleware l
nodeUrl: baseUrl,
})
reject({ nodeUrl: baseUrl, error: 'Unable inject transaction to the network' })
resolve({
nodeUrl: baseUrl,
reason: error.response?.data?.reason ?? 'Unable inject transaction to the network',
status: error.response?.status,
success: false
})
})
})
}
Expand Down Expand Up @@ -3632,7 +3637,7 @@ export const methods = {
countFailedResponse(api_name, 'Invalid address')
return
}

if (!isValidAddress(callObj.from)) {
if (verbose) console.log('Invalid params: `from` is not valid address', callObj.from)
callback({ code: -32000, message: 'Invalid params: `from` is not valid address' }, null)
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ export async function requestWithRetry(
if (typeof res.data === 'object') res.data.nodeUrl = nodeUrl
return res //break
}
} else if (res.data.error === 'node close to rotation edges') {
console.log(`${nodeUrl} Node is close to rotation edges. Changing node...`)
} else if (res.status === 503) {
if (res.data.error) console.log(`${nodeUrl} ${res.data.error}`)
if (nodeIpPort) {
const urlParts = nodeIpPort.split(':')
removeFromNodeList(urlParts[0], urlParts[1])
Expand Down
Loading