Skip to content

Commit

Permalink
Merge branch 'main' into 619-expose-opcodes-endpoint-by-default
Browse files Browse the repository at this point in the history
# Conflicts:
#	test/unit/states/InitState.spec.ts
  • Loading branch information
victor-yanev committed Jun 11, 2024
2 parents 0e4baa3 + 4fc8650 commit a6f2da5
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 228 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hashgraph/hedera-local",
"version": "2.25.3",
"version": "2.26.1",
"description": "Developer tooling for running Local Hedera Network (Consensus + Mirror Nodes).",
"main": "index.ts",
"scripts": {
Expand Down Expand Up @@ -57,14 +57,14 @@
"typescript": "^5.4.3"
},
"dependencies": {
"@hashgraph/sdk": "^2.43.0",
"@hashgraph/sdk": "2.43.0",
"blessed": "^0.1.81",
"blessed-terminal": "^0.1.22",
"csv-parser": "^3.0.0",
"detect-port": "^1.5.1",
"dockerode": "^4.0.2",
"dotenv": "^16.4.5",
"ethers": "^6.11.1",
"ethers": "^6.13.0",
"js-yaml": "^4.1.0",
"rimraf": "^5.0.5",
"semver": "^7.6.0",
Expand Down
9 changes: 5 additions & 4 deletions src/configuration/local.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"imageTagConfiguration": [
{"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.50.0"},
{"key": "HAVEGED_IMAGE_TAG", "value": "0.50.0"},
{"key": "MIRROR_IMAGE_TAG", "value": "0.104.0"},
{"key": "RELAY_IMAGE_TAG", "value": "0.47.0"},
{"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.51.0-alpha.4"},
{"key": "HAVEGED_IMAGE_TAG", "value": "0.51.0-alpha.4"},
{"key": "MIRROR_IMAGE_TAG", "value": "0.107.0-rc1"},
{"key": "RELAY_IMAGE_TAG", "value": "0.49.0"},
{"key": "MIRROR_NODE_EXPLORER_IMAGE_TAG", "value": "24.4.0"}
],
"envConfiguration": [
Expand All @@ -30,6 +30,7 @@
"properties": [
{"key": "files.maxSizeKb", "value": "6144"},
{"key": "contracts.precompile.atomicCryptoTransfer.enabled", "value": true},
{"key": "contracts.systemContract.accountService.enabled", "value": true},
{"key": "hedera.transaction.eip2930.enabled", "value": true},
{"key": "accounts.blocklist.enabled", "value": false},
{"key": "accounts.blocklist.path", "value": "data/config/evm-addresses-blocklist.csv"}
Expand Down
4 changes: 2 additions & 2 deletions src/configuration/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"imageTagConfiguration": [
{"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.49.7"},
{"key": "HAVEGED_IMAGE_TAG", "value": "0.49.7"},
{"key": "MIRROR_IMAGE_TAG", "value": "0.104.0"},
{"key": "RELAY_IMAGE_TAG", "value": "0.47.0"},
{"key": "MIRROR_IMAGE_TAG", "value": "0.105.0"},
{"key": "RELAY_IMAGE_TAG", "value": "0.49.0"},
{"key": "MIRROR_NODE_EXPLORER_IMAGE_TAG", "value": "24.4.0"}
],
"nodeConfiguration": {
Expand Down
8 changes: 4 additions & 4 deletions src/configuration/previewnet.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"imageTagConfiguration": [
{"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.50.0-alpha.1"},
{"key": "HAVEGED_IMAGE_TAG", "value": "0.50.0-alpha.1"},
{"key": "MIRROR_IMAGE_TAG", "value": "0.105.0-rc2"},
{"key": "RELAY_IMAGE_TAG", "value": "0.48.0-rc2"},
{"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.51.0-alpha.3"},
{"key": "HAVEGED_IMAGE_TAG", "value": "0.51.0-alpha.3"},
{"key": "MIRROR_IMAGE_TAG", "value": "0.107.0-rc1"},
{"key": "RELAY_IMAGE_TAG", "value": "0.49.0"},
{"key": "MIRROR_NODE_EXPLORER_IMAGE_TAG", "value": "24.4.0"}
],
"nodeConfiguration": {
Expand Down
8 changes: 4 additions & 4 deletions src/configuration/testnet.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"imageTagConfiguration": [
{"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.49.7"},
{"key": "HAVEGED_IMAGE_TAG", "value": "0.49.7"},
{"key": "MIRROR_IMAGE_TAG", "value": "0.104.0"},
{"key": "RELAY_IMAGE_TAG", "value": "0.48.0-rc2"},
{"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.50.0"},
{"key": "HAVEGED_IMAGE_TAG", "value": "0.50.0"},
{"key": "MIRROR_IMAGE_TAG", "value": "0.106.1"},
{"key": "RELAY_IMAGE_TAG", "value": "0.49.0"},
{"key": "MIRROR_NODE_EXPLORER_IMAGE_TAG", "value": "24.4.0"}
],
"nodeConfiguration": {
Expand Down
89 changes: 49 additions & 40 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,61 +71,70 @@ export const DEBUG_COLOR = '\x1b[36m'
// white
export const TRACE_COLOR = '\x1b[37m'

// check success
export const CHECK_SUCCESS = `${INFO_COLOR}[✔︎]${COLOR_RESET}`
// check warn
export const CHEKC_WARN = `${WARNING_COLOR}[!]${COLOR_RESET}`
// check fail
export const CHECK_FAIL = `${ERROR_COLOR}[✘]${COLOR_RESET}`
// waiting
export const LOADING = `⏳`;

// Start State
export const START_STATE_INIT_MESSAGE = 'Start State Initialized!';
export const START_STATE_STARTING_MESSAGE = 'Starting Hedera Local Node...';
export const START_STATE_ON_START_MESSAGE = 'Initiating start procedure. Trying to start docker containers...';
export const START_STATE_STARTED_DETECTING = 'Detecting network...';
export const START_STATE_STARTED_MESSAGE = 'Hedera Local Node successfully started!';
export const START_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Start State Initialized!`;
export const START_STATE_STARTING_MESSAGE = `${LOADING} Starting Hedera Local Node...`;
export const START_STATE_ON_START_MESSAGE = `${LOADING} Initiating start procedure. Trying to start docker containers...`;
export const START_STATE_STARTED_DETECTING = `${LOADING} Detecting network...`;
export const START_STATE_STARTED_MESSAGE = `${CHECK_SUCCESS} Hedera Local Node successfully started!`;

// Stop State
export const STOP_STATE_INIT_MESSAGE = 'Stop State Initialized!';
export const STOP_STATE_ON_START_MESSAGE = 'Initiating stop procedure. Trying to stop docker containers and clean up volumes...';
export const STOP_STATE_STOPPING_MESSAGE = 'Stopping the network...';
export const STOP_STATE_STOPPED_MESSAGE = 'Hedera Local Node was stopped successfully.';
export const STOP_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Stop State Initialized!`;
export const STOP_STATE_ON_START_MESSAGE = `${LOADING} Initiating stop procedure. Trying to stop docker containers and clean up volumes...`;
export const STOP_STATE_STOPPING_MESSAGE = `${LOADING} Stopping the network...`;
export const STOP_STATE_STOPPED_MESSAGE = `${CHECK_SUCCESS} Hedera Local Node was stopped successfully.`;

// Docker commands
export const DOCKER_STOPPING_CONTAINERS_MESSAGE = 'Stopping the docker containers...';
export const DOCKER_CLEANING_VALUMES_MESSAGE = 'Cleaning the volumes and temp files...';
export const DOCKER_STOPPING_CONTAINERS_MESSAGE = `${LOADING} Stopping the docker containers...`;
export const DOCKER_CLEANING_VALUMES_MESSAGE = `${LOADING} Cleaning the volumes and temp files...`;

// Recovery state
export const RECOVERY_STATE_INIT_MESSAGE = 'Recovery State Initialized!';
export const RECOVERY_STATE_STARTING_MESSAGE = "Starting Recovery State...";
export const RECOVERY_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Recovery State Initialized!`;
export const RECOVERY_STATE_STARTING_MESSAGE = `${LOADING} Starting Recovery State...`;

// Network Prep State
export const NETWORK_PREP_STATE_INIT_MESSAGE = 'Network Preparation State Initialized!'
export const NETWORK_PREP_STATE_STARTING_MESSAGE = 'Starting Network Preparation State...';
export const NETWORK_PREP_STATE_IMPORT_FEES_START = 'Starting Fees import...';
export const NETWORK_PREP_STATE_IMPORT_FEES_END = 'Imported fees successfully';
export const NETWORK_PREP_STATE_WAITING_TOPIC_CREATION = 'Waiting for topic creation...';
export const NETWORK_PREP_STATE_TOPIC_CREATED = 'Topic was created!';
export const NETWORK_PREP_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Network Preparation State Initialized!`;
export const NETWORK_PREP_STATE_STARTING_MESSAGE = `${LOADING} Starting Network Preparation State...`;
export const NETWORK_PREP_STATE_IMPORT_FEES_START = `${LOADING} Starting Fees import...`;
export const NETWORK_PREP_STATE_IMPORT_FEES_END = `${CHECK_SUCCESS} Imported fees successfully!`;
export const NETWORK_PREP_STATE_WAITING_TOPIC_CREATION = `${LOADING} Waiting for topic creation...`;
export const NETWORK_PREP_STATE_TOPIC_CREATED = `${CHECK_SUCCESS} Topic was created!`;

// Init state
export const INIT_STATE_INIT_MESSAGE = 'Initialization State Initialized!';
export const INIT_STATE_STARTING_MESSAGE = 'Initialization State Starting...';
export const INIT_STATE_START_DOCKER_CHECK = "Making sure that Docker is started and it's correct version...";
export const INIT_STATE_CONFIGURING_ENV_VARIABLES_FINISH = 'Needed environment variables were set for this configuration.';
export const INIT_STATE_RELAY_LIMITS_DISABLED = 'Hedera JSON-RPC Relay rate limits were disabled.';
export const INIT_STATE_BOOTSTRAPPED_PROP_SET = 'Needed bootsrap properties were set for this configuration.';
export const INIT_STATE_MIRROR_PROP_SET = 'Needed mirror node properties were set for this configuration.';
export const INIT_STATE_NO_NODE_CONF_NEEDED = 'No additional node configuration needed.';
export const INIT_STATE_NO_ENV_VAR_CONFIGURED = 'No new environment variables were configured.';
export const INIT_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Initialization State Initialized!`;
export const INIT_STATE_STARTING_MESSAGE = `${CHECK_SUCCESS} Initialization State Starting...`;
export const INIT_STATE_START_DOCKER_CHECK = `${LOADING} Making sure that Docker is started and it is correct version...`;
export const INIT_STATE_CONFIGURING_ENV_VARIABLES_FINISH = `${CHECK_SUCCESS} Needed environment variables were set for this configuration.`;
export const INIT_STATE_RELAY_LIMITS_DISABLED = `${CHECK_SUCCESS} Hedera JSON-RPC Relay rate limits were disabled.`;
export const INIT_STATE_BOOTSTRAPPED_PROP_SET = `${CHECK_SUCCESS} Needed bootsrap properties were set for this configuration.`;
export const INIT_STATE_MIRROR_PROP_SET = `${CHECK_SUCCESS} Needed mirror node properties were set for this configuration.`;
export const INIT_STATE_NO_NODE_CONF_NEEDED = `${CHECK_SUCCESS} No additional node configuration needed.`;
export const INIT_STATE_NO_ENV_VAR_CONFIGURED = `${CHECK_SUCCESS} No new environment variables were configured.`;

// Debug state
export const DEBUG_STATE_INIT_MESSAGE = 'Debug State Initialized!';
export const DEBUG_STATE_STARTING_MESSAGE = 'Debug State Starting...';
// StateController
export const STATE_CONTROLLER_MISSING_STATE_CONFIG_ERROR = 'Something is wrong with state configuration!';
export const DEBUG_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Debug State Initialized!`;
export const DEBUG_STATE_STARTING_MESSAGE = `${LOADING} Debug State Starting...`;

// StateController
export const STATE_CONTROLLER_MISSING_STATE_CONFIG_ERROR = `${CHECK_FAIL} Something is wrong with state configuration!`;

// Account Creation State

export const ACCOUNT_CREATION_STATE_INIT_MESSAGE = 'Account Creation State Initialized!';
export const ACCOUNT_CREATION_STARTING_SYNCHRONOUS_MESSAGE = 'Starting Account Creation state in synchronous mode ';
export const ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_MESSAGE ='Starting Account Creation state in asynchronous mode ';
export const ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_BLOCKLIST_MESSAGE = 'Starting Account Creation state in asynchronous mode with 1 blocklisted accounts';
export const ACCOUNT_CREATION_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Account Creation State Initialized!`;
export const ACCOUNT_CREATION_STARTING_SYNCHRONOUS_MESSAGE = `${LOADING} Starting Account Creation state in synchronous mode...`;
export const ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_MESSAGE = `${LOADING} Starting Account Creation state in asynchronous mode...`;
export const ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_BLOCKLIST_MESSAGE = `${LOADING} Starting Account Creation state in asynchronous mode with 1 blocklisted accounts...`;
export const ACCOUNT_CREATION_FINISHED = `${CHECK_SUCCESS} Accounts created succefully!`;

// Resource Creation State
export const RESOURCE_CREATION_STATE_INIT_MESSAGE = 'Resource Creation State Initialized!';
export const RESOURCE_CREATION_STARTING_SYNCHRONOUS_MESSAGE = 'Starting Resource Creation state in synchronous mode';
export const RESOURCE_CREATION_STARTING_ASYNCHRONOUS_MESSAGE ='Starting Resource Creation state in asynchronous mode';
export const RESOURCE_CREATION_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Resource Creation State Initialized!`;
export const RESOURCE_CREATION_STARTING_SYNCHRONOUS_MESSAGE = `${LOADING} Starting Resource Creation state in synchronous mode...`;
export const RESOURCE_CREATION_STARTING_ASYNCHRONOUS_MESSAGE = `${LOADING} Starting Resource Creation state in asynchronous mode...`;
7 changes: 4 additions & 3 deletions src/controller/StateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
*/

import { CHECK_FAIL, CHECK_SUCCESS } from '../constants';
import { StateData } from '../data/StateData';
import { LoggerService } from '../services/LoggerService';
import { ServiceLocator } from '../services/ServiceLocator';
Expand Down Expand Up @@ -73,8 +74,8 @@ export class StateController implements IOBserver{
this.stateConfiguration = new StateData().getSelectedStateConfiguration(stateName);
this.currStateNum = 0;
this.maxStateNum = 0;
this.logger.trace('State Controller Initialized!', this.controllerName);
this.logger.info(`Starting ${stateName} procedure!`, this.controllerName);
this.logger.trace(`${CHECK_SUCCESS} State Controller Initialized!`, this.controllerName);
this.logger.info(`${CHECK_SUCCESS} Starting ${stateName} procedure!`, this.controllerName);
}

/**
Expand All @@ -84,7 +85,7 @@ export class StateController implements IOBserver{
*/
public async startStateMachine() {
if (!this.stateConfiguration) {
this.logger.error('Something is wrong with state configuration!', this.controllerName);
this.logger.error(`${CHECK_FAIL} Something is wrong with state configuration!`, this.controllerName);
// TODO: handle error
process.exit(1);
} else {
Expand Down
27 changes: 15 additions & 12 deletions src/services/DockerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import semver from'semver';
import fs from 'fs';
import { IS_WINDOWS, NECESSARY_PORTS, UNKNOWN_VERSION, OPTIONAL_PORTS,
MIN_CPUS, MIN_MEMORY_MULTI_MODE, MIN_MEMORY_SINGLE_MODE,
RECOMMENDED_CPUS, RECOMMENDED_MEMORY_SINGLE_MODE } from '../constants';
RECOMMENDED_CPUS, RECOMMENDED_MEMORY_SINGLE_MODE,
CHECK_SUCCESS,
CHECK_FAIL,
LOADING} from '../constants';
import { IService } from './IService';
import { LoggerService } from './LoggerService';
import { ServiceLocator } from './ServiceLocator';
Expand Down Expand Up @@ -66,7 +69,7 @@ export class DockerService implements IService{
constructor() {
this.serviceName = DockerService.name;
this.logger = ServiceLocator.Current.get<LoggerService>(LoggerService.name);
this.logger.trace('Docker Service Initialized!', this.serviceName);
this.logger.trace(`${CHECK_SUCCESS} Docker Service Initialized!`, this.serviceName);

const defaultSocketPath = IS_WINDOWS
? '//./pipe/docker_engine'
Expand Down Expand Up @@ -109,11 +112,11 @@ export class DockerService implements IService{
await docker
.info()
.then(() => {
this.logger.trace('Docker is running.', this.serviceName);
this.logger.trace(`${CHECK_SUCCESS} Docker is running.`, this.serviceName);
isRunning = true;
})
.catch(() => {
this.logger.error('Docker is not running.', this.serviceName);
this.logger.error(`${CHECK_FAIL} Docker is not running.`, this.serviceName);
isRunning = false;
});
return isRunning;
Expand All @@ -140,16 +143,16 @@ export class DockerService implements IService{
resolvedPromises.forEach((result, index) => {
const port = portsToCheck[index];
if (result && OPTIONAL_PORTS.includes(port)) {
this.logger.info(`Port ${port} is in use.`, this.serviceName);
this.logger.warn(`Port ${port} is in use.`, this.serviceName);
} else if (result && NECESSARY_PORTS.includes(port)) {
this.logger.error(`Port ${port} is in use.`, this.serviceName);
this.logger.error(`${CHECK_FAIL} Port ${port} is in use.`, this.serviceName);
}
});

const resolvedPromisesNecessaryPortsOnly = resolvedPromises.slice(0, NECESSARY_PORTS.length);

if(!(resolvedPromisesNecessaryPortsOnly.every(value => value === false))) {
this.logger.error('Node cannot start properly because necessary ports are in use', this.serviceName);
this.logger.error(`${CHECK_FAIL} Node cannot start properly because necessary ports are in use!`, this.serviceName);
process.exit(1);
}
}
Expand All @@ -161,7 +164,7 @@ export class DockerService implements IService{
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the Docker Compose version is correct.
*/
public async isCorrectDockerComposeVersion (): Promise<boolean> {
this.logger.info('Checking docker compose version...', this.serviceName);
this.logger.info(`${LOADING} Checking docker compose version...`, this.serviceName);
// We are executing both commands because in Linux we may have docker-compose v2, so we need to check both
const resultFirstCommand = await shell.exec(
'docker compose version --short',
Expand All @@ -174,13 +177,13 @@ export class DockerService implements IService{

// Exit code is 127 when no docker installation is found
if (resultFirstCommand.code === 127 && resultSecondCommand.code === 127) {
this.logger.error('Please install docker compose V2.', this.serviceName);
this.logger.error(`Please install docker compose V2.`, this.serviceName);
} else if (
resultFirstCommand.code === 127 &&
resultSecondCommand.code === 0
) {
this.logger.error(
'Looks like you have docker-compose V1, but you need docker compose V2',
`Looks like you have docker-compose V1, but you need docker compose V2!`,
this.serviceName
);
} else {
Expand All @@ -200,7 +203,7 @@ export class DockerService implements IService{
}

public async checkDockerResources(isMultiNodeMode: boolean) {
this.logger.info('Checking docker resources...', this.serviceName);
this.logger.info(`${LOADING} Checking docker resources...`, this.serviceName);
const resultDockerInfoCommand = await shell.exec(
"docker system info --format='{{json .}}'",
{ silent: true }
Expand Down Expand Up @@ -389,6 +392,6 @@ export class DockerService implements IService{
this.logger.trace('Cleaning the volumes and temp files...', stateName);
shell.exec(`rm -rf network-logs/* >${nullOutput} 2>&1`);
shell.exec(`docker network prune -f 2>${nullOutput}`);
this.logger.info('Trying to startup again...', stateName);
this.logger.info(`${LOADING} Trying to startup again...`, stateName);
}
}
Loading

0 comments on commit a6f2da5

Please sign in to comment.