Skip to content

Commit

Permalink
Merge pull request #2909 from OriginTrail/origin/v6/hotfix-v6.2.0.hot…
Browse files Browse the repository at this point in the history
…fix4

OriginTrail Devnet Prerelease v6.2.0 Hotfix 4
  • Loading branch information
NZT48 authored Feb 1, 2024
2 parents 0d3c90b + 01bb1ac commit 19d23ad
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 68 deletions.
2 changes: 1 addition & 1 deletion ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class OTNode {

await this.initializeModules();

await MigrationExecutor.executeRemoveServiceAgreementsForChiadoDevnetMigration(
await MigrationExecutor.executeRemoveServiceAgreementsForChiadoMigration(
this.container,
this.logger,
this.config,
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.

50 changes: 34 additions & 16 deletions src/commands/protocols/common/epoch-check-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class EpochCheckCommand extends Command {
!migrationExecuted
) {
this.logger.info(
'Epoch check command will be postponed until ual extension triple store migration is completed',
'Epoch check: command will be postponed until ual extension triple store migration is completed',
);
return Command.repeat();
}
this.logger.info('Starting epoch check command');
this.logger.info('Epoch check: Starting epoch check command');
const operationId = this.operationIdService.generateId();

await Promise.all(
Expand Down Expand Up @@ -77,7 +77,7 @@ class EpochCheckCommand extends Command {
const [r0, r2, totalNodesNumber, minStake, maxStake] = await Promise.all([
this.blockchainModuleManager.getR0(blockchain),
this.blockchainModuleManager.getR2(blockchain),
this.blockchainModuleManager.getShardingTableLength(blockchain),
this.repositoryModuleManager.getPeersCount(blockchain),
this.blockchainModuleManager.getMinimumStake(blockchain),
this.blockchainModuleManager.getMaximumStake(blockchain),
]);
Expand Down Expand Up @@ -129,11 +129,18 @@ class EpochCheckCommand extends Command {
blockchain,
commitWindowDurationPerc,
);

this.logger.info(
`Epoch check: Found ${eligibleAgreementForSubmitCommit.length} eligible agreements for submit commit for blockchain: ${blockchain}`,
);
const scheduleSubmitCommitCommands = [];
const updateServiceAgreementsLastCommitEpoch = [];
for (const serviceAgreement of eligibleAgreementForSubmitCommit) {
if (scheduleSubmitCommitCommands.length >= maxTransactions) break;
if (scheduleSubmitCommitCommands.length >= maxTransactions) {
this.logger.warn(
`Epoch check: not scheduling new commits. Submit commit command length: ${scheduleSubmitCommitCommands.length}, max number of transactions: ${maxTransactions} for blockchain: ${blockchain}`,
);
break;
}

const neighbourhood = await this.shardingTableService.findNeighbourhood(
blockchain,
Expand All @@ -156,7 +163,10 @@ class EpochCheckCommand extends Command {
}

if (!neighbourhoodEdges && serviceAgreement.scoreFunctionId === 2) {
throw Error('Unable to find neighbourhood edges for asset');
this.logger.warn(
`Epoch check: unable to find neighbourhood edges for agreement id: ${serviceAgreement.agreementId} for blockchain: ${blockchain}`,
);
continue;
}

try {
Expand All @@ -182,28 +192,28 @@ class EpochCheckCommand extends Command {

if (rank == null) {
this.logger.trace(
`Node not in R2: ${r2} for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Skipping scheduling submitCommitCommand.`,
`Epoch check: Node not in R2: ${r2} for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Skipping scheduling submitCommitCommand for blockchain: ${blockchain}`,
);
continue;
}

if (rank >= r0) {
this.logger.trace(
`Calculated rank: ${
`Epoch check: Calculated rank: ${
rank + 1
}. Node not in R0: ${r0} for the Service Agreement with the ID: ${
serviceAgreement.agreementId
}. Skipping scheduling submitCommitCommand.`,
}. Skipping scheduling submitCommitCommand for blockchain: ${blockchain}`,
);
continue;
}

this.logger.trace(
`Calculated rank: ${
`Epoch check: Calculated rank: ${
rank + 1
}. Node in R0: ${r0} for the Service Agreement with the ID: ${
serviceAgreement.agreementId
}. Scheduling submitCommitCommand.`,
}. Scheduling submitCommitCommand for blockchain: ${blockchain}`,
);
const closestNode = neighbourhood[0];
scheduleSubmitCommitCommands.push(
Expand All @@ -215,7 +225,7 @@ class EpochCheckCommand extends Command {
);
} catch (error) {
this.logger.warn(
`Failed to schedule submitCommitCommand for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Error message: ${error.message}.`,
`Epoch check: Failed to schedule submitCommitCommand for the Service Agreement with the ID: ${serviceAgreement.agreementId} for blockchain: ${blockchain}. Error message: ${error.message}.`,
);
continue;
}
Expand All @@ -239,10 +249,18 @@ class EpochCheckCommand extends Command {
blockchain,
proofWindowDurationPerc,
);
this.logger.info(
`Epoch check: Found ${eligibleAgreementsForSubmitProofs.length} eligible agreements for submit proof for blockchain: ${blockchain}`,
);
const scheduleSubmitProofCommands = [];
const updateServiceAgreementsLastProofEpoch = [];
for (const serviceAgreement of eligibleAgreementsForSubmitProofs) {
if (scheduleSubmitProofCommands.length >= maxTransactions) break;
if (scheduleSubmitProofCommands.length >= maxTransactions) {
this.logger.warn(
`Epoch check: not scheduling new proofs. Submit proofs command length: ${scheduleSubmitProofCommands.length}, max number of transactions: ${maxTransactions} for blockchain: ${blockchain}`,
);
break;
}

try {
const eligibleForReward = await this.isEligibleForRewards(
Expand All @@ -254,15 +272,15 @@ class EpochCheckCommand extends Command {
);
if (eligibleForReward) {
this.logger.trace(
`Node is eligible for rewards for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Scheduling submitProofsCommand.`,
`Epoch check: Node is eligible for rewards for the Service Agreement with the ID: ${serviceAgreement.agreementId} for blockchain: ${blockchain}. Scheduling submitProofsCommand.`,
);

scheduleSubmitProofCommands.push(
this.scheduleSubmitProofsCommand(serviceAgreement),
);
} else {
this.logger.trace(
`Node is not eligible for rewards for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Skipping scheduling submitProofsCommand.`,
`Epoch check: Node is not eligible for rewards for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Skipping scheduling submitProofsCommand for blockchain: ${blockchain}`,
);
}
updateServiceAgreementsLastProofEpoch.push(
Expand All @@ -273,7 +291,7 @@ class EpochCheckCommand extends Command {
);
} catch (error) {
this.logger.warn(
`Failed to schedule submitProofsCommand for the Service Agreement with the ID: ${serviceAgreement.agreementId}. Error message: ${error.message}.`,
`Epoch check: Failed to schedule submitProofsCommand for the Service Agreement with the ID: ${serviceAgreement.agreementId} for blockchain: ${blockchain}. Error message: ${error.message}.`,
);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ class HandleUpdateRequestCommand extends HandleProtocolMessageCommand {
throw Error('Unable to find neighbourhood edges for asset');
}

const totalNodesNumber = await this.blockchainModuleManager.getShardingTableLength(
blockchain,
);
const totalNodesNumber = await this.repositoryModuleManager.getPeersCount(blockchain);
const minStake = await this.blockchainModuleManager.getMinimumStake(blockchain);
const maxStake = await this.blockchainModuleManager.getMaximumStake(blockchain);

Expand Down
10 changes: 6 additions & 4 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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 UINT256_MAX_BN = ethers.constants.MaxUint256;

export const UINT128_MAX_BN = BigNumber.from(2).pow(128).sub(1);

Expand All @@ -18,7 +18,7 @@ export const UINT40_MAX_BN = BigNumber.from(2).pow(40).sub(1);

export const UINT32_MAX_BN = BigNumber.from(2).pow(32).sub(1);

export const HASH_RING_SIZE = BigNumber.from(2).pow(256);
export const HASH_RING_SIZE = ethers.constants.MaxUint256;

export const STAKE_UINT256_MULTIPLIER_BN = UINT256_MAX_BN.div(500000000);

Expand Down Expand Up @@ -576,8 +576,8 @@ export const CONTRACTS = {
SERVICE_AGREEMENT_V1_CONTRACT: 'ServiceAgreementV1Contract',
PARAMETERS_STORAGE_CONTRACT: 'ParametersStorageContract',
IDENTITY_STORAGE_CONTRACT: 'IdentityStorageContract',
Log2PLDSF: 'Log2PLDSF',
LINEAR_SUM: 'LinearSum',
Log2PLDSF_CONTRACT: 'Log2PLDSFContract',
LINEAR_SUM_CONTRACT: 'LinearSumContract',
};

export const CONTRACT_EVENTS = {
Expand All @@ -588,6 +588,8 @@ export const CONTRACT_EVENTS = {
COMMIT_MANAGER_V1: ['StateFinalized'],
SERVICE_AGREEMENT_V1: ['ServiceAgreementV1Extended', 'ServiceAgreementV1Terminated'],
PARAMETERS_STORAGE: ['ParameterChanged'],
Log2PLDSF: ['ParameterChanged'],
LINEAR_SUM: ['ParameterChanged'],
};

export const NODE_ENVIRONMENTS = {
Expand Down
15 changes: 9 additions & 6 deletions src/migration/migration-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ServiceAgreementsInvalidDataMigration from './service-agreements-invalid-
import UalExtensionUserConfigurationMigration from './ual-extension-user-configuration-migration.js';
import UalExtensionTripleStoreMigration from './ual-extension-triple-store-migration.js';
import MarkStakingEventsAsProcessedMigration from './mark-staking-events-as-processed-migration.js';
import RemoveServiceAgreementsForChiadoDevnetMigration from './remove-service-agreements-for-chiado-devnet-migration.js';
import RemoveServiceAgreementsForChiadoMigration from './remove-service-agreements-for-chiado-migration.js';

class MigrationExecutor {
static async executePullShardingTableMigration(container, logger, config) {
Expand Down Expand Up @@ -365,12 +365,15 @@ class MigrationExecutor {
}
}

static async executeRemoveServiceAgreementsForChiadoDevnetMigration(container, logger, config) {
if (process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVNET) {
static async executeRemoveServiceAgreementsForChiadoMigration(container, logger, config) {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVNET ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TESTNET
) {
const repositoryModuleManager = container.resolve('repositoryModuleManager');

const migration = new RemoveServiceAgreementsForChiadoDevnetMigration(
'removeServiceAgreementsForChiadoDevnetMigrationV2',
const migration = new RemoveServiceAgreementsForChiadoMigration(
'removeServiceAgreementsForChiadoMigrationV2',
logger,
config,
repositoryModuleManager,
Expand All @@ -380,7 +383,7 @@ class MigrationExecutor {
await migration.migrate();
} catch (error) {
logger.error(
`Unable to execute remove service agreements for Chiado Devnet migration. Error: ${error.message}`,
`Unable to execute remove service agreements for Chiado migration. Error: ${error.message}`,
);
this.exitNode(1);
}
Expand Down
6 changes: 0 additions & 6 deletions src/migration/pull-sharding-table-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ class PullBlockchainShardingTableMigration extends BaseMigration {

const sha256 = await this.hashingService.callHashFunction(1, nodeId);

const cleanHexString = sha256.startsWith('0x')
? sha256.slice(2)
: sha256;
const sha256Blob = Buffer.from(cleanHexString, 'hex');

return {
peerId: nodeId,
blockchainId,
Expand All @@ -86,7 +81,6 @@ class PullBlockchainShardingTableMigration extends BaseMigration {
'ether',
),
sha256,
sha256Blob,
};
}),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BaseMigration from './base-migration.js';

const GNOSIS_DEVNET_CHAIN_ID = 'gnosis:10200';

class RemoveServiceAgreementsForChiadoDevnetMigration extends BaseMigration {
class RemoveServiceAgreementsForChiadoMigration extends BaseMigration {
constructor(migrationName, logger, config, repositoryModuleManager) {
super(migrationName, logger, config);
this.repositoryModuleManager = repositoryModuleManager;
Expand All @@ -15,4 +15,4 @@ class RemoveServiceAgreementsForChiadoDevnetMigration extends BaseMigration {
}
}

export default RemoveServiceAgreementsForChiadoDevnetMigration;
export default RemoveServiceAgreementsForChiadoMigration;
9 changes: 5 additions & 4 deletions src/modules/blockchain/implementation/web3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,10 @@ class Web3Service {
) {
const contract = this[contractName];
if (!contract) {
throw new Error(
`Error while getting all past events. Unknown contract: ${contractName}`,
);
// this will happen when we have different set of contracts on different blockchains
// eg LinearSum contract is available on gnosis but not on NeuroWeb, so the node should not fetch events
// from LinearSum contract on NeuroWeb blockchain
return [];
}

let fromBlock;
Expand Down Expand Up @@ -1294,7 +1295,7 @@ class Web3Service {
this.scoringFunctionsContracts[2],
'getParameters',
[],
CONTRACTS.LINEAR_SUM,
CONTRACTS.LINEAR_SUM_CONTRACT,
);
return {
distanceScaleFactor: BigNumber.from(linearSumParams[0]),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export async function up({ context: { queryInterface } }) {
const tableInfo = await queryInterface.describeTable('shard');

if (tableInfo.sha256_blob) {
await queryInterface.removeColumn('shard', 'sha256_blob');
}
}

export async function down({ context: { queryInterface, Sequelize } }) {
const tableInfo = await queryInterface.describeTable('shard');

if (!tableInfo.sha256_blob) {
await queryInterface.addColumn('shard', 'sha256_blob', {
type: Sequelize.BLOB,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export default (sequelize, DataTypes) => {
type: DataTypes.STRING,
allowNull: false,
},
sha256Blob: {
type: DataTypes.BLOB,
},
},
{ underscored: true },
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ShardRepository {
});
}

async createPeerRecord(peerId, blockchainId, ask, stake, lastSeen, sha256, sha256Blob) {
async createPeerRecord(peerId, blockchainId, ask, stake, lastSeen, sha256) {
return this.model.create(
{
peerId,
Expand All @@ -28,7 +28,6 @@ class ShardRepository {
stake,
lastSeen,
sha256,
sha256Blob,
},
{
ignoreDuplicates: true,
Expand All @@ -42,7 +41,7 @@ class ShardRepository {
blockchainId,
},
attributes: ['peerId', 'blockchainId', 'ask', 'stake', 'lastSeen', 'sha256'],
order: [['sha256Blob', 'ASC']],
order: [['sha256', 'asc']],
};

if (filterLastSeen) {
Expand Down
Loading

0 comments on commit 19d23ad

Please sign in to comment.