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

Fix docs #193

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/duplicated-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion docs/join-protocol-v2/join-protocol-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/network-safety-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`



2 changes: 1 addition & 1 deletion docs/tx-data-struct-cleanup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ sequenceDiagram
Note over S, A: StateManager.TransactionQueue.commitConsensedTransaction » <br> StateManager.setAccount » <br> 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)

45 changes: 29 additions & 16 deletions src/network/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', `${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) => {
Expand Down Expand Up @@ -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',
Expand Down