diff --git a/.changeset/dirty-turkeys-exist.md b/.changeset/dirty-turkeys-exist.md new file mode 100644 index 00000000..a845151c --- /dev/null +++ b/.changeset/dirty-turkeys-exist.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/config/test.yaml b/config/test.yaml index 24baaa34..9e13ba38 100644 --- a/config/test.yaml +++ b/config/test.yaml @@ -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 diff --git a/src/reprocess/EventReprocess.ts b/src/reprocess/EventReprocess.ts index 12133ecb..aa04eaad 100644 --- a/src/reprocess/EventReprocess.ts +++ b/src/reprocess/EventReprocess.ts @@ -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; @@ -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, diff --git a/src/synchronization/EventSynchronization.ts b/src/synchronization/EventSynchronization.ts index 4da04ae6..a6b8b80a 100644 --- a/src/synchronization/EventSynchronization.ts +++ b/src/synchronization/EventSynchronization.ts @@ -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; @@ -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(); @@ -216,13 +215,15 @@ class EventSynchronization extends Communicator { sendSyncBatch = async (): Promise => { 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; }, [] diff --git a/tests/synchronization/EventSynchronization.spec.ts b/tests/synchronization/EventSynchronization.spec.ts index e0808865..f6e1eb68 100644 --- a/tests/synchronization/EventSynchronization.spec.ts +++ b/tests/synchronization/EventSynchronization.spec.ts @@ -46,7 +46,7 @@ describe('EventSynchronization', () => { }); describe('processSyncQueue', () => { - const guardsLen = GuardPkHandler.getInstance().guardsLen; + const guardsLen = Configs.tssKeys.pubs.length; beforeAll(() => { vi.useFakeTimers(); @@ -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(); @@ -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 ); }); @@ -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 () => { @@ -991,7 +992,7 @@ describe('EventSynchronization', () => { }); describe(`verifySynchronizationResponse`, () => { - const guardsLen = GuardPkHandler.getInstance().guardsLen; + const guardsLen = Configs.tssKeys.pubs.length; beforeAll(() => { mockGetEventFeeConfig({ @@ -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, @@ -1862,7 +1861,7 @@ describe('EventSynchronization', () => { }); describe('timeoutActiveSyncs', () => { - const guardsLen = GuardPkHandler.getInstance().guardsLen; + const guardsLen = Configs.tssKeys.pubs.length; beforeAll(() => { vi.useFakeTimers(); diff --git a/tests/synchronization/TestEventSynchronization.ts b/tests/synchronization/TestEventSynchronization.ts index 315b15aa..d10b8ae1 100644 --- a/tests/synchronization/TestEventSynchronization.ts +++ b/tests/synchronization/TestEventSynchronization.ts @@ -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[] => {