Skip to content

Commit

Permalink
Merge branch 'v8/develop' into v8/fix/private-public-parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihajlo-Pavlovic committed Dec 16, 2024
2 parents 97530e4 + 906d619 commit f574c43
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 41 deletions.
15 changes: 7 additions & 8 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"localEndpoint": "http::addr=localhost:10000",
"signalingServiceEndpoint": "",
"sendToSignalingService": false
}
}
}
}
},
Expand Down Expand Up @@ -347,7 +347,7 @@
"localEndpoint": "http::addr=localhost:10000",
"signalingServiceEndpoint": "",
"sendToSignalingService": false
}
}
}
}
},
Expand Down Expand Up @@ -536,7 +536,7 @@
"localEndpoint": "http::addr=localhost:10000",
"signalingServiceEndpoint": "",
"sendToSignalingService": false
}
}
}
}
},
Expand Down Expand Up @@ -675,7 +675,7 @@
"package": "./blockchain/implementation/base/base-service.js",

"config": {
"hubContractAddress": "0xAB4A4794Fc1F415C24807B947280aCa8dC492238",
"hubContractAddress": "0x3e5dd82e7529F4e55AA64893D8f8879AE14BF87D",
"rpcEndpoints": ["https://sepolia.base.org"],
"operatorFee": 0
}
Expand Down Expand Up @@ -722,7 +722,7 @@
"localEndpoint": "http::addr=localhost:10000",
"signalingServiceEndpoint": "",
"sendToSignalingService": false
}
}
}
}
},
Expand All @@ -738,7 +738,7 @@
"base:84532": ["https://sepolia.base.org"]
},
"hubContractAddress": {
"base:84532": "0xAB4A4794Fc1F415C24807B947280aCa8dC492238"
"base:84532": "0x3e5dd82e7529F4e55AA64893D8f8879AE14BF87D"
}
}
}
Expand Down Expand Up @@ -931,8 +931,7 @@
"localEndpoint": "http::addr=localhost:10000",
"signalingServiceEndpoint": "",
"sendToSignalingService": false

}
}
}
}
},
Expand Down
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -519,6 +517,7 @@ class BlockchainEventListenerCommand extends Command {
contract: contractAddress,
tokenId: id,
merkleRoot,
chunksAmount,
remotePeerId: cachedData.remotePeerId,
publishOperationId,
assertion: cachedData.assertion,
Expand All @@ -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,
Expand All @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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],
},
]);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/telemetry/implementation/quest-telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
4 changes: 4 additions & 0 deletions src/service/data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/service/validation-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down

0 comments on commit f574c43

Please sign in to comment.