Skip to content

Commit

Permalink
Merge pull request #2778 from OriginTrail/v6/prerelease/mainnet
Browse files Browse the repository at this point in the history
OriginTrail Mainnet Release v6.0.19
  • Loading branch information
NZT48 authored Nov 9, 2023
2 parents 719b189 + 5f7b303 commit 9a4c91f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 73 deletions.
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.0.18",
"version": "6.0.19",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down
127 changes: 75 additions & 52 deletions src/commands/protocols/common/epoch-check-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
COMMAND_RETRIES,
TRANSACTION_CONFIRMATIONS,
OPERATION_ID_STATUS,
ERROR_TYPE,
} from '../../../constants/constants.js';

class EpochCheckCommand extends Command {
Expand All @@ -16,6 +17,8 @@ class EpochCheckCommand extends Command {
this.shardingTableService = ctx.shardingTableService;
this.blockchainModuleManager = ctx.blockchainModuleManager;
this.serviceAgreementService = ctx.serviceAgreementService;

this.errorType = ERROR_TYPE.COMMIT_PROOF.EPOCH_CHECK_ERROR;
}

async execute(command) {
Expand Down Expand Up @@ -99,43 +102,56 @@ class EpochCheckCommand extends Command {
for (const serviceAgreement of eligibleAgreementForSubmitCommit) {
if (scheduleSubmitCommitCommands.length >= maxTransactions) break;

const rank = await this.calculateRank(
blockchain,
serviceAgreement.keyword,
serviceAgreement.hashFunctionId,
r2,
);

updateServiceAgreementsLastCommitEpoch.push(
this.repositoryModuleManager.updateServiceAgreementLastCommitEpoch(
serviceAgreement.agreementId,
serviceAgreement.currentEpoch,
),
);
try {
const rank = await this.calculateRank(
blockchain,
serviceAgreement.keyword,
serviceAgreement.hashFunctionId,
r2,
);

if (rank == null) {
this.logger.trace(
`Node not in R2: ${r2} for agreement id: ${serviceAgreement.agreementId}. Skipping scheduling submit commit command.`,
updateServiceAgreementsLastCommitEpoch.push(
this.repositoryModuleManager.updateServiceAgreementLastCommitEpoch(
serviceAgreement.agreementId,
serviceAgreement.currentEpoch,
),
);
continue;
}

if (rank >= r0) {
if (rank == null) {
this.logger.trace(
`Node not in R2: ${r2} for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Skipping scheduling submitCommitCommand.`,
);
continue;
}

if (rank >= r0) {
this.logger.trace(
`Calculated rank: ${
rank + 1
}. Node not in R0: ${r0} for the Service Agreement with the ID: ${
serviceAgreement.agreementId
}. Skipping scheduling submitCommitCommand.`,
);
continue;
}

this.logger.trace(
`Calculated rank: ${rank + 1}. Node not in R0: ${r0} for agreement id: ${
`Calculated rank: ${
rank + 1
}. Node in R0: ${r0} for the Service Agreement with the ID: ${
serviceAgreement.agreementId
}. Skipping scheduling submit commit command.`,
}. Scheduling submitCommitCommand.`,
);

scheduleSubmitCommitCommands.push(
this.scheduleSubmitCommitCommand(serviceAgreement),
);
} catch (error) {
this.logger.warn(
`Failed to schedule submitCommitCommand for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Error message: ${error.message}.`,
);
continue;
}

this.logger.trace(
`Calculated rank: ${rank + 1}. Node in R0: ${r0} for agreement id: ${
serviceAgreement.agreementId
}. Scheduling submit commit command.`,
);

scheduleSubmitCommitCommands.push(this.scheduleSubmitCommitCommand(serviceAgreement));
}
await Promise.all([
...scheduleSubmitCommitCommands,
Expand All @@ -161,32 +177,39 @@ class EpochCheckCommand extends Command {
for (const serviceAgreement of eligibleAgreementsForSubmitProofs) {
if (scheduleSubmitProofCommands.length >= maxTransactions) break;

const eligibleForReward = await this.isEligibleForRewards(
blockchain,
serviceAgreement.agreementId,
serviceAgreement.currentEpoch,
serviceAgreement.stateIndex,
r0,
);
if (eligibleForReward) {
this.logger.trace(
`Node is eligible for rewards for agreement id: ${serviceAgreement.agreementId}. Scheduling submit proof command.`,
try {
const eligibleForReward = await this.isEligibleForRewards(
blockchain,
serviceAgreement.agreementId,
serviceAgreement.currentEpoch,
serviceAgreement.stateIndex,
r0,
);

scheduleSubmitProofCommands.push(
this.scheduleSubmitProofsCommand(serviceAgreement),
if (eligibleForReward) {
this.logger.trace(
`Node is eligible for rewards for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Scheduling submitProofsCommand.`,
);

scheduleSubmitProofCommands.push(
this.scheduleSubmitProofsCommand(serviceAgreement),
);
} else {
this.logger.trace(
`Node is not eligible for rewards for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Skipping scheduling submitProofsCommand.`,
);
}
updateServiceAgreementsLastProofEpoch.push(
this.repositoryModuleManager.updateServiceAgreementLastProofEpoch(
serviceAgreement.agreementId,
serviceAgreement.currentEpoch,
),
);
} else {
this.logger.trace(
`Node is not eligible for rewards for agreement id: ${serviceAgreement.agreementId}. Skipping scheduling submit proof command.`,
} catch (error) {
this.logger.warn(
`Failed to schedule submitProofsCommand for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Error message: ${error.message}.`,
);
continue;
}
updateServiceAgreementsLastProofEpoch.push(
this.repositoryModuleManager.updateServiceAgreementLastProofEpoch(
serviceAgreement.agreementId,
serviceAgreement.currentEpoch,
),
);
}
await Promise.all([
...scheduleSubmitProofCommands,
Expand Down Expand Up @@ -326,7 +349,7 @@ class EpochCheckCommand extends Command {
* @param error
*/
async recover(command, error) {
this.logger.warn(`Failed to execute ${command.name}: error: ${error.message}`);
this.logger.warn(`Failed to execute ${command.name}; Error: ${error.message}`);

return Command.repeat();
}
Expand Down
8 changes: 0 additions & 8 deletions src/commands/protocols/common/submit-proofs-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ class SubmitProofsCommand extends Command {
return Command.empty();
}

if (proof.length === 0) {
const errorMessage = `Error during Merkle Proof calculation for blockchain: ${blockchain} agreement id: ${agreementId}, epoch: ${epoch}, state index: ${stateIndex}, proof cannot be empty`;
this.logger.trace(errorMessage);

await this.handleError(operationId, errorMessage, this.errorType, true);
return Command.empty();
}

const transactionCompletePromise = new Promise((resolve, reject) => {
this.blockchainModuleManager.sendProof(
blockchain,
Expand Down
46 changes: 34 additions & 12 deletions src/modules/blockchain/implementation/web3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Web3Service {
await this.initializeWeb3();
this.startBlock = await this.getBlockNumber();
await this.initializeContracts();
// this.initializeProviderDebugging();
this.initializeProviderDebugging();
}

initializeTransactionQueue(concurrency) {
Expand Down Expand Up @@ -189,32 +189,38 @@ class Web3Service {
const { method } = info.request;

if (['call', 'estimateGas'].includes(method)) {
const contractInstance = this.contractAddresses[info.request.params.to];
const inputData = info.request.params.data;
const contractInstance = this.contractAddresses[info.request.params.transaction.to];
const inputData = info.request.params.transaction.data;
const decodedInputData = this._decodeInputData(
inputData,
contractInstance.interface,
);

const functionFragment = contractInstance.interface.getFunction(
inputData.slice(0, 10),
);
const functionName = functionFragment.name;
const inputs = functionFragment.inputs.map(
(input, i) => `${input.name}=${decodedInputData[i]}`,
);
if (info.backend.error) {
const decodedErrorData = this._decodeErrorData(
info.backend.error,
contractInstance.interface,
);
this.logger.debug(
`${decodedInputData} ${method} has failed; Error: ${decodedErrorData}; ` +
`${functionName}(${inputs}) ${method} has failed; Error: ${decodedErrorData}; ` +
`RPC: ${info.backend.provider.connection.url}.`,
);
} else if (info.backend.result !== undefined) {
let message = `${decodedInputData} ${method} has been successfully executed; `;
let message = `${functionName}(${inputs}) ${method} has been successfully executed; `;

if (info.backend.result !== null) {
if (info.backend.result !== null && method !== 'estimateGas') {
const decodedResultData = this._decodeResultData(
inputData.slice(0, 10),
info.backend.result,
contractInstance.interface,
);
message += `Result: ${decodedResultData} `;
message += `Result: ${decodedResultData}; `;
}

message += `RPC: ${info.backend.provider.connection.url}.`;
Expand Down Expand Up @@ -395,10 +401,17 @@ class Web3Service {
result = await contractInstance[functionName](...args);
} catch (error) {
const decodedErrorData = this._decodeErrorData(error, contractInstance.interface);

const functionFragment = contractInstance.interface.getFunction(
error.transaction.data.slice(0, 10),
);
const inputs = functionFragment.inputs.map(
(input, i) => `${input.name}=${args[i]}`,
);

// eslint-disable-next-line no-await-in-loop
await this.handleError(
Error(`Call failed, reason: ${decodedErrorData}`),
functionName,
Error(`Call ${functionName}(${inputs}) failed, reason: ${decodedErrorData}`),
);
}
}
Expand All @@ -419,9 +432,18 @@ class Web3Service {
gasLimit = await contractInstance.estimateGas[functionName](...args);
} catch (error) {
const decodedErrorData = this._decodeErrorData(error, contractInstance.interface);

const functionFragment = contractInstance.interface.getFunction(
error.transaction.data.slice(0, 10),
);
const inputs = functionFragment.inputs.map(
(input, i) => `${input.name}=${args[i]}`,
);

await this.handleError(
Error(`Gas estimation failed, reason: ${decodedErrorData}`),
functionName,
Error(
`Gas estimation ${functionName}(${inputs}) failed, reason: ${decodedErrorData}`,
),
);
}

Expand Down

0 comments on commit 9a4c91f

Please sign in to comment.