From 82100da75728ea4ef3983fd6439e175201cafc9b Mon Sep 17 00:00:00 2001 From: Sonali Thakur Date: Tue, 9 Jul 2024 13:45:36 +0530 Subject: [PATCH 1/6] error handling for all external endpoints --- src/network/index.ts | 45 ++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/network/index.ts b/src/network/index.ts index 3a926cb0f..b859bba78 100644 --- a/src/network/index.ts +++ b/src/network/index.ts @@ -127,6 +127,19 @@ export class NetworkClass extends EventEmitter { next() } + handleError(error: any, req: any, res: any, route: string) { + /* prettier-ignore */ if (logFlags.error) this.mainLogger.error(`Error in route ${route}: ${error.message}`) + + nestedCountersInstance.countEvent('endpoint-exception', `error-${route}`) + + // Send an error response + res.status(500).json({ + error: 'Internal Server Error', + message: isDebugMode() ? error.message : 'An unexpected error occurred', + route: route, + }) + } + // TODO: Allow for binding to a specified network interface _setupExternal() { return new Promise((resolve, reject) => { @@ -545,29 +558,29 @@ export class NetworkClass extends EventEmitter { handlers.push(authHandler) } - if (isDebugMode() && ['GET', 'POST'].includes(method)) { - const wrappedHandler = async (req, res, next) => { - profilerInstance.profileSectionStart('net-externl', false) - profilerInstance.profileSectionStart(`net-externl-${route}`, false) - profilerInstance.scopedProfileSectionStart(`net-externl-${route}`, false) - - let result - try { - result = await responseHandler(req, res, next) - } finally { + const wrappedHandler = async (req, res, next) => { + let result + try { + if (isDebugMode() && ['GET', 'POST'].includes(method)) { + profilerInstance.profileSectionStart('net-externl', false) + profilerInstance.profileSectionStart(`net-externl-${route}`, false) + profilerInstance.scopedProfileSectionStart(`net-externl-${route}`, false) + } + result = await responseHandler(req, res, next) + } catch (error) { + this.handleError(error, req, res, route) + } finally { + if (isDebugMode() && ['GET', 'POST'].includes(method)) { profilerInstance.scopedProfileSectionEnd(`net-externl-${route}`) profilerInstance.profileSectionEnd(`net-externl-${route}`, false) profilerInstance.profileSectionEnd('net-externl', false) } - - return result } - - handlers.push(wrappedHandler) - } else { - handlers.push(responseHandler) + return result } + handlers.push(wrappedHandler) + let expressMethod = { GET: 'get', POST: 'post', From 4d75f797a9d67af7a94dec8860220c4e0f9ade3c Mon Sep 17 00:00:00 2001 From: Sonali Thakur Date: Tue, 9 Jul 2024 13:49:54 +0530 Subject: [PATCH 2/6] update endpoint-exception counter message --- src/network/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/index.ts b/src/network/index.ts index b859bba78..ec6f9ad24 100644 --- a/src/network/index.ts +++ b/src/network/index.ts @@ -130,7 +130,7 @@ export class NetworkClass extends EventEmitter { handleError(error: any, req: any, res: any, route: string) { /* prettier-ignore */ if (logFlags.error) this.mainLogger.error(`Error in route ${route}: ${error.message}`) - nestedCountersInstance.countEvent('endpoint-exception', `error-${route}`) + nestedCountersInstance.countEvent('endpoint-exception', `${route}`) // Send an error response res.status(500).json({ From d091aab9d2a0b5cc00ba31a988fa99115513397b Mon Sep 17 00:00:00 2001 From: Elias Rad <146735585+nnsW3@users.noreply.github.com> Date: Mon, 15 Jul 2024 15:42:24 +0300 Subject: [PATCH 3/6] add missing verb join-protocol-v2.md --- docs/join-protocol-v2/join-protocol-v2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/join-protocol-v2/join-protocol-v2.md b/docs/join-protocol-v2/join-protocol-v2.md index 31ae49223..24bfe651f 100644 --- a/docs/join-protocol-v2/join-protocol-v2.md +++ b/docs/join-protocol-v2/join-protocol-v2.md @@ -73,7 +73,7 @@ The existing join code is in the repository "shardus-global-server", aka "Shardu - Where to make the request - There are multiple `shutdown()` methods in Shardus Core where this might be done, or: - The constructor of the `Shardus` class in `src/shardus/index.ts` contains multiple `this.exitHandler.registerAsync()` calls that could be used to register the `unjoin` request. -- The unjoin request will require a new list in the cycle record because it cannot remove immediately. +- The unjoin request will require a new list in the cycle record because it cannot be removed immediately. - Ignore the unjoin request if the node is not found in `standbyNodeByPublicKey` or `byJoinOrder`. ## Additional Context From 11e711cb387c322ce5889621923a54c93e609e4e Mon Sep 17 00:00:00 2001 From: Elias Rad <146735585+nnsW3@users.noreply.github.com> Date: Mon, 15 Jul 2024 15:44:02 +0300 Subject: [PATCH 4/6] fix link README.md --- docs/tx-data-struct-cleanup/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tx-data-struct-cleanup/README.md b/docs/tx-data-struct-cleanup/README.md index 4bc36efac..1f54dbd60 100644 --- a/docs/tx-data-struct-cleanup/README.md +++ b/docs/tx-data-struct-cleanup/README.md @@ -80,5 +80,5 @@ sequenceDiagram Note over S, A: StateManager.TransactionQueue.commitConsensedTransaction »
StateManager.setAccount »
App.updateAccountFull || App.updateAccountPartial A -->> S: Returns whether update was successful or not ``` -[Differences betweeen diagrams and actual implementation](./TODO.md) +[Differences between diagrams and actual implementation](./TODO.md) From e7f11afd1b8f097ac1aeea966070332f3bce8bc7 Mon Sep 17 00:00:00 2001 From: Elias Rad <146735585+nnsW3@users.noreply.github.com> Date: Mon, 15 Jul 2024 15:46:00 +0300 Subject: [PATCH 5/6] fix spelling issue duplicated-codes.md --- docs/duplicated-codes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/duplicated-codes.md b/docs/duplicated-codes.md index fb6a3b272..1fbb5e281 100644 --- a/docs/duplicated-codes.md +++ b/docs/duplicated-codes.md @@ -81,7 +81,7 @@ joinNetwork(nodes, firstTime) ----- ## Syncing Cycle Records and Building Node List ### Description -When a new consensor node or archiver joins the network, it trys to sync the cycle records and build active node list from the record +When a new consensor node or archiver joins the network, it tries to sync the cycle records and build active node list from the record ### Functions ``` ChangeSquasher() From c9e8fa1b88f66bbffa8f4bb5c49dd3a2c1b5e52e Mon Sep 17 00:00:00 2001 From: Elias Rad <146735585+nnsW3@users.noreply.github.com> Date: Mon, 15 Jul 2024 15:47:20 +0300 Subject: [PATCH 6/6] spelling issue network-safety-mode.md --- docs/network-safety-mode.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/network-safety-mode.md b/docs/network-safety-mode.md index 8c8689286..ac49042cd 100644 --- a/docs/network-safety-mode.md +++ b/docs/network-safety-mode.md @@ -8,7 +8,7 @@ The functional specification ["Network Safety"](https://docs.google.com/document There is a [Linear project](https://linear.app/shm/project/network-safety-mode-743d4f2d34fd) for the implementation. -There is already an implentation of safety mode in place, but it is more primitive, and the intention is to add a mode system. +There is already an implementation of safety mode in place, but it is more primitive, and the intention is to add a mode system. ## Benefits @@ -53,4 +53,4 @@ The existing safety mode implementation is inside the module `shardus-global-ser - `isReadyToJoin()` and `validateJoinRequest()`, mode argument should be added to both functions - then logic for when in processing mode, require `stakeCert` and in other modes require `adminCert` - \ No newline at end of file +