Skip to content

Commit

Permalink
Merge pull request #2334 from OriginTrail/v6/release/testnet
Browse files Browse the repository at this point in the history
OriginTrail 6.0.2 Mainnet Release
  • Loading branch information
NZT48 authored Jan 5, 2023
2 parents 29cf84e + 8e6aeaa commit 831c8ab
Show file tree
Hide file tree
Showing 24 changed files with 236 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/TEST-bdd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
graphdb:
image: khaller/graphdb-free:latest
image: khaller/graphdb-free:1.3.5-graphdb9.11.2
ports:
- 7200:7200
strategy:
Expand Down
4 changes: 3 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@
"blockchainTitle": "ganache",
"networkId": "ganache::testnet",
"hubContractAddress": "0x209679fA3B658Cd0fC74473aF28243bfe78a9b12",
"rpcEndpoints": ["http://localhost:7545"]
"rpcEndpoints": ["http://localhost:7545"],
"initialStakeAmount": 50000,
"initialAskAmount": 0.2
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CONTRACTS, MIN_NODE_VERSION } from './src/constants/constants.js';
import FileService from './src/service/file-service.js';
import OtnodeUpdateCommand from './src/commands/common/otnode-update-command.js';
import OtAutoUpdater from './src/modules/auto-updater/implementation/ot-auto-updater.js';
import PullBlockchainShardingTableMigration from './src/migration/pull-sharding-table-migration.js';

const require = createRequire(import.meta.url);
const pjson = require('./package.json');
Expand Down Expand Up @@ -43,6 +44,7 @@ class OTNode {
this.initializeEventEmitter();

await this.initializeModules();
await this.executePullShardingTableMigration();
await this.listenOnHubContractChanges();

await this.createProfiles();
Expand Down Expand Up @@ -220,6 +222,26 @@ class OTNode {
}
}

async executePullShardingTableMigration() {
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') return;

const blockchainModuleManager = this.container.resolve('blockchainModuleManager');
const repositoryModuleManager = this.container.resolve('repositoryModuleManager');
const validationModuleManager = this.container.resolve('validationModuleManager');

const migration = new PullBlockchainShardingTableMigration(
'pullShardingTableMigration',
this.logger,
this.config,
repositoryModuleManager,
blockchainModuleManager,
validationModuleManager,
);
if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
}
}

async initializeShardingTableService() {
const blockchainModuleManager = this.container.resolve('blockchainModuleManager');
const initShardingServices = blockchainModuleManager
Expand Down Expand Up @@ -290,6 +312,12 @@ class OTNode {
getLastCheckedBlock,
updateLastCheckedBlock,
);
await blockchainModuleManager.getAllPastEvents(
CONTRACTS.STAKING_CONTRACT,
onEventsReceived,
getLastCheckedBlock,
updateLastCheckedBlock,
);
await blockchainModuleManager.getAllPastEvents(
CONTRACTS.PROFILE_CONTRACT,
onEventsReceived,
Expand Down Expand Up @@ -357,6 +385,9 @@ class OTNode {
const blockchainModuleManager = this.container.resolve('blockchainModuleManager');
const that = this;
blockchainModuleManager.getImplementationNames().map(async (blockchain) => {
eventEmitter.on(`${blockchain}-NewContract`, async () => {
await that.reinitializeContracts(blockchainModuleManager, blockchain);
});
eventEmitter.on(`${blockchain}-ContractChanged`, async (event) => {
await that.reinitializeContracts(blockchainModuleManager, blockchain);
if (event.contractName === 'ShardingTable') {
Expand Down
95 changes: 13 additions & 82 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "6.0.1",
"version": "6.0.2",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down Expand Up @@ -50,7 +50,7 @@
"@polkadot/util-crypto": "^10.1.7",
"@truffle/hdwallet-provider": "^2.0.16",
"chai": "^4.3.6",
"dkg.js": "^6.0.0-beta.3.1.2",
"dkg.js": "^6.0.0-beta.3.5.1",
"eslint": "^8.23.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
Expand Down
4 changes: 3 additions & 1 deletion scripts/set-ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const argv = require('minimist')(process.argv.slice(1), {
string: ['ask', 'privateKey', 'hubContractAddress'],
});

const devEnvironment = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';

async function setAsk(rpcEndpoint, ask, walletPrivateKey, hubContractAddress) {
const provider = new ethers.providers.JsonRpcProvider(rpcEndpoint);
const wallet = new ethers.Wallet(walletPrivateKey);
Expand All @@ -33,7 +35,7 @@ async function setAsk(rpcEndpoint, ask, walletPrivateKey, hubContractAddress) {

const walletSigner = wallet.connect(provider);
await profile.connect(walletSigner).setAsk(identityId, askWei, {
gasPrice: process.env.NODE_ENV === 'development' ? undefined : 8,
gasPrice: devEnvironment ? undefined : 8,
gasLimit: 500_000,
});
}
Expand Down
6 changes: 4 additions & 2 deletions scripts/set-stake.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const argv = require('minimist')(process.argv.slice(1), {
],
});

const devEnvironment = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';

async function setStake(
rpcEndpoint,
stake,
Expand Down Expand Up @@ -51,14 +53,14 @@ async function setStake(
await tokenContract
.connect(managementWalletSigner)
.increaseAllowance(stakingContractAddress, stakeWei, {
gasPrice: process.env.NODE_ENV === 'development' ? undefined : 8,
gasPrice: devEnvironment ? undefined : 8,
gasLimit: 500_000,
});
// TODO: Add ABI instead of hard-coded function definition
await stakingContract
.connect(managementWalletSigner)
['addStake(uint72,uint96)'](identityId, stakeWei, {
gasPrice: process.env.NODE_ENV === 'development' ? undefined : 1_000,
gasPrice: devEnvironment ? undefined : 1_000,
gasLimit: 500_000,
});
}
Expand Down
1 change: 1 addition & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export const QUERY_TYPES = {
*/
export const CONTRACTS = {
SHARDING_TABLE_CONTRACT: 'ShardingTableContract',
STAKING_CONTRACT: 'StakingContract',
PROFILE_CONTRACT: 'ProfileContract',
HUB_CONTRACT: 'hubContract',
};
88 changes: 88 additions & 0 deletions src/migration/pull-sharding-table-migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { ethers } from 'ethers';
import BaseMigration from './base-migration.js';

class PullBlockchainShardingTableMigration extends BaseMigration {
constructor(
migrationName,
logger,
config,
repositoryModuleManager,
blockchainModuleManager,
validationModuleManager,
) {
super(migrationName, logger, config);
this.repositoryModuleManager = repositoryModuleManager;
this.blockchainModuleManager = blockchainModuleManager;
this.validationModuleManager = validationModuleManager;
}

async executeMigration() {
const promises = this.blockchainModuleManager
.getImplementationNames()
.map(async (blockchainId) => {
this.logger.debug(
`Removing nodes from local sharding table for blockchain ${blockchainId}.`,
);
await this.repositoryModuleManager.removeShardingTablePeerRecords(blockchainId);

const shardingTableLength = Number(
await this.blockchainModuleManager.getShardingTableLength(blockchainId),
);
let startingIdentityId = await this.blockchainModuleManager.getShardingTableHead(
blockchainId,
);
const pageSize = 10;
const shardingTable = [];

this.logger.debug(
`Started pulling ${shardingTableLength} nodes from blockchain sharding table.`,
);

let sliceIndex = 0;

while (shardingTable.length < shardingTableLength) {
// eslint-disable-next-line no-await-in-loop
const nodes = await this.blockchainModuleManager.getShardingTablePage(
blockchainId,
startingIdentityId,
pageSize,
);
shardingTable.push(
...nodes.slice(sliceIndex).filter((node) => node.nodeId !== '0x'),
);
sliceIndex = 1;
startingIdentityId = nodes[nodes.length - 1].identityId;
}

this.logger.debug(
`Finished pulling ${shardingTable.length} nodes from blockchain sharding table.`,
);

await this.repositoryModuleManager.createManyPeerRecords(
await Promise.all(
shardingTable.map(async (peer) => {
const nodeId = this.blockchainModuleManager.convertHexToAscii(
blockchainId,
peer.nodeId,
);

return {
peer_id: nodeId,
blockchain_id: blockchainId,
ask: ethers.utils.formatUnits(peer.ask, 'ether'),
stake: ethers.utils.formatUnits(peer.stake, 'ether'),
sha256: await this.validationModuleManager.callHashFunction(
1,
nodeId,
),
};
}),
),
);
});

await Promise.all(promises);
}
}

export default PullBlockchainShardingTableMigration;
4 changes: 4 additions & 0 deletions src/modules/blockchain/blockchain-module-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class BlockchainModuleManager extends BaseModuleManager {
]);
}

async getNodeStake(blockchain, identityId) {
return this.callImplementationFunction(blockchain, 'getNodeStake', [identityId]);
}

async getIdentityId(blockchain) {
return this.callImplementationFunction(blockchain, 'getIdentityId');
}
Expand Down
Loading

0 comments on commit 831c8ab

Please sign in to comment.