Skip to content

Commit

Permalink
Merge pull request #2758 from OriginTrail/v6/development-network
Browse files Browse the repository at this point in the history
OriginTrail Testnet Prerelease v6.0.18
  • Loading branch information
NZT48 authored Nov 3, 2023
2 parents be3e311 + d26c83c commit ca7c169
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 46 deletions.
8 changes: 6 additions & 2 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@
"config": {
"networkId": "otp::testnet",
"hubContractAddress": "0x707233a55bD035C6Bc732196CA4dbffa63CbA169",
"rpcEndpoints": ["https://lofar-tm-rpc.origin-trail.network"],
"rpcEndpoints": [
"https://lofar-tm-rpc.origin-trail.network",
"https://lofar.origintrail.network/"
],
"initialStakeAmount": 50000,
"initialAskAmount": 2
}
Expand Down Expand Up @@ -585,7 +588,8 @@
"hubContractAddress": "0x5fA7916c48Fe6D5F1738d12Ad234b78c90B4cAdA",
"rpcEndpoints": [
"https://astrosat-parachain-rpc.origin-trail.network",
"https://astrosat.origintrail.network/"
"https://astrosat.origintrail.network/",
"https://astrosat-2.origintrail.network/"
]
}
}
Expand Down
4 changes: 2 additions & 2 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.0.17",
"version": "6.0.18+hotfix.1",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down
12 changes: 10 additions & 2 deletions src/commands/protocols/common/submit-commit-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ class SubmitCommitCommand extends Command {
const errorMessage = `Commit already submitted for blockchain: ${blockchain} agreement id: ${agreementId}, epoch: ${epoch}, state index: ${stateIndex}`;
this.logger.trace(errorMessage);

await this.handleError(operationId, errorMessage, this.errorType, true);
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_COMMIT_END,
operationId,
agreementId,
epoch,
);
return Command.empty();
}

Expand All @@ -66,7 +71,10 @@ class SubmitCommitCommand extends Command {
epoch,
stateIndex,
(result) => {
if (result?.error) {
if (
result?.error &&
!result.error.message.includes('NodeAlreadySubmittedCommit')
) {
reject(result.error);
}
resolve();
Expand Down
9 changes: 7 additions & 2 deletions src/commands/protocols/common/submit-proofs-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ class SubmitProofsCommand extends Command {
const errorMessage = `Proofs already submitted for blockchain: ${blockchain} agreement id: ${agreementId}, epoch: ${epoch}, state index: ${stateIndex}`;
this.logger.trace(errorMessage);

await this.handleError(operationId, errorMessage, this.errorType, true);
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.COMMIT_PROOF.SUBMIT_PROOFS_END,
operationId,
agreementId,
epoch,
);
return Command.empty();
}

Expand All @@ -127,7 +132,7 @@ class SubmitProofsCommand extends Command {
leaf,
stateIndex,
(result) => {
if (result?.error) {
if (result?.error && !result.error.message.includes('NodeAlreadyRewarded')) {
reject(result.error);
}
resolve();
Expand Down
8 changes: 8 additions & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { BigNumber } from 'ethers';

export const WS_RPC_PROVIDER_PRIORITY = 2;

export const HTTP_RPC_PROVIDER_PRIORITY = 1;

export const FALLBACK_PROVIDER_QUORUM = 1;

export const RPC_PROVIDER_STALL_TIMEOUT = 60 * 1000;

export const UINT256_MAX_BN = BigNumber.from(2).pow(256).sub(1);

export const UINT32_MAX_BN = BigNumber.from(2).pow(32).sub(1);
Expand Down
73 changes: 36 additions & 37 deletions src/modules/blockchain/implementation/web3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {
TRANSACTION_POLLING_TIMEOUT_MILLIS,
TRANSACTION_CONFIRMATIONS,
BLOCK_TIME_MILLIS,
WS_RPC_PROVIDER_PRIORITY,
HTTP_RPC_PROVIDER_PRIORITY,
FALLBACK_PROVIDER_QUORUM,
RPC_PROVIDER_STALL_TIMEOUT,
} from '../../../constants/constants.js';

const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -53,7 +57,6 @@ class Web3Service {
this.config = config;
this.logger = logger;

this.rpcNumber = 0;
this.initializeTransactionQueue(TRANSACTION_QUEUE_CONCURRENCY);
await this.initializeWeb3();
this.startBlock = await this.getBlockNumber();
Expand Down Expand Up @@ -89,37 +92,44 @@ class Web3Service {
}

async initializeWeb3() {
let tries = 0;
let isRpcConnected = false;
while (!isRpcConnected) {
if (tries >= this.config.rpcEndpoints.length) {
throw Error('RPC initialization failed');
}

const rpcProviders = [];
for (const rpcEndpoint of this.config.rpcEndpoints) {
try {
if (this.config.rpcEndpoints[this.rpcNumber].startsWith('ws')) {
this.provider = new ethers.providers.WebSocketProvider(
this.config.rpcEndpoints[this.rpcNumber],
);
if (rpcEndpoint.startsWith('ws')) {
rpcProviders.push({
provider: new ethers.providers.WebSocketProvider(rpcEndpoint),
priority: WS_RPC_PROVIDER_PRIORITY,
weight: 1,
stallTimeout: RPC_PROVIDER_STALL_TIMEOUT,
});
} else {
this.provider = new ethers.providers.JsonRpcProvider(
this.config.rpcEndpoints[this.rpcNumber],
);
rpcProviders.push({
provider: new ethers.providers.JsonRpcProvider(rpcEndpoint),
priority: HTTP_RPC_PROVIDER_PRIORITY,
weight: 1,
stallTimeout: RPC_PROVIDER_STALL_TIMEOUT,
});
}
// eslint-disable-next-line no-await-in-loop
await this.providerReady();
isRpcConnected = true;
this.logger.debug(`Connected to the blockchain RPC: ${rpcEndpoint}.`);
} catch (e) {
this.logger.warn(
`Unable to connect to blockchain rpc : ${
this.config.rpcEndpoints[this.rpcNumber]
}.`,
);
tries += 1;
this.rpcNumber = (this.rpcNumber + 1) % this.config.rpcEndpoints.length;
this.logger.warn(`Unable to connect to the blockchain RPC: ${rpcEndpoint}.`);
}
}

try {
this.provider = new ethers.providers.FallbackProvider(
rpcProviders,
FALLBACK_PROVIDER_QUORUM,
);
} catch (e) {
throw Error(
`RPC Fallback Provider initialization failed. Fallback Provider quorum: ${FALLBACK_PROVIDER_QUORUM}. Error: ${e.message}.`,
);
}

// eslint-disable-next-line no-await-in-loop
await this.providerReady();

this.wallet = new ethers.Wallet(this.getPrivateKey(), this.provider);
}

Expand Down Expand Up @@ -164,9 +174,6 @@ class Web3Service {
});

this.logger.info(`Contracts initialized`);
this.logger.debug(
`Connected to blockchain rpc : ${this.config.rpcEndpoints[this.rpcNumber]}.`,
);

await this.logBalances();
}
Expand Down Expand Up @@ -925,12 +932,6 @@ class Web3Service {
}

async restartService() {
this.rpcNumber = (this.rpcNumber + 1) % this.config.rpcEndpoints.length;
this.logger.warn(
`There was an issue with current blockchain rpc. Connecting to ${
this.config.rpcEndpoints[this.rpcNumber]
}`,
);
await this.initializeWeb3();
await this.initializeContracts();
}
Expand All @@ -942,9 +943,7 @@ class Web3Service {
} catch (rpcError) {
isRpcError = true;
this.logger.warn(
`Unable to execute smart contract function ${functionName} using blockchain rpc : ${
this.config.rpcEndpoints[this.rpcNumber]
}.`,
`Unable to execute smart contract function ${functionName} using Fallback RPC Provider.`,
);
await this.restartService();
}
Expand Down

0 comments on commit ca7c169

Please sign in to comment.