diff --git a/packages/cli/src/download.ts b/packages/cli/src/download.ts index c73fa36f..7d1d0702 100644 --- a/packages/cli/src/download.ts +++ b/packages/cli/src/download.ts @@ -157,7 +157,7 @@ export async function download( if (!preserveCLI) { // make sure the CLI is always the latest - await updateCLI({ verbose }); + await updateCLI({ verbose, version }); } else { // TODO figure out the cause of errors try { diff --git a/packages/cli/src/node/export-snapshot.ts b/packages/cli/src/node/export-snapshot.ts index f78e4e69..a6e988f9 100644 --- a/packages/cli/src/node/export-snapshot.ts +++ b/packages/cli/src/node/export-snapshot.ts @@ -19,7 +19,6 @@ import { getBlockHeight, getDBEnvVars, hasLocalPostgres, - isLinux, printUsingConfig, runSQL, } from '../shared/misc'; @@ -36,7 +35,6 @@ import { nodeStart } from './start'; export type TOptions = IConfig & INetwork & IVerbose; -// TODO allow re-using an existing backup file export default leaf({ commandName: 'export-snapshot', description: `Creates an optimized database snapshot using the provided config and places it in ./${BACKUPS_DIR}.`, @@ -45,6 +43,7 @@ export default leaf({ ...configOption, ...networkOption, ...verboseOption, + // TODO --file options, which points to backup (to avoid exporting the db) }, async action({ config, network, verbose }: TOptions) { @@ -116,7 +115,6 @@ export async function nodeExportSnapshot({ // TODO merge with `nodeImportDB()` // import the exported file - log('Importing the backup file...'); // TODO unify with others by piping manually const backupPath = path.resolve(getBackupsDir(), 'latest'); try { @@ -128,6 +126,7 @@ export async function nodeExportSnapshot({ execSyncAsUser(cmd, null, { env }); } catch (e) { log(`Cannot import "${backupPath}" into the snap DB`); + throw e; } await runSQL('delete from exceptions;', network, config, verbose, targetDB); @@ -167,6 +166,7 @@ export async function nodeExportSnapshot({ execSyncAsUser(cmd, null, { env }); } catch (e) { log("Couldn't dump the DB"); + throw e; } log('Snapshot ready, removing the temp DB'); diff --git a/packages/cli/src/node/start.ts b/packages/cli/src/node/start.ts index f3c38b45..928080fb 100644 --- a/packages/cli/src/node/start.ts +++ b/packages/cli/src/node/start.ts @@ -27,8 +27,10 @@ import { createParseNodeOutput, dbConnectionInfo, execCmd, - getDBEnvVars, getSudoUsername, - isDevEnv, isSudo, + getDBEnvVars, + getSudoUsername, + isDevEnv, + isSudo, mergeConfig, printUsingConfig, } from '../shared/misc'; @@ -134,7 +136,6 @@ export async function nodeStart( log('Starting RISE Node...'); let ready = false; - removeNodeLock(); // add the crontab entry if requested if (crontab) { @@ -222,7 +223,6 @@ function startLaunchpad( params.push( '-s', '--override-config', - // TODO test this works `db.database="${mergedConfig.db.database}_snap"` ); } @@ -238,7 +238,9 @@ function startLaunchpad( { foreground, verbose }, () => { setReady(); - setNodeLock(proc.pid, NodeStates.READY); + if (!isDevEnv()) { + setNodeLock(proc.pid, NodeStates.READY); + } if (!foreground) { resolve(); } diff --git a/packages/cli/src/shared/constants.ts b/packages/cli/src/shared/constants.ts index d457a618..0514a9be 100644 --- a/packages/cli/src/shared/constants.ts +++ b/packages/cli/src/shared/constants.ts @@ -1,6 +1,6 @@ const isLinux = process.platform === 'linux'; // TODO keep in sync with /packages/cli/package.json -export const VERSION_CLI = 'v1.1.2'; +export const VERSION_CLI = 'v1.1.5'; // TODO keep in sync with /package.json export const VERSION_RISE = 'v2.0.1-beta1'; // TODO single enum for NETWORKS and NetworkType @@ -27,9 +27,9 @@ export const DB_LOG_FILE = isLinux export const DB_LOCK_FILE = DB_DATA_DIR + '/postmaster.pid'; export const DB_PG_PATH = isLinux ? '/usr/lib/postgresql/11/bin/' : ''; export const DOWNLOAD_URL = 'https://github.com/RiseVision/rise-node/releases/'; -export const NODE_LOCK_FILE = '/tmp/rise-node.pid.lock'; -export const SNAPSHOT_LOCK_FILE = '/tmp/rise-snapshot.pid.lock'; -export const BACKUP_LOCK_FILE = '/tmp/rise-backup.pid.lock'; +export const NODE_LOCK_FILE = '/tmp/rise-node-v2.pid.lock'; +export const SNAPSHOT_LOCK_FILE = '/tmp/rise-snapshot-v2.pid.lock'; +export const BACKUP_LOCK_FILE = '/tmp/rise-backup-v2.pid.lock'; export const BACKUPS_DIR = DATA_DIR + '/backups'; export const LOGS_DIR = DATA_DIR + '/logs'; export const SHELL_LOG_FILE = LOGS_DIR + '/shell'; diff --git a/packages/cli/src/shared/fs-ops.ts b/packages/cli/src/shared/fs-ops.ts index d5c19057..0c02b335 100644 --- a/packages/cli/src/shared/fs-ops.ts +++ b/packages/cli/src/shared/fs-ops.ts @@ -17,7 +17,6 @@ import { NoRiseDistFileError } from './exceptions'; import { debug, log } from './log'; import { execCmd, - execSyncAsUser, getSudoUsername, isDevEnv, isSudo, @@ -172,6 +171,7 @@ export function setNodeLock(pid: number, state: NodeStates) { } export function removeNodeLock() { + debug('removing node lock'); if (!isDevEnv() && fs.existsSync(NODE_LOCK_FILE)) { fs.unlinkSync(NODE_LOCK_FILE); } @@ -192,11 +192,15 @@ export function getPID(filePath: string): [number, NodeStates] | false { .split('\n'); let exists: string; try { - exists = execSyncAsUser(`ps -p ${pid} -o pid=`, null, null, false); + // null output when using execSyncAsUser + exists = execSync(`ps -p ${pid} -o pid=`) + .toString('utf8') + .trim(); } catch { // empty } if (!exists) { + log(`PID ${pid} doesn't exist, removing the lock file`); fs.unlinkSync(filePath); return false; } diff --git a/packages/cli/src/shared/log.ts b/packages/cli/src/shared/log.ts index 99c778b1..8aaa6b62 100644 --- a/packages/cli/src/shared/log.ts +++ b/packages/cli/src/shared/log.ts @@ -3,7 +3,7 @@ import { execSync } from 'child_process'; import { debug as createDebug } from 'debug'; import fs from 'fs'; import { sync as mkdirpSync } from 'mkdirp'; -import { LOGS_DIR, SHELL_LOG_FILE } from './constants'; +import { DATA_DIR, LOGS_DIR, SHELL_LOG_FILE } from './constants'; import { getSudoUsername, isSudo } from './misc'; export const debug = createDebug('rise-cli'); @@ -17,7 +17,7 @@ function createShellLogHandler(): number { appendHeader(fd); // fix perms when in sudo if (isSudo()) { - execSync(`chown ${getSudoUsername()} ${SHELL_LOG_FILE}`); + execSync(`chown -R ${getSudoUsername()} ${DATA_DIR}`); } return fd; } diff --git a/packages/cli/src/shared/misc.ts b/packages/cli/src/shared/misc.ts index 344b8673..86a048ac 100644 --- a/packages/cli/src/shared/misc.ts +++ b/packages/cli/src/shared/misc.ts @@ -234,7 +234,10 @@ export function createParseNodeOutput( return; } // DB corrupted - if (data.includes('SequelizeUniqueConstraintError')) { + if ( + data.includes('SequelizeUniqueConstraintError') || + data.includes('violates not-null constraint') + ) { debug('DBCorruptedError'); reject(new DBCorruptedError()); return; @@ -408,6 +411,11 @@ export function checkSudo(requireSudo = true) { throw new ConditionsNotMetError('Needs sudo'); // TODO show the whole command for copy&pasting } + if (isSudo() && getSudoUsername() === 'root' && getUsername() !== 'root') { + throw new ConditionsNotMetError( + 'Logging in as root and switching with `su - USER` not supported' + ); + } } export function execSyncAsUser( diff --git a/packages/core-p2p/src/peersLogic.ts b/packages/core-p2p/src/peersLogic.ts index 700b3404..c20dd6ed 100644 --- a/packages/core-p2p/src/peersLogic.ts +++ b/packages/core-p2p/src/peersLogic.ts @@ -81,12 +81,16 @@ export class PeersLogic { return false; } // insert peer! + // TODO fix if (!_.isEmpty(this.acceptable([thePeer]))) { thePeer.updated = Date.now(); this.peers[thePeer.string] = thePeer; this.logger.debug('Inserted new peer', thePeer.string); } else { - this.logger.debug('Rejecting unacceptable peer', thePeer.string); + this.logger.debug( + 'Rejecting unacceptable peer', + thePeer.string + ' v' + thePeer.version + ); } } diff --git a/packages/core/src/modules/loader.ts b/packages/core/src/modules/loader.ts index 4ab1591f..5583684f 100644 --- a/packages/core/src/modules/loader.ts +++ b/packages/core/src/modules/loader.ts @@ -212,6 +212,7 @@ export class LoaderModule implements ILoaderModule { await this.blocksProcessModule.loadBlocksOffset( Math.min(limitPerIteration, 1 + count - offset), // exclusive limit offset, + // TODO true /*verify*/ ); offset = offset + limitPerIteration; diff --git a/packages/rise/etc/mainnet/config.json b/packages/rise/etc/mainnet/config.json index 0ee9d80e..9e2550f1 100644 --- a/packages/rise/etc/mainnet/config.json +++ b/packages/rise/etc/mainnet/config.json @@ -1,7 +1,7 @@ { "port": 5554, "address": "0.0.0.0", - "version": "2.0.0", + "version": "2.1.0", "fileLogLevel": "info", "logFileName": "logs/rise-mainnet.log", "consoleLogLevel": "info", @@ -39,7 +39,7 @@ "peers": { "enabled": true, "trustProxy": false, - "seeds": ["45.32.136.66:5554", "45.76.36.14:5554", "212.24.96.99:5554"], + "seeds": ["51.15.52.67:5554", "45.76.36.14:5554", "45.63.0.54:5554"], "access": { "blackList": [] },