Skip to content

Commit

Permalink
Merge branch '378-remove-keygen' into 'dev'
Browse files Browse the repository at this point in the history
remove keygen scenario from guard-service

Closes #378

See merge request ergo/rosen-bridge/guard-service!358
  • Loading branch information
vorujack committed Jun 17, 2024
2 parents 4cbc5ba + 3b51934 commit 270ed4b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 145 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-carrots-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'guard-service': patch
---

remove keygen scenario from guard-service
5 changes: 0 additions & 5 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,3 @@ healthCheck:
defectConfirmationTimeWindow: 120 # Time to wait after any peer disconnection
revenue:
interval: 120 # revenue update interval
keygen: # only set when you want to start keygen process
active: false # set true to start keygen process on startup
guards: 0 # total number of guards
threshold: 0 # signing threshold (at least threshold + 1 guards are required)
algorithm: eddsa # keygen algorithm. only eddsa supported
44 changes: 0 additions & 44 deletions src/api/keygen.ts

This file was deleted.

21 changes: 1 addition & 20 deletions src/configs/Configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ThresholdConfig } from '../coldStorage/types';
import { JsonBI } from '../network/NetworkModels';
import Utils from '../utils/Utils';
import { ConfigError } from '../utils/errors';
import { SUPPORTED_CHAINS, TssAlgorithms } from '../utils/constants';
import { SUPPORTED_CHAINS } from '../utils/constants';
import { TransportOptions } from '@rosen-bridge/winston-logger';
import { cloneDeep } from 'lodash-es';

Expand Down Expand Up @@ -49,23 +49,6 @@ const getOptionalConfig = <T>(key: string, defaultValue: T) => {
return defaultValue;
};

const SupportedAlgorithms: string[] = [
TssAlgorithms.curve,
TssAlgorithms.edward,
];
class KeygenConfig {
static isActive = config.get<boolean>('keygen.active');
static guardsCount = getConfigIntKeyOrDefault('keygen.guards', 0);
static threshold = getConfigIntKeyOrDefault('keygen.threshold', 0);
static algorithm = () => {
const algorithm = config.get<string>('keygen.algorithm');
if (SupportedAlgorithms.indexOf(algorithm) !== -1) {
return algorithm;
}
throw Error(`Invalid keygen algorithm ${algorithm}`);
};
}

class Configs {
// express config
static apiPort = getConfigIntKeyOrDefault('api.port', 8080);
Expand Down Expand Up @@ -110,7 +93,6 @@ class Configs {
static tssUrl = config.get<string>('tss.url');
static tssPort = config.get<string>('tss.port');
static tssBaseCallBackUrl = `http://${this.apiHost}:${this.apiPort}/tss/sign`;
static tssKeygenCallBackUrl = `http://${this.apiHost}:${this.apiPort}/tss/keygen`;
static tssKeys = {
secret: config.get<string>('tss.secret'),
pubs: config.get<
Expand Down Expand Up @@ -316,7 +298,6 @@ class Configs {
'revenue.interval',
120
);
static keygen = KeygenConfig;
}

export default Configs;
Expand Down
48 changes: 0 additions & 48 deletions src/guard/Tss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import {
StatusEnum,
TssSigner,
} from '@rosen-bridge/tss';
import axios from 'axios';
import * as crypto from 'crypto';
import CommunicationConfig from '../communication/CommunicationConfig';
import Dialer from '../communication/Dialer';
import Configs from '../configs/Configs';
import { spawn } from 'child_process';
Expand Down Expand Up @@ -196,52 +194,6 @@ class Tss {
);
};

/**
* start keygen process for guards
* @param guardsCount
* @param threshold
*/
static keygen = async (guardsCount: number, threshold: number) => {
Tss.runBinary();

// initialize dialer
Tss.dialer = await Dialer.getInstance();

Tss.tryCallApi(guardsCount, threshold);
};

/**
* wait until all peers are connected then call tss keygen api
* @param guardsCount
* @param threshold
*/
private static tryCallApi = (guardsCount: number, threshold: number) => {
const peerIds = Tss.dialer
.getPeerIds()
.filter((peerId) => !CommunicationConfig.relays.peerIDs.includes(peerId));
if (peerIds.length < guardsCount - 1 || !Tss.dialer.getDialerId()) {
setTimeout(() => Tss.tryCallApi(guardsCount, threshold), 1000);
} else {
setTimeout(() => {
axios
.post(`${Configs.tssUrl}:${Configs.tssPort}/keygen`, {
p2pIDs: [Tss.dialer.getDialerId(), ...peerIds],
callBackUrl: Configs.tssKeygenCallBackUrl,
crypto: Configs.keygen.algorithm(),
threshold: threshold,
peersCount: guardsCount,
operationTimeout: 10 * 60, // 10 minutes
})
.then((res) => {
logger.info(JSON.stringify(res.data));
})
.catch((err) => {
logger.error(`an error occurred during call keygen ${err}`);
logger.debug(err.stack);
});
}, 10000);
}
};
/**
* generates a function to wrap channel send message to dialer
* @param channel
Expand Down
17 changes: 1 addition & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import GuardPkHandler from './handlers/GuardPkHandler';
import MinimumFeeHandler from './handlers/MinimumFeeHandler';
import { minimumFeeUpdateJob } from './jobs/minimumFee';

const initService = async () => {
const init = async () => {
// initialize Notification object
await Notification.getInstance();

Expand Down Expand Up @@ -72,19 +72,4 @@ const initService = async () => {
await revenueJob();
};

const initKeygen = async () => {
// initialize express Apis
await initApiServer();

await Tss.keygen(Configs.keygen.guardsCount, Configs.keygen.threshold);
};

const init = async () => {
if (Configs.keygen.isActive) {
return initKeygen();
} else {
return initService();
}
};

init().then(() => null);
20 changes: 8 additions & 12 deletions src/jobs/apiServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fastify, { FastifyInstance, FastifyRequest } from 'fastify';
import swagger from '@fastify/swagger';
import swaggerUi from '@fastify/swagger-ui';
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
import { keygenRoute } from '../api/keygen';
import { p2pRoutes } from '../api/p2p';
import Configs from '../configs/Configs';
import { generalInfoRoute } from '../api/generalInfo';
Expand Down Expand Up @@ -96,17 +95,14 @@ const initApiServer = async () => {
});

await apiServer.register(p2pRoutes);
if (Configs.keygen.isActive) {
await apiServer.register(keygenRoute);
} else {
await apiServer.register(tssRoute);
await apiServer.register(generalInfoRoute);
await apiServer.register(eventRoutes);
await apiServer.register(healthRoutes);
await apiServer.register(revenueRoutes);
await apiServer.register(assetRoutes);
await apiServer.register(signRoute);
}
await apiServer.register(tssRoute);
await apiServer.register(generalInfoRoute);
await apiServer.register(eventRoutes);
await apiServer.register(healthRoutes);
await apiServer.register(revenueRoutes);
await apiServer.register(assetRoutes);
await apiServer.register(signRoute);

apiServer.get('/', (request, reply) => {
reply.redirect('/swagger');
});
Expand Down

0 comments on commit 270ed4b

Please sign in to comment.