Skip to content

Commit

Permalink
Merge pull request #2881 from OriginTrail/v6/develop
Browse files Browse the repository at this point in the history
OriginTrail Devnet prerelease v6.1.3
  • Loading branch information
NZT48 authored Jan 12, 2024
2 parents 509a24e + d411166 commit 529f2eb
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 50 deletions.
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
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "6.1.2",
"version": "6.1.3",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down
17 changes: 14 additions & 3 deletions src/commands/common/send-telemetry-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SendTelemetryCommand extends Command {
this.config = ctx.config;
this.networkModuleManager = ctx.networkModuleManager;
this.blockchainModuleManager = ctx.blockchainModuleManager;
this.tripleStoreModuleManager = ctx.tripleStoreModuleManager;
this.repositoryModuleManager = ctx.repositoryModuleManager;
this.telemetryModuleManager = ctx.telemetryModuleManager;
}
Expand All @@ -31,8 +32,8 @@ class SendTelemetryCommand extends Command {
try {
const events = (await this.getUnpublishedEvents()) || [];
const blockchainsNodeInfo = [];
const implementations = this.blockchainModuleManager.getImplementationNames();
for (const implementation of implementations) {
const blockchainImplementations = this.blockchainModuleManager.getImplementationNames();
for (const implementation of blockchainImplementations) {
const blockchainInfo = {
blockchain_id: implementation,
// eslint-disable-next-line no-await-in-loop
Expand All @@ -43,11 +44,21 @@ class SendTelemetryCommand extends Command {
};
blockchainsNodeInfo.push(blockchainInfo);
}

const tripleStoreNodeInfo = [];
const tripleStoreImplementations =
this.tripleStoreModuleManager.getImplementationNames();
for (const implementation of tripleStoreImplementations) {
const tripleStoreInfo = {
implementationName: implementation,
};
tripleStoreNodeInfo.push(tripleStoreInfo);
}
const nodeData = {
version: pjson.version,
identity: this.networkModuleManager.getPeerId().toB58String(),
hostname: this.config.hostname,
triple_store: this.config.modules.tripleStore.defaultImplementation,
triple_stores: tripleStoreNodeInfo,
auto_update_enabled: this.config.modules.autoUpdater.enabled,
multiaddresses: this.networkModuleManager.getMultiaddrs(),
blockchains: blockchainsNodeInfo,
Expand Down
34 changes: 33 additions & 1 deletion src/commands/protocols/common/submit-commit-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,17 @@ class SubmitCommitCommand extends Command {
);
});

const sendSubmitCommitTransactionOperationId = this.operationIdService.generateId();
let txSuccess;
try {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_START,
sendSubmitCommitTransactionOperationId,
blockchain,
agreementId,
epoch,
operationId,
);
txSuccess = await transactionCompletePromise;
} catch (error) {
this.logger.warn(
Expand All @@ -121,7 +130,14 @@ class SubmitCommitCommand extends Command {
`Epoch: ${epoch}, State Index: ${stateIndex}, Operation ID: ${operationId}, ` +
`Retry number: ${COMMAND_RETRIES.SUBMIT_COMMIT - command.retries + 1}.`,
);

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR,
sendSubmitCommitTransactionOperationId,
blockchain,
error.message,
this.errorType,
operationId,
);
let newGasPrice;
if (
error.message.includes(`timeout exceeded`) ||
Expand All @@ -142,6 +158,14 @@ class SubmitCommitCommand extends Command {

let msgBase;
if (txSuccess) {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_END,
sendSubmitCommitTransactionOperationId,
blockchain,
agreementId,
epoch,
operationId,
);
msgBase = 'Successfully executed';

this.operationIdService.emitChangeEvent(
Expand All @@ -153,6 +177,14 @@ class SubmitCommitCommand extends Command {
);
} else {
msgBase = 'Node has already submitted commit. Finishing';
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR,
sendSubmitCommitTransactionOperationId,
blockchain,
msgBase,
this.errorType,
operationId,
);
}

this.logger.trace(
Expand Down
31 changes: 29 additions & 2 deletions src/commands/protocols/common/submit-proofs-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,16 @@ class SubmitProofsCommand extends Command {
txGasPrice,
);
});

const sendSubmitProofsTransactionOperationId = this.operationIdService.generateId();
let txSuccess;
try {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_START,
sendSubmitProofsTransactionOperationId,
blockchain,
agreementId,
epoch,
);
txSuccess = await transactionCompletePromise;
} catch (error) {
this.logger.warn(
Expand All @@ -173,7 +180,13 @@ class SubmitProofsCommand extends Command {
`Epoch: ${epoch}, State Index: ${stateIndex}, Operation ID: ${operationId}, ` +
`Retry number: ${COMMAND_RETRIES.SUBMIT_PROOFS - command.retries + 1}.`,
);

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR,
sendSubmitProofsTransactionOperationId,
blockchain,
error.message,
this.errorType,
);
let newGasPrice;
if (
error.message.includes(`timeout exceeded`) ||
Expand All @@ -194,6 +207,13 @@ class SubmitProofsCommand extends Command {

let msgBase;
if (txSuccess) {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_PROOFS_SEND_TX_START,
sendSubmitProofsTransactionOperationId,
blockchain,
agreementId,
epoch,
);
msgBase = 'Successfully executed';

this.operationIdService.emitChangeEvent(
Expand All @@ -205,6 +225,13 @@ class SubmitProofsCommand extends Command {
);
} else {
msgBase = 'Node has already sent proof. Finishing';
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR,
sendSubmitProofsTransactionOperationId,
blockchain,
msgBase,
this.errorType,
);
}

this.logger.trace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand {
constructor(ctx) {
super(ctx);
this.operationService = ctx.publishService;
this.serviceAgreementService = ctx.serviceAgreementService;
this.blockchainModuleManager = ctx.blockchainModuleManager;
this.repositoryModuleManager = ctx.repositoryModuleManager;

this.startEvent = OPERATION_ID_STATUS.PUBLISH.PUBLISH_REPLICATE_START;
this.errorType = ERROR_TYPE.PUBLISH.PUBLISH_START_ERROR;
Expand All @@ -26,7 +29,7 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand {
} = command.data;
let isValid = true;
// perform check only first time not for every batch
if (leftoverNodes === numberOfFoundNodes) {
if (leftoverNodes.length === numberOfFoundNodes) {
isValid = await this.validateBidsForNeighbourhood(
blockchain,
contract,
Expand Down Expand Up @@ -90,15 +93,15 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand {

let validBids = 0;

nodes.forEach((node) => {
const askNumber = this.blockchainModuleManager.convertToWei(blockchain, node.ask);

const ask = this.blockchainModuleManager.toBigNumber(blockchain, askNumber);
await Promise.all(
nodes.map(async (node) => {
const ask = await this.getAsk(blockchain, node.id);
if (ask.lte(serviceAgreementBid)) {
validBids += 1;
}
}),
);

if (ask.lte(serviceAgreementBid)) {
validBids += 1;
}
});
if (validBids < minAckResponses) {
await this.operationService.markOperationAsFailed(
operationId,
Expand All @@ -111,6 +114,13 @@ class PublishScheduleMessagesCommand extends ProtocolScheduleMessagesCommand {
return true;
}

async getAsk(blockchain, nodeId) {
const peerRecord = await this.repositoryModuleManager.getPeerRecord(nodeId, blockchain);
const ask = this.blockchainModuleManager.convertToWei(blockchain, peerRecord.ask);

return this.blockchainModuleManager.toBigNumber(blockchain, ask);
}

/**
* Builds default publishScheduleMessagesCommand
* @param map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,23 @@ class SubmitUpdateCommitCommand extends Command {
);
});

const sendSubmitUpdateCommitTransactionOperationId = this.operationIdService.generateId();
try {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_UPDATE_COMMIT_SEND_TX_START,
sendSubmitUpdateCommitTransactionOperationId,
blockchain,
agreementId,
epoch,
);
await transactionCompletePromise;
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_UPDATE_COMMIT_SEND_TX_END,
sendSubmitUpdateCommitTransactionOperationId,
blockchain,
agreementId,
epoch,
);
} catch (error) {
this.logger.warn(
`Failed to execute ${command.name}, Error Message: ${error.message} for the Service Agreement ` +
Expand All @@ -100,7 +115,13 @@ class SubmitUpdateCommitCommand extends Command {
COMMAND_RETRIES.SUBMIT_UPDATE_COMMIT - command.retries + 1
}.`,
);

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_SEND_TX_ERROR,
sendSubmitUpdateCommitTransactionOperationId,
blockchain,
error.message,
this.errorType,
);
let newGasPrice;
if (
error.message.includes(`timeout exceeded`) ||
Expand Down
13 changes: 13 additions & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,11 @@ export const ERROR_TYPE = {
CALCULATE_PROOFS_ERROR: 'CalculateProofsError',
EPOCH_CHECK_ERROR: 'EpochCheckError',
SUBMIT_COMMIT_ERROR: 'SubmitCommitError',
SUBMIT_COMMIT_SEND_TX_ERROR: 'SubmitCommitSendTxError',
SUBMIT_PROOFS_ERROR: 'SubmitProofsError',
SUBMIT_PROOFS_SEND_TX_ERROR: 'SubmitProofsSendTxError',
SUBMIT_UPDATE_COMMIT_ERROR: 'SubmitUpdateCommitError',
SUBMIT_UPDATE_COMMIT_SEND_TX_ERROR: 'SubmitUpdateCommitSendTxError',
},
};
export const OPERATION_ID_STATUS = {
Expand Down Expand Up @@ -344,12 +347,18 @@ export const OPERATION_ID_STATUS = {
EPOCH_CHECK_END: 'EPOCH_CHECK_END',
SUBMIT_COMMIT_START: 'SUBMIT_COMMIT_START',
SUBMIT_COMMIT_END: 'SUBMIT_COMMIT_END',
SUBMIT_COMMIT_SEND_TX_START: 'SUBMIT_COMMIT_SEND_TX_START',
SUBMIT_COMMIT_SEND_TX_END: 'SUBMIT_COMMIT_SEND_TX_END',
CALCULATE_PROOFS_START: 'CALCULATE_PROOFS_START',
CALCULATE_PROOFS_END: 'CALCULATE_PROOFS_END',
SUBMIT_PROOFS_START: 'SUBMIT_PROOFS_START',
SUBMIT_PROOFS_END: 'SUBMIT_PROOFS_END',
SUBMIT_PROOFS_SEND_TX_START: 'SUBMIT_PROOFS_START',
SUBMIT_PROOFS_SEND_TX_END: 'SUBMIT_PROOFS_END',
SUBMIT_UPDATE_COMMIT_START: 'SUBMIT_UPDATE_COMMIT_START',
SUBMIT_UPDATE_COMMIT_END: 'SUBMIT_UPDATE_COMMIT_END',
SUBMIT_UPDATE_COMMIT_SEND_TX_START: 'SUBMIT_UPDATE_COMMIT_START',
SUBMIT_UPDATE_COMMIT_SEND_TX_END: 'SUBMIT_UPDATE_COMMIT_END',
},
QUERY: {
QUERY_INIT_START: 'QUERY_INIT_START',
Expand Down Expand Up @@ -576,6 +585,10 @@ export const NODE_ENVIRONMENTS = {
MAINNET: 'mainnet',
};

export const MAXIMUM_FETCH_EVENTS_FAILED_COUNT = 1000;

export const DELAY_BETWEEN_FAILED_FETCH_EVENTS_MILLIS = 10 * 1000;

export const CONTRACT_EVENT_FETCH_INTERVALS = {
MAINNET: 10 * 1000,
DEVELOPMENT: 4 * 1000,
Expand Down
4 changes: 4 additions & 0 deletions src/modules/blockchain/blockchain-module-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ class BlockchainModuleManager extends BaseModuleManager {
]);
}

async getAssertionData(blockchain, assertionid) {
return this.callImplementationFunction(blockchain, 'getAssertionData', [assertionid]);
}

submitCommit(
blockchain,
assetContractAddress,
Expand Down
14 changes: 14 additions & 0 deletions src/modules/blockchain/implementation/web3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,20 @@ class Web3Service {
return Number(assertionChunksNumber);
}

async getAssertionData(assertionId) {
const assertionData = await this.callContractFunction(
this.AssertionStorageContract,
'getAssertion',
[assertionId],
);
return {
timestamp: Number(assertionData.timestamp),
size: Number(assertionData.size),
triplesNumber: Number(assertionData.triplesNumber),
chunksNumber: Number(assertionData.chunksNumber),
};
}

selectCommitManagerContract(latestStateIndex) {
return latestStateIndex === 0
? this.CommitManagerV1Contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default (authService) => async (req, res, next) => {
const match = req.path.match(/^\/(?:v[0-9]+\/)?([^\/\?]+)/);
if (!match) return res.status(404).send('Not found.');

const operation = match[0].substring(1);
const operation = match[0].substring(1).toUpperCase();

if (authService.isPublicOperation(operation)) {
return next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default (authService) => async (req, res, next) => {
const match = req.path.match(/^\/(?:v[0-9]+\/)?([^\/\?]+)/);
if (!match) return res.status(404).send('Not found.');

const operation = match[0].substring(1);
const operation = match[0].substring(1).toUpperCase();

if (authService.isPublicOperation(operation)) {
return next();
Expand Down
Loading

0 comments on commit 529f2eb

Please sign in to comment.