From 2e7c8ea201a4c8347474987322d5bf173ff1e602 Mon Sep 17 00:00:00 2001 From: Joe Uhren Date: Tue, 16 May 2023 20:29:57 -0600 Subject: [PATCH] Added an rpc cmd queue --- app.js | 2 +- lib/explorer.js | 17 +++++++++++------ lib/settings.js | 2 ++ settings.json.template | 2 ++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index 939a6f0..abaf336 100644 --- a/app.js +++ b/app.js @@ -19,7 +19,7 @@ const { exec } = require('child_process'); nodeapi.setWalletDetails(settings.wallet); // dynamically build the nodeapi cmd access list by adding all non-blockchain-specific api cmds that have a value Object.keys(settings.api_cmds).forEach(function(key, index, map) { - if (key != 'use_rpc' && settings.api_cmds[key] != null && settings.api_cmds[key] != '') + if (key != 'use_rpc' && key != 'rpc_concurrent_tasks' && settings.api_cmds[key] != null && settings.api_cmds[key] != '') apiAccessList.push(key); }); // dynamically find and add additional blockchain_specific api cmds diff --git a/lib/explorer.js b/lib/explorer.js index 3694a16..fc50d76 100644 --- a/lib/explorer.js +++ b/lib/explorer.js @@ -1,4 +1,5 @@ var request = require('postman-request'), + async = require('async'), settings = require('./settings'), locale = require('./locale'), Address = require('../models/address'); @@ -8,6 +9,15 @@ var base_url = base_server + 'api/'; const onode = require('./node'); const client = new onode.Client(settings.wallet); +const rpc_queue = async.queue((task_params, cb) => { + client.cmd([task_params], function(err, response) { + if (err) + return cb('There was an error. Check your console.'); + else + return cb(response); + }); +}, settings.api_cmds.rpc_concurrent_tasks); + // returns coinbase total sent as current coin supply function coinbase_supply(cb) { Address.findOne({a_id: 'coinbase'}).then((address) => { @@ -22,12 +32,7 @@ function coinbase_supply(cb) { } function rpcCommand(params, cb) { - client.cmd([{method: params[0].method, params: params[0].parameters}], function(err, response) { - if (err) - return cb('There was an error. Check your console.'); - else - return cb(response); - }); + rpc_queue.push({method: params[0].method, params: params[0].parameters}, cb); } function prepareRpcCommand(cmd, addParams) { diff --git a/lib/settings.js b/lib/settings.js index 6142296..4f5d35c 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -1258,6 +1258,8 @@ exports.api_cmds = { // use_rpc: Determine whether to call rpc api cmds directly using the faster rpc method or using the older method via internal http api (true/false) // NOTE: This should always be set to true unless there is a specific need to test or log certain apis "use_rpc": true, + // rpc_concurrent_tasks: The maximum number of rpc cmds that can be run simultaneously. Additional rpc cmds will go into a queue and be run on a first-in-first-out basis + "rpc_concurrent_tasks": 1, // getnetworkhashps: Returns the estimated network hashes per second. This should be a positive whole number "getnetworkhashps": "getnetworkhashps", // getmininginfo: Returns a json object containing mining-related information diff --git a/settings.json.template b/settings.json.template index cd2eabe..dbfa06b 100644 --- a/settings.json.template +++ b/settings.json.template @@ -1375,6 +1375,8 @@ // use_rpc: Determine whether to call rpc api cmds directly using the faster rpc method or using the older method via internal http api (true/false) // NOTE: This should always be set to true unless there is a specific need to test or log certain apis "use_rpc": true, + // rpc_concurrent_tasks: The maximum number of rpc cmds that can be run simultaneously. Additional rpc cmds will go into a queue and be run on a first-in-first-out basis + "rpc_concurrent_tasks": 1, // getnetworkhashps: Returns the estimated network hashes per second. This should be a positive whole number "getnetworkhashps": "getnetworkhashps", // getmininginfo: Returns a json object containing mining-related information