diff --git a/package.json b/package.json index 9d63e4c3..2af5884d 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "eslint-plugin-prettier": "^4.0.0", "jest": "^27.4.7", "prettier": "^2.5.1", - "simple-dvt-v1": "^0.0.5", + "simple-dvt-v1": "^0.0.7", "supertest": "^6.2.1", "ts-jest": "^27.1.3", "ts-loader": "^9.2.6", diff --git a/src/app/simple-dvt-deploy.e2e-chain.ts b/src/app/simple-dvt-deploy.e2e-chain.ts index 2e7e14f7..365fb0b4 100644 --- a/src/app/simple-dvt-deploy.e2e-chain.ts +++ b/src/app/simple-dvt-deploy.e2e-chain.ts @@ -37,6 +37,7 @@ describe('Simple DVT deploy', () => { let deployState: chronix.StoryResult<'simple-dvt/deploy'>; let reduceNOState: chronix.StoryResult<'simple-dvt/reduce-no'>; let sdvtNodeOperator1: chronix.StoryResult<'simple-dvt/add-node-operator'>; + let dvtNodeOperator2WithoutKeys: chronix.StoryResult<'simple-dvt/set-node-operator-name'>; let moduleRef: TestingModule; @@ -203,7 +204,7 @@ describe('Simple DVT deploy', () => { const simpleDvtState = deployState.stakingRouterData.stakingModules[1]; const srModuleAddress = convertAddressToLowerCase(simpleDvtState.stakingModuleAddress); const moduleInstance = stakingRouterService.getStakingRouterModuleImpl(simpleDvtState.type); - const newOperator = await session.story('simple-dvt/add-node-operator', { + dvtNodeOperator2WithoutKeys = await session.story('simple-dvt/add-node-operator', { norAddress: simpleDvtState.stakingModuleAddress, name: 'new simple dvt operator ', rewardAddress: '0x' + '6'.repeat(40), @@ -215,6 +216,42 @@ describe('Simple DVT deploy', () => { expect(currentKeys).toHaveLength(1); expect(currentOperators).toHaveLength(2); - expect(currentOperators[1].name).toBe(newOperator.name); + expect(currentOperators[1].name).toBe(dvtNodeOperator2WithoutKeys.name); + }); + + test('update operator', async () => { + const simpleDvtState = deployState.stakingRouterData.stakingModules[1]; + const srModuleAddress = convertAddressToLowerCase(simpleDvtState.stakingModuleAddress); + const moduleInstance = stakingRouterService.getStakingRouterModuleImpl(simpleDvtState.type); + + await session.story('simple-dvt/set-node-operator-name', { + norAddress: simpleDvtState.stakingModuleAddress, + nodeOperatorId: dvtNodeOperator2WithoutKeys.nodeOperatorId, + name: 'some other name', + }); + + await keysUpdateService.update(); + + const keys1 = await moduleInstance.getKeys(srModuleAddress, {}); + const operators1 = await moduleInstance.getOperators(srModuleAddress); + + expect(keys1).toHaveLength(1); + expect(operators1).toHaveLength(2); + expect(operators1[1].name).toBe('some other name'); + + await session.story('simple-dvt/set-node-operator-reward-address', { + norAddress: simpleDvtState.stakingModuleAddress, + nodeOperatorId: dvtNodeOperator2WithoutKeys.nodeOperatorId, + rewardAddress: '0x' + '3'.repeat(40), + }); + + await keysUpdateService.update(); + + const keys2 = await moduleInstance.getKeys(srModuleAddress, {}); + const operators2 = await moduleInstance.getOperators(srModuleAddress); + + expect(keys2).toHaveLength(1); + expect(operators2).toHaveLength(2); + expect(operators2[1].rewardAddress).toBe('0x' + '3'.repeat(40)); }); }); diff --git a/src/common/registry/fetch/operator.fetch.ts b/src/common/registry/fetch/operator.fetch.ts index 7462ae71..2e5110f6 100644 --- a/src/common/registry/fetch/operator.fetch.ts +++ b/src/common/registry/fetch/operator.fetch.ts @@ -14,7 +14,7 @@ export class RegistryOperatorFetchService { return this.contract.attach(moduleAddress); } - public async operatorsWereUpdated( + public async operatorsWereChanged( moduleAddress: string, fromBlockNumber: number, toBlockNumber: number, diff --git a/src/common/registry/main/abstract-registry.ts b/src/common/registry/main/abstract-registry.ts index 3f390f92..ff451d1d 100644 --- a/src/common/registry/main/abstract-registry.ts +++ b/src/common/registry/main/abstract-registry.ts @@ -69,16 +69,14 @@ export abstract class AbstractRegistryService { /** * * @param moduleAddress contract address - * @param prevBlockHash previous block number for that operators were updated - * @param currBlockHash current block number - * @returns were operators updated or not + * @returns Check if operators have been changed */ - public async operatorsWereUpdated( + public async operatorsWereChanged( moduleAddress: string, fromBlockNumber: number, toBlockNumber: number, ): Promise { - return await this.operatorFetch.operatorsWereUpdated(moduleAddress, fromBlockNumber, toBlockNumber); + return await this.operatorFetch.operatorsWereChanged(moduleAddress, fromBlockNumber, toBlockNumber); } /** returns operators from the contract */ diff --git a/src/jobs/keys-update/keys-update.service.ts b/src/jobs/keys-update/keys-update.service.ts index 0ce73371..76cdcd88 100644 --- a/src/jobs/keys-update/keys-update.service.ts +++ b/src/jobs/keys-update/keys-update.service.ts @@ -151,10 +151,11 @@ export class KeysUpdateService { if (prevNonce === currNonce) { // case when prevELMeta is undefined but prevNonce === currNonce looks like invalid + // use here prevElMeta.blockNumber + 1 because operators were updated in database for prevElMeta.blockNumber block if ( prevElMeta && - prevElMeta.blockNumber + 1 <= currElMeta.number && - (await moduleInstance.operatorsWereUpdated( + prevElMeta.blockNumber < currElMeta.number && + (await moduleInstance.operatorsWereChanged( contractModule.stakingModuleAddress, prevElMeta.blockNumber + 1, currElMeta.number, diff --git a/src/staking-router-modules/curated-module.service.ts b/src/staking-router-modules/curated-module.service.ts index 2ce0c2b6..96546652 100644 --- a/src/staking-router-modules/curated-module.service.ts +++ b/src/staking-router-modules/curated-module.service.ts @@ -24,12 +24,12 @@ export class CuratedModuleService implements StakingModuleInterface { await this.keyRegistryService.update(moduleAddress, blockHash); } - public async operatorsWereUpdated( + public async operatorsWereChanged( moduleAddress: string, fromBlockNumber: number, toBlockNumber: number, ): Promise { - return await this.keyRegistryService.operatorsWereUpdated(moduleAddress, fromBlockNumber, toBlockNumber); + return await this.keyRegistryService.operatorsWereChanged(moduleAddress, fromBlockNumber, toBlockNumber); } public async updateOperators(moduleAddress: string, blockHash: string): Promise { diff --git a/src/staking-router-modules/interfaces/staking-module.interface.ts b/src/staking-router-modules/interfaces/staking-module.interface.ts index 882532fb..12271aab 100644 --- a/src/staking-router-modules/interfaces/staking-module.interface.ts +++ b/src/staking-router-modules/interfaces/staking-module.interface.ts @@ -33,7 +33,7 @@ export interface StakingModule { export interface StakingModuleInterface { update(moduleAddress: string, blockHash: string): Promise; - operatorsWereUpdated(moduleAddress: string, fromBlockNumber: number, toBlockNumber: number): Promise; + operatorsWereChanged(moduleAddress: string, fromBlockNumber: number, toBlockNumber: number): Promise; updateOperators(moduleAddress: string, blockHash: string): Promise; diff --git a/yarn.lock b/yarn.lock index 47f11eda..0151b1b1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -85,7 +85,7 @@ "@aragon/apps-vault" "^4.0.0" "@aragon/os" "4.2.0" -"@aragon/apps-lido@lidofinance/aragon-apps#master": +"@aragon/apps-lido@github:lidofinance/aragon-apps#master": version "1.0.0" resolved "https://codeload.github.com/lidofinance/aragon-apps/tar.gz/b09834d29c0db211ddd50f50905cbeff257fc8e0" @@ -11058,10 +11058,10 @@ simple-concat@^1.0.0: resolved "https://registry.yarnpkg.com/simple-concat/-/simple-concat-1.0.1.tgz#f46976082ba35c2263f1c8ab5edfe26c41c9552f" integrity sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q== -simple-dvt-v1@^0.0.5: - version "0.0.5" - resolved "https://registry.yarnpkg.com/simple-dvt-v1/-/simple-dvt-v1-0.0.5.tgz#6c221ab3757931c62736117388a3db4da340589c" - integrity sha512-NEtatJ7KZFWjSyKzDD03V1wxbHXvi2oi65SVZ+LVHQNKIUO/tYIOtTRa01y6AH20wEl3hL/W68GS3+/wOLOH6g== +simple-dvt-v1@^0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/simple-dvt-v1/-/simple-dvt-v1-0.0.7.tgz#fb366f03a3b2aa90352c59361e0da9ef69ce0705" + integrity sha512-hEzxC7SUgJylLkUP+dtCvRGJ0N7BUULeOwR34GTdNM4HsYVHRBuonsyHgwhcQ5wof1mzTXO6l4jv3ZOSEVUbHQ== dependencies: "@aragon/apps-agent" "^2.1.0" "@aragon/apps-finance" "^3.0.0"