Fix some fee logic: (RIPD-614)

* fee_default sets cost in drops of reference transaction
* Offline signing uses fee_default
* Signing multiplier maximum works correctly
* Fix bugs in load fee track
* Remove dead code, add comments
This commit is contained in:
JoelKatz
2014-10-01 11:35:05 -07:00
committed by Nik Bougalis
parent a0dbbb2d84
commit b651e0146d
7 changed files with 28 additions and 24 deletions

View File

@@ -602,6 +602,13 @@
# #
# #
# #
# [fee_default]
#
# Sets the base cost of a transaction in drops. Used when the server has
# no other source of fee information, such as signing transactions offline.
#
#
#
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
# 6. HTTPS Client # 6. HTTPS Client

View File

@@ -2018,7 +2018,7 @@ void Ledger::updateFees ()
if (mBaseFee) if (mBaseFee)
return; return;
std::uint64_t baseFee = getConfig ().FEE_DEFAULT; std::uint64_t baseFee = getConfig ().FEE_DEFAULT;
std::uint32_t referenceFeeUnits = 10; std::uint32_t referenceFeeUnits = getConfig ().TRANSACTION_FEE_BASE;
std::uint32_t reserveBase = getConfig ().FEE_ACCOUNT_RESERVE; std::uint32_t reserveBase = getConfig ().FEE_ACCOUNT_RESERVE;
std::int64_t reserveIncrement = getConfig ().FEE_OWNER_RESERVE; std::int64_t reserveIncrement = getConfig ().FEE_OWNER_RESERVE;
@@ -2054,6 +2054,7 @@ void Ledger::updateFees ()
std::uint64_t Ledger::scaleFeeBase (std::uint64_t fee) std::uint64_t Ledger::scaleFeeBase (std::uint64_t fee)
{ {
// Converts a fee in fee units to a fee in drops
updateFees (); updateFees ();
return getApp().getFeeTrack ().scaleFeeBase ( return getApp().getFeeTrack ().scaleFeeBase (
fee, mBaseFee, mReferenceFeeUnits); fee, mBaseFee, mReferenceFeeUnits);

View File

@@ -451,22 +451,24 @@ public:
std::uint32_t getReferenceFeeUnits () std::uint32_t getReferenceFeeUnits ()
{ {
// Returns the cost of the reference transaction in fee units
updateFees (); updateFees ();
return mReferenceFeeUnits; return mReferenceFeeUnits;
} }
std::uint64_t getBaseFee () std::uint64_t getBaseFee ()
{ {
// Returns the cost of the reference transaction in drops
updateFees (); updateFees ();
return mBaseFee; return mBaseFee;
} }
std::uint64_t getReserve (int increments) std::uint64_t getReserve (int increments)
{ {
// Returns the required reserve in drops
updateFees (); updateFees ();
return scaleFeeBase ( return static_cast<std::uint64_t> (increments) * mReserveIncrement
static_cast<std::uint64_t> (increments) * mReserveIncrement + mReserveBase;
+ mReserveBase);
} }
std::uint64_t getReserveInc () std::uint64_t getReserveInc ()

View File

@@ -99,7 +99,8 @@ void Transactor::calculateFee ()
std::uint64_t Transactor::calculateBaseFee () std::uint64_t Transactor::calculateBaseFee ()
{ {
return getConfig ().FEE_DEFAULT; // Returns the fee in fee units
return getConfig ().TRANSACTION_FEE_BASE;
} }
TER Transactor::payFee () TER Transactor::payFee ()

View File

@@ -49,6 +49,9 @@ namespace ripple {
#define DEFAULT_FEE_OFFER DEFAULT_FEE_DEFAULT #define DEFAULT_FEE_OFFER DEFAULT_FEE_DEFAULT
#define DEFAULT_FEE_OPERATION 1 #define DEFAULT_FEE_OPERATION 1
// Fee in fee units
#define DEFAULT_TRANSACTION_FEE_BASE 10
#define SECTION_DEFAULT_NAME "" #define SECTION_DEFAULT_NAME ""
IniFileSections IniFileSections
@@ -323,7 +326,7 @@ Config::Config ()
PEER_PRIVATE = false; PEER_PRIVATE = false;
PEERS_MAX = 0; // indicates "use default" PEERS_MAX = 0; // indicates "use default"
TRANSACTION_FEE_BASE = DEFAULT_FEE_DEFAULT; TRANSACTION_FEE_BASE = DEFAULT_TRANSACTION_FEE_BASE;
NETWORK_QUORUM = 0; // Don't need to see other nodes NETWORK_QUORUM = 0; // Don't need to see other nodes
VALIDATION_QUORUM = 1; // Only need one node to vouch VALIDATION_QUORUM = 1; // Only need one node to vouch

View File

@@ -46,9 +46,9 @@ public:
bool big = (fee > midrange); bool big = (fee > midrange);
if (big) // big fee, divide first to avoid overflow if (big) // big fee, divide first to avoid overflow
fee /= baseFee; fee /= referenceFeeUnits;
else // normal fee, multiply first for accuracy else // normal fee, multiply first for accuracy
fee *= referenceFeeUnits; fee *= baseFee;
std::uint32_t feeFactor = std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee); std::uint32_t feeFactor = std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee);
@@ -63,9 +63,9 @@ public:
} }
if (big) // Fee was big to start, must now multiply if (big) // Fee was big to start, must now multiply
fee *= referenceFeeUnits; fee *= baseFee;
else // Fee was small to start, mst now divide else // Fee was small to start, mst now divide
fee /= baseFee; fee /= referenceFeeUnits;
return fee; return fee;
} }
@@ -73,7 +73,7 @@ public:
// Scale from fee units to millionths of a ripple // Scale from fee units to millionths of a ripple
std::uint64_t scaleFeeBase (std::uint64_t fee, std::uint64_t baseFee, std::uint32_t referenceFeeUnits) std::uint64_t scaleFeeBase (std::uint64_t fee, std::uint64_t baseFee, std::uint32_t referenceFeeUnits)
{ {
return mulDiv (fee, referenceFeeUnits, baseFee); return mulDiv (fee, baseFee, referenceFeeUnits);
} }
std::uint32_t getRemoteFee () std::uint32_t getRemoteFee ()

View File

@@ -73,11 +73,12 @@ static void autofill_fee (
} }
} }
std::uint64_t const feeDefault = getConfig().FEE_DEFAULT; // Default fee in fee units
std::uint64_t const feeDefault = getConfig().TRANSACTION_FEE_BASE;
// Administrative endpoints are exempt from local fees // Administrative endpoints are exempt from local fees
std::uint64_t const fee = ledger->scaleFeeLoad (feeDefault, admin); std::uint64_t const fee = ledger->scaleFeeLoad (feeDefault, admin);
std::uint64_t const limit = mult * feeDefault; std::uint64_t const limit = mult * ledger->scaleFeeBase (feeDefault);
if (fee > limit) if (fee > limit)
{ {
@@ -280,17 +281,6 @@ Json::Value transactionSign (
return e; return e;
} }
if (!tx_json.isMember ("Fee")) {
auto const& transactionType = tx_json["TransactionType"].asString ();
if ("AccountSet" == transactionType
|| "OfferCreate" == transactionType
|| "OfferCancel" == transactionType
|| "TrustSet" == transactionType)
{
tx_json["Fee"] = (int) getConfig ().FEE_DEFAULT;
}
}
if (!tx_json.isMember ("Sequence")) if (!tx_json.isMember ("Sequence"))
tx_json["Sequence"] = asSrc->getSeq (); tx_json["Sequence"] = asSrc->getSeq ();