diff --git a/package.json b/package.json index 11eec6e27d..78fca32837 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.0.18", + "version": "6.0.19", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/protocols/common/epoch-check-command.js b/src/commands/protocols/common/epoch-check-command.js index 3d674f498b..330a700f09 100644 --- a/src/commands/protocols/common/epoch-check-command.js +++ b/src/commands/protocols/common/epoch-check-command.js @@ -5,6 +5,7 @@ import { COMMAND_RETRIES, TRANSACTION_CONFIRMATIONS, OPERATION_ID_STATUS, + ERROR_TYPE, } from '../../../constants/constants.js'; class EpochCheckCommand extends Command { @@ -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) { @@ -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, @@ -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, @@ -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(); } diff --git a/src/commands/protocols/common/submit-proofs-command.js b/src/commands/protocols/common/submit-proofs-command.js index 7e26edf5c5..699f7e2cb3 100644 --- a/src/commands/protocols/common/submit-proofs-command.js +++ b/src/commands/protocols/common/submit-proofs-command.js @@ -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, diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js index 63545eedf2..5f7478ec2f 100644 --- a/src/modules/blockchain/implementation/web3-service.js +++ b/src/modules/blockchain/implementation/web3-service.js @@ -61,7 +61,7 @@ class Web3Service { await this.initializeWeb3(); this.startBlock = await this.getBlockNumber(); await this.initializeContracts(); - // this.initializeProviderDebugging(); + this.initializeProviderDebugging(); } initializeTransactionQueue(concurrency) { @@ -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}.`; @@ -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}`), ); } } @@ -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}`, + ), ); }