Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
X.X.X
* New setting to adjust concurrent rpc calls: rpc_concurrent_tasks, rpc_task_timeout

1.7.4
* Updated themes to Bootstrap 4.5 by using latest Bootswatch themes
* Deleted unmaintained themes that were never ported to Bootstrap4
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Note: All updates require the explorer to be restarted
X.X.X
* Add new setting to settings.json (see settings.json.template)
* rpc_concurrent_tasks
* rpc_task_timeout
1.7.3 -> 1.7.4
* Ensure that you are not using theme "Paper" or "Readable" as these were not ported by Bootswatch
* Add new settings to settings.json (see settings.json.template)
Expand Down
49 changes: 42 additions & 7 deletions lib/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@ var base_url = 'http://127.0.0.1:' + settings.port + '/api/';
const Client = require('bitcoin-core');
const client = new Client(settings.wallet);

class API_Task_Queue {
constructor() {
this.max_tasks = settings.rpc_concurrent_tasks;
this.active_tasks = 0;
}
start_task() {
if (this.active_tasks < this.max_tasks) {
this.active_tasks++;
return true;
} else {
// console.log('cannot start task');
return false;
}
}
finish_task() {
this.active_tasks--;
return true;
}
queue_task(run_task) {
var Queue = this;
if (Queue.start_task()) {
return run_task();
} else {
setTimeout(function() {
Queue.finish_task();
return Queue.queue_task(run_task);
}, settings.rpc_task_timeout);
}
}
}

var API_Queue = new API_Task_Queue();


// returns coinbase total sent as current coin supply
function coinbase_supply(cb) {
Expand All @@ -20,14 +53,16 @@ function coinbase_supply(cb) {
}

function rpcCommand(params, cb) {
client.command([{method: params[0].method, parameters: params[0].parameters}], function(err, response){
if(err){console.log('Error: ', err); }
else{
if(response[0].name == 'RpcError'){
return cb('There was an error. Check your console.');
API_Queue.queue_task(function() {
client.command([{method: params[0].method, parameters: params[0].parameters}], function(err, response){
if(err){console.log('Error: ', err); }
else{
if(response[0].name == 'RpcError'){
return cb('There was an error. Check your console.');
}
return cb(response[0]);
}
return cb(response[0]);
}
});
});
}

Expand Down
2 changes: 2 additions & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ exports.confirmations = 6;
exports.update_timeout = 125;
exports.check_timeout = 250;
exports.block_parallel_tasks = 1;
exports.rpc_concurrent_tasks = 1;
exports.rpc_task_timeout = 8;


//genesis
Expand Down
3 changes: 3 additions & 0 deletions settings.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"update_timeout": 10,
"check_timeout": 250,
"block_parallel_tasks": 1,
// limits and timeouts for RPC concurrent task queue
"rpc_concurrent_tasks": 4,
"rpc_task_timeout": 8,

// wallet settings
"use_rpc": false,
Expand Down