Skip to content

Commit 2efc19b

Browse files
Merge pull request #4016 from OriginTrail/v8/develop
v8.1.1-rc.8
2 parents 97905df + 55605b6 commit 2efc19b

File tree

11 files changed

+273
-89
lines changed

11 files changed

+273
-89
lines changed

config/config.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@
9595
"query": 60000,
9696
"get": 10000,
9797
"batchGet": 10000,
98-
"insert": 300000
98+
"insert": 300000,
99+
"ask": 10000
99100
},
100101
"implementation": {
101102
"ot-blazegraph": {
@@ -349,7 +350,8 @@
349350
"query": 60000,
350351
"get": 10000,
351352
"batchGet": 10000,
352-
"insert": 300000
353+
"insert": 300000,
354+
"ask": 10000
353355
},
354356
"implementation": {
355357
"ot-blazegraph": {
@@ -567,7 +569,8 @@
567569
"query": 60000,
568570
"get": 10000,
569571
"batchGet": 10000,
570-
"insert": 300000
572+
"insert": 300000,
573+
"ask": 10000
571574
},
572575
"implementation": {
573576
"ot-blazegraph": {
@@ -776,7 +779,8 @@
776779
"query": 60000,
777780
"get": 10000,
778781
"batchGet": 10000,
779-
"insert": 300000
782+
"insert": 300000,
783+
"ask": 10000
780784
},
781785
"implementation": {
782786
"ot-blazegraph": {
@@ -991,7 +995,8 @@
991995
"query": 60000,
992996
"get": 10000,
993997
"batchGet": 10000,
994-
"insert": 300000
998+
"insert": 300000,
999+
"ask": 10000
9951000
},
9961001
"implementation": {
9971002
"ot-blazegraph": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "origintrail_node",
3-
"version": "8.1.1-rc.7",
3+
"version": "8.1.1-rc.8",
44
"description": "OTNode V8",
55
"main": "index.js",
66
"type": "module",

src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-batch-get-request-command.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class HandleBatchGetRequestCommand extends HandleProtocolMessageCommand {
3030
const { operationId, blockchain, includeMetadata } = commandData;
3131
let { uals, tokenIds } = commandData;
3232

33+
console.time(`HandleBatchGetRequestCommand [PREPARE]: ${operationId} ${uals.length}`);
3334
await this.operationIdService.updateOperationIdStatus(
3435
operationId,
3536
blockchain,
@@ -57,11 +58,16 @@ class HandleBatchGetRequestCommand extends HandleProtocolMessageCommand {
5758
}
5859
}
5960

61+
console.timeEnd(`HandleBatchGetRequestCommand [PREPARE]: ${operationId} ${uals.length}`);
62+
63+
console.time(`HandleBatchGetRequestCommand [PROCESSING]: ${operationId} ${uals.length}`);
64+
6065
const assertionPromise = this.tripleStoreService.getAssertionsInBatch(
6166
TRIPLE_STORE_REPOSITORY.DKG,
6267
uals,
6368
tokenIds,
6469
TRIPLES_VISIBILITY.PUBLIC,
70+
operationId,
6571
);
6672

6773
promises.push(assertionPromise);
@@ -81,6 +87,10 @@ class HandleBatchGetRequestCommand extends HandleProtocolMessageCommand {
8187
...(includeMetadata && metadata && { metadata }),
8288
};
8389

90+
console.timeEnd(`HandleBatchGetRequestCommand [PROCESSING]: ${operationId} ${uals.length}`);
91+
92+
console.time(`HandleBatchGetRequestCommand [RESPONSE]: ${operationId} ${uals.length}`);
93+
8494
if (assertions?.length) {
8595
await this.operationIdService.updateOperationIdStatus(
8696
operationId,
@@ -89,6 +99,8 @@ class HandleBatchGetRequestCommand extends HandleProtocolMessageCommand {
8999
);
90100
}
91101

102+
console.timeEnd(`HandleBatchGetRequestCommand [RESPONSE]: ${operationId} ${uals.length}`);
103+
92104
return { messageType: NETWORK_MESSAGE_TYPES.RESPONSES.ACK, messageData: responseData };
93105
}
94106

src/commands/protocols/get/sender/batch-get-command.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class BatchGetCommand extends Command {
6868
paranetNodesAccessPolicy,
6969
} = command.data;
7070

71+
console.time(`BatchGetCommand [PREPARE]: ${operationId} ${uals.length}`);
72+
7173
await this.operationIdService.updateOperationIdStatus(
7274
operationId,
7375
blockchain,
@@ -88,6 +90,8 @@ class BatchGetCommand extends Command {
8890

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

93+
console.timeEnd(`BatchGetCommand [PREPARE]: ${operationId} ${uals.length}`);
94+
9195
if (!isValid) {
9296
await this.handleError(
9397
operationId,
@@ -98,6 +102,8 @@ class BatchGetCommand extends Command {
98102
return Command.empty();
99103
}
100104

105+
console.time(`BatchGetCommand [NETWORK]: ${operationId} ${uals.length}`);
106+
101107
const currentPeerId = this.networkModuleManager.getPeerId().toB58String();
102108
// let paranetId;
103109
const repository = TRIPLE_STORE_REPOSITORIES.DKG;
@@ -127,6 +133,10 @@ class BatchGetCommand extends Command {
127133
OPERATION_ID_STATUS.BATCH_GET.BATCH_GET_LOCAL_START,
128134
);
129135

136+
console.timeEnd(`BatchGetCommand [NETWORK]: ${operationId} ${uals.length}`);
137+
138+
console.time(`BatchGetCommand [TOKEN_IDS]: ${operationId} ${uals.length}`);
139+
130140
const tokenIds = {};
131141

132142
const tokenIdPromises = uals.map(async (ual) => {
@@ -149,19 +159,28 @@ class BatchGetCommand extends Command {
149159

150160
await Promise.all(tokenIdPromises);
151161

162+
console.timeEnd(`BatchGetCommand [TOKEN_IDS]: ${operationId} ${uals.length}`);
163+
164+
console.time(`BatchGetCommand [LOCAL_BATCH_GET]: ${operationId} ${uals.length}`);
165+
152166
const promises = [];
153167
const assertionPromise = this.tripleStoreService.getAssertionsInBatch(
154168
TRIPLE_STORE_REPOSITORY.DKG,
155169
uals,
156170
tokenIds,
157171
TRIPLES_VISIBILITY.PUBLIC,
172+
operationId,
158173
);
159174
promises.push(assertionPromise);
160175

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

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

180+
console.timeEnd(`BatchGetCommand [LOCAL_BATCH_GET]: ${operationId} ${uals.length}`);
181+
182+
console.time(`BatchGetCommand [LOCAL_BATCH_GET_VALIDATE]: ${operationId} ${uals.length}`);
183+
165184
const localGetResultValid = await this.validateBatchResponse(
166185
batchAssertions,
167186
blockchain,
@@ -178,6 +197,12 @@ class BatchGetCommand extends Command {
178197
(ual) => !localGetResultValid[ual],
179198
);
180199

200+
console.timeEnd(
201+
`BatchGetCommand [LOCAL_BATCH_GET_VALIDATE]: ${operationId} ${uals.length}`,
202+
);
203+
204+
console.time(`BatchGetCommand [LOCAL]: ${operationId} ${uals.length}`);
205+
181206
ualPresentLocally.forEach((ual) => {
182207
finalResult.local.push(ual);
183208
delete tokenIds[ual];
@@ -198,6 +223,8 @@ class BatchGetCommand extends Command {
198223
return Command.empty();
199224
}
200225

226+
console.timeEnd(`BatchGetCommand [LOCAL]: ${operationId} ${uals.length}`);
227+
201228
await this.operationIdService.updateOperationIdStatus(
202229
operationId,
203230
blockchain,
@@ -210,6 +237,8 @@ class BatchGetCommand extends Command {
210237
OPERATION_ID_STATUS.BATCH_GET.BATCH_GET_FIND_SHARD_START,
211238
);
212239

240+
console.time(`BatchGetCommand [FIND_SHARD]: ${operationId} ${uals.length}`);
241+
213242
let nodesInfo = [];
214243
// if (paranetNodesAccessPolicy === PARANET_ACCESS_POLICY.PERMISSIONED) {
215244
// const onChainNodes = await this.blockchainModuleManager.getPermissionedNodes(
@@ -247,12 +276,16 @@ class BatchGetCommand extends Command {
247276
return Command.empty();
248277
}
249278

279+
console.timeEnd(`BatchGetCommand [FIND_SHARD]: ${operationId} ${uals.length}`);
280+
250281
await this.operationIdService.updateOperationIdStatus(
251282
operationId,
252283
blockchain,
253284
OPERATION_ID_STATUS.BATCH_GET.BATCH_GET_FIND_SHARD_END,
254285
);
255286

287+
console.time(`BatchGetCommand [NETWORK]: ${operationId} ${uals.length}`);
288+
256289
let index = 0;
257290
let commandCompleted = false;
258291

@@ -280,12 +313,21 @@ class BatchGetCommand extends Command {
280313
// eslint-disable-next-line no-loop-func
281314
const messagePromises = batch.map(async (node) => {
282315
try {
316+
console.time(
317+
`BatchGetCommand [NETWORK_SEND_MESSAGE]: ${operationId} ${uals.length} ${node.id}`,
318+
);
283319
const result = await this.sendMessage(node, operationId, message);
320+
console.timeEnd(
321+
`BatchGetCommand [NETWORK_SEND_MESSAGE]: ${operationId} ${uals.length} ${node.id}`,
322+
);
284323

285324
if (commandCompleted || !result.success) {
286325
return;
287326
}
288327

328+
console.time(
329+
`BatchGetCommand [NETWORK_VALIDATE_RESPONSE]: ${operationId} ${uals.length} ${node.id}`,
330+
);
289331
const validationResult = await this.validateBatchResponse(
290332
result.responseData.assertions,
291333
blockchain,
@@ -294,6 +336,9 @@ class BatchGetCommand extends Command {
294336
finalResult,
295337
[OPERATION_ID_STATUS.GET.GET_END, OPERATION_ID_STATUS.COMPLETED],
296338
);
339+
console.timeEnd(
340+
`BatchGetCommand [NETWORK_VALIDATE_RESPONSE]: ${operationId} ${uals.length} ${node.id}`,
341+
);
297342

298343
if (commandCompleted) {
299344
return;
@@ -312,12 +357,18 @@ class BatchGetCommand extends Command {
312357

313358
if (hasReachedThreshold() && !commandCompleted) {
314359
commandCompleted = true;
360+
console.time(
361+
`BatchGetCommand [NETWORK_MARK_AS_COMPLETED]: ${operationId} ${uals.length} ${node.id}`,
362+
);
315363
await this.operationService.markOperationAsCompleted(
316364
operationId,
317365
blockchain,
318366
finalResult,
319367
[OPERATION_ID_STATUS.GET.GET_END, OPERATION_ID_STATUS.COMPLETED],
320368
);
369+
console.timeEnd(
370+
`BatchGetCommand [NETWORK_MARK_AS_COMPLETED]: ${operationId} ${uals.length} ${node.id}`,
371+
);
321372
}
322373
} catch (err) {
323374
this.logger.warn(`Node ${node.id} failed: ${err.message}`);
@@ -357,6 +408,8 @@ class BatchGetCommand extends Command {
357408
);
358409
}
359410

411+
console.timeEnd(`BatchGetCommand [NETWORK]: ${operationId} ${uals.length}`);
412+
360413
return Command.empty();
361414
}
362415

src/constants/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,9 @@ export const EXPECTED_TRANSACTION_ERRORS = {
712712
NODE_NOT_AWARDED: 'NodeNotAwarded',
713713
WRONG_MERKLE_PROOF: 'WrongMerkleProof',
714714
NO_MINTED_ASSETS: 'NoMintedAssets',
715+
NONCE_TOO_LOW: 'nonce too low',
716+
REPLACEMENT_UNDERPRICED: 'replacement transaction underpriced',
717+
ALREADY_KNOWN: 'already known',
715718
};
716719

717720
/**

src/modules/blockchain/implementation/web3-service.js

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
TRANSACTION_PRIORITY,
2424
CONTRACT_FUNCTION_GAS_LIMIT_INCREASE_FACTORS,
2525
ABIs,
26+
EXPECTED_TRANSACTION_ERRORS,
2627
} from '../../../constants/constants.js';
2728
import Web3ServiceValidator from './web3-service-validator.js';
2829

@@ -561,8 +562,10 @@ class Web3Service {
561562
operationalWallet,
562563
) {
563564
let result;
564-
const gasPrice = predefinedGasPrice ?? (await this.getGasPrice());
565+
let gasPrice = predefinedGasPrice ?? (await this.getGasPrice());
565566
let gasLimit;
567+
let retryCount = 0;
568+
const maxRetries = 3;
566569

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

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

580-
this.logger.debug(
581-
`Sending signed transaction ${functionName} to the blockchain ${this.getBlockchainId()}` +
582-
` with gas limit: ${gasLimit.toString()} and gasPrice ${gasPrice.toString()}. ` +
583-
`Transaction queue length: ${this.getTotalTransactionQueueLength()}. Wallet used: ${
584-
operationalWallet.address
585-
}`,
586-
);
583+
while (retryCount < maxRetries) {
584+
try {
585+
this.logger.debug(
586+
`Sending signed transaction ${functionName} to the blockchain ${this.getBlockchainId()}` +
587+
` with gas limit: ${gasLimit.toString()} and gasPrice ${gasPrice.toString()}. ` +
588+
`Transaction queue length: ${this.getTotalTransactionQueueLength()}. Wallet used: ${
589+
operationalWallet.address
590+
}${retryCount > 0 ? ` (retry ${retryCount})` : ''}`,
591+
);
587592

588-
const tx = await contractInstance.connect(operationalWallet)[functionName](...args, {
589-
gasPrice,
590-
gasLimit,
591-
});
593+
const tx = await contractInstance
594+
.connect(operationalWallet)
595+
[functionName](...args, {
596+
gasPrice,
597+
gasLimit,
598+
});
592599

593-
try {
594-
result = await this.provider.waitForTransaction(
595-
tx.hash,
596-
TRANSACTION_CONFIRMATIONS,
597-
TRANSACTION_POLLING_TIMEOUT_MILLIS,
598-
);
600+
try {
601+
result = await this.provider.waitForTransaction(
602+
tx.hash,
603+
TRANSACTION_CONFIRMATIONS,
604+
TRANSACTION_POLLING_TIMEOUT_MILLIS,
605+
);
599606

600-
if (result.status === 0) {
601-
await this.provider.call(tx, tx.blockNumber);
607+
if (result.status === 0) {
608+
await this.provider.call(tx, tx.blockNumber);
609+
}
610+
} catch (error) {
611+
this._decodeWaitForTxError(contractInstance, functionName, error, args);
612+
}
613+
return result;
614+
} catch (error) {
615+
const errorMessage = error.message.toLowerCase();
616+
617+
// Check for nonce-related errors
618+
if (
619+
errorMessage.includes(
620+
EXPECTED_TRANSACTION_ERRORS.NONCE_TOO_LOW.toLowerCase(),
621+
) ||
622+
errorMessage.includes(
623+
EXPECTED_TRANSACTION_ERRORS.REPLACEMENT_UNDERPRICED.toLowerCase(),
624+
) ||
625+
errorMessage.includes(EXPECTED_TRANSACTION_ERRORS.ALREADY_KNOWN.toLowerCase())
626+
) {
627+
retryCount += 1;
628+
if (retryCount < maxRetries) {
629+
// Increase gas price by 20% for nonce errors
630+
gasPrice = Math.ceil(gasPrice * 1.2);
631+
this.logger.warn(
632+
`Nonce error detected for ${functionName}. Retrying with increased gas price: ${gasPrice} (retry ${retryCount}/${maxRetries})`,
633+
);
634+
continue;
635+
} else {
636+
this.logger.error(
637+
`Max retries (${maxRetries}) reached for nonce error in ${functionName}. Final gas price: ${gasPrice}`,
638+
);
639+
}
640+
}
641+
642+
// If it's not a nonce error or we've exhausted retries, re-throw the error
643+
throw error;
602644
}
603-
} catch (error) {
604-
this._decodeWaitForTxError(contractInstance, functionName, error, args);
605645
}
606-
return result;
607646
}
608647

609648
_decodeEstimateGasError(contractInstance, functionName, error, args) {

0 commit comments

Comments
 (0)