Skip to content

Commit

Permalink
put back UInt160 in AutobridgeCalculator
Browse files Browse the repository at this point in the history
fix lint issues
  • Loading branch information
darkdarkdragon committed Sep 24, 2015
1 parent 0d6dda5 commit 45db95d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
17 changes: 9 additions & 8 deletions src/core/autobridgecalculator.js
Expand Up @@ -3,6 +3,7 @@
const _ = require('lodash');
const assert = require('assert');
const Amount = require('./amount').Amount;
const UInt160 = require('./uint160').UInt160;
const Utils = require('./orderbookutils');

function assertValidNumber(number, message) {
Expand Down Expand Up @@ -42,8 +43,6 @@ const NULL_AMOUNT = Utils.normalizeAmount('0');
*/

AutobridgeCalculator.prototype.calculate = function(callback) {
this._oldMode = Amount.strict_mode;
Amount.strict_mode = false;

const legOnePointer = 0;
const legTwoPointer = 0;
Expand All @@ -60,6 +59,12 @@ AutobridgeCalculator.prototype._calculateInternal = function(
legOnePointer_, legTwoPointer_, offersAutobridged, callback
) {

// Amount class is calling _check_limits after each operation in strict mode,
// and _check_limits is very computationally expensive, so we turning it off
// whle doing calculations
this._oldMode = Amount.strict_mode;
Amount.strict_mode = false;

let legOnePointer = legOnePointer_;
let legTwoPointer = legTwoPointer_;

Expand All @@ -70,12 +75,8 @@ AutobridgeCalculator.prototype._calculateInternal = function(
// of execution so user's browser stays responsive
const lasted = (Date.now() - startTime);
if (lasted > 30) {
setTimeout(() => {
this._oldMode = Amount.strict_mode;
Amount.strict_mode = false;
this._calculateInternal(legOnePointer, legTwoPointer, offersAutobridged,
callback);
}, 0);
setTimeout(this._calculateInternal.bind(this, legOnePointer,
legTwoPointer, offersAutobridged, callback), 0);

Amount.strict_mode = this._oldMode;
return;
Expand Down
24 changes: 11 additions & 13 deletions src/core/orderbook.js
Expand Up @@ -88,7 +88,7 @@ function OrderBook(remote,
this._gotOffersFromLegTwo = false;

this._waitingForOffers = false;
this._offersModifiedAt = 0;
this._lastUpdateLedgerSequence = 0;
this._transactionsLeft = 0;
this._calculatorRunning = false;

Expand Down Expand Up @@ -839,29 +839,29 @@ OrderBook.prototype.isBalanceChangeNode = function(node) {

OrderBook.prototype._canRunAutobridgeCalc = function(): boolean {
return !this._calculatorRunning;
}
};

OrderBook.prototype.onTransaction = function(transaction) {
this.updateFundedAmounts(transaction);


if (--this._transactionsLeft === 0 && !this._waitingForOffers) {
const lastClosedLedger = this._remote.getLedgerSequence() - 1;
const lastClosedLedger = this._remote.getLedgerSequence();
if (this._isAutobridgeable) {
if (this._canRunAutobridgeCalc()) {
if (this._legOneBook._offersModifiedAt === lastClosedLedger ||
this._legTwoBook._offersModifiedAt === lastClosedLedger
if (this._legOneBook._lastUpdateLedgerSequence === lastClosedLedger ||
this._legTwoBook._lastUpdateLedgerSequence === lastClosedLedger
) {
this.computeAutobridgedOffersWrapper();
} else if (this._offersModifiedAt === lastClosedLedger) {
} else if (this._lastUpdateLedgerSequence === lastClosedLedger) {
this.mergeDirectAndAutobridgedBooks();
}
}
} else if (this._offersModifiedAt === lastClosedLedger) {
} else if (this._lastUpdateLedgerSequence === lastClosedLedger) {
this.emit('model', this._offers);
}
}
}
};

/**
* Updates funded amounts/balances using modified balance nodes
Expand Down Expand Up @@ -978,7 +978,7 @@ OrderBook.prototype.onLedgerClosed = function(message) {
return;
}
this._transactionsLeft = message.txn_count;
}
};

/**
* Notify orderbook of a relevant transaction
Expand Down Expand Up @@ -1080,7 +1080,7 @@ OrderBook.prototype.notify = function(transaction) {

this.emit('transaction', transaction);

this._offersModifiedAt = this._remote.getLedgerSequence() - 1;
this._lastUpdateLedgerSequence = this._remote.getLedgerSequence();

if (!takerGetsTotal.is_zero()) {
this.emit('trade', takerPaysTotal, takerGetsTotal);
Expand Down Expand Up @@ -1370,7 +1370,7 @@ OrderBook.prototype.computeAutobridgedOffers = function(callback = function() {}
assert(!this._currencyGets.is_native() && !this._currencyPays.is_native(),
'Autobridging is only for IOU:IOU orderbooks');


if (this._destroyed) {
return;
}
Expand All @@ -1384,8 +1384,6 @@ OrderBook.prototype.computeAutobridgedOffers = function(callback = function() {}
this._issuerPays
);

const lastClosedLedger = this._remote.getLedgerSequence() - 1;

autobridgeCalculator.calculate((autobridgedOffers) => {
this._offersAutobridged = autobridgedOffers;
callback();
Expand Down
2 changes: 1 addition & 1 deletion test/orderbook-autobridge-test.js
Expand Up @@ -589,7 +589,7 @@ describe('OrderBook Autobridging', function() {

assert(book._offersAutobridged[2].autobridged);

done();
done();
});

});
Expand Down

0 comments on commit 45db95d

Please sign in to comment.