Skip to content

Commit d359dc4

Browse files
committed
- fixed network version number
- fixed seed IPs - fixed reading PIDs from lock files - more error handling - update-cli to the same version when `download --version`
1 parent ded03bb commit d359dc4

10 files changed

Lines changed: 40 additions & 21 deletions

File tree

packages/cli/src/download.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export async function download(
157157

158158
if (!preserveCLI) {
159159
// make sure the CLI is always the latest
160-
await updateCLI({ verbose });
160+
await updateCLI({ verbose, version });
161161
} else {
162162
// TODO figure out the cause of errors
163163
try {

packages/cli/src/node/export-snapshot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
getBlockHeight,
2020
getDBEnvVars,
2121
hasLocalPostgres,
22-
isLinux,
2322
printUsingConfig,
2423
runSQL,
2524
} from '../shared/misc';
@@ -36,7 +35,6 @@ import { nodeStart } from './start';
3635

3736
export type TOptions = IConfig & INetwork & IVerbose;
3837

39-
// TODO allow re-using an existing backup file
4038
export default leaf({
4139
commandName: 'export-snapshot',
4240
description: `Creates an optimized database snapshot using the provided config and places it in ./${BACKUPS_DIR}.`,
@@ -45,6 +43,7 @@ export default leaf({
4543
...configOption,
4644
...networkOption,
4745
...verboseOption,
46+
// TODO --file options, which points to backup (to avoid exporting the db)
4847
},
4948

5049
async action({ config, network, verbose }: TOptions) {
@@ -116,7 +115,6 @@ export async function nodeExportSnapshot({
116115

117116
// TODO merge with `nodeImportDB()`
118117
// import the exported file
119-
log('Importing the backup file...');
120118
// TODO unify with others by piping manually
121119
const backupPath = path.resolve(getBackupsDir(), 'latest');
122120
try {
@@ -128,6 +126,7 @@ export async function nodeExportSnapshot({
128126
execSyncAsUser(cmd, null, { env });
129127
} catch (e) {
130128
log(`Cannot import "${backupPath}" into the snap DB`);
129+
throw e;
131130
}
132131
await runSQL('delete from exceptions;', network, config, verbose, targetDB);
133132

@@ -167,6 +166,7 @@ export async function nodeExportSnapshot({
167166
execSyncAsUser(cmd, null, { env });
168167
} catch (e) {
169168
log("Couldn't dump the DB");
169+
throw e;
170170
}
171171

172172
log('Snapshot ready, removing the temp DB');

packages/cli/src/node/start.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ import {
2727
createParseNodeOutput,
2828
dbConnectionInfo,
2929
execCmd,
30-
getDBEnvVars, getSudoUsername,
31-
isDevEnv, isSudo,
30+
getDBEnvVars,
31+
getSudoUsername,
32+
isDevEnv,
33+
isSudo,
3234
mergeConfig,
3335
printUsingConfig,
3436
} from '../shared/misc';
@@ -134,7 +136,6 @@ export async function nodeStart(
134136
log('Starting RISE Node...');
135137

136138
let ready = false;
137-
removeNodeLock();
138139

139140
// add the crontab entry if requested
140141
if (crontab) {
@@ -222,7 +223,6 @@ function startLaunchpad(
222223
params.push(
223224
'-s',
224225
'--override-config',
225-
// TODO test this works
226226
`db.database="${mergedConfig.db.database}_snap"`
227227
);
228228
}
@@ -238,7 +238,9 @@ function startLaunchpad(
238238
{ foreground, verbose },
239239
() => {
240240
setReady();
241-
setNodeLock(proc.pid, NodeStates.READY);
241+
if (!isDevEnv()) {
242+
setNodeLock(proc.pid, NodeStates.READY);
243+
}
242244
if (!foreground) {
243245
resolve();
244246
}

packages/cli/src/shared/constants.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const isLinux = process.platform === 'linux';
22
// TODO keep in sync with /packages/cli/package.json
3-
export const VERSION_CLI = 'v1.1.2';
3+
export const VERSION_CLI = 'v1.1.5';
44
// TODO keep in sync with /package.json
55
export const VERSION_RISE = 'v2.0.1-beta1';
66
// TODO single enum for NETWORKS and NetworkType
@@ -27,9 +27,9 @@ export const DB_LOG_FILE = isLinux
2727
export const DB_LOCK_FILE = DB_DATA_DIR + '/postmaster.pid';
2828
export const DB_PG_PATH = isLinux ? '/usr/lib/postgresql/11/bin/' : '';
2929
export const DOWNLOAD_URL = 'https://github.com/RiseVision/rise-node/releases/';
30-
export const NODE_LOCK_FILE = '/tmp/rise-node.pid.lock';
31-
export const SNAPSHOT_LOCK_FILE = '/tmp/rise-snapshot.pid.lock';
32-
export const BACKUP_LOCK_FILE = '/tmp/rise-backup.pid.lock';
30+
export const NODE_LOCK_FILE = '/tmp/rise-node-v2.pid.lock';
31+
export const SNAPSHOT_LOCK_FILE = '/tmp/rise-snapshot-v2.pid.lock';
32+
export const BACKUP_LOCK_FILE = '/tmp/rise-backup-v2.pid.lock';
3333
export const BACKUPS_DIR = DATA_DIR + '/backups';
3434
export const LOGS_DIR = DATA_DIR + '/logs';
3535
export const SHELL_LOG_FILE = LOGS_DIR + '/shell';

packages/cli/src/shared/fs-ops.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { NoRiseDistFileError } from './exceptions';
1717
import { debug, log } from './log';
1818
import {
1919
execCmd,
20-
execSyncAsUser,
2120
getSudoUsername,
2221
isDevEnv,
2322
isSudo,
@@ -172,6 +171,7 @@ export function setNodeLock(pid: number, state: NodeStates) {
172171
}
173172

174173
export function removeNodeLock() {
174+
debug('removing node lock');
175175
if (!isDevEnv() && fs.existsSync(NODE_LOCK_FILE)) {
176176
fs.unlinkSync(NODE_LOCK_FILE);
177177
}
@@ -192,11 +192,15 @@ export function getPID(filePath: string): [number, NodeStates] | false {
192192
.split('\n');
193193
let exists: string;
194194
try {
195-
exists = execSyncAsUser(`ps -p ${pid} -o pid=`, null, null, false);
195+
// null output when using execSyncAsUser
196+
exists = execSync(`ps -p ${pid} -o pid=`)
197+
.toString('utf8')
198+
.trim();
196199
} catch {
197200
// empty
198201
}
199202
if (!exists) {
203+
log(`PID ${pid} doesn't exist, removing the lock file`);
200204
fs.unlinkSync(filePath);
201205
return false;
202206
}

packages/cli/src/shared/log.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { execSync } from 'child_process';
33
import { debug as createDebug } from 'debug';
44
import fs from 'fs';
55
import { sync as mkdirpSync } from 'mkdirp';
6-
import { LOGS_DIR, SHELL_LOG_FILE } from './constants';
6+
import { DATA_DIR, LOGS_DIR, SHELL_LOG_FILE } from './constants';
77
import { getSudoUsername, isSudo } from './misc';
88

99
export const debug = createDebug('rise-cli');
@@ -17,7 +17,7 @@ function createShellLogHandler(): number {
1717
appendHeader(fd);
1818
// fix perms when in sudo
1919
if (isSudo()) {
20-
execSync(`chown ${getSudoUsername()} ${SHELL_LOG_FILE}`);
20+
execSync(`chown -R ${getSudoUsername()} ${DATA_DIR}`);
2121
}
2222
return fd;
2323
}

packages/cli/src/shared/misc.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,10 @@ export function createParseNodeOutput(
234234
return;
235235
}
236236
// DB corrupted
237-
if (data.includes('SequelizeUniqueConstraintError')) {
237+
if (
238+
data.includes('SequelizeUniqueConstraintError') ||
239+
data.includes('violates not-null constraint')
240+
) {
238241
debug('DBCorruptedError');
239242
reject(new DBCorruptedError());
240243
return;
@@ -408,6 +411,11 @@ export function checkSudo(requireSudo = true) {
408411
throw new ConditionsNotMetError('Needs sudo');
409412
// TODO show the whole command for copy&pasting
410413
}
414+
if (isSudo() && getSudoUsername() === 'root' && getUsername() !== 'root') {
415+
throw new ConditionsNotMetError(
416+
'Logging in as root and switching with `su - USER` not supported'
417+
);
418+
}
411419
}
412420

413421
export function execSyncAsUser(

packages/core-p2p/src/peersLogic.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ export class PeersLogic {
8181
return false;
8282
}
8383
// insert peer!
84+
// TODO fix
8485
if (!_.isEmpty(this.acceptable([thePeer]))) {
8586
thePeer.updated = Date.now();
8687
this.peers[thePeer.string] = thePeer;
8788
this.logger.debug('Inserted new peer', thePeer.string);
8889
} else {
89-
this.logger.debug('Rejecting unacceptable peer', thePeer.string);
90+
this.logger.debug(
91+
'Rejecting unacceptable peer',
92+
thePeer.string + ' v' + thePeer.version
93+
);
9094
}
9195
}
9296

packages/core/src/modules/loader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export class LoaderModule implements ILoaderModule {
212212
await this.blocksProcessModule.loadBlocksOffset(
213213
Math.min(limitPerIteration, 1 + count - offset), // exclusive limit
214214
offset,
215+
// TODO
215216
true /*verify*/
216217
);
217218
offset = offset + limitPerIteration;

packages/rise/etc/mainnet/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"port": 5554,
33
"address": "0.0.0.0",
4-
"version": "2.0.0",
4+
"version": "2.1.0",
55
"fileLogLevel": "info",
66
"logFileName": "logs/rise-mainnet.log",
77
"consoleLogLevel": "info",
@@ -39,7 +39,7 @@
3939
"peers": {
4040
"enabled": true,
4141
"trustProxy": false,
42-
"seeds": ["45.32.136.66:5554", "45.76.36.14:5554", "212.24.96.99:5554"],
42+
"seeds": ["51.15.52.67:5554", "45.76.36.14:5554", "45.63.0.54:5554"],
4343
"access": {
4444
"blackList": []
4545
},

0 commit comments

Comments
 (0)