Skip to content

Commit

Permalink
Merge pull request #2151 from OriginTrail/v6/prerelease/testnet
Browse files Browse the repository at this point in the history
OriginTrail 6.0.0-beta.2.2.9 Testnet Release
  • Loading branch information
zeroxbt authored Oct 21, 2022
2 parents 2418d05 + ea90668 commit 6c69f10
Show file tree
Hide file tree
Showing 22 changed files with 340 additions and 197 deletions.
4 changes: 2 additions & 2 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"config": {
"blockchainTitle": "ganache",
"networkId": "ganache::testnet",
"hubContractAddress": "0xF21dD87cFC5cF5D073398833AFe5EFC543b78a00",
"hubContractAddress": "0x209679fA3B658Cd0fC74473aF28243bfe78a9b12",
"rpcEndpoints": ["http://localhost:7545"],
"evmManagementPublicKey": "0x1B420da5f7Be66567526E32bc68ab29F1A63765A"
}
Expand Down Expand Up @@ -262,7 +262,7 @@
"config": {
"blockchainTitle": "ganache",
"networkId": "ganache::testnet",
"hubContractAddress": "0xF21dD87cFC5cF5D073398833AFe5EFC543b78a00",
"hubContractAddress": "0x209679fA3B658Cd0fC74473aF28243bfe78a9b12",
"rpcEndpoints": ["http://localhost:7545"]
}
}
Expand Down
59 changes: 47 additions & 12 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Logger from './src/logger/logger.js';
import { MIN_NODE_VERSION } from './src/constants/constants.js';
import FileService from './src/service/file-service.js';
import NetworkPrivateKeyMigration from './src/migration/network-private-key-migration.js';
import OtnodeUpdateCommand from './src/commands/common/otnode-update-command.js';
import OtAutoUpdater from './src/modules/auto-updater/implementation/ot-auto-updater.js';

const require = createRequire(import.meta.url);
const pjson = require('./package.json');
Expand All @@ -18,20 +20,16 @@ const configjson = require('./config/config.json');
class OTNode {
constructor(config) {
this.initializeConfiguration(config);
this.logger = new Logger(this.config.logLevel, this.config.telemetry.enabled);
this.initializeLogger();
this.initializeFileService();
this.initializeAutoUpdaterModule();
this.checkNodeVersion();
}

async start() {
await this.checkForUpdate();
await this.removeUpdateFile();
const migrationManager = new NetworkPrivateKeyMigration(
'NetworkPrivateKeyMigration',
this.logger,
this.config,
);
if (!(await migrationManager.migrationAlreadyExecuted())) {
await migrationManager.migrate();
}
await this.executeMigrations();

this.logger.info(' ██████╗ ████████╗███╗ ██╗ ██████╗ ██████╗ ███████╗');
this.logger.info('██╔═══██╗╚══██╔══╝████╗ ██║██╔═══██╗██╔══██╗██╔════╝');
Expand Down Expand Up @@ -72,6 +70,22 @@ class OTNode {
this.logger.warn('======================================================');
}

initializeLogger() {
this.logger = new Logger(this.config.logLevel, this.config.telemetry.enabled);
}

initializeFileService() {
this.fileService = new FileService({ config: this.config, logger: this.logger });
}

initializeAutoUpdaterModule() {
this.autoUpdaterModuleManager = new OtAutoUpdater();
this.autoUpdaterModuleManager.initialize(
this.config.modules.autoUpdater.implementation['ot-auto-updater'].config,
this.logger,
);
}

initializeConfiguration(userConfig) {
const defaultConfig = JSON.parse(JSON.stringify(configjson[process.env.NODE_ENV]));

Expand Down Expand Up @@ -278,14 +292,35 @@ class OTNode {
}

async removeUpdateFile() {
const fileService = new FileService({ config: this.config, logger: this.logger });
const updateFilePath = fileService.getUpdateFilePath();
await fileService.removeFile(updateFilePath).catch((error) => {
const updateFilePath = this.fileService.getUpdateFilePath();
await this.fileService.removeFile(updateFilePath).catch((error) => {
this.logger.warn(`Unable to remove update file. Error: ${error}`);
});
this.config.otNodeUpdated = true;
}

async executeMigrations() {
const networkPrivateKeyMigration = new NetworkPrivateKeyMigration(
'NetworkPrivateKeyMigration',
this.logger,
this.config,
);
if (!(await networkPrivateKeyMigration.migrationAlreadyExecuted())) {
await networkPrivateKeyMigration.migrate();
}
}

async checkForUpdate() {
const autoUpdaterCommand = new OtnodeUpdateCommand({
logger: this.logger,
config: this.config,
fileService: this.fileService,
autoUpdaterModuleManager: this.autoUpdaterModuleManager,
});

await autoUpdaterCommand.execute();
}

stop(code = 0) {
this.logger.info('Stopping node...');
process.exit(code);
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": "6.0.0-beta.2.2.8",
"version": "6.0.0-beta.2.2.9",
"description": "OTNode v6 Beta 2",
"main": "index.js",
"type": "module",
Expand Down
71 changes: 71 additions & 0 deletions src/commands/protocols/publish/sender/local-store-command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { OPERATION_ID_STATUS, ERROR_TYPE, PUBLISH_TYPES } from '../../../../constants/constants.js';
import Command from '../../../command.js';

class LocalStoreCommand extends Command {
constructor(ctx) {
super(ctx);
this.operationService = ctx.publishService;

this.errorType = ERROR_TYPE.PUBLISH.PUBLISH_LOCAL_STORE_REMOTE_ERROR;
}

async execute(command) {
const { publishType, operationId, assertionId } = command.data;

await this.operationIdService.updateOperationIdStatus(
operationId,
OPERATION_ID_STATUS.PUBLISH.PUBLISH_LOCAL_STORE_START,
);

switch (publishType) {
case PUBLISH_TYPES.ASSERTION:
await this.operationService.localStoreAssertion(assertionId, operationId);
break;
case PUBLISH_TYPES.ASSET:
await this.operationService.localStoreAsset(
assertionId,
command.data.blockchain,
command.data.contract,
command.data.tokenId,
operationId,
);
break;
case PUBLISH_TYPES.INDEX:
await this.operationService.localStoreIndex(
assertionId,
command.data.blockchain,
command.data.contract,
command.data.tokenId,
command.data.keyword,
operationId,
);
break;
default:
throw Error(`Unknown publish type ${publishType}`);
}

await this.operationIdService.updateOperationIdStatus(
operationId,
OPERATION_ID_STATUS.PUBLISH.PUBLISH_LOCAL_STORE_END,
);

return this.continueSequence(command.data, command.sequence);
}

/**
* Builds default localStoreCommand
* @param map
* @returns {{add, data: *, delay: *, deadline: *}}
*/
default(map) {
const command = {
name: 'localStoreCommand',
delay: 0,
transactional: false,
};
Object.assign(command, map);
return command;
}
}

export default LocalStoreCommand;
7 changes: 4 additions & 3 deletions src/controllers/http-api/publish-http-api-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ class PublishController extends BaseController {
operationId,
};

const commandSequence = ['validateAssertionCommand', 'networkPublishCommand'];
const commandSequence = req.body.localStore ? ['localStoreCommand'] : [];
commandSequence.push('networkPublishCommand');

await this.commandExecutor.add({
name: commandSequence[0],
sequence: commandSequence.slice(1),
name: 'validateAssertionCommand',
sequence: commandSequence,
delay: 0,
period: 5000,
retries: 3,
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/http-api/request-schema/publish-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const assertionSchemaProperties = (blockchainImplementationNames) => ({
type: 'string',
minLength: 1,
},
localStore: {
type: 'boolean',
},
});

const assertionSchemaRequired = ['assertionId', 'assertion', 'blockchain', 'contract'];
Expand Down
13 changes: 9 additions & 4 deletions src/migration/base-migration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path';
import fs from 'fs-extra';
import FileService from '../service/file-service.js';

class BaseMigration {
Expand Down Expand Up @@ -41,15 +40,21 @@ class BaseMigration {
await this.executeMigration();

const migrationFolderPath = migrationPath || this.fileService.getMigrationFolderPath();
await fs.ensureDir(migrationFolderPath);
const migrationFilePath = path.join(migrationFolderPath, this.migrationName);
await fs.writeFile(migrationFilePath, 'MIGRATED');
await this.fileService.writeContentsToFile(
migrationFolderPath,
this.migrationName,
'MIGRATED',
);
this.logger.info(
`${this.migrationName} migration completed. Lasted: ${
Date.now() - this.startedTimestamp
} millisecond(s).`,
);
}

async executeMigration() {
throw Error('Execute migration method not implemented');
}
}

export default BaseMigration;
9 changes: 5 additions & 4 deletions src/migration/network-private-key-migration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { join } from 'path';
import appRootPath from 'app-root-path';
import { mkdir, writeFile } from 'fs/promises';
import BaseMigration from './base-migration.js';
import { LIBP2P_KEY_DIRECTORY, LIBP2P_KEY_FILENAME } from '../constants/constants.js';

Expand All @@ -25,9 +24,11 @@ class NetworkPrivateKeyMigration extends BaseMigration {
LIBP2P_KEY_DIRECTORY,
);
}
const fullPath = join(directoryPath, LIBP2P_KEY_FILENAME);
await mkdir(directoryPath, { recursive: true });
await writeFile(fullPath, networkPrivateKey);
await this.fileService.writeContentsToFile(
directoryPath,
LIBP2P_KEY_FILENAME,
networkPrivateKey,
);
}
}
}
Expand Down
Loading

0 comments on commit 6c69f10

Please sign in to comment.