Skip to content

Commit

Permalink
Merge pull request #3103 from OriginTrail/v6/prerelease/mainnet
Browse files Browse the repository at this point in the history
OriginTrail Mainnet Release v6.2.3
  • Loading branch information
djordjekovac authored Mar 11, 2024
2 parents de85f9c + c897b6c commit 85b272d
Show file tree
Hide file tree
Showing 23 changed files with 596 additions and 342 deletions.
82 changes: 71 additions & 11 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.2.2",
"version": "6.2.3",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down
156 changes: 156 additions & 0 deletions src/commands/common/send-transaction-command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import Command from '../command.js';
import { EXPECTED_TRANSACTION_ERRORS, OPERATION_ID_STATUS } from '../../constants/constants.js';

class SendTransactionCommand extends Command {
async sendTransactionAndHandleResult(transactionCompletePromise, data, command) {
const {
blockchain,
agreementId,
epoch,
operationId,
closestNode,
leftNeighborhoodEdge,
rightNeighborhoodEdge,
contract,
tokenId,
keyword,
hashFunctionId,
stateIndex,
txGasPrice,
} = data;
const sendTransactionOperationId = this.operationIdService.generateId();
let txSuccess;
let msgBase;
try {
this.operationIdService.emitChangeEvent(
this.txStartStatus,
sendTransactionOperationId,
blockchain,
agreementId,
epoch,
operationId,
);
txSuccess = await transactionCompletePromise;
} catch (error) {
this.logger.warn(
`Failed to execute ${command.name}, Error Message: ${error.message} for the Service Agreement ` +
`with the ID: ${agreementId}, Blockchain: ${blockchain}, Contract: ${contract}, ` +
`Token ID: ${tokenId}, Keyword: ${keyword}, Hash function ID: ${hashFunctionId}, ` +
`Epoch: ${epoch}, State Index: ${stateIndex}, Operation ID: ${operationId}, ` +
`Closest Node: ${closestNode}, Left neighborhood edge: ${leftNeighborhoodEdge}, ` +
`Right neighborhood edge: ${rightNeighborhoodEdge}, ` +
`Retry number: ${this.commandRetryNumber - command.retries + 1}.`,
);
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.FAILED,
sendTransactionOperationId,
blockchain,
error.message,
this.txErrorType,
);
txSuccess = false;
if (error.message.includes(EXPECTED_TRANSACTION_ERRORS.NODE_ALREADY_SUBMITTED_COMMIT)) {
msgBase = 'Node has already submitted commit. Finishing';
} else if (error.message.includes(EXPECTED_TRANSACTION_ERRORS.NODE_ALREADY_REWARDED)) {
msgBase = 'Node already rewarded. Finishing';
} else if (
error.message.includes(EXPECTED_TRANSACTION_ERRORS.SERVICE_AGREEMENT_DOESNT_EXIST)
) {
msgBase = 'Service agreement doesnt exist. Finishing';
} else if (
error.message.includes(
EXPECTED_TRANSACTION_ERRORS.INVALID_PROXIMITY_SCORE_FUNCTIONS_PAIR_ID,
)
) {
msgBase = 'Invalid proximity score functions pair id. Finishing';
} else if (
error.message.includes(EXPECTED_TRANSACTION_ERRORS.INVALID_SCORE_FUNCTION_ID)
) {
msgBase = 'Invalid score function id. Finishing';
} else if (error.message.includes(EXPECTED_TRANSACTION_ERRORS.COMMIT_WINDOW_CLOSED)) {
msgBase = 'Commit window closed. Finishing';
} else if (
error.message.includes(EXPECTED_TRANSACTION_ERRORS.NODE_NOT_IN_SHARDING_TABLE)
) {
msgBase = 'Node not in sharding table. Finishing';
} else if (error.message.includes(EXPECTED_TRANSACTION_ERRORS.PROOF_WINDOW_CLOSED)) {
msgBase = 'Proof window closed. Finishing';
} else if (error.message.includes(EXPECTED_TRANSACTION_ERRORS.NODE_NOT_AWARDED)) {
msgBase = 'Node not awarded. Finishing';
} else if (error.message.includes(EXPECTED_TRANSACTION_ERRORS.WRONG_MERKLE_PROOF)) {
msgBase = 'Wrong merkle proof. Finishing';
} else if (error.message.includes(EXPECTED_TRANSACTION_ERRORS.INSUFFICIENT_FUNDS)) {
msgBase = 'Insufficient funds. Finishing';
if (this.insufficientFundsErrorReceived) {
await this.insufficientFundsErrorReceived(command.data);
}
} else {
let newGasPrice;
if (
error.message.includes(EXPECTED_TRANSACTION_ERRORS.TIMEOUT_EXCEEDED) ||
error.message.includes(EXPECTED_TRANSACTION_ERRORS.TOO_LOW_PRIORITY)
) {
newGasPrice = Math.ceil(txGasPrice * this.txGasIncreaseFactor);
} else {
newGasPrice = null;
}

Object.assign(command, {
data: { ...command.data, gasPrice: newGasPrice },
message: error.message,
});

return Command.retry();
}
}

if (txSuccess) {
this.operationIdService.emitChangeEvent(
this.txEndStatus,
sendTransactionOperationId,
blockchain,
agreementId,
epoch,
operationId,
);
msgBase = 'Successfully executed';

this.operationIdService.emitChangeEvent(
this.operationEndStatus,
operationId,
blockchain,
agreementId,
epoch,
);
}

this.logger.trace(
`${msgBase} ${command.name} for the Service Agreement with the ID: ${agreementId}, ` +
`Blockchain: ${blockchain}, Contract: ${contract}, Token ID: ${tokenId}, ` +
`Keyword: ${keyword}, Hash function ID: ${hashFunctionId}, Epoch: ${epoch}, ` +
`State Index: ${stateIndex}, Operation ID: ${operationId}, ` +
`Closest Node: ${closestNode}, Left neighborhood edge: ${leftNeighborhoodEdge}, ` +
`Right neighborhood edge: ${rightNeighborhoodEdge}, ` +
`Retry number: ${this.commandRetryNumber - command.retries + 1}`,
);

return Command.empty();
}

/**
* Builds default sendTransactionCommand
* @param map
* @returns {{add, data: *, delay: *, deadline: *}}
*/
default(map) {
const command = {
name: 'sendTransactionCommand',
delay: 0,
transactional: false,
};
Object.assign(command, map);
return command;
}
}

export default SendTransactionCommand;
Loading

0 comments on commit 85b272d

Please sign in to comment.