Skip to content

Commit

Permalink
fix update peer last seen and dialed (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroxbt authored Aug 14, 2023
1 parent 2c06c9e commit 3f2c863
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ShardRepository {
}

async updatePeerRecordLastDialed(peerId, timestamp) {
await this.model.update(
return this.model.update(
{
lastDialed: timestamp,
},
Expand All @@ -119,7 +119,7 @@ class ShardRepository {
}

async updatePeerRecordLastSeenAndLastDialed(peerId, timestamp) {
await this.model.update(
return this.model.update(
{
lastDialed: timestamp,
lastSeen: timestamp,
Expand Down
21 changes: 16 additions & 5 deletions src/service/sharding-table-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,21 @@ class ShardingTableService {
};
}
if (this.memoryCachedPeerIds[peerId].lastUpdated < timestampThreshold) {
await this.repositoryModuleManager.updatePeerRecordLastSeenAndLastDialed(peerId, now);
this.memoryCachedPeerIds[peerId].lastUpdated = now;
const [rowsUpdated] =
await this.repositoryModuleManager.updatePeerRecordLastSeenAndLastDialed(
peerId,
now,
);
if (rowsUpdated) {
this.memoryCachedPeerIds[peerId].lastUpdated = now;
}
}
this.memoryCachedPeerIds[peerId].lastDialed = now;
this.memoryCachedPeerIds[peerId].lastSeen = now;
}

async updatePeerRecordLastDialed(peerId) {
const now = new Date();
const now = Date.now();
const timestampThreshold = now - PEER_RECORD_UPDATE_DELAY;
if (!this.memoryCachedPeerIds[peerId]) {
this.memoryCachedPeerIds[peerId] = {
Expand All @@ -232,8 +238,13 @@ class ShardingTableService {
};
}
if (this.memoryCachedPeerIds[peerId].lastUpdated < timestampThreshold) {
await this.repositoryModuleManager.updatePeerRecordLastDialed(peerId, now);
this.memoryCachedPeerIds[peerId].lastUpdated = now;
const [rowsUpdated] = await this.repositoryModuleManager.updatePeerRecordLastDialed(
peerId,
now,
);
if (rowsUpdated) {
this.memoryCachedPeerIds[peerId].lastUpdated = now;
}
}
this.memoryCachedPeerIds[peerId].lastDialed = now;
}
Expand Down

0 comments on commit 3f2c863

Please sign in to comment.