Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OriginTrail Devnet Release v6.4.0 Hotfix 6 #3198

Merged
merged 14 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"axios": "^1.6.0",
"cors": "^2.8.5",
"deep-extend": "^0.6.0",
"dkg-evm-module": "github:OriginTrail/dkg-evm-module#feature/paranets",
"dkg-evm-module": "^4.3.0",
"dotenv": "^16.0.1",
"ethers": "^5.7.2",
"express": "^4.18.1",
Expand Down
14 changes: 7 additions & 7 deletions src/commands/paranet/paranet-sync-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ParanetSyncCommand extends Command {
const paranetId = this.paranetService.constructParanetId(blockchain, contract, tokenId);

this.logger.info(
`Paranet sync: Starting paranet sync for paranetId: ${paranetId}, operation ID: ${operationId}`,
`Paranet sync: Starting paranet sync for paranet: ${paranetUAL}, operation ID: ${operationId}`,
);

let contractKaCount = await this.blockchainModuleManager.getParanetKnowledgeAssetsCount(
Expand All @@ -50,17 +50,17 @@ class ParanetSyncCommand extends Command {
const cachedMissedKaCount =
await this.repositoryModuleManager.getCountOfMissedAssetsOfParanet(paranetUAL);

if (cachedKaCount + cachedMissedKaCount === contractKaCount) {
if (cachedKaCount + cachedMissedKaCount >= contractKaCount) {
this.logger.info(
`Paranet sync: KA count from contract and in DB is the same, nothing new to sync, for paranetId: ${paranetId}, operation ID: ${operationId}!`,
`Paranet sync: KA count from contract and in DB is the same, nothing new to sync, for paranet: ${paranetUAL}, operation ID: ${operationId}!`,
);
if (cachedMissedKaCount > 0) {
this.logger.info(
`Paranet sync: Missed KA count is ${cachedMissedKaCount} syncing ${
cachedMissedKaCount > PARANET_SYNC_KA_COUNT
? PARANET_SYNC_KA_COUNT
: cachedMissedKaCount
} assets, for paranetId: ${paranetId}, operation ID: ${operationId}!`,
} assets, for paranet: ${paranetUAL}, operation ID: ${operationId}!`,
);
const missedParanetAssets =
await this.repositoryModuleManager.getMissedParanetAssetsRecords(
Expand All @@ -76,7 +76,7 @@ class ParanetSyncCommand extends Command {
(async () => {
const { knowledgeAssetId } = missedParanetAsset;
this.logger.info(
`Paranet sync: Syncing missed token id: ${knowledgeAssetId} for ${paranetId} with operation id: ${operationId}`,
`Paranet sync: Syncing missed token id: ${knowledgeAssetId} for ${paranetUAL} with operation id: ${operationId}`,
);

const { knowledgeAssetStorageContract, tokenId: kaTokenId } =
Expand Down Expand Up @@ -172,7 +172,7 @@ class ParanetSyncCommand extends Command {
this.logger.info(
`Paranet sync: Syncing ${
contractKaCount + cachedMissedKaCount - cachedKaCount
} new assets for paranetId: ${paranetId}, operation ID: ${operationId}`,
} new assets for paranet: ${paranetUAL}, operation ID: ${operationId}`,
);
// TODO: Rename i, should it be cachedKaCount + 1 as cachedKaCount is already in, but count is index
const kaToUpdate = [];
Expand All @@ -199,7 +199,7 @@ class ParanetSyncCommand extends Command {
promises.push(
(async () => {
this.logger.info(
`Paranet sync: Syncing token id: ${knowledgeAssetId} for ${paranetId} with operation id: ${operationId}`,
`Paranet sync: Syncing token id: ${knowledgeAssetId} for ${paranetUAL} with operation id: ${operationId}`,
);

const { knowledgeAssetStorageContract, tokenId: kaTokenId } =
Expand Down
4 changes: 2 additions & 2 deletions src/modules/blockchain/implementation/web3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -1659,8 +1659,8 @@ class Web3Service {

async getKnowledgeAssetLocatorFromParanetId(paranetId) {
const [paranetKAStorageContract, paranetKATokenId] = await this.callContractFunction(
this.ParanetRegistryContract,
'getKnowledgeAssetLocator',
this.ParanetsRegistryContract,
'getParanetKnowledgeAssetLocator',
[paranetId],
);
const tokenId = paranetKATokenId.toNumber();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Sequelize } from 'sequelize';

class ParanetRepository {
constructor(models) {
this.sequelize = models.sequelize;
Expand Down Expand Up @@ -59,6 +61,14 @@ class ParanetRepository {
},
});
}

async getParanetsBlockchains() {
return this.model.findAll({
attributes: [
[Sequelize.fn('DISTINCT', Sequelize.col('blockchain_id')), 'blockchain_id'],
],
});
}
}

export default ParanetRepository;
4 changes: 4 additions & 0 deletions src/modules/repository/repository-module-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ class RepositoryModuleManager extends BaseModuleManager {
async getCountOfMissedAssetsOfParanet(ual) {
return this.getRepository('missed_paranet_asset').getCountOfMissedAssetsOfParanet(ual);
}

async getParanetsBlockchains() {
return this.getRepository('paranet').getParanetsBlockchains();
}
}

export default RepositoryModuleManager;
86 changes: 52 additions & 34 deletions src/service/blockchain-event-listener-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DELAY_BETWEEN_FAILED_FETCH_EVENTS_MILLIS,
CONTRACT_EVENT_TO_GROUP_MAPPING,
GROUPED_CONTRACT_EVENTS,
ZERO_BYTES32,
} from '../constants/constants.js';

const fetchEventsFailedCount = {};
Expand Down Expand Up @@ -578,49 +579,66 @@ class BlockchainEventListenerService {
]);

// eslint-disable-next-line no-await-in-loop
const knowledgeAssetId = await this.paranetService.constructKnowledgeAssetId(
blockchain,
contract,
tokenId,
);
const paranetsBlockchains = await this.repositoryModuleManager.getParanetsBlockchains();

// eslint-disable-next-line no-await-in-loop
const paranetId = await this.blockchainModuleManager.getParanetId(knowledgeAssetId);
if (paranetId) {
const {
knowledgeAssetStorageContract: paranetKasContract,
tokenId: paranetTokenId,
// eslint-disable-next-line no-await-in-loop
} = await this.blockchainModuleManager.getKnowledgeAssetLocatorFromParanetId(
paranetId,
);
const paranetUAL = this.ualService.deriveUAL(
if (paranetsBlockchains.includes(blockchain)) {
// eslint-disable-next-line no-await-in-loop
const knowledgeAssetId = await this.paranetService.constructKnowledgeAssetId(
blockchain,
paranetKasContract,
paranetTokenId,
contract,
tokenId,
);

// eslint-disable-next-line no-await-in-loop
const paranetAssetExists = await this.tripleStoreService.paranetAssetExists(
const paranetId = await this.blockchainModuleManager.getParanetId(
blockchain,
contract,
tokenId,
paranetKasContract,
paranetTokenId,
knowledgeAssetId,
);
if (paranetId && paranetId !== ZERO_BYTES32) {
// eslint-disable-next-line no-await-in-loop
const paranetExists = await this.repositoryModuleManager.paranetExists(
paranetId,
blockchain,
);
if (paranetExists) {
const {
paranetKAStorageContract: paranetKasContract,
tokenId: paranetTokenId,
} =
// eslint-disable-next-line no-await-in-loop
await this.blockchainModuleManager.getKnowledgeAssetLocatorFromParanetId(
blockchain,
paranetId,
);
const paranetUAL = this.ualService.deriveUAL(
blockchain,
paranetKasContract,
paranetTokenId,
);

if (paranetAssetExists) {
const kaUAL = this.ualService.deriveUAL(blockchain, contract, tokenId);
// eslint-disable-next-line no-await-in-loop
const paranetAssetExists = await this.tripleStoreService.paranetAssetExists(
blockchain,
contract,
tokenId,
paranetKasContract,
paranetTokenId,
);

// Create a record for missing Paranet KA
// Paranet sync command will get it from network
// eslint-disable-next-line no-await-in-loop
await this.repositoryModuleManager.createMissedParanetAssetRecord({
blockchainId: blockchain,
ual: kaUAL,
paranetUal: paranetUAL,
knowledgeAssetId,
});
if (paranetAssetExists) {
const kaUAL = this.ualService.deriveUAL(blockchain, contract, tokenId);

// Create a record for missing Paranet KA
// Paranet sync command will get it from network
// eslint-disable-next-line no-await-in-loop
await this.repositoryModuleManager.createMissedParanetAssetRecord({
blockchainId: blockchain,
ual: kaUAL,
paranetUal: paranetUAL,
knowledgeAssetId,
});
}
}
}
}
}
Expand Down
Loading