diff --git a/config/config.json b/config/config.json index b9a156aa5..8d0e9f689 100644 --- a/config/config.json +++ b/config/config.json @@ -158,7 +158,7 @@ "localEndpoint": "http::addr=localhost:10000", "signalingServiceEndpoint": "", "sendToSignalingService": false - } + } } } }, @@ -347,7 +347,7 @@ "localEndpoint": "http::addr=localhost:10000", "signalingServiceEndpoint": "", "sendToSignalingService": false - } + } } } }, @@ -536,7 +536,7 @@ "localEndpoint": "http::addr=localhost:10000", "signalingServiceEndpoint": "", "sendToSignalingService": false - } + } } } }, @@ -675,7 +675,7 @@ "package": "./blockchain/implementation/base/base-service.js", "config": { - "hubContractAddress": "0xAB4A4794Fc1F415C24807B947280aCa8dC492238", + "hubContractAddress": "0x3e5dd82e7529F4e55AA64893D8f8879AE14BF87D", "rpcEndpoints": ["https://sepolia.base.org"], "operatorFee": 0 } @@ -722,7 +722,7 @@ "localEndpoint": "http::addr=localhost:10000", "signalingServiceEndpoint": "", "sendToSignalingService": false - } + } } } }, @@ -738,7 +738,7 @@ "base:84532": ["https://sepolia.base.org"] }, "hubContractAddress": { - "base:84532": "0xAB4A4794Fc1F415C24807B947280aCa8dC492238" + "base:84532": "0x3e5dd82e7529F4e55AA64893D8f8879AE14BF87D" } } } @@ -931,8 +931,7 @@ "localEndpoint": "http::addr=localhost:10000", "signalingServiceEndpoint": "", "sendToSignalingService": false - - } + } } } }, diff --git a/package-lock.json b/package-lock.json index f218030fe..3e8f56afc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "8.0.0-gamma.0", + "version": "8.0.0-gamma.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "8.0.0-gamma.0", + "version": "8.0.0-gamma.3", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", @@ -26,7 +26,7 @@ "axios": "^1.6.0", "cors": "^2.8.5", "deep-extend": "^0.6.0", - "dkg-evm-module": "^8.0.3-gamma.7", + "dkg-evm-module": "^8.0.3-gamma.8", "dotenv": "^16.0.1", "ethers": "^5.7.2", "express": "^4.18.1", @@ -9077,9 +9077,10 @@ } }, "node_modules/dkg-evm-module": { - "version": "8.0.3-gamma.7", - "resolved": "https://registry.npmjs.org/dkg-evm-module/-/dkg-evm-module-8.0.3-gamma.7.tgz", - "integrity": "sha512-cEjPz8c6vqwhsYiDx5ibIJ0xh9BZDvqtYHigaYf4gE26QaFJs6+NFFoQOSwwbaKmB7FKlSPHw0mOJASqVaWwbw==", + "version": "8.0.3-gamma.8", + "resolved": "https://registry.npmjs.org/dkg-evm-module/-/dkg-evm-module-8.0.3-gamma.8.tgz", + "integrity": "sha512-splfWS1kHMXt0B20B6pXnniE7cT+8x1kmhibBXhDLBQuO32l5yAZrfxoD3v6CUUBY6Au2Nin1BPUHKy1s6CqVA==", + "license": "Apache-2.0", "dependencies": { "@openzeppelin/contracts": "^4.9.3", "@polkadot/api": "^11.0.3", @@ -30199,9 +30200,9 @@ "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==" }, "dkg-evm-module": { - "version": "8.0.3-gamma.7", - "resolved": "https://registry.npmjs.org/dkg-evm-module/-/dkg-evm-module-8.0.3-gamma.7.tgz", - "integrity": "sha512-cEjPz8c6vqwhsYiDx5ibIJ0xh9BZDvqtYHigaYf4gE26QaFJs6+NFFoQOSwwbaKmB7FKlSPHw0mOJASqVaWwbw==", + "version": "8.0.3-gamma.8", + "resolved": "https://registry.npmjs.org/dkg-evm-module/-/dkg-evm-module-8.0.3-gamma.8.tgz", + "integrity": "sha512-splfWS1kHMXt0B20B6pXnniE7cT+8x1kmhibBXhDLBQuO32l5yAZrfxoD3v6CUUBY6Au2Nin1BPUHKy1s6CqVA==", "requires": { "@openzeppelin/contracts": "^4.9.3", "@polkadot/api": "^11.0.3", diff --git a/package.json b/package.json index ebed6da5e..be0a95d25 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "8.0.0-gamma.0", + "version": "8.0.0-gamma.3", "description": "OTNode V8", "main": "index.js", "type": "module", @@ -81,7 +81,7 @@ "axios": "^1.6.0", "cors": "^2.8.5", "deep-extend": "^0.6.0", - "dkg-evm-module": "^8.0.3-gamma.7", + "dkg-evm-module": "^8.0.3-gamma.8", "dotenv": "^16.0.1", "ethers": "^5.7.2", "express": "^4.18.1", diff --git a/src/commands/blockchain-event-listener/blockchain-event-listener-command.js b/src/commands/blockchain-event-listener/blockchain-event-listener-command.js index 3a49b5709..bbb8670d4 100644 --- a/src/commands/blockchain-event-listener/blockchain-event-listener-command.js +++ b/src/commands/blockchain-event-listener/blockchain-event-listener-command.js @@ -76,14 +76,15 @@ class BlockchainEventListenerCommand extends Command { await this.repositoryModuleManager.insertBlockchainEvents(newEvents, { transaction: repositoryTransaction, }); - await this.repositoryModuleManager.updateLastCheckedBlock( - blockchainId, - this.currentBlock, - Date.now(), - { transaction: repositoryTransaction }, - ); } + await this.repositoryModuleManager.updateLastCheckedBlock( + blockchainId, + this.currentBlock, + Date.now(), + { transaction: repositoryTransaction }, + ); + const unprocessedEvents = await this.repositoryModuleManager.getAllUnprocessedBlockchainEvents( blockchainId, @@ -470,10 +471,8 @@ class BlockchainEventListenerCommand extends Command { async handleKnowledgeCollectionCreatedEvent(event) { const eventData = JSON.parse(event.data); - - const { id, merkleRoot, publishOperationId } = eventData; + const { id, publishOperationId, merkleRoot, chunksAmount } = eventData; const { blockchain, contractAddress } = event; - const operationId = await this.operationIdService.generateOperationId( OPERATION_ID_STATUS.PUBLISH_FINALIZATION.PUBLISH_FINALIZATION_START, publishOperationId, @@ -482,7 +481,6 @@ class BlockchainEventListenerCommand extends Command { let cachedData; try { datasetPath = this.fileService.getPendingStorageDocumentPath(publishOperationId); - cachedData = await this.fileService.readFile(datasetPath, true); } catch (error) { this.operationIdService.updateOperationIdStatus( @@ -519,6 +517,7 @@ class BlockchainEventListenerCommand extends Command { contract: contractAddress, tokenId: id, merkleRoot, + chunksAmount, remotePeerId: cachedData.remotePeerId, publishOperationId, assertion: cachedData.assertion, @@ -540,11 +539,11 @@ class BlockchainEventListenerCommand extends Command { OPERATION_ID_STATUS.UPDATE_FINALIZATION.UPDATE_FINALIZATION_START, ); - let data; let datasetPath; + let cachedData; try { datasetPath = this.fileService.getPendingStorageDocumentPath(updateOperationId); - data = await this.fileService.readFile(datasetPath, true); + cachedData = await this.fileService.readFile(datasetPath, true); } catch (error) { this.operationIdService.markOperationAsFailed( operationId, @@ -567,8 +566,8 @@ class BlockchainEventListenerCommand extends Command { tokenId, assetStateIndex, merkleRoot: state, - assertion: data.assertion, - cachedMerkleRoot: data.merkleRoot, + assertion: cachedData.assertion, + cachedMerkleRoot: cachedData.merkleRoot, }, transactional: false, }); diff --git a/src/commands/protocols/publish/publish-validate-assertion-metadata-command.js b/src/commands/protocols/publish/publish-validate-assertion-metadata-command.js index 306669aaf..7d63e6cb0 100644 --- a/src/commands/protocols/publish/publish-validate-assertion-metadata-command.js +++ b/src/commands/protocols/publish/publish-validate-assertion-metadata-command.js @@ -1,10 +1,12 @@ import ValidateAssertionMetadataCommand from '../common/validate-assertion-metadata-command.js'; import { OPERATION_ID_STATUS, ERROR_TYPE } from '../../../constants/constants.js'; +import Command from '../../command.js'; class PublishValidateAssertionMetadataCommand extends ValidateAssertionMetadataCommand { constructor(ctx) { super(ctx); this.operationIdService = ctx.operationIdService; + this.dataService = ctx.dataService; this.errorType = ERROR_TYPE.PUBLISH.PUBLISH_VALIDATE_ASSERTION_METADATA_ERROR; this.operationStartEvent = @@ -13,6 +15,59 @@ class PublishValidateAssertionMetadataCommand extends ValidateAssertionMetadataC OPERATION_ID_STATUS.PUBLISH_FINALIZATION.PUBLISH_FINALIZATION_METADATA_VALIDATION_END; } + async execute(command) { + const { + operationId, + ual, + blockchain, + assertion, + merkleRoot, + cachedMerkleRoot, + chunksAmount, + } = command.data; + + await this.operationIdService.updateOperationIdStatus( + operationId, + blockchain, + this.operationStartEvent, + ); + + try { + if (merkleRoot !== cachedMerkleRoot) { + await this.handleError( + operationId, + blockchain, + `Invalid Merkle Root for Knowledge Collection with UAL: ${ual}. Received value from blockchain: ${merkleRoot}, Cached value from publish operation: ${cachedMerkleRoot}`, + this.errorType, + true, + ); + + const calculatedChunksAmount = this.dataService.calculateChunksAmount(assertion); + + if (chunksAmount !== calculatedChunksAmount) { + await this.handleError( + operationId, + blockchain, + `Invalid Chunks Amount for Knowledge Collection with UAL: ${ual}. Received value from blockchain: ${chunksAmount}, Calculated value: ${calculatedChunksAmount}`, + this.errorType, + true, + ); + } + } + } catch (e) { + await this.handleError(operationId, blockchain, e.message, this.errorType, true); + return Command.empty(); + } + + await this.operationIdService.updateOperationIdStatus( + operationId, + blockchain, + this.operationEndEvent, + ); + + return this.continueSequence(command.data, command.sequence); + } + /** * Builds default publishValidateAssertionMetadataCommand * @param map diff --git a/src/commands/protocols/update/sender/update-validate-asset-command.js b/src/commands/protocols/update/sender/update-validate-asset-command.js index 3272b82cf..fd3ae9c33 100644 --- a/src/commands/protocols/update/sender/update-validate-asset-command.js +++ b/src/commands/protocols/update/sender/update-validate-asset-command.js @@ -47,7 +47,7 @@ class UpdateValidateAssetCommand extends ValidateAssetCommand { operationId, blockchain, ); - this.validationService.validateDatasetRoot(cachedData.dataset, datasetRoot); + await this.validationService.validateDatasetRoot(cachedData.dataset, datasetRoot); this.operationIdService.emitChangeEvent( OPERATION_ID_STATUS.UPDATE.UPDATE_VALIDATE_DATASET_ROOT_END, operationId, diff --git a/src/constants/constants.js b/src/constants/constants.js index 1c64dbd46..77aa55edc 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -247,7 +247,7 @@ const require = createRequire(import.meta.url); export const ABIs = { KnowledgeCollection: require('dkg-evm-module/abi/KnowledgeCollection.json'), - KnowledgeCollectionStorage: require('dkg-evm-module/abi/KnowledgeCollectionLib.json'), + KnowledgeCollectionStorage: require('dkg-evm-module/abi/KnowledgeCollectionStorage.json'), Staking: require('dkg-evm-module/abi/Staking.json'), Token: require('dkg-evm-module/abi/Token.json'), Hub: require('dkg-evm-module/abi/Hub.json'), diff --git a/src/controllers/http-api/v1/finality-http-api-controller-v1.js b/src/controllers/http-api/v1/finality-http-api-controller-v1.js index 65336125c..a7d97c645 100644 --- a/src/controllers/http-api/v1/finality-http-api-controller-v1.js +++ b/src/controllers/http-api/v1/finality-http-api-controller-v1.js @@ -15,7 +15,6 @@ class FinalityController extends BaseController { const { ual } = req.query; const finality = await this.repositoryModuleManager.getFinalityAcksCount(ual || ''); - console.log(finality); if (typeof finality !== 'number') return this.returnResponse(res, 400, { diff --git a/src/modules/blockchain-events/implementation/ot-ethers/ot-ethers.js b/src/modules/blockchain-events/implementation/ot-ethers/ot-ethers.js index ca40db542..acf9c4f87 100644 --- a/src/modules/blockchain-events/implementation/ot-ethers/ot-ethers.js +++ b/src/modules/blockchain-events/implementation/ot-ethers/ot-ethers.js @@ -122,7 +122,6 @@ class OtEthers extends BlockchainEventsService { let fromBlock = currentBlock - lastCheckedBlock > maxBlocksToSync ? currentBlock : lastCheckedBlock + 1; const eventsMissed = currentBlock - lastCheckedBlock > maxBlocksToSync; - if (eventsMissed) { return { events: [], @@ -168,12 +167,19 @@ class OtEthers extends BlockchainEventsService { fromBlock + MAXIMUM_NUMBERS_OF_BLOCKS_TO_FETCH - 1, currentBlock, ); + + const fromBlockParam = ethers.BigNumber.from(fromBlock) + .toHexString() + .replace(/^0x0+/, '0x'); + const toBlockParam = ethers.BigNumber.from(toBlock) + .toHexString() + .replace(/^0x0+/, '0x'); const provider = this._getRandomProvider(blockchain); const newLogs = await provider.send('eth_getLogs', [ { address: contractAddresses, - fromBlock: ethers.BigNumber.from(fromBlock).toHexString(), - toBlock: ethers.BigNumber.from(toBlock).toHexString(), + fromBlock: fromBlockParam, + toBlock: toBlockParam, topics: [topics], }, ]); diff --git a/src/modules/telemetry/implementation/quest-telemetry.js b/src/modules/telemetry/implementation/quest-telemetry.js index 13ae80192..13faf4fab 100644 --- a/src/modules/telemetry/implementation/quest-telemetry.js +++ b/src/modules/telemetry/implementation/quest-telemetry.js @@ -38,7 +38,7 @@ class QuestTelemetry { await this.localSender.flush(); await this.localSender.close(); - this.logger.info('Event telemetry successfully sent to local QuestDB'); + // this.logger.info('Event telemetry successfully sent to local QuestDB'); } catch (err) { this.logger.error(`Error sending telemetry to local QuestDB: ${err.message}`); } diff --git a/src/service/data-service.js b/src/service/data-service.js index 0b7adc6c0..ac2cff87c 100644 --- a/src/service/data-service.js +++ b/src/service/data-service.js @@ -13,6 +13,10 @@ class DataService { this.cryptoService = ctx.cryptoService; } + calculateChunksAmount(assertion) { + return kcTools.calculateNumberOfChunks(assertion); + } + createTripleAnnotations(groupedTriples, annotationPredicate, annotations) { return groupedTriples.flatMap((knowledgeAssetTriples, index) => knowledgeAssetTriples.map( diff --git a/src/service/validation-service.js b/src/service/validation-service.js index e844987f9..743d49c4b 100644 --- a/src/service/validation-service.js +++ b/src/service/validation-service.js @@ -39,7 +39,7 @@ class ValidationService { } async validateDatasetRootOnBlockchain(knowledgeCollectionId, assertionId, blockchain) { - // call contract TO DO, dont return anything or return true + // TODO: call contract TO DO, dont return anything or return true return { knowledgeCollectionId, assertionId, blockchain }; }