From 8faa25e9ff7563361c8b3a00c9f3cf95a1c3f5c0 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 11 Dec 2012 15:12:21 -0800 Subject: [PATCH 1/5] Restore [(10X+3)(10Y+3)]/100 rounding. Arthur, please double check. --- src/cpp/ripple/Amount.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/cpp/ripple/Amount.cpp b/src/cpp/ripple/Amount.cpp index 6e2276ae4..3b2bbad0a 100644 --- a/src/cpp/ripple/Amount.cpp +++ b/src/cpp/ripple/Amount.cpp @@ -15,6 +15,8 @@ SETUP_LOG(); uint64 STAmount::uRateOne = STAmount::getRate(STAmount(1), STAmount(1)); +static const uint64_t tenTo16 = 10000000000000000ul; +static const uint64_t tenTo18 = 1000000000000000000ul; bool STAmount::issuerFromString(uint160& uDstIssuer, const std::string& sIssuer) { @@ -900,7 +902,7 @@ STAmount STAmount::divide(const STAmount& num, const STAmount& den, const uint16 // Compute (numerator * 10^16) / denominator CBigNum v; if ((BN_add_word(&v, numVal) != 1) || - (BN_mul_word(&v, 10000000000000000ul) != 1) || + (BN_mul_word(&v, tenTo16) != 1) || (BN_div_word(&v, denVal) == ((BN_ULONG) -1))) { throw std::runtime_error("internal bn error"); @@ -953,9 +955,9 @@ STAmount STAmount::multiply(const STAmount& v1, const STAmount& v2, const uint16 // Compute (numerator*10 * denominator*10) / 10^18 with rounding CBigNum v; - if ((BN_add_word(&v, value1) != 1) || - (BN_mul_word(&v, value2) != 1) || - (BN_div_word(&v, 100000000000000ul) == ((BN_ULONG) -1))) + if ((BN_add_word(&v, value1 * 10 + 3) != 1) || + (BN_mul_word(&v, value2 * 10 + 3) != 1) || + (BN_div_word(&v, tenTo18) == ((BN_ULONG) -1))) { throw std::runtime_error("internal bn error"); } @@ -963,7 +965,7 @@ STAmount STAmount::multiply(const STAmount& v1, const STAmount& v2, const uint16 // 10^16 <= product <= 10^18 assert(BN_num_bytes(&v) <= 64); - return STAmount(uCurrencyID, uIssuerID, v.getulong(), offset1 + offset2 + 14, v1.mIsNegative != v2.mIsNegative); + return STAmount(uCurrencyID, uIssuerID, v.getulong(), offset1 + offset2 + 16, v1.mIsNegative != v2.mIsNegative); } // Convert an offer into an index amount so they sort by rate. @@ -1116,8 +1118,8 @@ uint64 STAmount::muldiv(uint64 a, uint64 b, uint64 c) if ((a == 0) || (b == 0)) return 0; CBigNum v; - if ((BN_add_word(&v, a * 10) != 1) || - (BN_mul_word(&v, b * 10) != 1) || + if ((BN_add_word(&v, a * 10 + 3) != 1) || + (BN_mul_word(&v, b * 10 + 3) != 1) || (BN_add_word(&v, 50) != 1) || (BN_div_word(&v, c) == ((BN_ULONG) -1)) || (BN_div_word(&v, 100) == ((BN_ULONG) -1))) From 7652a75edb6051436c4cf46281c772c4701e8abc Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 11 Dec 2012 16:02:35 -0800 Subject: [PATCH 2/5] Start of fix. --- src/js/amount.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/js/amount.js b/src/js/amount.js index a3e1ef4d5..82307a389 100644 --- a/src/js/amount.js +++ b/src/js/amount.js @@ -758,8 +758,14 @@ Amount.prototype.multiply = function (v) { result._value = this._value.multiply(v._value); } else { + + var v1 = this._value.multiply(consts.bi_10).add(3); + var o1 = this._offset - 1; + var v2 = v._value.multiply(consts.bi_10).add(3); + var o2 = v._offset - 1; + result = new Amount(); - result._offset = o1 + o2; + result._offset = o1 + o2 + 2; result._value = v1.multiply(v2); result._is_negative = this._is_negative !== v._is_negative; result._currency = this._currency.clone(); From 44b3c6eda733adb0afc4d8d7c76299c2bc4fdaf8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 11 Dec 2012 16:10:13 -0800 Subject: [PATCH 3/5] Restore [(10X+3)(10Y+3)]/100 rounding. --- src/js/amount.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/js/amount.js b/src/js/amount.js index 82307a389..acf2eefd6 100644 --- a/src/js/amount.js +++ b/src/js/amount.js @@ -750,19 +750,31 @@ Amount.prototype.issuer = function () { Amount.prototype.multiply = function (v) { var result; - if (!this.is_comparable(v)) { - result = Amount.NaN(); - } - else if (this._is_native) { + if (this._is_native && v._is_native) { result = new Amount(); result._value = this._value.multiply(v._value); } else { - var v1 = this._value.multiply(consts.bi_10).add(3); - var o1 = this._offset - 1; - var v2 = v._value.multiply(consts.bi_10).add(3); - var o2 = v._offset - 1; + var v1 = this._value; + var o1 = this._offset; + var v2 = v._value; + var o2 = v._offset; + + while (o1._value.compareTo(consts.bi_man_min_value) < 0 ) { + v1 = v1.multiply(consts.bi_10); + o1 -= 1; + } + + while (o2._value.compareTo(consts.bi_man_min_value) < 0 ) { + v2 = v2.multiply(consts.bi_10); + o2 -= 1; + } + + v1 = v1.multiply(consts.bi_10).add(3); + o1 -= 1; + v2 = v2.multiply(consts.bi_10).add(3); + o2 -= 1; result = new Amount(); result._offset = o1 + o2 + 2; From 94e2affb937fed7eeb599f8b6113a97cee9420e7 Mon Sep 17 00:00:00 2001 From: jed Date: Tue, 11 Dec 2012 18:24:58 -0800 Subject: [PATCH 4/5] lower account create fee. --- src/cpp/ripple/Config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/ripple/Config.cpp b/src/cpp/ripple/Config.cpp index cede9d248..71b67774f 100644 --- a/src/cpp/ripple/Config.cpp +++ b/src/cpp/ripple/Config.cpp @@ -48,7 +48,7 @@ // Fees are in XRP. #define DEFAULT_FEE_DEFAULT 10 -#define DEFAULT_FEE_ACCOUNT_CREATE 1000*SYSTEM_CURRENCY_PARTS +#define DEFAULT_FEE_ACCOUNT_CREATE 200*SYSTEM_CURRENCY_PARTS #define DEFAULT_FEE_NICKNAME_CREATE 1000 #define DEFAULT_FEE_OFFER DEFAULT_FEE_DEFAULT #define DEFAULT_FEE_OPERATION 1 From bb77dc2bc00f7fa1f592e29ffd06123d806b9cc5 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 11 Dec 2012 18:42:17 -0800 Subject: [PATCH 5/5] Cleanup. --- src/cpp/ripple/LoadManager.cpp | 3 ++- src/cpp/ripple/LoadManager.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cpp/ripple/LoadManager.cpp b/src/cpp/ripple/LoadManager.cpp index adac5d0b3..f8047af15 100644 --- a/src/cpp/ripple/LoadManager.cpp +++ b/src/cpp/ripple/LoadManager.cpp @@ -1,7 +1,8 @@ #include "LoadManager.h" LoadManager::LoadManager(int creditRate, int creditLimit, int debitWarn, int debitLimit) : - mCreditRate(creditRate), mCreditLimit(creditLimit), mDebitWarn(debitWarn), mDebitLimit(debitLimit), mCosts(LT_MAX) + mCreditRate(creditRate), mCreditLimit(creditLimit), mDebitWarn(debitWarn), mDebitLimit(debitLimit), + mCosts(LT_MAX) { addLoadCost(LoadCost(LT_InvalidRequest, 10, LC_CPU | LC_Network)); addLoadCost(LoadCost(LT_RequestNoReply, 1, LC_CPU | LC_Disk)); diff --git a/src/cpp/ripple/LoadManager.h b/src/cpp/ripple/LoadManager.h index a48166577..71eb79d39 100644 --- a/src/cpp/ripple/LoadManager.h +++ b/src/cpp/ripple/LoadManager.h @@ -26,10 +26,10 @@ enum LoadType LT_RequestData, // A request that is hard to satisfy, disk access LT_CheapQuery, // A query that is trivial, cached data - LT_MAX = LT_CheapQuery + LT_MAX // MUST BE LAST }; -// load categoryies +// load categories static const int LC_Disk = 1; static const int LC_CPU = 2; static const int LC_Network = 4;