Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
"query": 60000,
"get": 10000,
"batchGet": 10000,
"insert": 300000
"insert": 300000,
"ask": 10000
},
"implementation": {
"ot-blazegraph": {
Expand Down Expand Up @@ -349,7 +350,8 @@
"query": 60000,
"get": 10000,
"batchGet": 10000,
"insert": 300000
"insert": 300000,
"ask": 10000
},
"implementation": {
"ot-blazegraph": {
Expand Down Expand Up @@ -567,7 +569,8 @@
"query": 60000,
"get": 10000,
"batchGet": 10000,
"insert": 300000
"insert": 300000,
"ask": 10000
},
"implementation": {
"ot-blazegraph": {
Expand Down Expand Up @@ -776,7 +779,8 @@
"query": 60000,
"get": 10000,
"batchGet": 10000,
"insert": 300000
"insert": 300000,
"ask": 10000
},
"implementation": {
"ot-blazegraph": {
Expand Down Expand Up @@ -991,7 +995,8 @@
"query": 60000,
"get": 10000,
"batchGet": 10000,
"insert": 300000
"insert": 300000,
"ask": 10000
},
"implementation": {
"ot-blazegraph": {
Expand Down
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": "8.1.1-rc.7",
"version": "8.1.1-rc.8",
"description": "OTNode V8",
"main": "index.js",
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
const { operationId, blockchain, includeMetadata } = commandData;
let { uals, tokenIds } = commandData;

console.time(`HandleBatchGetRequestCommand [PREPARE]: ${operationId} ${uals.length}`);

Check warning on line 33 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 33 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
Expand Down Expand Up @@ -57,11 +58,16 @@
}
}

console.timeEnd(`HandleBatchGetRequestCommand [PREPARE]: ${operationId} ${uals.length}`);

Check warning on line 61 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 61 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

console.time(`HandleBatchGetRequestCommand [PROCESSING]: ${operationId} ${uals.length}`);

Check warning on line 63 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 63 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

const assertionPromise = this.tripleStoreService.getAssertionsInBatch(
TRIPLE_STORE_REPOSITORY.DKG,
uals,
tokenIds,
TRIPLES_VISIBILITY.PUBLIC,
operationId,
);

promises.push(assertionPromise);
Expand All @@ -81,6 +87,10 @@
...(includeMetadata && metadata && { metadata }),
};

console.timeEnd(`HandleBatchGetRequestCommand [PROCESSING]: ${operationId} ${uals.length}`);

Check warning on line 90 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 90 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

console.time(`HandleBatchGetRequestCommand [RESPONSE]: ${operationId} ${uals.length}`);

Check warning on line 92 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 92 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

if (assertions?.length) {
await this.operationIdService.updateOperationIdStatus(
operationId,
Expand All @@ -89,6 +99,8 @@
);
}

console.timeEnd(`HandleBatchGetRequestCommand [RESPONSE]: ${operationId} ${uals.length}`);

Check warning on line 102 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 102 in src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

return { messageType: NETWORK_MESSAGE_TYPES.RESPONSES.ACK, messageData: responseData };
}

Expand Down
53 changes: 53 additions & 0 deletions src/commands/protocols/get/sender/batch-get-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
paranetNodesAccessPolicy,
} = command.data;

console.time(`BatchGetCommand [PREPARE]: ${operationId} ${uals.length}`);

Check warning on line 71 in src/commands/protocols/get/sender/batch-get-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 71 in src/commands/protocols/get/sender/batch-get-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
Expand All @@ -88,6 +90,8 @@

const { isValid, errorMessage } = await this.validateUALs(operationId, blockchain, uals);

console.timeEnd(`BatchGetCommand [PREPARE]: ${operationId} ${uals.length}`);

Check warning on line 93 in src/commands/protocols/get/sender/batch-get-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 93 in src/commands/protocols/get/sender/batch-get-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

if (!isValid) {
await this.handleError(
operationId,
Expand All @@ -98,6 +102,8 @@
return Command.empty();
}

console.time(`BatchGetCommand [NETWORK]: ${operationId} ${uals.length}`);

Check warning on line 105 in src/commands/protocols/get/sender/batch-get-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 105 in src/commands/protocols/get/sender/batch-get-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

const currentPeerId = this.networkModuleManager.getPeerId().toB58String();
// let paranetId;
const repository = TRIPLE_STORE_REPOSITORIES.DKG;
Expand Down Expand Up @@ -127,6 +133,10 @@
OPERATION_ID_STATUS.BATCH_GET.BATCH_GET_LOCAL_START,
);

console.timeEnd(`BatchGetCommand [NETWORK]: ${operationId} ${uals.length}`);

Check warning on line 136 in src/commands/protocols/get/sender/batch-get-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 136 in src/commands/protocols/get/sender/batch-get-command.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

console.time(`BatchGetCommand [TOKEN_IDS]: ${operationId} ${uals.length}`);

const tokenIds = {};

const tokenIdPromises = uals.map(async (ual) => {
Expand All @@ -149,19 +159,28 @@

await Promise.all(tokenIdPromises);

console.timeEnd(`BatchGetCommand [TOKEN_IDS]: ${operationId} ${uals.length}`);

console.time(`BatchGetCommand [LOCAL_BATCH_GET]: ${operationId} ${uals.length}`);

const promises = [];
const assertionPromise = this.tripleStoreService.getAssertionsInBatch(
TRIPLE_STORE_REPOSITORY.DKG,
uals,
tokenIds,
TRIPLES_VISIBILITY.PUBLIC,
operationId,
);
promises.push(assertionPromise);

const [batchAssertions] = await Promise.all(promises);

const finalResult = { local: [], remote: {}, metadata: {} };

console.timeEnd(`BatchGetCommand [LOCAL_BATCH_GET]: ${operationId} ${uals.length}`);

console.time(`BatchGetCommand [LOCAL_BATCH_GET_VALIDATE]: ${operationId} ${uals.length}`);

const localGetResultValid = await this.validateBatchResponse(
batchAssertions,
blockchain,
Expand All @@ -178,6 +197,12 @@
(ual) => !localGetResultValid[ual],
);

console.timeEnd(
`BatchGetCommand [LOCAL_BATCH_GET_VALIDATE]: ${operationId} ${uals.length}`,
);

console.time(`BatchGetCommand [LOCAL]: ${operationId} ${uals.length}`);

ualPresentLocally.forEach((ual) => {
finalResult.local.push(ual);
delete tokenIds[ual];
Expand All @@ -198,6 +223,8 @@
return Command.empty();
}

console.timeEnd(`BatchGetCommand [LOCAL]: ${operationId} ${uals.length}`);

await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
Expand All @@ -210,6 +237,8 @@
OPERATION_ID_STATUS.BATCH_GET.BATCH_GET_FIND_SHARD_START,
);

console.time(`BatchGetCommand [FIND_SHARD]: ${operationId} ${uals.length}`);

let nodesInfo = [];
// if (paranetNodesAccessPolicy === PARANET_ACCESS_POLICY.PERMISSIONED) {
// const onChainNodes = await this.blockchainModuleManager.getPermissionedNodes(
Expand Down Expand Up @@ -247,12 +276,16 @@
return Command.empty();
}

console.timeEnd(`BatchGetCommand [FIND_SHARD]: ${operationId} ${uals.length}`);

await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
OPERATION_ID_STATUS.BATCH_GET.BATCH_GET_FIND_SHARD_END,
);

console.time(`BatchGetCommand [NETWORK]: ${operationId} ${uals.length}`);

let index = 0;
let commandCompleted = false;

Expand Down Expand Up @@ -280,12 +313,21 @@
// eslint-disable-next-line no-loop-func
const messagePromises = batch.map(async (node) => {
try {
console.time(
`BatchGetCommand [NETWORK_SEND_MESSAGE]: ${operationId} ${uals.length} ${node.id}`,
);
const result = await this.sendMessage(node, operationId, message);
console.timeEnd(
`BatchGetCommand [NETWORK_SEND_MESSAGE]: ${operationId} ${uals.length} ${node.id}`,
);

if (commandCompleted || !result.success) {
return;
}

console.time(
`BatchGetCommand [NETWORK_VALIDATE_RESPONSE]: ${operationId} ${uals.length} ${node.id}`,
);
const validationResult = await this.validateBatchResponse(
result.responseData.assertions,
blockchain,
Expand All @@ -294,6 +336,9 @@
finalResult,
[OPERATION_ID_STATUS.GET.GET_END, OPERATION_ID_STATUS.COMPLETED],
);
console.timeEnd(
`BatchGetCommand [NETWORK_VALIDATE_RESPONSE]: ${operationId} ${uals.length} ${node.id}`,
);

if (commandCompleted) {
return;
Expand All @@ -312,12 +357,18 @@

if (hasReachedThreshold() && !commandCompleted) {
commandCompleted = true;
console.time(
`BatchGetCommand [NETWORK_MARK_AS_COMPLETED]: ${operationId} ${uals.length} ${node.id}`,
);
await this.operationService.markOperationAsCompleted(
operationId,
blockchain,
finalResult,
[OPERATION_ID_STATUS.GET.GET_END, OPERATION_ID_STATUS.COMPLETED],
);
console.timeEnd(
`BatchGetCommand [NETWORK_MARK_AS_COMPLETED]: ${operationId} ${uals.length} ${node.id}`,
);
}
} catch (err) {
this.logger.warn(`Node ${node.id} failed: ${err.message}`);
Expand Down Expand Up @@ -357,6 +408,8 @@
);
}

console.timeEnd(`BatchGetCommand [NETWORK]: ${operationId} ${uals.length}`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Debugging Code Leaks into Production

Extensive console.time() and console.timeEnd() calls, intended for temporary debugging and performance measurement, have been accidentally committed. These statements are present in BatchGetCommand, HandleBatchGetRequestCommand, and TripleStoreService methods (getAssertion, getAssertionsInBatch). They will pollute production logs with excessive timing information and should be removed.

Locations (3)

Fix in CursorFix in Web


return Command.empty();
}

Expand Down
3 changes: 3 additions & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,9 @@ export const EXPECTED_TRANSACTION_ERRORS = {
NODE_NOT_AWARDED: 'NodeNotAwarded',
WRONG_MERKLE_PROOF: 'WrongMerkleProof',
NO_MINTED_ASSETS: 'NoMintedAssets',
NONCE_TOO_LOW: 'nonce too low',
REPLACEMENT_UNDERPRICED: 'replacement transaction underpriced',
ALREADY_KNOWN: 'already known',
};

/**
Expand Down
85 changes: 62 additions & 23 deletions src/modules/blockchain/implementation/web3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
TRANSACTION_PRIORITY,
CONTRACT_FUNCTION_GAS_LIMIT_INCREASE_FACTORS,
ABIs,
EXPECTED_TRANSACTION_ERRORS,
} from '../../../constants/constants.js';
import Web3ServiceValidator from './web3-service-validator.js';

Expand Down Expand Up @@ -561,8 +562,10 @@ class Web3Service {
operationalWallet,
) {
let result;
const gasPrice = predefinedGasPrice ?? (await this.getGasPrice());
let gasPrice = predefinedGasPrice ?? (await this.getGasPrice());
let gasLimit;
let retryCount = 0;
const maxRetries = 3;

try {
/* eslint-disable no-await-in-loop */
Expand All @@ -577,33 +580,69 @@ class Web3Service {

gasLimit = gasLimit.mul(gasLimitMultiplier * 100).div(100);

this.logger.debug(
`Sending signed transaction ${functionName} to the blockchain ${this.getBlockchainId()}` +
` with gas limit: ${gasLimit.toString()} and gasPrice ${gasPrice.toString()}. ` +
`Transaction queue length: ${this.getTotalTransactionQueueLength()}. Wallet used: ${
operationalWallet.address
}`,
);
while (retryCount < maxRetries) {
try {
this.logger.debug(
`Sending signed transaction ${functionName} to the blockchain ${this.getBlockchainId()}` +
` with gas limit: ${gasLimit.toString()} and gasPrice ${gasPrice.toString()}. ` +
`Transaction queue length: ${this.getTotalTransactionQueueLength()}. Wallet used: ${
operationalWallet.address
}${retryCount > 0 ? ` (retry ${retryCount})` : ''}`,
);

const tx = await contractInstance.connect(operationalWallet)[functionName](...args, {
gasPrice,
gasLimit,
});
const tx = await contractInstance
.connect(operationalWallet)
[functionName](...args, {
gasPrice,
gasLimit,
});

try {
result = await this.provider.waitForTransaction(
tx.hash,
TRANSACTION_CONFIRMATIONS,
TRANSACTION_POLLING_TIMEOUT_MILLIS,
);
try {
result = await this.provider.waitForTransaction(
tx.hash,
TRANSACTION_CONFIRMATIONS,
TRANSACTION_POLLING_TIMEOUT_MILLIS,
);

if (result.status === 0) {
await this.provider.call(tx, tx.blockNumber);
if (result.status === 0) {
await this.provider.call(tx, tx.blockNumber);
}
} catch (error) {
this._decodeWaitForTxError(contractInstance, functionName, error, args);
}
return result;
} catch (error) {
const errorMessage = error.message.toLowerCase();

// Check for nonce-related errors
if (
errorMessage.includes(
EXPECTED_TRANSACTION_ERRORS.NONCE_TOO_LOW.toLowerCase(),
) ||
errorMessage.includes(
EXPECTED_TRANSACTION_ERRORS.REPLACEMENT_UNDERPRICED.toLowerCase(),
) ||
errorMessage.includes(EXPECTED_TRANSACTION_ERRORS.ALREADY_KNOWN.toLowerCase())
) {
retryCount += 1;
if (retryCount < maxRetries) {
// Increase gas price by 20% for nonce errors
gasPrice = Math.ceil(gasPrice * 1.2);
this.logger.warn(
`Nonce error detected for ${functionName}. Retrying with increased gas price: ${gasPrice} (retry ${retryCount}/${maxRetries})`,
);
continue;
} else {
this.logger.error(
`Max retries (${maxRetries}) reached for nonce error in ${functionName}. Final gas price: ${gasPrice}`,
);
}
}

// If it's not a nonce error or we've exhausted retries, re-throw the error
throw error;
}
} catch (error) {
this._decodeWaitForTxError(contractInstance, functionName, error, args);
}
return result;
}

_decodeEstimateGasError(contractInstance, functionName, error, args) {
Expand Down
Loading
Loading