Skip to content

Commit 7f04e66

Browse files
author
Antoine de Chevigné
committed
more tests
1 parent 0cd3b5c commit 7f04e66

22 files changed

+817
-289
lines changed

pm2-server/tests/lib/pm2.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,26 @@ describe('start', () => {
106106
done();
107107
});
108108
});
109-
});
109+
});
110+
111+
describe('startSafeBlockListener', () => {
112+
it('Should resolve with started process', (done) => {
113+
jest.spyOn(pm2, 'describe').mockImplementation((_, cb) => cb(null, [{ process: 1 }]));
114+
pm2Lib.startSafeBlockListener('slug', 1)
115+
.then(process => {
116+
expect(process).toEqual({ process: 1 });
117+
done();
118+
});
119+
});
120+
});
121+
122+
describe('startLogListener', () => {
123+
it('Should resolve with started process', (done) => {
124+
jest.spyOn(pm2, 'describe').mockImplementation((_, cb) => cb(null, [{ process: 1 }]));
125+
pm2Lib.startLogListener('slug', { arg1: 'value1' })
126+
.then(process => {
127+
expect(process).toEqual({ process: 1 });
128+
done();
129+
});
130+
});
131+
});

run/jobs/finalizePendingOrbitBatches.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const logger = require('../lib/logger');
12
const { OrbitBatch, OrbitChainConfig } = require('../models');
23
const { Op } = require('sequelize');
34

@@ -15,14 +16,14 @@ module.exports = async () => {
1516
for (const config of orbitParentConfigs) {
1617
const parentWorkspace = await config.getTopParentWorkspace();
1718
const orbitChildConfigs = await parentWorkspace.getOrbitChildConfigs();
18-
workspaces[parentWorkspace.id] = { ...parentWorkspace.toJSON(), orbitChildConfigs, client: parentWorkspace.getViemPublicClient() };
19+
workspaces[parentWorkspace.id] = Object.assign({}, parentWorkspace.toJSON(), { orbitChildConfigs, client: parentWorkspace.getViemPublicClient() });
1920
}
2021

21-
let pendingBatches = [];
22+
let allPendingBatches = [];
2223
for (const workspace of Object.values(workspaces)) {
2324
const block = await workspace.client.getBlock({ blockTag: 'safe' });
2425
for (const orbitChildConfig of workspace.orbitChildConfigs) {
25-
console.log(`Validating batches posted on ${workspace.name} by config ${orbitChildConfig.workspaceId} with block number ${block.number}`);
26+
logger.info(`Validating batches posted on ${workspace.name} by config ${orbitChildConfig.workspaceId} with block number ${block.number}`);
2627
const pendingBatches = await OrbitBatch.findAll({
2728
where: {
2829
workspaceId: orbitChildConfig.workspaceId,
@@ -36,8 +37,10 @@ module.exports = async () => {
3637
for (const batch of pendingBatches) {
3738
await batch.confirm();
3839
}
40+
41+
allPendingBatches = allPendingBatches.concat(pendingBatches);
3942
}
4043
}
4144

42-
return pendingBatches.map(batch => batch.id);
45+
return allPendingBatches.map(batch => batch.id);
4346
};

run/jobs/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ module.exports = {
33
blockSync: require('./blockSync'),
44
processBlock: require('./processBlock'),
55
batchBlockSync: require('./batchBlockSync'),
6-
discoverOrbitBatches: require('./discoverOrbitBatches'),
7-
indexOrbitNodes: require('./indexOrbitNodes'),
86
sendResetPasswordEmail: require('./sendResetPasswordEmail'),
97
updateExplorerSyncingProcess: require('./updateExplorerSyncingProcess'),
108
receiptSync: require('./receiptSync'),
119
removeStalledBlock: require('./removeStalledBlock'),
1210
increaseStripeBillingQuota: require('./increaseStripeBillingQuota'),
1311
finalizePendingOrbitBatches: require('./finalizePendingOrbitBatches'),
14-
startSafeBlockListener: require('./startSafeBlockListener'),
1512
checkOrbitMessageDeliveredLogs: require('./checkOrbitMessageDeliveredLogs'),
1613
backfillOrbitMessageDeliveredLogs: require('./backfillOrbitMessageDeliveredLogs'),
1714
storeOrbitDeposit: require('./storeOrbitDeposit'),

run/jobs/receiptSync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ module.exports = async job => {
7676
if (!workspace.explorer)
7777
return 'Inactive explorer';
7878

79-
// if (!workspace.explorer.shouldSync)
80-
// return 'Disabled sync';
79+
if (!workspace.explorer.shouldSync)
80+
return 'Disabled sync';
8181

8282
if (workspace.rpcHealthCheck && workspace.rpcHealthCheckEnabled && !workspace.rpcHealthCheck.isReachable)
8383
return 'RPC is unreachable';

run/jobs/safeBlockListenerCheck.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { Op } = require('sequelize');
2+
const { getPm2Host, getPm2Secret } = require('../lib/env');
23
const { OrbitChainConfig } = require('../models');
3-
const { bulkEnqueue } = require('../lib/queue');
4+
const PM2 = require('../lib/pm2');
45

56
module.exports = async () => {
67
const orbitParentConfigs = await OrbitChainConfig.findAll({
@@ -11,25 +12,23 @@ module.exports = async () => {
1112
}
1213
});
1314

14-
const workspaceIds = [];
15+
const pm2 = new PM2(getPm2Host(), getPm2Secret());
16+
17+
const existingProcesses = [];
18+
const newProcesses = [];
1519
for (const config of orbitParentConfigs) {
1620
const parentWorkspace = await config.getTopParentWorkspace();
17-
workspaceIds.push(parentWorkspace.id);
18-
}
21+
const explorer = await parentWorkspace.getExplorer();
1922

20-
const uniqueWorkspaceIds = [...new Set(workspaceIds)];
23+
const { data: existingProcess } = await pm2.find(`safeBlockListener-${explorer.slug}`);
2124

22-
const jobs = [];
23-
for (let i = 0; i < uniqueWorkspaceIds.length; i++) {
24-
const workspaceId = uniqueWorkspaceIds[i];
25-
console.log(workspaceId);
26-
jobs.push({
27-
name: `startSafeBlockListener-${workspaceId}`,
28-
data: { workspaceId }
29-
});
25+
if (existingProcess)
26+
existingProcesses.push(explorer.slug);
27+
else {
28+
await pm2.startSafeBlockListener(explorer.slug, parentWorkspace.id);
29+
newProcesses.push(explorer.slug);
30+
}
3031
}
3132

32-
await bulkEnqueue('startSafeBlockListener', jobs);
33-
34-
return true;
33+
return { newProcesses, existingProcesses };
3534
};

run/jobs/startSafeBlockListener.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

run/lib/firebase.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ const OrbitChainConfig = models.OrbitChainConfig;
3838
const OrbitWithdrawal = models.OrbitWithdrawal;
3939
const OrbitDeposit = models.OrbitDeposit;
4040

41+
/**
42+
* Retrieves a list of orbit deposits for a workspace
43+
* @param {string} workspaceId - The workspace id
44+
* @param {number} page - The page number
45+
* @param {number} itemsPerPage - The number of items per page
46+
* @param {string} order - The order to sort by
47+
* @returns {Promise<Array>} - A list of orbit deposits
48+
*/
4149
const getWorkspaceOrbitDeposits = async (workspaceId, page, itemsPerPage, order) => {
4250
if (!workspaceId)
4351
throw new Error('Missing parameter');
@@ -54,6 +62,14 @@ const getWorkspaceOrbitDeposits = async (workspaceId, page, itemsPerPage, order)
5462
});
5563
}
5664

65+
/**
66+
* Retrieves the l2 transaction containing an orbit withdrawal
67+
* Data will be used to build claim calldata
68+
* @param {string} workspaceId - The workspace id
69+
* @param {string} hash - The hash of the transaction
70+
* @param {number} messsageNumber - The message number of the withdrawal
71+
* @returns {Promise<Object>} - The orbit withdrawal
72+
*/
5773
const getL2TransactionForOrbitWithdrawalClaim = async (workspaceId, hash, messsageNumber) => {
5874
if (!workspaceId || !hash)
5975
throw new Error('Missing parameter');
@@ -248,17 +264,6 @@ const getOrbitBatch = async (workspaceId, batchNumber) => {
248264
return batch.toJSON();
249265
};
250266

251-
const getWorkspaceByIdWithOrbitConfig = async (workspaceId) => {
252-
if (!workspaceId)
253-
throw new Error('Missing parameter');
254-
255-
const workspace = await Workspace.findByPk(workspaceId, {
256-
include: 'orbitConfig'
257-
});
258-
259-
return workspace.toJSON();
260-
};
261-
262267
/**
263268
* Retrieves a list of orbit batches for a workspace
264269
* @param {string} workspaceId - The workspace id
@@ -3410,7 +3415,6 @@ module.exports = {
34103415
getImportedAccounts: getImportedAccounts,
34113416
getFilteredNativeAccounts: getFilteredNativeAccounts,
34123417
getWorkspaceOrbitBatches: getWorkspaceOrbitBatches,
3413-
getWorkspaceByIdWithOrbitConfig: getWorkspaceByIdWithOrbitConfig,
34143418
getOrbitBatch: getOrbitBatch,
34153419
getOrbitBatchBlocks: getOrbitBatchBlocks,
34163420
getWorkspaceOrbitBatchTransactions: getWorkspaceOrbitBatchTransactions,

run/lib/orbitNodes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ module.exports = {
6868
isOrbitNodeRejectedLog,
6969
getOrbitCreatedNodeData,
7070
getOrbitConfirmedNodeData
71-
};
71+
};

run/migrations/20250901134001-cleanup-orbit-fields.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ module.exports = {
2222

2323
await queryInterface.dropTable('orbit_batch_block', { transaction });
2424

25-
await queryInterface.removeColumn('orbit_chain_configs', 'parentChainRpcServer', { transaction });
2625
await queryInterface.removeColumn('orbit_chain_configs', 'parentChainType', { transaction });
2726

2827
await queryInterface.sequelize.query('DROP TYPE IF EXISTS "enum_orbit_chain_configs_parentChainType";', { transaction });

0 commit comments

Comments
 (0)