Skip to content

Commit

Permalink
Merge branch '423-fix-self-dial' into 'dev'
Browse files Browse the repository at this point in the history
Resolve "Fix self dial in EventSynchronization"

Closes #423

See merge request ergo/rosen-bridge/guard-service!440
  • Loading branch information
vorujack committed Jan 24, 2025
2 parents 43993e8 + 2937f9f commit 39bc062
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .changeset/dirty-turkeys-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
18 changes: 18 additions & 0 deletions config/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ reward:
networkFeeRepoAddress: '9es3xKFSehNNwCpuNpY31ScAubDqeLbSWwaCysjN1ee51bgHKTq'
watchersSharePercent: 50
watchersEmissionSharePercent: 20
tss:
secret: 'd3995e34a3870748f14958b24a79c7015cdae46f35a24f06cf935a8d7993a5c9' # guard index: 1
pubs:
- curveShareId: 'cs-0'
edwardShareId: 'es-0'
curvePub: '02a196b00f674182cbd2507c1321179d0e21ae7b95c57a46b3fcb03d27c05102a7'
- curveShareId: 'cs-1'
edwardShareId: 'es-1'
curvePub: '02dc253d23b0f843ef30f9f0d1d39ff547640aea40b21679e572b4add9e8e30c7c'
- curveShareId: 'cs-2'
edwardShareId: 'es-2'
curvePub: '03f47ae7692d77ab57faac9f46c0c47a4fe8c019caa009c7c48c7481a114d777bc'
- curveShareId: 'cs-3'
edwardShareId: 'es-3'
curvePub: '0338320cb1e7d0fa0ae923157592346408bbecdf447da25169f7b06c4119bc177d'
- curveShareId: 'cs-4'
edwardShareId: 'es-4'
curvePub: '034af770b46f5d566c642a4c19da90f76b13cd389dd44d41e9c92611214d01556a'
guard:
mnemonic: ''
txSignTimeout: 1
Expand Down
8 changes: 3 additions & 5 deletions src/reprocess/EventReprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class EventReprocess extends Communicator {
protected static dialer: Dialer;
protected reprocessCooldown: number;

protected constructor(publicKeys: string[]) {
protected constructor() {
super(
logger,
new ECDSA(Configs.tssKeys.secret),
EventReprocess.sendMessageWrapper,
publicKeys,
Configs.tssKeys.pubs.map((pub) => pub.curvePub),
GuardTurn.UP_TIME_LENGTH
);
this.reprocessCooldown = Configs.eventReprocessCooldown;
Expand All @@ -37,9 +37,7 @@ class EventReprocess extends Communicator {
* initializes EventReprocess
*/
static init = async () => {
EventReprocess.instance = new EventReprocess(
Configs.tssKeys.pubs.map((pub) => pub.curvePub)
);
EventReprocess.instance = new EventReprocess();
this.dialer = await Dialer.getInstance();
this.dialer.subscribeChannel(
EventReprocess.CHANNEL,
Expand Down
9 changes: 5 additions & 4 deletions src/synchronization/EventSynchronization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class EventSynchronization extends Communicator {
protected parallelRequestCount: number;
protected requiredApproval: number;

protected constructor(publicKeys: string[], detection: GuardDetection) {
protected constructor(detection: GuardDetection) {
super(
logger,
new ECDSA(Configs.tssKeys.secret),
EventSynchronization.sendMessageWrapper,
publicKeys,
Configs.tssKeys.pubs.map((pub) => pub.curvePub),
GuardTurn.UP_TIME_LENGTH
);
this.detection = detection;
Expand All @@ -65,7 +65,6 @@ class EventSynchronization extends Communicator {
*/
static init = async () => {
EventSynchronization.instance = new EventSynchronization(
Configs.tssKeys.pubs.map((pub) => pub.curvePub),
DetectionHandler.getInstance().getDetection().curve
);
this.dialer = await Dialer.getInstance();
Expand Down Expand Up @@ -216,13 +215,15 @@ class EventSynchronization extends Communicator {
sendSyncBatch = async (): Promise<void> => {
logger.info(`Sending event synchronization batches`);
for (const [eventId, activeSync] of this.activeSyncMap) {
const restrictedIndex = await this.getIndex();
const indexes = activeSync.responses.reduce(
(
indexes: number[],
response: PaymentTransaction | undefined,
index: number
) => {
if (response === undefined) indexes.push(index);
if (response === undefined && index !== restrictedIndex)
indexes.push(index);
return indexes;
},
[]
Expand Down
21 changes: 10 additions & 11 deletions tests/synchronization/EventSynchronization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('EventSynchronization', () => {
});

describe('processSyncQueue', () => {
const guardsLen = GuardPkHandler.getInstance().guardsLen;
const guardsLen = Configs.tssKeys.pubs.length;

beforeAll(() => {
vi.useFakeTimers();
Expand Down Expand Up @@ -396,8 +396,9 @@ describe('EventSynchronization', () => {
});

describe('sendSyncBatch', () => {
const guardsLen = GuardPkHandler.getInstance().guardsLen;
const publicKeys = GuardPkHandler.getInstance().publicKeys;
const guardIndex = TestConfigs.guardIndex;
const guardsLen = Configs.tssKeys.pubs.length;
const publicKeys = Configs.tssKeys.pubs.map((pub) => pub.curvePub);

beforeAll(() => {
vi.useFakeTimers();
Expand Down Expand Up @@ -463,13 +464,13 @@ describe('EventSynchronization', () => {
expect(mockedSendMessage).toHaveBeenCalledWith(
SynchronizationMessageTypes.request,
{ eventId: eventId1 },
expect.any(Array),
expect.not.arrayContaining([`peer-${guardIndex}`]),
TestConfigs.currentTimeStamp / 1000
);
expect(mockedSendMessage).toHaveBeenCalledWith(
SynchronizationMessageTypes.request,
{ eventId: eventId2 },
expect.any(Array),
expect.not.arrayContaining([`peer-${guardIndex}`]),
TestConfigs.currentTimeStamp / 1000
);
});
Expand Down Expand Up @@ -775,7 +776,7 @@ describe('EventSynchronization', () => {
});

describe('processSyncResponse', () => {
const guardsLen = GuardPkHandler.getInstance().guardsLen;
const guardsLen = Configs.tssKeys.pubs.length;
const requiredApproval = GuardPkHandler.getInstance().requiredSign - 1;

beforeEach(async () => {
Expand Down Expand Up @@ -991,7 +992,7 @@ describe('EventSynchronization', () => {
});

describe(`verifySynchronizationResponse`, () => {
const guardsLen = GuardPkHandler.getInstance().guardsLen;
const guardsLen = Configs.tssKeys.pubs.length;

beforeAll(() => {
mockGetEventFeeConfig({
Expand Down Expand Up @@ -1823,9 +1824,7 @@ describe('EventSynchronization', () => {

// insert event into active sync
const eventSync = new TestEventSynchronization();
const responses = Array(GuardPkHandler.getInstance().guardsLen).fill(
undefined
);
const responses = Array(Configs.tssKeys.pubs.length).fill(undefined);
eventSync.insertEventIntoActiveSync(eventId, {
timestamp: TestConfigs.currentTimeStamp / 1000 - 100,
responses: responses,
Expand Down Expand Up @@ -1862,7 +1861,7 @@ describe('EventSynchronization', () => {
});

describe('timeoutActiveSyncs', () => {
const guardsLen = GuardPkHandler.getInstance().guardsLen;
const guardsLen = Configs.tssKeys.pubs.length;

beforeAll(() => {
vi.useFakeTimers();
Expand Down
6 changes: 2 additions & 4 deletions tests/synchronization/TestEventSynchronization.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { PaymentTransaction } from '@rosen-chains/abstract-chain';
import GuardPkHandler from '../../src/handlers/GuardPkHandler';
import Configs from '../../src/configs/Configs';
import EventSynchronization from '../../src/synchronization/EventSynchronization';
import { ActiveSync } from '../../src/synchronization/Interfaces';

class TestEventSynchronization extends EventSynchronization {
constructor() {
super(GuardPkHandler.getInstance().publicKeys, {
activeGuards: vi.fn(),
} as any);
super({ activeGuards: vi.fn() } as any);
}

getEventQueue = (): string[] => {
Expand Down

0 comments on commit 39bc062

Please sign in to comment.