diff --git a/find_divergent_block.js b/find_divergent_block.js index d6f46ef..6e21f4f 100644 --- a/find_divergent_block.js +++ b/find_divergent_block.js @@ -26,9 +26,22 @@ async function getBlock(blockNumber) { })).data.result; } -const blockData = (t) => ({ refHiveBlockNumber: t.refHiveBlockNumber, transactionId: t.transactionId, sender: t.sender, contract: t.contract, payload: t.payload, executedCodeHash: t.executedCodeHash, logs: t.logs }); +const blockData = t => ({ + refHiveBlockNumber: t.refHiveBlockNumber, + transactionId: t.transactionId, + sender: t.sender, + contract: t.contract, + payload: t.payload, + executedCodeHash: t.executedCodeHash, + logs: t.logs, +}); function compareBlocks(block1, block2) { - return JSON.stringify(block1.transactions.map(blockData).concat(block1.virtualTransactions.map(blockData))) === JSON.stringify(block2.transactions.map(blockData).concat(block2.virtualTransactions.map(blockData))); + return JSON.stringify(block1.transactions.map(blockData).concat( + block1.virtualTransactions.map(blockData), + )) + === JSON.stringify(block2.transactions.map(blockData).concat( + block2.virtualTransactions.map(blockData), + )); } async function findDivergentBlock() { @@ -49,8 +62,9 @@ async function findDivergentBlock() { const check = Math.floor((low + high) / 2); mainBlock = await getBlock(check); block = await chain.findOne({ _id: check }); - //if (mainBlock.databaseHash !== block.databaseHash) { - //if (mainBlock.refHiveBlockNumber !== block.refHiveBlockNumber) { + // Different comparison modes, uncomment desired comparison. + // if (mainBlock.databaseHash !== block.databaseHash) { + // if (mainBlock.refHiveBlockNumber !== block.refHiveBlockNumber) { if (!compareBlocks(mainBlock, block)) { high = check - 1; } else { diff --git a/libs/Block.js b/libs/Block.js index 8c15a9d..a8a7e83 100644 --- a/libs/Block.js +++ b/libs/Block.js @@ -78,7 +78,7 @@ class Block { async blockAdjustments(database) { if (this.refHiveBlockNumber === 43447729 || this.refHiveBlockNumber === 44870101) { // main node skipped this due to space issue - this.transactions = []; + this.transactions = []; } // To keep in sync with primary node history after hack @@ -188,7 +188,8 @@ class Block { // don't save logs } else { this.virtualTransactions.push(transaction); - if (mainBlock && currentDatabaseHash !== mainBlock.virtualTransactions[relIndex].databaseHash) { + if (mainBlock && currentDatabaseHash + !== mainBlock.virtualTransactions[relIndex].databaseHash) { console.warn(mainBlock.virtualTransactions[relIndex]); // eslint-disable-line no-console console.warn(transaction); // eslint-disable-line no-console throw new Error('tx hash mismatch with api'); @@ -206,8 +207,7 @@ class Block { this.merkleRoot = merkleRoots.hash; this.databaseHash = merkleRoots.databaseHash; this.hash = this.calculateHash(); - } else if (currentDatabaseHash != this.previousDatabaseHash) { - //throw new Error("Database hash changed without sidechain block at " + this.refHiveBlockNumber); + } else if (currentDatabaseHash !== this.previousDatabaseHash) { await database.noteHashChange(this.refHiveBlockNumber); } } diff --git a/libs/Database.js b/libs/Database.js index c52a619..25f65ce 100644 --- a/libs/Database.js +++ b/libs/Database.js @@ -204,7 +204,7 @@ class Database { lastBlock.otherHashChangeRefHiveBlocks = []; } lastBlock.otherHashChangeRefHiveBlocks.push(refHiveBlockNumber); - await this.chain.updateOne({ _id: lastBlock._id }, { $set: { otherHashChangeRefHiveBlocks: lastBlock.otherHashChangeRefHiveBlocks }}, { session: this.session }); + await this.chain.updateOne({ _id: lastBlock._id }, { $set: { otherHashChangeRefHiveBlocks: lastBlock.otherHashChangeRefHiveBlocks } }, { session: this.session }); // eslint-disable-line no-underscore-dangle } async getLatestBlockInfo() { diff --git a/plugins/Blockchain.js b/plugins/Blockchain.js index 75431c7..0874702 100644 --- a/plugins/Blockchain.js +++ b/plugins/Blockchain.js @@ -112,7 +112,7 @@ const produceNewBlockSync = async (block, callback = null) => { // the stream parsed transactions from the Hive blockchain const { refHiveBlockNumber, refHiveBlockId, prevRefHiveBlockId, - transactions, timestamp, virtualTransactions, replay + transactions, timestamp, virtualTransactions, replay, } = block; const newTransactions = []; @@ -130,7 +130,8 @@ const produceNewBlockSync = async (block, callback = null) => { }); // if there are transactions pending we produce a block - if (newTransactions.length > 0 || (virtualTransactions && virtualTransactions.length > 0) || replay) { + if (newTransactions.length > 0 + || (virtualTransactions && virtualTransactions.length > 0) || replay) { await producePendingTransactions( refHiveBlockNumber, refHiveBlockId, prevRefHiveBlockId, newTransactions, timestamp, ); diff --git a/plugins/P2P.js b/plugins/P2P.js index 9662ddc..1de0991 100644 --- a/plugins/P2P.js +++ b/plugins/P2P.js @@ -378,8 +378,8 @@ const proposeRoundHandler = async (args, callback) => { let attempt = 1; while (!calculatedRoundHash && attempt <= 3) { if (attempt > 1) { - console.log("null round hash, waiting for block"); - await new Promise(r => setTimeout(r, 3000)); + console.log('null round hash, waiting for block'); + await new Promise(r => setTimeout(r, 3000)); } calculatedRoundHash = await calculateRoundHash(startblockNum, lastBlockRound); attempt += 1; diff --git a/plugins/Replay.js b/plugins/Replay.js index 28a3377..dba3110 100644 --- a/plugins/Replay.js +++ b/plugins/Replay.js @@ -57,7 +57,6 @@ function replayFile(callback) { refHiveBlockNumber, refHiveBlockId, prevRefHiveBlockId, - virtualTransactions, } = block; let finalRefHiveBlockId = refHiveBlockId; @@ -74,7 +73,7 @@ function replayFile(callback) { finalPrevRefHiveBlockId = hiveBlock.previous; } - // do not pass over the virtual txs, it will be generated by Blockchain plugin + // do not pass over the virtual txs, it will be generated by Blockchain plugin await sendBlock({ blockNumber, timestamp, @@ -82,7 +81,7 @@ function replayFile(callback) { refHiveBlockId: finalRefHiveBlockId, prevRefHiveBlockId: finalPrevRefHiveBlockId, transactions, - replay: true, + replay: true, }); } } diff --git a/plugins/Streamer.js b/plugins/Streamer.js index 271bd53..c0ffa64 100644 --- a/plugins/Streamer.js +++ b/plugins/Streamer.js @@ -326,7 +326,7 @@ const throttledGetBlockFromNode = async (blockNumber, node) => { totalTime[node] += Date.now() - timeStart; } catch (err) { // eslint-disable-next-line no-console - console.error(`Error fetching block ${blockNumber} on node ${node}, took ${ Date.now() - timeStart } ms`); + console.error(`Error fetching block ${blockNumber} on node ${node}, took ${Date.now() - timeStart} ms`); // eslint-disable-next-line no-console console.error(err); } diff --git a/sync_hashes.js b/sync_hashes.js index da438c1..dfd823a 100644 --- a/sync_hashes.js +++ b/sync_hashes.js @@ -79,10 +79,12 @@ async function getHashes() { await database.init(databaseURL, databaseName); const contracts = database.database.collection('contracts'); const chain = database.database.collection('chain'); - const localBlock = (await chain.find().sort({ _id: -1}).limit(1).toArray())[0]._id; + // eslint-disable-next-line no-underscore-dangle + const localBlock = (await chain.find().sort({ _id: -1 }).limit(1).toArray())[0]._id; for (let i = 0; i < contractNames.length; i += 1) { const contract = contractNames[i]; + // eslint-disable-next-line no-underscore-dangle const contractInDb = await contracts.findOne({ _id: contract }); console.log(`Checking contract ${contract}`); const tables = hashes1[i]; @@ -97,7 +99,9 @@ async function getHashes() { } } } - const localBlockAfterFetch = (await chain.find().sort({ _id: -1}).limit(1).toArray())[0]._id; + // eslint-disable-next-line no-underscore-dangle + const localBlockAfterFetch = (await chain.find().sort({ _id: -1 }).limit(1).toArray())[0]._id; + console.log(`Local block before hash fetch: ${localBlock}. Block after: ${localBlockAfterFetch}`); database.close(); } diff --git a/witness_action.js b/witness_action.js index f879406..7f93c8c 100644 --- a/witness_action.js +++ b/witness_action.js @@ -9,19 +9,20 @@ const privateSigningKey = dhive.PrivateKey.fromString(process.env.ACTIVE_SIGNING const publicSigningKey = privateSigningKey.createPublic().toString(); function broadcastWitnessAction(contractAction, contractPayload) { - const client = new dhive.Client('https://api.hive.blog'); - const transaction = { - required_auths: [witnessAccount], - required_posting_auths: [], - id: 'ssc-mainnet-hive', - json: JSON.stringify({ - contractName: 'witnesses', - contractAction, - contractPayload, - }), - }; + const client = new dhive.Client('https://api.hive.blog'); + const transaction = { + required_auths: [witnessAccount], + required_posting_auths: [], + id: 'ssc-mainnet-hive', + json: JSON.stringify({ + contractName: 'witnesses', + contractAction, + contractPayload, + }), + }; - client.broadcast.json(transaction, privateSigningKey, (x, y) => console.log(x ? x : y)); + // eslint-disable-next-line no-console + client.broadcast.json(transaction, privateSigningKey, (x, y) => console.log(x || y)); } program.version(packagejson.version); @@ -34,22 +35,22 @@ program program .command('register') - .action(witness => broadcastWitnessAction('register', { - IP: ip, - RPCPort: 5000, - P2PPort: 5001, - signingKey: publicSigningKey, - enabled: true, - })); + .action(() => broadcastWitnessAction('register', { + IP: ip, + RPCPort: 5000, + P2PPort: 5001, + signingKey: publicSigningKey, + enabled: true, + })); program .command('unregister') - .action(witness => broadcastWitnessAction('register', { - IP: ip, - RPCPort: 5000, - P2PPort: 5001, - signingKey: publicSigningKey, - enabled: false, - })); + .action(() => broadcastWitnessAction('register', { + IP: ip, + RPCPort: 5000, + P2PPort: 5001, + signingKey: publicSigningKey, + enabled: false, + })); program.parse(process.argv);