From 0efcd22a8a10e36c854970d9ea3fb79f5fb6fc6f Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Mon, 13 Feb 2017 11:26:30 -0800 Subject: [PATCH 1/2] Adding a blockLocker to the system. --- debug_scripts/block_locker.js | 19 +++++++++++++++++++ lib/local_comms.js | 11 +++++++++++ 2 files changed, 30 insertions(+) create mode 100644 debug_scripts/block_locker.js diff --git a/debug_scripts/block_locker.js b/debug_scripts/block_locker.js new file mode 100644 index 0000000..e164eb0 --- /dev/null +++ b/debug_scripts/block_locker.js @@ -0,0 +1,19 @@ +"use strict"; +let mysql = require("promise-mysql"); +let fs = require("fs"); +let argv = require('minimist')(process.argv.slice(2)); +let config = fs.readFileSync("../config.json"); +let coinConfig = fs.readFileSync("../coinConfig.json"); +let protobuf = require('protocol-buffers'); + +global.support = require("../lib/support.js")(); +global.config = JSON.parse(config); +global.mysql = mysql.createPool(global.config.mysql); +global.protos = protobuf(fs.readFileSync('../lib/data.proto')); +let comms; +comms = require('../lib/local_comms'); +global.database = new comms(); +global.database.initEnv(); +global.database.lockBlock(argv.blockID); +console.log("Block "+argv.blockID+" re-locked! Exiting!"); +process.exit(); \ No newline at end of file diff --git a/lib/local_comms.js b/lib/local_comms.js index 43ddb06..0f8b0a7 100644 --- a/lib/local_comms.js +++ b/lib/local_comms.js @@ -324,6 +324,17 @@ function Database(){ txn.commit(); }; + this.lockBlock = function(blockId){ + let txn = this.env.beginTxn(); + let blockProto = txn.getBinary(this.blockDB, blockId); + if (blockProto !== null){ + let blockData = global.protos.Block.decode(blockProto); + blockData['unlocked'] = false; + txn.putBinary(this.blockDB, blockId, global.protos.Block.encode(blockData)); + } + txn.commit(); + }; + this.getCache = function(cacheKey){ debug("Getting Key: "+cacheKey); try { From 2b8b2777251f6d388476f11eb678395fe3dfa5f5 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Mon, 13 Feb 2017 11:50:15 -0800 Subject: [PATCH 2/2] NodeJS is weird with async callbacks. --- lib/blockManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blockManager.js b/lib/blockManager.js index d702bef..5026474 100644 --- a/lib/blockManager.js +++ b/lib/blockManager.js @@ -286,7 +286,7 @@ function calculatePPLNSPayments(blockHeader) { } cursor.close(); txn.abort(); - callback(null, totalPaid); + setImmediate(callback, null, totalPaid); }, function (totalPayment) { blockCheckHeight = blockCheckHeight - 1; debug("Decrementing the block chain check height to:" + blockCheckHeight);