Skip to content

Commit

Permalink
- fixed network version number
Browse files Browse the repository at this point in the history
- fixed seed IPs
- fixed reading PIDs from lock files
- more error handling
- update-cli to the same version when `download --version`
  • Loading branch information
TobiaszCudnik committed Oct 20, 2019
1 parent ded03bb commit d359dc4
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/download.ts
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/node/export-snapshot.ts
Expand Up @@ -19,7 +19,6 @@ import {
getBlockHeight,
getDBEnvVars,
hasLocalPostgres,
isLinux,
printUsingConfig,
runSQL,
} from '../shared/misc';
Expand All @@ -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}.`,
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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);

Expand Down Expand Up @@ -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');
Expand Down
12 changes: 7 additions & 5 deletions packages/cli/src/node/start.ts
Expand Up @@ -27,8 +27,10 @@ import {
createParseNodeOutput,
dbConnectionInfo,
execCmd,
getDBEnvVars, getSudoUsername,
isDevEnv, isSudo,
getDBEnvVars,
getSudoUsername,
isDevEnv,
isSudo,
mergeConfig,
printUsingConfig,
} from '../shared/misc';
Expand Down Expand Up @@ -134,7 +136,6 @@ export async function nodeStart(
log('Starting RISE Node...');

let ready = false;
removeNodeLock();

// add the crontab entry if requested
if (crontab) {
Expand Down Expand Up @@ -222,7 +223,6 @@ function startLaunchpad(
params.push(
'-s',
'--override-config',
// TODO test this works
`db.database="${mergedConfig.db.database}_snap"`
);
}
Expand All @@ -238,7 +238,9 @@ function startLaunchpad(
{ foreground, verbose },
() => {
setReady();
setNodeLock(proc.pid, NodeStates.READY);
if (!isDevEnv()) {
setNodeLock(proc.pid, NodeStates.READY);
}
if (!foreground) {
resolve();
}
Expand Down
8 changes: 4 additions & 4 deletions 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
Expand All @@ -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';
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/shared/fs-ops.ts
Expand Up @@ -17,7 +17,6 @@ import { NoRiseDistFileError } from './exceptions';
import { debug, log } from './log';
import {
execCmd,
execSyncAsUser,
getSudoUsername,
isDevEnv,
isSudo,
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/shared/log.ts
Expand Up @@ -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');
Expand All @@ -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;
}
Expand Down
10 changes: 9 additions & 1 deletion packages/cli/src/shared/misc.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion packages/core-p2p/src/peersLogic.ts
Expand Up @@ -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
);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/modules/loader.ts
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions 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",
Expand Down Expand Up @@ -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": []
},
Expand Down

0 comments on commit d359dc4

Please sign in to comment.