Page MenuHomePhabricator

D13398.id38724.diff
No OneTemporary

D13398.id38724.diff

diff --git a/web/alias-server/websocket.js b/web/alias-server/websocket.js
--- a/web/alias-server/websocket.js
+++ b/web/alias-server/websocket.js
@@ -89,7 +89,6 @@
.toArray();
if (serverStateArray.length === 0) {
// Special case where you are just starting the app
-
log(
`App has no serverState. processedConfirmedTxs will default to 0`,
);
@@ -131,8 +130,14 @@
mostRecentAlias =
validAliasesInDb[validAliasesInDb.length - 1];
- processedBlockheight = mostRecentAlias.blockheight;
+ /*
+ Note processedBlockheight is not the same as the blockheight of
+ the most recent alias tx
+ */
+ processedBlockheight = serverState.processedBlockheight;
processedConfirmedTxs = serverState.processedConfirmedTxs;
+ log(`processedBlockheight`, processedBlockheight);
+ log(`processedConfirmedTxs`, processedConfirmedTxs);
} else {
log(
`Server startup. There are no valid aliases in the database.`,
@@ -187,7 +192,7 @@
const unprocessedTxs = await getUnprocessedTxHistory(
config.aliasConstants.registrationHash160,
processedBlockheight,
- processedTxCount,
+ processedConfirmedTxs,
);
// Debug logging for unprocessed txs
@@ -240,7 +245,23 @@
const updatedProcessedConfirmedTxs =
processedConfirmedTxs + confirmedTxsToBeAddedToDb.length;
+ // Also calculate new processedBlockheight
+ // Note that this is the true latest processedBlockheight (most recent confirmed tx, not most recent confirmed alias tx)
+ // first blockheight
+
+ // If no new confirmed txs, this is static
+ let updatedProcessedBlockheight = processedBlockheight;
+
if (confirmedTxsToBeAddedToDb.length > 0) {
+ // Due to the ordering of confirmedTxsToBeAddedToDb[0] will have the highest blockheight
+ updatedProcessedBlockheight =
+ confirmedTxsToBeAddedToDb[0].block.height;
+ log(
+ `Updating processedBlockheight from ${processedBlockheight} to ${updatedProcessedBlockheight}`,
+ );
+ log(
+ `Updating ${processedConfirmedTxs} from ${processedTxCount} to ${updatedProcessedConfirmedTxs}`,
+ );
log(
`Adding ${confirmedTxsToBeAddedToDb.length} confirmed txs to the db`,
);
@@ -274,11 +295,6 @@
*/
}
- // Update serverState.processedConfirmedTxs
- log(
- `Updating serverState.processedConfirmedTxs from ${processedConfirmedTxs} to ${updatedProcessedConfirmedTxs}.`,
- );
-
// else update by id
if (serverStateArray.length > 0 && serverState._id) {
const serverStateQuery = { _id: serverState._id };
@@ -286,6 +302,8 @@
$set: {
processedConfirmedTxs:
updatedProcessedConfirmedTxs,
+ processedBlockheight:
+ updatedProcessedBlockheight,
},
};
let serverStateUpdateResult;
@@ -322,11 +340,13 @@
.insertOne({
processedConfirmedTxs:
updatedProcessedConfirmedTxs,
+ processedBlockheight:
+ updatedProcessedBlockheight,
});
} catch (err) {
// If this isn't updated, the server will process too many txs next time
// Let the admin know. This won't impact parsing but will cause processing too many txs
- const errMsg = `Error in db.collection(${config.database.collections.serverState}).insertOne({processedConfirmedTxs: ${updatedProcessedConfirmedTxs}}`;
+ const errMsg = `Error in db.collection(${config.database.collections.serverState}).insertOne({processedConfirmedTxs: ${updatedProcessedConfirmedTxs}, processedBlockheight: ${updatedProcessedBlockheight}}`;
log(errMsg, err);
const adminNotifyMsg = `${errMsg}\n\n${err}`;
const adminNotified = await sendAdminAlert(

File Metadata

Mime Type
text/plain
Expires
Thu, Feb 6, 16:38 (17 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5082714
Default Alt Text
D13398.id38724.diff (5 KB)

Event Timeline