From 5dd1acdbd06e387840e99b81eccf8ffc2a40bfd0 Mon Sep 17 00:00:00 2001 From: zeroxbt <89495162+zeroxbt@users.noreply.github.com> Date: Tue, 18 Apr 2023 13:52:39 +0200 Subject: [PATCH] select commit and proof manager contract according to latest state index (#2442) * select coomit or proof manager contract according to latest state index * fix abi imports for v1 commit and proof managers * fix args for getChallenge, getTopCommitSubmissions * fix submit commit parameters * bump version --- package-lock.json | 4 +- package.json | 2 +- .../receiver/calculate-proofs-command.js | 1 + .../publish/receiver/epoch-check-command.js | 1 + .../publish/receiver/submit-commit-command.js | 16 +++-- .../publish/receiver/submit-proofs-command.js | 1 + .../blockchain/blockchain-module-manager.js | 21 ++++-- .../blockchain/implementation/web3-service.js | 71 ++++++++++++++----- 8 files changed, 81 insertions(+), 36 deletions(-) diff --git a/package-lock.json b/package-lock.json index a5d0d34f40..e839aa2165 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.0.5", + "version": "6.0.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.0.5", + "version": "6.0.6", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 161c92df87..9f2aadba40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.5", + "version": "6.0.6", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/protocols/publish/receiver/calculate-proofs-command.js b/src/commands/protocols/publish/receiver/calculate-proofs-command.js index b6f0c215d3..04a342e8e5 100644 --- a/src/commands/protocols/publish/receiver/calculate-proofs-command.js +++ b/src/commands/protocols/publish/receiver/calculate-proofs-command.js @@ -87,6 +87,7 @@ class CalculateProofsCommand extends EpochCommand { contract, tokenId, epoch, + stateIndex, ); const assertion = await this.tripleStoreService.getAssertion( diff --git a/src/commands/protocols/publish/receiver/epoch-check-command.js b/src/commands/protocols/publish/receiver/epoch-check-command.js index fc9683d43d..a1471ba648 100644 --- a/src/commands/protocols/publish/receiver/epoch-check-command.js +++ b/src/commands/protocols/publish/receiver/epoch-check-command.js @@ -73,6 +73,7 @@ class EpochCheckCommand extends EpochCommand { blockchain, agreementId, epoch, + stateIndex, ); if (!commitWindowOpen) { this.logger.trace( diff --git a/src/commands/protocols/publish/receiver/submit-commit-command.js b/src/commands/protocols/publish/receiver/submit-commit-command.js index e74abcd6fa..b8650bc3ce 100644 --- a/src/commands/protocols/publish/receiver/submit-commit-command.js +++ b/src/commands/protocols/publish/receiver/submit-commit-command.js @@ -112,6 +112,7 @@ class SubmitCommitCommand extends EpochCommand { keyword, hashFunctionId, epoch, + stateIndex, async (result) => { if (!result.error) { const currentEpochStartTime = @@ -142,18 +143,19 @@ class SubmitCommitCommand extends EpochCommand { `Scheduling calculateProofsCommand for agreement id: ${agreementId} in ${delay} seconds`, ); + await that.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_END, + operationId, + agreementId, + epoch, + ); + await that.commandExecutor.add({ name: 'calculateProofsCommand', delay: delay * 1000, data: { ...command.data, proofWindowStartTime }, transactional: false, }); - that.operationIdService.emitChangeEvent( - OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_END, - operationId, - agreementId, - epoch, - ); } else if (command.retries - 1 === 0) { await that.scheduleNextEpochCheck( blockchain, @@ -168,7 +170,7 @@ class SubmitCommitCommand extends EpochCommand { ); const errorMessage = `Failed executing submit commit command, maximum number of retries reached. Error: ${result.error.message}. Scheduling next epoch check.`; that.logger.error(errorMessage); - that.operationIdService.emitChangeEvent( + await that.operationIdService.emitChangeEvent( OPERATION_ID_STATUS.FAILED, operationId, errorMessage, diff --git a/src/commands/protocols/publish/receiver/submit-proofs-command.js b/src/commands/protocols/publish/receiver/submit-proofs-command.js index 32f91cee55..03bd9f2dd5 100644 --- a/src/commands/protocols/publish/receiver/submit-proofs-command.js +++ b/src/commands/protocols/publish/receiver/submit-proofs-command.js @@ -84,6 +84,7 @@ class SubmitProofsCommand extends EpochCommand { epoch, proof, leaf, + stateIndex, async (result) => { if (!result.error) { that.logger.trace( diff --git a/src/modules/blockchain/blockchain-module-manager.js b/src/modules/blockchain/blockchain-module-manager.js index 3ebbe5092d..6c924e0b04 100644 --- a/src/modules/blockchain/blockchain-module-manager.js +++ b/src/modules/blockchain/blockchain-module-manager.js @@ -175,26 +175,27 @@ class BlockchainModuleManager extends BaseModuleManager { return this.callImplementationFunction(blockchain, 'convertFromWei', [value, toUnit]); } - async isCommitWindowOpen(blockchain, agreementId, epoch) { + async isCommitWindowOpen(blockchain, agreementId, epoch, stateIndex) { return this.callImplementationFunction(blockchain, 'isCommitWindowOpen', [ agreementId, epoch, + stateIndex, ]); } - async isUpdateCommitWindowOpen(blockchain, agreementId, epoch, stateIndex) { + async isUpdateCommitWindowOpen(blockchain, agreementId, epoch, latestStateIndex) { return this.callImplementationFunction(blockchain, 'isUpdateCommitWindowOpen', [ agreementId, epoch, - stateIndex, + latestStateIndex, ]); } - async getTopCommitSubmissions(blockchain, agreementId, epoch, stateIndex) { + async getTopCommitSubmissions(blockchain, agreementId, epoch, latestStateIndex) { return this.callImplementationFunction(blockchain, 'getTopCommitSubmissions', [ agreementId, epoch, - stateIndex, + latestStateIndex, ]); } @@ -225,6 +226,7 @@ class BlockchainModuleManager extends BaseModuleManager { keyword, hashFunctionId, epoch, + latestStateIndex, callback, ) { return this.callImplementationFunction(blockchain, 'submitCommit', [ @@ -233,6 +235,7 @@ class BlockchainModuleManager extends BaseModuleManager { keyword, hashFunctionId, epoch, + latestStateIndex, callback, ]); } @@ -256,18 +259,20 @@ class BlockchainModuleManager extends BaseModuleManager { ]); } - async isProofWindowOpen(blockchain, agreementId, epoch) { + async isProofWindowOpen(blockchain, agreementId, epoch, latestStateIndex) { return this.callImplementationFunction(blockchain, 'isProofWindowOpen', [ agreementId, epoch, + latestStateIndex, ]); } - async getChallenge(blockchain, assetContractAddress, tokenId, epoch) { + async getChallenge(blockchain, assetContractAddress, tokenId, epoch, latestStateIndex) { return this.callImplementationFunction(blockchain, 'getChallenge', [ assetContractAddress, tokenId, epoch, + latestStateIndex, ]); } @@ -280,6 +285,7 @@ class BlockchainModuleManager extends BaseModuleManager { epoch, proof, chunkHash, + latestStateIndex, callback, ) { return this.callImplementationFunction(blockchain, 'sendProof', [ @@ -290,6 +296,7 @@ class BlockchainModuleManager extends BaseModuleManager { epoch, proof, chunkHash, + latestStateIndex, callback, ]); } diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index 93253dc40d..f7680323cf 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -26,7 +26,9 @@ const ProfileABI = require('dkg-evm-module/abi/Profile.json'); const ProfileStorageABI = require('dkg-evm-module/abi/ProfileStorage.json'); const ScoringProxyABI = require('dkg-evm-module/abi/ScoringProxy.json'); const ServiceAgreementV1ABI = require('dkg-evm-module/abi/ServiceAgreementV1.json'); +const CommitManagerV1ABI = require('dkg-evm-module/abi/CommitManagerV1.json'); const CommitManagerV1U1ABI = require('dkg-evm-module/abi/CommitManagerV1U1.json'); +const ProofManagerV1ABI = require('dkg-evm-module/abi/ProofManagerV1.json'); const ProofManagerV1U1ABI = require('dkg-evm-module/abi/ProofManagerV1U1.json'); const ShardingTableABI = require('dkg-evm-module/abi/ShardingTable.json'); const ShardingTableStorageABI = require('dkg-evm-module/abi/ShardingTableStorage.json'); @@ -123,7 +125,9 @@ class Web3Service { this.initializeContract('Profile', ProfileABI), this.initializeContract('ProfileStorage', ProfileStorageABI), this.initializeContract('ServiceAgreementV1', ServiceAgreementV1ABI), + this.initializeContract('CommitManagerV1', CommitManagerV1ABI), this.initializeContract('CommitManagerV1U1', CommitManagerV1U1ABI), + this.initializeContract('ProofManagerV1', ProofManagerV1ABI), this.initializeContract('ProofManagerV1U1', ProofManagerV1U1ABI), this.initializeContract( 'ServiceAgreementStorageProxy', @@ -540,11 +544,18 @@ class Web3Service { return Number(assertionChunksNumber); } - async isCommitWindowOpen(agreementId, epoch) { - return this.callContractFunction(this.CommitManagerV1U1Contract, 'isCommitWindowOpen', [ - agreementId, - epoch, - ]); + selectCommitManagerContract(latestStateIndex) { + return latestStateIndex === 0 + ? this.CommitManagerV1Contract + : this.CommitManagerV1U1Contract; + } + + async isCommitWindowOpen(agreementId, epoch, latestStateIndex) { + return this.callContractFunction( + this.selectCommitManagerContract(latestStateIndex), + 'isCommitWindowOpen', + [agreementId, epoch], + ); } async isUpdateCommitWindowOpen(agreementId, epoch, stateIndex) { @@ -555,11 +566,14 @@ class Web3Service { ); } - async getTopCommitSubmissions(agreementId, epoch, stateIndex) { + async getTopCommitSubmissions(agreementId, epoch, latestStateIndex) { + const args = + latestStateIndex === 0 ? [agreementId, epoch] : [agreementId, epoch, latestStateIndex]; + const commits = await this.callContractFunction( - this.CommitManagerV1U1Contract, + this.selectCommitManagerContract(latestStateIndex), 'getTopCommitSubmissions', - [agreementId, epoch, stateIndex], + args, ); return commits @@ -596,9 +610,17 @@ class Web3Service { return finalizationCommitsNumber; } - async submitCommit(assetContractAddress, tokenId, keyword, hashFunctionId, epoch, callback) { + async submitCommit( + assetContractAddress, + tokenId, + keyword, + hashFunctionId, + epoch, + latestStateIndex, + callback, + ) { return this.queueTransaction( - this.CommitManagerV1U1Contract, + this.selectCommitManagerContract(latestStateIndex), 'submitCommit', [[assetContractAddress, tokenId, keyword, hashFunctionId, epoch]], callback, @@ -621,18 +643,28 @@ class Web3Service { ); } - async isProofWindowOpen(agreementId, epoch) { - return this.callContractFunction(this.ProofManagerV1U1Contract, 'isProofWindowOpen', [ - agreementId, - epoch, - ]); + selectProofManagerContract(latestStateIndex) { + return latestStateIndex === 0 ? this.ProofManagerV1Contract : this.ProofManagerV1U1Contract; } - async getChallenge(assetContractAddress, tokenId, epoch) { + async isProofWindowOpen(agreementId, epoch, latestStateIndex) { + return this.callContractFunction( + this.selectProofManagerContract(latestStateIndex), + 'isProofWindowOpen', + [agreementId, epoch], + ); + } + + async getChallenge(assetContractAddress, tokenId, epoch, latestStateIndex) { + const args = + latestStateIndex === 0 + ? [this.getPublicKey(), assetContractAddress, tokenId, epoch] + : [assetContractAddress, tokenId, epoch]; + const result = await this.callContractFunction( - this.ProofManagerV1U1Contract, + this.selectProofManagerContract(latestStateIndex), 'getChallenge', - [assetContractAddress, tokenId, epoch], + args, ); return { assertionId: result['0'], challenge: result['1'] }; @@ -646,10 +678,11 @@ class Web3Service { epoch, proof, chunkHash, + latestStateIndex, callback, ) { return this.queueTransaction( - this.ProofManagerV1U1Contract, + this.selectProofManagerContract(latestStateIndex), 'sendProof', [[assetContractAddress, tokenId, keyword, hashFunctionId, epoch, proof, chunkHash]], callback,