diff --git a/.gitignore b/.gitignore index 75753f6d..5f86aa9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,37 @@ +dapps/ +docs/jsdoc/ +release +ssl/ + +# Config files +config.json +test/config.json +sftp-config.json + +# Logs +logs/*.log +stacktrace* + +# Code Editors .DS_Store .ed25519-node .idea/ .project .vscode/ __MACOSX/ -dapps/ -docs/jsdoc/ -logs/*.log -node_modules -nodejs/ -npm-debug.log -release -ssl/ -stacktrace* + +# Tests test/.coverage-unit test/.coverage test/.nyc_output + +# Temporary data tmp -sftp-config.json *.swp *.swo -package-lock.json +# npm +node_modules +package-lock.json +npm-debug.log +nodejs diff --git a/README.md b/README.md index bae988d2..5f96021a 100644 --- a/README.md +++ b/README.md @@ -79,12 +79,12 @@ F. e., wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add - sudo apt-get update sudo apt-get install -y postgresql postgresql-contrib libpq-dev - + # Create user if you are working from superuser adduser adamant sudo usermod -aG sudo adamant su - adamant - + # Create db sudo -u postgres createuser --createdb $USER createdb adamant_test @@ -107,12 +107,26 @@ cd adamant npm install ``` -Then set db.password in config: +Copy the default config file by running the following command: + +``` +cp config.default.json config.json +``` + +Edit the "config.json" file using your preferred text editor, for example, Vim or Nano. ``` nano config.json ``` +or + +``` +vim config.json +``` + +Make the necessary changes to the configuration values in the file. At minimum, you should change the value of the `db.password` property to your actual database password. + ### Bootstrap with a blockchain image Blockchain image saves time on node sync but you must completely trust the image. If you skip this step, your node will check every single transaction, which takes time (up for several days). @@ -190,9 +204,9 @@ This program is free software: you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the [GNU General Public License](https://github.com/LiskHQ/lisk/tree/master/LICENSE) along with this program. If not, see . +You should have received a copy of the [GNU General Public License](https://github.com/LiskHQ/lisk/tree/master/LICENSE) along with this program. If not, see . -*** +--- This program also incorporates work previously released with lisk `0.7.0` (and earlier) versions under the [MIT License](https://opensource.org/licenses/MIT). To comply with the requirements of that license, the following permission notice, applicable to those parts of the code only, is included below: diff --git a/app.js b/app.js index 9b7f1f8a..23dd7d6b 100644 --- a/app.js +++ b/app.js @@ -219,7 +219,7 @@ d.run(function () { } if (!appConfig.cors) { - appConfig.cors = { origin: true }; + appConfig.cors = { origin: '*' }; } appConfig.cors.credentials = true; diff --git a/config.default.json b/config.default.json new file mode 100644 index 00000000..01fcf138 --- /dev/null +++ b/config.default.json @@ -0,0 +1,127 @@ +{ + "port": 36666, + "address": "0.0.0.0", + "fileLogLevel": "warn", + "logFileName": "logs/adamant.log", + "consoleLogLevel": "info", + "trustProxy": false, + "topAccounts": false, + "cacheEnabled": false, + "db": { + "host": "localhost", + "port": 5432, + "database": "adamant_main", + "user": "adamant", + "password": "password", + "poolSize": 95, + "poolIdleTimeout": 30000, + "reapIntervalMillis": 1000, + "logEvents": [ + "error" + ] + }, + "redis": { + "url": "redis://127.0.0.1:6379/0", + "password": null + }, + "api": { + "enabled": true, + "access": { + "public": false, + "whiteList": [ + "127.0.0.1" + ] + }, + "options": { + "limits": { + "max": 0, + "delayMs": 0, + "delayAfter": 0, + "windowMs": 60000 + } + } + }, + "peers": { + "enabled": true, + "list": [ + { + "ip": "51.15.221.205", + "port": 36666 + }, + { + "ip": "51.15.88.53", + "port": 36666 + }, + { + "ip": "5.161.68.61", + "port": 36666 + }, + { + "ip": "78.47.205.206", + "port": 36666 + }, + { + "ip": "107.161.26.184", + "port": 36666 + }, + { + "ip": "138.201.152.191", + "port": 36666 + } + ], + "access": { + "blackList": [] + }, + "options": { + "limits": { + "max": 0, + "delayMs": 0, + "delayAfter": 0, + "windowMs": 60000 + }, + "timeout": 5000 + } + }, + "broadcasts": { + "broadcastInterval": 1500, + "broadcastLimit": 20, + "parallelLimit": 20, + "releaseLimit": 25, + "relayLimit": 4 + }, + "transactions": { + "maxTxsPerQueue": 1000 + }, + "forging": { + "force": false, + "secret": [], + "access": { + "whiteList": [ + "127.0.0.1" + ] + } + }, + "loading": { + "verifyOnLoading": false, + "loadPerIteration": 5000 + }, + "ssl": { + "enabled": false, + "options": { + "port": 443, + "address": "0.0.0.0", + "key": "./ssl/adamant.key", + "cert": "./ssl/adamant.crt" + } + }, + "dapp": { + "masterrequired": true, + "masterpassword": "", + "autoexec": [] + }, + "wsClient": { + "portWS": 36668, + "enabled": true + }, + "nethash": "bd330166898377fb28743ceef5e43a5d9d0a3efd9b3451fb7bc53530bb0a6d64" +} diff --git a/helpers/database.js b/helpers/database.js index a56dac68..1af79e61 100644 --- a/helpers/database.js +++ b/helpers/database.js @@ -15,7 +15,7 @@ var path = require('path'); * @param {Object} pgp - pg promise * @param {Object} db - pg connection */ -function Migrator (pgp, db) { +function Migrator (pgp, db, logger) { /** * Gets one record from `migrations` table * @method @@ -108,6 +108,10 @@ function Migrator (pgp, db) { * @return {function} waterCb with error | appliedMigrations */ this.applyPendingMigrations = function (pendingMigrations, waterCb) { + if (pendingMigrations.length) { + logger.info(`Found ${pendingMigrations.length} pending migrations. Start executing, this may take a while…`); + } + var appliedMigrations = []; async.eachSeries(pendingMigrations, function (file, eachCb) { @@ -120,6 +124,10 @@ function Migrator (pgp, db) { return eachCb(err); }); }, function (err) { + if (pendingMigrations.length && !err) { + logger.info('Migrations have been successfully completed.'); + } + return waterCb(err, appliedMigrations); }); }; @@ -198,7 +206,7 @@ module.exports.connect = function (config, logger, cb) { config.user = config.user || process.env.USER; var db = pgp(config); - var migrator = new Migrator(pgp, db); + var migrator = new Migrator(pgp, db, logger); async.waterfall([ migrator.checkMigrations, diff --git a/package.json b/package.json index 991ef624..3204a981 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "adamant", - "version": "0.8.0", + "version": "0.8.1", "private": true, "scripts": { "start": "node app.js", diff --git a/test/config.json b/test/config.default.json similarity index 100% rename from test/config.json rename to test/config.default.json diff --git a/tools/install_node.sh b/tools/install_node.sh index 541adfa1..deef907c 100644 --- a/tools/install_node.sh +++ b/tools/install_node.sh @@ -141,6 +141,15 @@ npm i #Setup node: set DB password in config.json printf "\n\nSetting node's config…\n\n" + +if [[ $configfile == "config.json" ]] +then + cp default.config.json config.json +elif [ "$configfile" == "test/config.json" ] +then + cp test/config.default.json test/config.json +fi + rpl -i -q '"password": "password",' "\"password\": \"${DB_PASSWORD}\"," "$configfile" #By default, node's API is available only from localhost diff --git a/tools/install_node_centos.sh b/tools/install_node_centos.sh index 6d4dd4fe..2cdf6086 100644 --- a/tools/install_node_centos.sh +++ b/tools/install_node_centos.sh @@ -113,14 +113,14 @@ sudo dnf -y update printf "\n\nInstalling postgresql and other prerequisites…\n\n" -sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm +sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm sudo dnf -qy module disable postgresql sudo dnf -y install postgresql13 postgresql13-server postgresql13-contrib sudo /usr/pgsql-13/bin/postgresql-13-setup initdb sudo systemctl enable --now postgresql-13 sudo dnf group install "Development Tools" -y sudo dnf -y install wget python2 curl mc git nano automake autoconf libtool rpl wget libpq5-devel redis -sudo systemctl enable --now redis +sudo systemctl enable --now redis #Postgres printf "\n\nCreating database '%s' and database user '%s'…\n\n" "$databasename" "$username" @@ -149,6 +149,15 @@ npm i #Setup node: set DB password in config.json printf "\n\nSetting node's config…\n\n" + +if [[ $configfile == "config.json" ]] +then + cp default.config.json config.json +elif [ "$configfile" == "test/config.json" ] +then + cp test/config.default.json test/config.json +fi + rpl -i -q '"password": "password",' "\"password\": \"${DB_PASSWORD}\"," "$configfile" #By default, node's API is available only from localhost