From 748178d2c46f2d4896a4cd9f750bc82e76d8fa8d Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 10 Aug 2017 17:29:24 +0200 Subject: [PATCH] make tx run in parallel --- src/app/execution/txRunner.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/app/execution/txRunner.js b/src/app/execution/txRunner.js index 03b48b708f..fd6ade4840 100644 --- a/src/app/execution/txRunner.js +++ b/src/app/execution/txRunner.js @@ -14,31 +14,17 @@ function TxRunner (executionContext, vmaccounts, opts) { if (this.executionContext.isVM()) { this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. } - this.running = false - this.pendingTxs = [] + this.pendingTxs = {} this.vmaccounts = vmaccounts } TxRunner.prototype.rawRun = function (args, cb) { - this.pendingTxs.push({tx: args, cb: cb}) - this.execute() + run(this, args, Date.now(), cb) } -TxRunner.prototype.execute = function () { +TxRunner.prototype.execute = function (args, callback) { var self = this - if (this.running || this.pendingTxs.length === 0) { - return - } - var args = this.pendingTxs[0].tx - var cb = this.pendingTxs[0].cb - this.pendingTxs.shift() - var callback = function (error, result) { - cb(error, result) - self.running = false - self.execute() - } - this.running = true var from = args.from var to = args.to var data = args.data @@ -153,4 +139,12 @@ function tryTillResponse (web3, txhash, done) { }) } +function run (self, tx, stamp, callback) { + self.pendingTxs[stamp] = tx + self.execute(tx, (error, result) => { + delete self.pendingTxs[stamp] + callback(error, result) + }) +} + module.exports = TxRunner