Skip to content

Commit

Permalink
Merge pull request #2120 from OriginTrail/v6/develop
Browse files Browse the repository at this point in the history
OriginTrail 6.0.0-beta.2.2.5 Testnet Prerelease
  • Loading branch information
zeroxbt authored Oct 13, 2022
2 parents d4e7d35 + 3135b9a commit c320dff
Show file tree
Hide file tree
Showing 55 changed files with 17,119 additions and 28,000 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @branarakic @djordjekovac @kotlarmilos @NZT48
* @branarakic @djordjekovac @kotlarmilos @NZT48 @zeroxbt
2 changes: 1 addition & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -627,4 +627,4 @@
"publicOperations": []
}
}
}
}
43,815 changes: 16,357 additions & 27,458 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"@openzeppelin/contracts": "^4.7.3",
"@polkadot/util": "^10.1.7",
"@polkadot/util-crypto": "^10.1.7",
"@truffle/hdwallet-provider": "^2.0.14",
"@truffle/hdwallet-provider": "^2.0.16",
"chai": "^4.3.6",
"dkg.js": "^6.0.0-beta.3.0.4",
"dkg.js": "^6.0.0-beta.3.1.2",
"eslint": "^8.23.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -58,8 +58,7 @@
"prettier": "^2.7.1",
"sinon": "^14.0.0",
"slugify": "^1.6.5",
"solhint": "^3.3.7",
"truffle": "^5.5.29"
"solhint": "^3.3.7"
},
"dependencies": {
"@chainsafe/libp2p-noise": "^8.0.1",
Expand All @@ -72,7 +71,7 @@
"@libp2p/tcp": "^3.1.2",
"@multiformats/multiaddr": "^11.0.1",
"@polkadot/api": "^9.3.2",
"@tracelabs/kad-dht": "^3.0.6",
"@tracelabs/kad-dht": "^3.1.0",
"app-root-path": "^3.1.0",
"assertion-tools": "^1.0.9",
"async": "^3.2.4",
Expand Down
19 changes: 13 additions & 6 deletions src/commands/protocols/common/find-nodes-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@ class FindNodesCommand extends Command {
* @param command
*/
async execute(command) {
const { keyword, operationId, minimumAckResponses, networkProtocol, errorType } =
const { keyword, operationId, minimumAckResponses, errorType, networkProtocols } =
command.data;

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

const closestNodes = await this.findNodes(keyword, networkProtocol, operationId);
const closestNodes = [];
for (const node of await this.findNodes(keyword, operationId)) {
for (const protocol of networkProtocols) {
if (node.protocols.includes(protocol)) {
closestNodes.push({ id: node.id, protocol });
break;
}
}
}

this.logger.debug(`Found ${closestNodes.length} node(s) for keyword ${keyword}`);

const batchSize = 2 * minimumAckResponses;
if (closestNodes.length < batchSize) {
this.handleError(
operationId,
`Unable to find enough nodes for ${networkProtocol}. Minimum number of nodes required: ${batchSize}`,
`Unable to find enough nodes for ${operationId}. Minimum number of nodes required: ${batchSize}`,
this.errorType,
true,
);
Expand All @@ -43,7 +51,7 @@ class FindNodesCommand extends Command {
);
}

async findNodes(keyword, networkProtocol, operationId) {
async findNodes(keyword, operationId) {
await this.operationIdService.updateOperationIdStatus(
operationId,
OPERATION_ID_STATUS.FIND_NODES_START,
Expand All @@ -55,7 +63,6 @@ class FindNodesCommand extends Command {

const { nodes: closestNodes, telemetryData } = await this.networkModuleManager.findNodes(
keyword,
networkProtocol,
);

const promises = [];
Expand Down Expand Up @@ -118,7 +125,7 @@ class FindNodesCommand extends Command {

let differences = 0;
for (const closestNode of closestNodes) {
if (!localPeers.includes(closestNode.toString())) {
if (!localPeers.includes(closestNode.id.toString())) {
differences += 1;
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/commands/protocols/common/find-nodes-local-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import FindNodesCommand from './find-nodes-command.js';
import { OPERATION_ID_STATUS } from '../../../constants/constants.js';

class FindNodesLocalCommand extends FindNodesCommand {
async findNodes(keyword, networkProtocol, operationId) {
async findNodes(keyword, operationId) {
await this.operationIdService.updateOperationIdStatus(
operationId,
OPERATION_ID_STATUS.FIND_NODES_LOCAL_START,
);

const closestNodes = await this.networkModuleManager.findNodesLocal(
keyword,
networkProtocol,
);
const closestNodes = await this.networkModuleManager.findNodesLocal(keyword);

await this.operationIdService.updateOperationIdStatus(
operationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { NETWORK_MESSAGE_TYPES } from '../../../constants/constants.js';
class HandleProtocolMessageCommand extends Command {
constructor(ctx) {
super(ctx);
this.config = ctx.config;
this.networkModuleManager = ctx.networkModuleManager;
this.operationIdService = ctx.operationIdService;
}
Expand All @@ -14,12 +13,12 @@ class HandleProtocolMessageCommand extends Command {
* @param command
*/
async execute(command) {
const { remotePeerId, operationId, keywordUuid } = command.data;
const { remotePeerId, operationId, keywordUuid, networkProtocols } = command.data;

try {
const { messageType, messageData } = await this.prepareMessage(command.data);
await this.networkModuleManager.sendMessageResponse(
this.operationService.getNetworkProtocol(),
networkProtocols,
remotePeerId,
messageType,
operationId,
Expand All @@ -42,11 +41,11 @@ class HandleProtocolMessageCommand extends Command {
}

async handleError(errorMessage, command) {
const { operationId, remotePeerId, keywordUuid } = command.data;
const { operationId, remotePeerId, keywordUuid, networkProtocols } = command.data;

await super.handleError(operationId, errorMessage, this.errorType, true);
await this.networkModuleManager.sendMessageResponse(
this.operationService.getNetworkProtocol(),
networkProtocols,
remotePeerId,
NETWORK_MESSAGE_TYPES.RESPONSES.NACK,
operationId,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/protocols/common/network-protocol-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NetworkProtocolCommand extends Command {
keyword,
minimumAckResponses: this.operationService.getMinimumAckResponses(),
errorType: this.errorType,
networkProtocol: this.operationService.getNetworkProtocol(),
networkProtocols: this.operationService.getNetworkProtocols(),
},
transactional: false,
}),
Expand Down
4 changes: 2 additions & 2 deletions src/commands/protocols/common/protocol-message-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class ProtocolMessageCommand extends Command {
const { node, operationId, keyword } = command.data;

const response = await this.networkModuleManager.sendMessage(
this.operationService.getNetworkProtocol(),
node,
node.protocol,
node.id,
messageType,
operationId,
keyword,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@ class ProtocolScheduleMessagesCommand extends Command {
constructor(ctx) {
super(ctx);
this.commandExecutor = ctx.commandExecutor;
this.protocolService = ctx.protocolService;
}

/**
* Executes command and produces one or more events
* @param command
*/
async execute(command) {
const { operationId, keyword, leftoverNodes, batchSize, nodesSeen = [] } = command.data;
const { operationId, keyword, batchSize, leftoverNodes, nodesSeen = [] } = command.data;

const currentBatchNodes = leftoverNodes.slice(0, batchSize);
const currentBatchLeftoverNodes =
batchSize < leftoverNodes.length ? leftoverNodes.slice(batchSize) : [];
currentBatchNodes.forEach((node) => nodesSeen.push(node.toString()));
currentBatchNodes.forEach((node) => nodesSeen.push(node.id.toString()));

await this.operationIdService.updateOperationIdStatus(operationId, this.startEvent);

const commandSequence = [
`${this.operationService.getOperationName()}InitCommand`,
`${this.operationService.getOperationName()}RequestCommand`,
];

this.logger.debug(
`Trying to ${this.operationService.getOperationName()} to batch of ${
currentBatchNodes.length
Expand All @@ -33,8 +29,9 @@ class ProtocolScheduleMessagesCommand extends Command {
}`,
);

const addCommandPromises = currentBatchNodes.map((node) =>
this.commandExecutor.add({
const addCommandPromises = currentBatchNodes.map(async (node) => {
const commandSequence = this.protocolService.getSenderCommandSequence(node.protocol);
await this.commandExecutor.add({
name: commandSequence[0],
sequence: commandSequence.slice(1),
delay: 0,
Expand All @@ -45,15 +42,14 @@ class ProtocolScheduleMessagesCommand extends Command {
node,
numberOfFoundNodes: currentBatchLeftoverNodes.length + nodesSeen.length,
batchSize,

leftoverNodes: currentBatchLeftoverNodes,
nodesSeen,
},
period: 5000,
retries: 3,
transactional: false,
}),
);
});
});

await Promise.all(addCommandPromises);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import HandleProtocolMessageCommand from '../../common/handle-protocol-message-command.js';
import HandleProtocolMessageCommand from '../../../common/handle-protocol-message-command.js';

import {
ERROR_TYPE,
NETWORK_MESSAGE_TYPES,
OPERATION_ID_STATUS,
} from '../../../../constants/constants.js';
} from '../../../../../constants/constants.js';

class HandleGetInitCommand extends HandleProtocolMessageCommand {
constructor(ctx) {
Expand All @@ -30,14 +30,14 @@ class HandleGetInitCommand extends HandleProtocolMessageCommand {
message.messageType = NETWORK_MESSAGE_TYPES.RESPONSES.ACK;
message.messageData = {};
} else {
const nodeIds = await this.networkModuleManager.findNodesLocal(
const peers = await this.networkModuleManager.findNodesLocal(
assertionId,
networkProtocol,
);

message.messageType = NETWORK_MESSAGE_TYPES.RESPONSES.NACK;
message.messageData = {
nodes: await this.networkModuleManager.serializePeers(nodeIds),
nodes: await this.networkModuleManager.serializePeers(peers),
};
}

Expand All @@ -56,7 +56,7 @@ class HandleGetInitCommand extends HandleProtocolMessageCommand {
*/
default(map) {
const command = {
name: 'handleGetInitCommand',
name: 'v1_0_0HandleGetInitCommand',
delay: 0,
transactional: false,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import HandleProtocolMessageCommand from '../../common/handle-protocol-message-command.js';
import HandleProtocolMessageCommand from '../../../common/handle-protocol-message-command.js';

import {
ERROR_TYPE,
NETWORK_MESSAGE_TYPES,
OPERATION_ID_STATUS,
} from '../../../../constants/constants.js';
} from '../../../../../constants/constants.js';

class HandleGetRequestCommand extends HandleProtocolMessageCommand {
constructor(ctx) {
Expand Down Expand Up @@ -43,7 +43,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
*/
default(map) {
const command = {
name: 'handleGetRequestCommand',
name: 'v1_0_0HandleGetRequestCommand',
delay: 0,
transactional: false,
errorType: ERROR_TYPE.HANDLE_GET_REQUEST_ERROR,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import ProtocolInitCommand from '../../common/protocol-init-command.js';
import { ERROR_TYPE, OPERATION_REQUEST_STATUS } from '../../../../constants/constants.js';
import Command from '../../../command.js';
import ProtocolInitCommand from '../../../common/protocol-init-command.js';
import { ERROR_TYPE, OPERATION_REQUEST_STATUS } from '../../../../../constants/constants.js';
import Command from '../../../../command.js';

class GetInitCommand extends ProtocolInitCommand {
constructor(ctx) {
super(ctx);
this.operationService = ctx.getService;
this.repositoryModuleManager = ctx.repositoryModuleManager;

this.errorType = ERROR_TYPE.GET.GET_INIT_ERROR;
}
Expand All @@ -33,7 +32,7 @@ class GetInitCommand extends ProtocolInitCommand {
*/
default(map) {
const command = {
name: 'getInitCommand',
name: 'v1_0_0GetInitCommand',
delay: 0,
retries: 0,
transactional: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ProtocolRequestCommand from '../../common/protocol-request-command.js';
import { ERROR_TYPE } from '../../../../constants/constants.js';
import ProtocolRequestCommand from '../../../common/protocol-request-command.js';
import { ERROR_TYPE } from '../../../../../constants/constants.js';

class GetRequestCommand extends ProtocolRequestCommand {
constructor(ctx) {
Expand All @@ -22,7 +22,7 @@ class GetRequestCommand extends ProtocolRequestCommand {
*/
default(map) {
const command = {
name: 'getRequestCommand',
name: 'v1_0_0GetRequestCommand',
delay: 0,
retries: 0,
transactional: false,
Expand Down
Loading

0 comments on commit c320dff

Please sign in to comment.