Skip to content

Commit

Permalink
Merge pull request #2900 from OriginTrail/v6/develop
Browse files Browse the repository at this point in the history
Devnet Prerelease v6.2.0
  • Loading branch information
NZT48 authored Jan 30, 2024
2 parents ecf2e12 + 214c494 commit 53ff733
Show file tree
Hide file tree
Showing 48 changed files with 4,651 additions and 224 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,6 @@ data*

# VS code files
.vscode/launch.json

# KAs Distribution Simulation Script Plots
tools/knowledge-assets-distribution-simulation/plots/**/*jpg
6 changes: 6 additions & 0 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class OTNode {

await this.initializeModules();

await MigrationExecutor.executeRemoveServiceAgreementsForChiadoDevnetMigration(
this.container,
this.logger,
this.config,
);

await this.createProfiles();

await this.initializeCommandExecutor();
Expand Down
2,779 changes: 2,741 additions & 38 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "6.1.3",
"version": "6.2.0",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down Expand Up @@ -48,7 +48,9 @@
"devDependencies": {
"@cucumber/cucumber": "^8.5.2",
"chai": "^4.3.6",
"dkg.js": "^6.0.2",
"d3": "^7.8.5",
"d3-node": "^3.0.0",
"dkg.js": "^6.1.2",
"eslint": "^8.23.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -57,6 +59,7 @@
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"sharp": "^0.32.6",
"sinon": "^14.0.0",
"slugify": "^1.6.5"
},
Expand All @@ -77,7 +80,7 @@
"axios": "^1.6.0",
"cors": "^2.8.5",
"deep-extend": "^0.6.0",
"dkg-evm-module": "^4.1.0",
"dkg-evm-module": "github:OriginTrail/dkg-evm-module#release/delegations",
"dotenv": "^16.0.1",
"ethers": "^5.7.2",
"express": "^4.18.1",
Expand Down
89 changes: 53 additions & 36 deletions src/commands/protocols/common/epoch-check-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class EpochCheckCommand extends Command {
this.blockchainModuleManager = ctx.blockchainModuleManager;
this.serviceAgreementService = ctx.serviceAgreementService;
this.fileService = ctx.fileService;
this.proximityScoringService = ctx.proximityScoringService;
this.hashingService = ctx.hashingService;

this.errorType = ERROR_TYPE.COMMIT_PROOF.EPOCH_CHECK_ERROR;
}
Expand Down Expand Up @@ -72,9 +74,12 @@ class EpochCheckCommand extends Command {

totalTransactions -= transactionQueueLength;

const [r0, r2] = await Promise.all([
const [r0, r2, totalNodesNumber, minStake, maxStake] = await Promise.all([
this.blockchainModuleManager.getR0(blockchain),
this.blockchainModuleManager.getR2(blockchain),
this.blockchainModuleManager.getShardingTableLength(blockchain),
this.blockchainModuleManager.getMinimumStake(blockchain),
this.blockchainModuleManager.getMaximumStake(blockchain),
]);

await Promise.all([
Expand All @@ -84,6 +89,9 @@ class EpochCheckCommand extends Command {
commitWindowDurationPerc,
r0,
r2,
totalNodesNumber,
minStake,
maxStake,
),
this.scheduleCalculateProofsCommands(
blockchain,
Expand All @@ -110,6 +118,9 @@ class EpochCheckCommand extends Command {
commitWindowDurationPerc,
r0,
r2,
totalNodesNumber,
minStake,
maxStake,
) {
const timestamp = await this.blockchainModuleManager.getBlockchainTimestamp(blockchain);
const eligibleAgreementForSubmitCommit =
Expand All @@ -124,12 +135,42 @@ class EpochCheckCommand extends Command {
for (const serviceAgreement of eligibleAgreementForSubmitCommit) {
if (scheduleSubmitCommitCommands.length >= maxTransactions) break;

const neighbourhood = await this.shardingTableService.findNeighbourhood(
blockchain,
serviceAgreement.keyword,
r2,
serviceAgreement.hashFunctionId,
serviceAgreement.scoreFunctionId,
true,
);

let neighbourhoodEdges = null;
if (serviceAgreement.scoreFunctionId === 2) {
neighbourhoodEdges = await this.shardingTableService.getNeighboorhoodEdgeNodes(
neighbourhood,
blockchain,
serviceAgreement.hashFunctionId,
serviceAgreement.scoreFunctionId,
serviceAgreement.keyword,
);
}

if (!neighbourhoodEdges && serviceAgreement.scoreFunctionId === 2) {
throw Error('Unable to find neighbourhood edges for asset');
}

try {
const rank = await this.calculateRank(
const rank = await this.serviceAgreementService.calculateRank(
blockchain,
serviceAgreement.keyword,
serviceAgreement.hashFunctionId,
serviceAgreement.scoreFunctionId,
r2,
neighbourhood,
neighbourhoodEdges,
totalNodesNumber,
minStake,
maxStake,
);

updateServiceAgreementsLastCommitEpoch.push(
Expand Down Expand Up @@ -164,9 +205,13 @@ class EpochCheckCommand extends Command {
serviceAgreement.agreementId
}. Scheduling submitCommitCommand.`,
);

const closestNode = neighbourhood[0];
scheduleSubmitCommitCommands.push(
this.scheduleSubmitCommitCommand(serviceAgreement),
this.scheduleSubmitCommitCommand(
serviceAgreement,
neighbourhoodEdges,
closestNode,
),
);
} catch (error) {
this.logger.warn(
Expand Down Expand Up @@ -239,37 +284,6 @@ class EpochCheckCommand extends Command {
]);
}

async calculateRank(blockchain, keyword, hashFunctionId, r2) {
const neighbourhood = await this.shardingTableService.findNeighbourhood(
blockchain,
keyword,
r2,
hashFunctionId,
true,
);

const peerId = this.networkModuleManager.getPeerId().toB58String();
if (!neighbourhood.some((node) => node.peerId === peerId)) {
return;
}

const scores = await Promise.all(
neighbourhood.map(async (node) => ({
score: await this.serviceAgreementService.calculateScore(
node.peerId,
blockchain,
keyword,
hashFunctionId,
),
peerId: node.peerId,
})),
);

scores.sort((a, b) => b.score - a.score);

return scores.findIndex((node) => node.peerId === peerId);
}

async isEligibleForRewards(blockchain, agreementId, epoch, stateIndex, r0) {
const identityId = await this.blockchainModuleManager.getIdentityId(blockchain);
const commits = await this.blockchainModuleManager.getTopCommitSubmissions(
Expand All @@ -288,7 +302,7 @@ class EpochCheckCommand extends Command {
return false;
}

async scheduleSubmitCommitCommand(agreement) {
async scheduleSubmitCommitCommand(agreement, neighbourhoodEdges, closestNode) {
const commandData = {
operationId: this.operationIdService.generateId(),
blockchain: agreement.blockchainId,
Expand All @@ -299,6 +313,9 @@ class EpochCheckCommand extends Command {
epoch: agreement.currentEpoch,
agreementId: agreement.agreementId,
stateIndex: agreement.stateIndex,
closestNode: closestNode.index,
leftNeighborhoodEdge: neighbourhoodEdges?.leftEdge.index,
rightNeighborhoodEdge: neighbourhoodEdges?.rightEdge.index,
};

await this.commandExecutor.add({
Expand Down
18 changes: 16 additions & 2 deletions src/commands/protocols/common/find-nodes-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ class FindNodesCommand extends Command {
networkProtocols,
hashFunctionId,
minAckResponses,
proximityScoreFunctionsPairId,
} = command.data;

this.errorType = errorType;
this.logger.debug(`Searching for closest node(s) for keyword ${keyword}`);

// TODO: protocol selection
const closestNodes = [];
const foundNodes = await this.findNodes(blockchain, keyword, operationId, hashFunctionId);
const foundNodes = await this.findNodes(
blockchain,
keyword,
operationId,
hashFunctionId,
proximityScoreFunctionsPairId,
);
for (const node of foundNodes) {
if (node.id !== this.networkModuleManager.getPeerId().toB58String()) {
closestNodes.push({ id: node.id, protocol: networkProtocols[0] });
Expand Down Expand Up @@ -66,7 +73,13 @@ class FindNodesCommand extends Command {
);
}

async findNodes(blockchainId, keyword, operationId, hashFunctionId) {
async findNodes(
blockchainId,
keyword,
operationId,
hashFunctionId,
proximityScoreFunctionsPairId,
) {
await this.operationIdService.updateOperationIdStatus(
operationId,
blockchainId,
Expand All @@ -78,6 +91,7 @@ class FindNodesCommand extends Command {
keyword,
r2,
hashFunctionId,
proximityScoreFunctionsPairId,
true,
);

Expand Down
20 changes: 18 additions & 2 deletions src/commands/protocols/common/handle-protocol-message-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ class HandleProtocolMessageCommand extends Command {
throw Error('prepareMessage not implemented');
}

async validateNeighborhood(blockchain, keyword, hashFunctionId, ual) {
async validateNeighborhood(
blockchain,
keyword,
hashFunctionId,
proximityScoreFunctionsPairId,
ual,
) {
const closestNodes = await this.shardingTableService.findNeighbourhood(
blockchain,
keyword,
await this.blockchainModuleManager.getR2(blockchain),
hashFunctionId,
proximityScoreFunctionsPairId,
true,
);
const peerId = this.networkModuleManager.getPeerId().toB58String();
Expand Down Expand Up @@ -179,11 +186,20 @@ class HandleProtocolMessageCommand extends Command {
tokenId,
keyword,
hashFunctionId,
proximityScoreFunctionsPairId,
) {
const ual = this.ualService.deriveUAL(blockchain, contract, tokenId);

this.logger.trace(`Validating neighborhood for ual: ${ual}`);
if (!(await this.validateNeighborhood(blockchain, keyword, hashFunctionId, ual))) {
if (
!(await this.validateNeighborhood(
blockchain,
keyword,
hashFunctionId,
proximityScoreFunctionsPairId,
ual,
))
) {
return {
messageType: NETWORK_MESSAGE_TYPES.RESPONSES.NACK,
messageData: { errorMessage: 'Invalid neighbourhood' },
Expand Down
18 changes: 17 additions & 1 deletion src/commands/protocols/common/network-protocol-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,34 @@ class NetworkProtocolCommand extends Command {
constructor(ctx) {
super(ctx);
this.commandExecutor = ctx.commandExecutor;
this.blockchainModuleManager = ctx.blockchainModuleManager;
this.serviceAgreementService = ctx.serviceAgreementService;
}

/**
* Executes command and produces one or more events
* @param command
*/
async execute(command) {
const { blockchain } = command.data;
const { blockchain, contract, tokenId, hashFunctionId } = command.data;

const keywords = await this.getKeywords(command);
const batchSize = await this.getBatchSize(blockchain);
const minAckResponses = await this.getMinAckResponses(blockchain);

const serviceAgreementId = await this.serviceAgreementService.generateId(
blockchain,
contract,
tokenId,
keywords[0],
hashFunctionId,
);
const proximityScoreFunctionsPairId =
await this.blockchainModuleManager.getAgreementScoreFunctionId(
blockchain,
serviceAgreementId,
);

const commandSequence = [
'findNodesCommand',
`${this.operationService.getOperationName()}ScheduleMessagesCommand`,
Expand All @@ -34,6 +49,7 @@ class NetworkProtocolCommand extends Command {
minAckResponses,
errorType: this.errorType,
networkProtocols: this.operationService.getNetworkProtocols(),
proximityScoreFunctionsPairId,
},
transactional: false,
}),
Expand Down
19 changes: 17 additions & 2 deletions src/commands/protocols/common/protocol-init-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@ import { NETWORK_MESSAGE_TYPES } from '../../../constants/constants.js';

class ProtocolInitCommand extends ProtocolMessageCommand {
async prepareMessage(command) {
const { assertionId, contract, tokenId, keyword, hashFunctionId } = command.data;
const {
assertionId,
contract,
tokenId,
keyword,
hashFunctionId,
proximityScoreFunctionsPairId,
} = command.data;

// TODO: Backwards compatibility, send blockchain without chainId
const blockchain = command.data.blockchain.split(':')[0];

return { assertionId, blockchain, contract, tokenId, keyword, hashFunctionId };
return {
assertionId,
blockchain,
contract,
tokenId,
keyword,
hashFunctionId,
proximityScoreFunctionsPairId,
};
}

async execute(command) {
Expand Down
Loading

0 comments on commit 53ff733

Please sign in to comment.