Skip to content

Commit

Permalink
Merge pull request #2873 from OriginTrail/v6/otnode-events-for-transa…
Browse files Browse the repository at this point in the history
…ctions

Added new events for sending commit and proof transactions
  • Loading branch information
NZT48 authored Jan 12, 2024
2 parents 1c96063 + bdd3235 commit 5f45b26
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 4 deletions.
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 @@ -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
9 changes: 9 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

0 comments on commit 5f45b26

Please sign in to comment.