Skip to content

Commit 5b7d218

Browse files
author
Antoine de Chevigné
committed
fix reset fn + tests
1 parent 51791b3 commit 5b7d218

38 files changed

Lines changed: 200 additions & 938 deletions

pm2-server/app.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,6 @@ app.post('/log-listener', secretMiddleware, async (req, res) => {
2828
}
2929
});
3030

31-
app.post('/safe-block-listener', secretMiddleware, async (req, res) => {
32-
const data = req.body;
33-
34-
try {
35-
if (!data.slug || !data.workspaceId)
36-
throw new Error('Missing parameter');
37-
38-
const pm2Process = await pm2.startSafeBlockListener(data.slug, data.workspaceId);
39-
40-
return res.status(200).send(pm2Process);
41-
} catch(error) {
42-
handleError(res, error);
43-
}
44-
});
45-
4631
app.get('/processes', secretMiddleware, async (req, res) => {
4732
try {
4833
const processes = await pm2.list()

pm2-server/index.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ const app = require('./app.js');
33

44
const port = process.env.PORT || 9090;
55

6-
const startL1Trackers = () => {
7-
axios.post(`${process.env.ETHERNAL_HOST}/api/explorers/startSafeBlockListeners?secret=${process.env.ETHERNAL_SECRET}`)
8-
.then(({ data }) => console.log(data))
9-
.catch((error) => {
10-
console.log(`Error when starting safe block listeners. Trying again in 1 second...`);
11-
console.log(error);
12-
setTimeout(triggerSync, 1000);
13-
});
14-
}
15-
166
const triggerSync = () => {
177
axios.post(`${process.env.ETHERNAL_HOST}/api/explorers/syncExplorers?secret=${process.env.ETHERNAL_SECRET}`)
188
.then(({ data }) => console.log(data))

pm2-server/lib/pm2.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -131,34 +131,6 @@ const _delete = (slug) => {
131131
});
132132
};
133133

134-
const startSafeBlockListener = (slug, workspaceId) => {
135-
return new Promise((resolve, reject) => {
136-
if (!slug || !workspaceId) reject(new Error('Missing parameter'));
137-
138-
pm2.connect(error => {
139-
if (error) reject(new Error(error));
140-
141-
const options = {
142-
name: `safeBlockListener-${slug}`,
143-
script: './safeBlockListener.js',
144-
args: String(workspaceId),
145-
interpreter: 'none',
146-
log_type: 'json'
147-
};
148-
149-
pm2.start(options, (error) => {
150-
if (error) reject(new Error(error));
151-
152-
pm2.describe(slug, (error, process) => {
153-
if (error) reject(new Error(error));
154-
155-
resolve(process[0]);
156-
});
157-
});
158-
});
159-
});
160-
};
161-
162134
const startLogListener = (slug, jsonArgs) => {
163135
return new Promise((resolve, reject) => {
164136
if (!slug || !jsonArgs) reject(new Error('Missing parameter'));
@@ -215,4 +187,4 @@ const start = (slug, workspaceId) => {
215187
});
216188
};
217189

218-
module.exports = { list, show, stop, reload, restart, delete: _delete, start, resume, startSafeBlockListener, startLogListener };
190+
module.exports = { list, show, stop, reload, restart, delete: _delete, start, resume, startLogListener };

pm2-server/safeBlockListener.js

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

pm2-server/tests/app.test.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -214,31 +214,4 @@ describe('POST /safe-block-listener', () => {
214214
done();
215215
});
216216
});
217-
218-
it('Should successfully start safe block listener when all parameters are valid', (done) => {
219-
const mockPm2Process = { id: 2, name: 'safe-block-process', status: 'online' };
220-
jest.spyOn(pm2, 'startSafeBlockListener').mockResolvedValue(mockPm2Process);
221-
222-
request.post('/safe-block-listener')
223-
.send({ slug: 'safe-block-process', workspaceId: 'workspace-123' })
224-
.expect(200)
225-
.then(({ body }) => {
226-
expect(body).toEqual(mockPm2Process);
227-
expect(pm2.startSafeBlockListener).toHaveBeenCalledWith('safe-block-process', 'workspace-123');
228-
done();
229-
});
230-
});
231-
232-
it('Should handle pm2.startSafeBlockListener errors', (done) => {
233-
const errorMessage = 'Safe block listener failed to start';
234-
jest.spyOn(pm2, 'startSafeBlockListener').mockRejectedValue(new Error(errorMessage));
235-
236-
request.post('/safe-block-listener')
237-
.send({ slug: 'safe-block-process', workspaceId: 'workspace-123' })
238-
.expect(400)
239-
.then(({ text }) => {
240-
expect(text).toBe(errorMessage);
241-
done();
242-
});
243-
});
244217
});

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,6 @@ describe('start', () => {
108108
});
109109
});
110110

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-
122111
describe('startLogListener', () => {
123112
it('Should resolve with started process', (done) => {
124113
jest.spyOn(pm2, 'describe').mockImplementation((_, cb) => cb(null, [{ process: 1 }]));

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ jest.mock('../../../lib/pm2', () => ({
77
delete: jest.fn(),
88
start: jest.fn(),
99
resume: jest.fn(),
10-
startLogListener: jest.fn(),
11-
startSafeBlockListener: jest.fn()
10+
startLogListener: jest.fn()
1211
}));

run/api/explorers.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ router.get('/:id/orbitConfig', authMiddleware, async (req, res, next) => {
5656
* @param {string} config.challengeManagerContract - Challenge manager contract address
5757
* @param {string} config.validatorWalletCreatorContract - Validator wallet creator contract address
5858
* @param {string} config.stakeToken - Stake token address
59-
* @param {number} config.confirmationPeriodBlocks - The number of blocks to wait for confirmation
6059
* @param {string} config.parentMessageCountShift - The number of blocks to shift when counting messages
6160
* @returns {Promise<object>} - The updated orbit config
6261
*/
@@ -118,7 +117,6 @@ router.put('/:id/orbitConfig', authMiddleware, async (req, res, next) => {
118117
* @param {string} config.challengeManagerContract - Challenge manager contract address
119118
* @param {string} config.validatorWalletCreatorContract - Validator wallet creator contract address
120119
* @param {string} config.stakeToken - Stake token address
121-
* @param {number} config.confirmationPeriodBlocks - The number of blocks to wait for confirmation
122120
* @param {string} config.parentMessageCountShift - The number of blocks to shift when counting messages
123121
* @returns {Promise<object>} - The updated orbit config
124122
*/
@@ -300,16 +298,6 @@ router.post('/:id/startTrial', authMiddleware, async (req, res, next) => {
300298
}
301299
});
302300

303-
router.post('/startSafeBlockListeners', secretMiddleware, async (req, res, next) => {
304-
try {
305-
await enqueue('safeBlockListenerCheck', 'safeBlockListenerCheck', {});
306-
307-
res.sendStatus(200);
308-
} catch(error) {
309-
unmanagedError(error, req, next);
310-
}
311-
});
312-
313301
router.post('/syncExplorers', secretMiddleware, async (req, res, next) => {
314302
try {
315303
const explorers = await Explorer.findAll();
@@ -810,7 +798,6 @@ router.post('/', authMiddleware, async (req, res, next) => {
810798
options['token'] = data.token;
811799
options['slug'] = data.slug;
812800
options['totalSupply'] = data.totalSupply;
813-
options['l1Explorer'] = data.l1Explorer;
814801
options['branding'] = data.branding;
815802

816803
const usingDefaultPlan = !data.plan && (!isStripeEnabled() || user.canUseDemoPlan);
@@ -961,7 +948,6 @@ router.get('/search', async (req, res, next) => {
961948
chainId: explorer.chainId,
962949
domain: explorer.domain,
963950
domains: explorer.domains,
964-
l1Explorer: explorer.l1Explorer,
965951
name: explorer.name,
966952
rpcServer: explorer.rpcServer,
967953
slug: explorer.slug,

run/constants/orbit.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

run/jobs/finalizePendingOrbitBatches.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
const logger = require('../lib/logger');
2-
const { OrbitBatch, OrbitChainConfig } = require('../models');
2+
const { OrbitBatch, Workspace } = require('../models');
33
const { Op } = require('sequelize');
44

55
module.exports = async () => {
66

7-
const orbitParentConfigs = await OrbitChainConfig.findAll({
8-
where: {
9-
topParentChainBlockValidationType: {
10-
[Op.in]: ['SAFE', 'FINALIZED']
11-
}
12-
}
13-
});
14-
15-
const workspaces = {};
16-
for (const config of orbitParentConfigs) {
17-
const parentWorkspace = await config.getTopParentWorkspace();
18-
const orbitChildConfigs = await parentWorkspace.getOrbitChildConfigs();
19-
workspaces[parentWorkspace.id] = Object.assign({}, parentWorkspace.toJSON(), { orbitChildConfigs, client: parentWorkspace.getViemPublicClient() });
20-
}
7+
const workspaces = await Workspace.findAll({ where: { isTopOrbitParent: true } });
218

229
let allPendingBatches = [];
23-
for (const workspace of Object.values(workspaces)) {
24-
const block = await workspace.client.getBlock({ blockTag: 'safe' });
10+
for (const workspace of workspaces) {
11+
const client = workspace.getViemPublicClient();
12+
const block = await client.getBlock({ blockTag: 'safe' });
2513
for (const orbitChildConfig of workspace.orbitChildConfigs) {
2614
logger.info(`Validating batches posted on ${workspace.name} by config ${orbitChildConfig.workspaceId} with block number ${block.number}`);
2715
const pendingBatches = await OrbitBatch.findAll({
@@ -37,7 +25,7 @@ module.exports = async () => {
3725
for (const batch of pendingBatches) {
3826
await batch.confirm();
3927
}
40-
28+
4129
allPendingBatches = allPendingBatches.concat(pendingBatches);
4230
}
4331
}

0 commit comments

Comments
 (0)