Skip to content

Commit

Permalink
Merge pull request #53 from harpagon210/witnesses-mainnet
Browse files Browse the repository at this point in the history
Witnesses mainnet
  • Loading branch information
harpagon210 committed Jan 13, 2020
2 parents 0e3e07e + 4f5a101 commit 27528f7
Show file tree
Hide file tree
Showing 46 changed files with 16,387 additions and 4,598 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NODE_ENV=test
ACTIVE_SIGNING_KEY=5K...
ACTIVE_SIGNING_KEY=5K...
ACCOUNT=acc...
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contracts/bootstrap/*.js
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ services: mongodb
language: node_js
node_js:
- "10.5"
script:
- npm run lint
- npm run test
93 changes: 45 additions & 48 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
require('dotenv').config();
const nodeCleanup = require('node-cleanup');
const fs = require('fs-extra');
const program = require('commander');
const { fork } = require('child_process');
const { createLogger, format, transports } = require('winston');
const packagejson = require('./package.json');
const database = require('./plugins/Database');
const blockchain = require('./plugins/Blockchain');
const jsonRPCServer = require('./plugins/JsonRPCServer');
const streamer = require('./plugins/Streamer');
const replay = require('./plugins/Replay');
// const p2p = require('./plugins/P2P');

const conf = require('./config');

Expand Down Expand Up @@ -43,14 +42,17 @@ const jobs = new Map();
let currentJobId = 0;

// send an IPC message to a plugin with a promise in return
function send(plugin, message) {
const send = (plugin, message) => {
const newMessage = {
...message,
to: plugin.name,
from: 'MASTER',
type: 'request',
};
currentJobId += 1;
if (currentJobId > Number.MAX_SAFE_INTEGER) {
currentJobId = 1;
}
newMessage.jobId = currentJobId;
plugin.cp.send(newMessage);
return new Promise((resolve) => {
Expand All @@ -59,7 +61,7 @@ function send(plugin, message) {
resolve,
});
});
}
};

// function to route the IPC requests
const route = (message) => {
Expand Down Expand Up @@ -102,6 +104,7 @@ const loadPlugin = (newPlugin) => {
plugin.name = newPlugin.PLUGIN_NAME;
plugin.cp = fork(newPlugin.PLUGIN_PATH, [], { silent: true, detached: true });
plugin.cp.on('message', msg => route(msg));
plugin.cp.on('error', err => logger.error(`[${newPlugin.PLUGIN_NAME}] ${err}`));
plugin.cp.stdout.on('data', (data) => {
logger.info(`[${newPlugin.PLUGIN_NAME}] ${data.toString()}`);
});
Expand All @@ -122,30 +125,26 @@ const unloadPlugin = async (plugin) => {
plg.cp.kill('SIGINT');
plg = null;
}

return res;
};

// start streaming the Steem blockchain and produce the sidechain blocks accordingly
async function start() {
let res = await loadPlugin(database);
const start = async () => {
let res = await loadPlugin(blockchain);
if (res && res.payload === null) {
res = await loadPlugin(blockchain);
await send(getPlugin(database),
{ action: database.PLUGIN_ACTIONS.GENERATE_GENESIS_BLOCK, payload: conf });
res = await send(getPlugin(blockchain),
{ action: blockchain.PLUGIN_ACTIONS.START_BLOCK_PRODUCTION });
res = await loadPlugin(streamer);
if (res && res.payload === null) {
res = await loadPlugin(streamer);
// res = await loadPlugin(p2p);
if (res && res.payload === null) {
res = await loadPlugin(jsonRPCServer);
}
}
}
}
};

async function stop(callback) {
const stop = async () => {
await unloadPlugin(jsonRPCServer);
// await unloadPlugin(p2p);
// get the last Steem block parsed
let res = null;
const streamerPlugin = getPlugin(streamer);
Expand All @@ -156,40 +155,34 @@ async function stop(callback) {
}

await unloadPlugin(blockchain);
await unloadPlugin(database);
callback(res.payload);
}

function saveConfig(lastBlockParsed) {
return res.payload;
};

const saveConfig = (lastBlockParsed) => {
logger.info('Saving config');
const config = fs.readJSONSync('./config.json');
config.startSteemBlock = lastBlockParsed;
fs.writeJSONSync('./config.json', config, { spaces: 4 });
}
};

function stopApp(signal = 0) {
stop((lastBlockParsed) => {
logger.info('Saving config');
saveConfig(lastBlockParsed);
// calling process.exit() won't inform parent process of signal
process.kill(process.pid, signal);
});
}
const stopApp = async (signal = 0) => {
const lastBlockParsed = await stop();
saveConfig(lastBlockParsed);
// calling process.exit() won't inform parent process of signal
process.kill(process.pid, signal);
};

// replay the sidechain from a blocks log file
async function replayBlocksLog() {
let res = await loadPlugin(database);
const replayBlocksLog = async () => {
let res = await loadPlugin(blockchain);
if (res && res.payload === null) {
res = await loadPlugin(blockchain);
await send(getPlugin(database),
{ action: database.PLUGIN_ACTIONS.GENERATE_GENESIS_BLOCK, payload: conf });
if (res && res.payload === null) {
await loadPlugin(replay);
res = await send(getPlugin(replay),
{ action: replay.PLUGIN_ACTIONS.REPLAY_FILE });
stopApp();
}
await loadPlugin(replay);
res = await send(getPlugin(replay),
{ action: replay.PLUGIN_ACTIONS.REPLAY_FILE });
stopApp();
}
}
};

// manage the console args
program
Expand All @@ -204,15 +197,19 @@ if (program.replay !== undefined) {
}

// graceful app closing
nodeCleanup((exitCode, signal) => {
if (signal) {
logger.info(`Closing App... exitCode: ${exitCode} signal: ${signal}`);

stopApp(signal);
let shuttingDown = false;

nodeCleanup.uninstall(); // don't call cleanup handler again
return false;
const gracefulShutdown = () => {
if (shuttingDown === false) {
shuttingDown = true;
stopApp('SIGINT');
}
};

process.on('SIGTERM', () => {
gracefulShutdown();
});

return true;
process.on('SIGINT', () => {
gracefulShutdown();
});
4 changes: 2 additions & 2 deletions benchmarks/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NODE_ENV=test
ACTIVE_SIGNING_KEY=5K...
ACTIVE_SIGNING_KEY=5K...
ACCOUNT=acc...
36 changes: 15 additions & 21 deletions benchmarks/load.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require('dotenv').config();
const nodeCleanup = require('node-cleanup');
const fs = require('fs-extra');
const { fork } = require('child_process');
const database = require('../plugins/Database');
const blockchain = require('../plugins/Blockchain');
const jsonRPCServer = require('../plugins/JsonRPCServer');
const streamer = require('../plugins/Streamer.simulator');
Expand Down Expand Up @@ -96,18 +94,11 @@ const unloadPlugin = async (plugin) => {

// start streaming the Steem blockchain and produce the sidechain blocks accordingly
async function start() {
let res = await loadPlugin(database);
let res = await loadPlugin(blockchain);
if (res && res.payload === null) {
res = await loadPlugin(blockchain);
await send(getPlugin(database),
{ action: database.PLUGIN_ACTIONS.GENERATE_GENESIS_BLOCK, payload: conf });
res = await send(getPlugin(blockchain),
{ action: blockchain.PLUGIN_ACTIONS.START_BLOCK_PRODUCTION });
res = await loadPlugin(streamer);
if (res && res.payload === null) {
res = await loadPlugin(streamer);
if (res && res.payload === null) {
res = await loadPlugin(jsonRPCServer);
}
res = await loadPlugin(jsonRPCServer);
}
}
}
Expand All @@ -116,7 +107,6 @@ async function stop(callback) {
await unloadPlugin(jsonRPCServer);
const res = await unloadPlugin(streamer);
await unloadPlugin(blockchain);
await unloadPlugin(database);
callback(res.payload);
}

Expand All @@ -137,15 +127,19 @@ function stopApp(signal = 0) {
start();

// graceful app closing
nodeCleanup((exitCode, signal) => {
if (signal) {
console.log('Closing App... ', exitCode, signal); // eslint-disable-line

stopApp();
let shuttingDown = false;

nodeCleanup.uninstall(); // don't call cleanup handler again
return false;
const gracefulShutdown = () => {
if (shuttingDown === false) {
shuttingDown = true;
stopApp('SIGINT');
}
};

process.on('SIGTERM', () => {
gracefulShutdown();
});

return true;
process.on('SIGINT', () => {
gracefulShutdown();
});
15 changes: 7 additions & 8 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"chainId": "mainnet1",
"rpcNodePort": 5000,
"p2pPort": 5001,
"databaseURL": "mongodb://localhost:27017",
"databaseName": "ssc",
"dataDirectory": "./data/",
"databaseFileName": "database.db",
"blocksLogFilePath": "./blocks.log",
"autosaveInterval": 1800000,
"javascriptVMTimeout": 10000,
"streamNodes": [
"https://api.steemit.com",
"https://rpc.buildteam.io",
"https://rpc.steemviz.com",
"https://steemd.minnowsupportproject.org"
"https://anyx.io"
],
"startSteemBlock": 29864752,
"genesisSteemBlock": 29862600
"steemAddressPrefix": "STM",
"steemChainId": "0000000000000000000000000000000000000000000000000000000000000000",
"startSteemBlock": 29862600,
"genesisSteemBlock": 29862600,
"witnessEnabled": false
}
17 changes: 0 additions & 17 deletions contracts/bootstrap/Bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,6 @@ class Bootstrap {

transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'contract', 'deploy', JSON.stringify(contractPayload)));

// dice contract
/* contractCode = await fs.readFileSync('./contracts/bootstrap/dice.js');
contractCode = contractCode.toString();
base64ContractCode = Base64.encode(contractCode);
contractPayload = {
name: 'dice',
params: '',
code: base64ContractCode,
};
transactions.push(new Transaction(
genesisSteemBlock, 0, 'steemsc', 'contract', 'deploy', JSON.stringify(contractPayload)));
*/


// bootstrap transactions
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'create', `{ "name": "Steem Engine Token", "symbol": "${CONSTANTS.UTILITY_TOKEN_SYMBOL}", "precision": ${CONSTANTS.UTILITY_TOKEN_PRECISION}, "maxSupply": ${Number.MAX_SAFE_INTEGER} }`));
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'updateMetadata', `{"symbol":"${CONSTANTS.UTILITY_TOKEN_SYMBOL}", "metadata": { "url":"https://steem-engine.com", "icon": "https://s3.amazonaws.com/steem-engine/images/icon_steem-engine_gradient.svg", "desc": "ENG is the native token for the Steem Engine platform" }}`));
Expand Down
Loading

0 comments on commit 27528f7

Please sign in to comment.