Skip to content

Commit

Permalink
fix: light rest node's API status is not query plus upgrade dependencies
Browse files Browse the repository at this point in the history
Problem: light rest node's API status is not query
         Jenkins fail, because the project can't run in node v20
Solution: add support for light rest nodes by query the API status of every node
          upgrade project dependencies
  • Loading branch information
AnthonyLaw authored and Wayonb committed Dec 17, 2024
1 parent 2a42acd commit e1597dd
Show file tree
Hide file tree
Showing 15 changed files with 3,343 additions and 7,719 deletions.
10,751 changes: 3,136 additions & 7,615 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"swagger-cli": "^4.0.4",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.1",
"typescript": "^3.8.3",
"typescript": "^5.7.2",
"ws": "^8.11.0"
},
"dependencies": {
Expand All @@ -61,7 +61,7 @@
"express": "^4.18.2",
"humanize-duration": "^3.27.3",
"module-alias": "^2.2.2",
"mongoose": "^5.13.15",
"mongoose": "^8.8.4",
"symbol-sdk": "^2.0.3",
"tcp-ping": "^0.1.1",
"utf8": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Logger {
});
}

static logTemplate(info: { level: string; message: string; [key: string]: any }): string {
static logTemplate(info: winston.Logform.TransformableInfo): string {
return `${info.timestamp} ${info.level}: [${info.label}] ${info.message}`;
}
}
11 changes: 1 addition & 10 deletions src/models/HostDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const HostDetailSchema: Schema = new Schema({
required: true,
},
},
required: false,
},
location: {
type: String,
Expand All @@ -58,40 +57,32 @@ const HostDetailSchema: Schema = new Schema({
},
organization: {
type: String,
required: false,
},
as: {
type: String,
required: false,
},
continent: {
type: String,
required: false,
},
country: {
type: String,
required: false,
},
region: {
type: String,
required: false,
},
city: {
type: String,
required: false,
},
district: {
type: String,
required: false,
},
zip: {
type: String,
required: false,
},
});

HostDetailSchema.set('toObject', {
transform: (doc: Document, ret: Document) => {
transform: (doc: Document, ret) => {
delete ret._id;
delete ret.__v;
},
Expand Down
30 changes: 1 addition & 29 deletions src/models/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface NodeDocument extends INode, Document {}
const NodeSchema: Schema = new Schema({
friendlyName: {
type: String,
required: false,
},
host: {
type: String,
Expand All @@ -45,96 +44,73 @@ const NodeSchema: Schema = new Schema({
peerStatus: {
isAvailable: {
type: Boolean,
required: false,
},
lastStatusCheck: {
type: Number,
required: false,
},
required: false,
},
apiStatus: {
webSocket: {
type: {
isAvailable: {
type: Boolean,
required: false,
},
wss: {
type: Boolean,
required: false,
},
url: {
type: String,
required: false,
},
},
required: false,
},
restGatewayUrl: {
type: String,
required: false,
},
isAvailable: {
type: Boolean,
required: false,
},
isHttpsEnabled: {
type: Boolean,
required: false,
},
nodeStatus: {
type: {
apiNode: {
type: String,
required: false,
},
db: {
type: String,
required: false,
},
},
required: false,
},
chainHeight: {
type: Number,
required: false,
},
finalization: {
type: {
height: {
type: Number,
required: false,
},
epoch: {
type: Number,
required: false,
},
point: {
type: Number,
required: false,
},
hash: {
type: String,
required: false,
},
},
required: false,
},
nodePublicKey: {
type: String,
required: false,
index: true,
},
restVersion: {
type: String,
required: false,
},
lastStatusCheck: {
type: Number,
required: false,
},
required: false,
},
publicKey: {
type: String,
Expand Down Expand Up @@ -167,7 +143,6 @@ const NodeSchema: Schema = new Schema({
required: true,
},
},
required: false,
},
location: {
type: String,
Expand All @@ -187,7 +162,6 @@ const NodeSchema: Schema = new Schema({
},
continent: {
type: String,
required: false,
},
country: {
type: String,
Expand All @@ -210,11 +184,9 @@ const NodeSchema: Schema = new Schema({
required: true,
},
},
required: false,
},
lastAvailable: {
type: Date,
required: false,
},
});

Expand All @@ -233,7 +205,7 @@ NodeSchema.index(
);

NodeSchema.set('toObject', {
transform: (doc: Document, ret: Document) => {
transform: (doc: Document, ret) => {
delete ret._id;
delete ret.__v;
},
Expand Down
1 change: 0 additions & 1 deletion src/models/NodeCountSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const schema: Schema = new Schema({
},
values: {
type: Schema.Types.Mixed,
required: false,
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/models/NodeHeightStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const NodeHeightStatsSchema: Schema = new Schema({
});

NodeHeightStatsSchema.set('toObject', {
transform: (doc: Document, ret: Document) => {
transform: (doc: Document, ret) => {
delete ret._id;
delete ret.__v;
},
Expand Down
4 changes: 1 addition & 3 deletions src/models/NodesStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ export interface NodesStatsDocument extends INodesStats, Document {}
const NodesStatsSchema: Schema = new Schema({
nodeTypes: {
type: Schema.Types.Mixed,
required: false,
},
nodeVersion: {
type: Schema.Types.Mixed,
required: false,
},
});

NodesStatsSchema.set('toObject', {
transform: (doc: Document, ret: Document) => {
transform: (doc: Document, ret) => {
delete ret._id;
delete ret.__v;
},
Expand Down
4 changes: 2 additions & 2 deletions src/services/ChainHeightMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ChainHeightMonitor {
await sleep(this.interval);
this.start();
}
} catch (e) {
} catch (e: any) {
logger.error(`Unhandled error during a loop. ${e.message}. Restarting Monitor..`);
await sleep(this.interval);
this.stop();
Expand Down Expand Up @@ -100,7 +100,7 @@ export class ChainHeightMonitor {
this.finalizedHeights[chainInfo.latestFinalizedBlock.height] =
(this.finalizedHeights[chainInfo.latestFinalizedBlock.height] || 0) + 1;
}
} catch (e) {
} catch (e: any) {
logger.error(`Node chain height monitor failed. ${e.message}`);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/services/DataBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface NodeSearchCriteria {
export class DataBase {
static connect = async (url: string) => {
try {
await mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true });
await mongoose.connect(url);
} catch (err) {
logger.error(`DataBase Failed to connect MongoDB`);
throw err;
Expand Down Expand Up @@ -112,7 +112,7 @@ export class DataBase {

try {
await model.deleteMany();
} catch (e) {
} catch (e: any) {
const msg = `Update collection "${collectionName}" failed. Error during "model.deleteMany()". ${e.message}`;

logger.error(msg);
Expand All @@ -121,7 +121,7 @@ export class DataBase {

try {
await model.insertMany(documents);
} catch (e) {
} catch (e: any) {
const msg = `Update collection "${collectionName}" failed. Error during "model.insertMany()". ${e.message}`;

logger.error(msg);
Expand Down
8 changes: 4 additions & 4 deletions src/services/GeolocationMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class GeolocationMonitor {
await sleep(this.interval);
this.start();
}
} catch (e) {
} catch (e: any) {
logger.error(`Unhandled error during a loop. ${e.message}. Restarting Monitor..`);
await sleep(this.interval);
this.stop();
Expand Down Expand Up @@ -92,7 +92,7 @@ export class GeolocationMonitor {
}

// await this.updateCollection();
} catch (e) {
} catch (e: any) {
logger.error(`Error getting host info. ${e.message}`);
}
}
Expand All @@ -115,7 +115,7 @@ export class GeolocationMonitor {
await DataBase.insertNodeHostDetail(hostDetail);
logger.info(`New host info added to collection`);
}
} catch (e) {
} catch (e: any) {
logger.error(`Failed to add new host info to collection`, e.message);
}
};
Expand All @@ -132,7 +132,7 @@ export class GeolocationMonitor {
const nodesHostDetail = await DataBase.getNodesHostDetail();

memoryCache.setArray('nodesHostDetail', nodesHostDetail, ['host']);
} catch (e) {
} catch (e: any) {
logger.error('Failed to cache "nodesHostDetail" collection to memory. ' + e.message);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/services/HostInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class HostInfo {
district: data.district,
zip: data.zip,
};
} catch (e) {
} catch (e: any) {
logger.error(`[getHostDetail] Failed to get host ${host} info ${e.message}`);
return null;
}
Expand Down
Loading

0 comments on commit e1597dd

Please sign in to comment.