Fix FeeUint64->XRPAmount mismatch after merge

This commit is contained in:
Richard Holland
2023-04-06 12:07:16 +00:00
parent 311d0b8bf1
commit a56034b47c
17 changed files with 48 additions and 85 deletions

View File

@@ -77,29 +77,6 @@ include(deps/cassandra)
include(deps/Postgres)
include(deps/WasmEdge)
target_link_libraries(ripple_libs INTERFACE
ed25519::ed25519
LibArchive::LibArchive
lz4::lz4
nudb::core
OpenSSL::Crypto
OpenSSL::SSL
Ripple::grpc_pbufs
Ripple::pbufs
secp256k1::secp256k1
soci::soci
SQLite::SQLite3
)
if(reporting)
find_package(cassandra-cpp-driver REQUIRED)
find_package(PostgreSQL REQUIRED)
target_link_libraries(ripple_libs INTERFACE
cassandra-cpp-driver::cassandra-cpp-driver
PostgreSQL::PostgreSQL
)
endif()
###
include(RippledCore)

View File

@@ -4194,12 +4194,10 @@ DEFINE_HOOK_FUNCTION(
std::unique_ptr<STTx const> stpTrans;
stpTrans = std::make_unique<STTx const>(std::ref(sitTrans));
FeeUnit64 fee =
return
Transactor::calculateBaseFee(
*(applyCtx.app.openLedger().current()),
*stpTrans);
return fee.fee();
*stpTrans).drops();
}
catch (std::exception& e)
{

View File

@@ -359,7 +359,7 @@ public:
@returns a `Json objectvalue`
*/
Json::Value
doRPC(Application& app, std::optional<FeeUnit64> hookFeeUnits = std::nullopt) const;
doRPC(Application& app, std::optional<XRPAmount> hookFeeUnits = std::nullopt) const;
private:
// Implementation for nextQueuableSeq(). The passed lock must be held.

View File

@@ -1969,7 +1969,7 @@ TxQ::getTxs() const
}
Json::Value
TxQ::doRPC(Application& app, std::optional<FeeUnit64> hookFeeUnits) const
TxQ::doRPC(Application& app, std::optional<XRPAmount> hookFeeUnits) const
{
auto const view = app.openLedger().current();
if (!view)
@@ -1996,7 +1996,7 @@ TxQ::doRPC(Application& app, std::optional<FeeUnit64> hookFeeUnits) const
levels[jss::median_level] = to_string(metrics.medFeeLevel);
levels[jss::open_ledger_level] = to_string(metrics.openLedgerFeeLevel);
auto const baseFee = view->fees().base + (hookFeeUnits ? hookFeeUnits->fee() : 0);
auto const baseFee = view->fees().base + (hookFeeUnits ? hookFeeUnits->drops() : 0);
// If the base fee is 0 drops, but escalation has kicked in, treat the
// base fee as if it is 1 drop, which makes the rest of the math
// work.

View File

@@ -336,7 +336,7 @@ calculateDefaultBaseFee(ReadView const& view, STTx const& tx);
std::pair<TER, bool>
doApply(PreclaimResult const& preclaimResult, Application& app, OpenView& view);
FeeUnit64
XRPAmount
invoke_calculateBaseFee(ReadView const& view, STTx const& tx);
} // namespace ripple

View File

@@ -73,13 +73,13 @@ Invoke::doApply()
return tesSUCCESS;
}
FeeUnit64
XRPAmount
Invoke::calculateBaseFee(ReadView const& view, STTx const& tx)
{
FeeUnit64 extraFee{0};
XRPAmount extraFee{0};
if (tx.isFieldPresent(sfBlob))
extraFee += FeeUnit64{ tx.getFieldVL(sfBlob).size() };
extraFee += XRPAmount{ tx.getFieldVL(sfBlob).size() };
if (tx.isFieldPresent(sfHookParameters))
{
@@ -93,7 +93,7 @@ Invoke::calculateBaseFee(ReadView const& view, STTx const& tx)
(param.isFieldPresent(sfHookParameterValue) ?
param.getFieldVL(sfHookParameterValue).size() : 0);
}
extraFee += FeeUnit64 { paramBytes };
extraFee += XRPAmount { paramBytes };
}
return Transactor::calculateBaseFee(view, tx) + extraFee;

View File

@@ -36,7 +36,7 @@ public:
{
}
static FeeUnit64
static XRPAmount
calculateBaseFee(ReadView const& view, STTx const& tx);
static TxConsequences

View File

@@ -518,10 +518,10 @@ SetHook::validateHookSetEntry(SetHookCtx& ctx, STObject const& hookSetObj)
}
}
FeeUnit64
XRPAmount
SetHook::calculateBaseFee(ReadView const& view, STTx const& tx)
{
FeeUnit64 extraFee{0};
XRPAmount extraFee{0};
auto const& hookSets = tx.getFieldArray(sfHooks);
@@ -530,7 +530,7 @@ SetHook::calculateBaseFee(ReadView const& view, STTx const& tx)
if (!hookSetObj.isFieldPresent(sfCreateCode))
continue;
extraFee += FeeUnit64{
extraFee += XRPAmount{
hook::computeCreationFee(
hookSetObj.getFieldVL(sfCreateCode).size())};
@@ -547,7 +547,7 @@ SetHook::calculateBaseFee(ReadView const& view, STTx const& tx)
(param.isFieldPresent(sfHookParameterValue) ?
param.getFieldVL(sfHookParameterValue).size() : 0);
}
extraFee += FeeUnit64 { paramBytes };
extraFee += XRPAmount { paramBytes };
}
}

View File

@@ -82,7 +82,7 @@ public:
static TER
preclaim(PreclaimContext const&);
static FeeUnit64
static XRPAmount
calculateBaseFee(ReadView const& view, STTx const& tx);

View File

@@ -199,7 +199,7 @@ Transactor::Transactor(ApplyContext& ctx)
// RH NOTE: this only computes one chain at a time, so if there is a receiving side to a txn
// then it must seperately be computed by a second call here
FeeUnit64
XRPAmount
Transactor::
calculateHookChainFee(
ReadView const& view,
@@ -210,9 +210,9 @@ calculateHookChainFee(
std::shared_ptr<SLE const> hookSLE = view.read(hookKeylet);
if (!hookSLE)
return FeeUnit64{0};
return XRPAmount{0};
FeeUnit64 fee{0};
XRPAmount fee{0};
auto const& hooks = hookSLE->getFieldArray(sfHooks);
@@ -247,7 +247,7 @@ calculateHookChainFee(
if (hook::canHook(tx.getTxnType(), hookOn) &&
(!collectCallsOnly || (flags & hook::hsfCOLLECT)))
{
FeeUnit64 const toAdd {
XRPAmount const toAdd {
hookDef->getFieldAmount(sfFee).xrp().drops()
};
@@ -255,7 +255,7 @@ calculateHookChainFee(
// fee is set to the largest possible valid xrp value to force
// fail the transaction
if (fee + toAdd < fee)
fee = FeeUnit64{INITIAL_XRP.drops()};
fee = XRPAmount{INITIAL_XRP.drops()};
else
fee += toAdd;
}
@@ -279,13 +279,13 @@ Transactor::calculateBaseFee(ReadView const& view, STTx const& tx)
std::size_t const signerCount =
tx.isFieldPresent(sfSigners) ? tx.getFieldArray(sfSigners).size() : 0;
FeeUnit64 hookExecutionFee{0};
XRPAmount hookExecutionFee{0};
uint64_t burden {1};
if (view.rules().enabled(featureHooks))
{
// if this is a "cleanup" txn we regard it as already paid up
if (tx.getFieldU16(sfTransactionType) == ttEMIT_FAILURE)
return FeeUnit64{0};
return XRPAmount{0};
// if the txn is an emitted txn then we add the callback fee
// if the txn is NOT an emitted txn then we process the sending account's hook chain
@@ -300,7 +300,7 @@ Transactor::calculateBaseFee(ReadView const& view, STTx const& tx)
if (hookDef && hookDef->isFieldPresent(sfHookCallbackFee))
{
FeeUnit64 const toAdd {
XRPAmount const toAdd {
hookDef->getFieldAmount(sfHookCallbackFee).xrp().drops()
};
@@ -308,7 +308,7 @@ Transactor::calculateBaseFee(ReadView const& view, STTx const& tx)
// fee is set to the largest possible valid xrp value to force
// fail the transaction
if (hookExecutionFee + toAdd < hookExecutionFee)
hookExecutionFee = FeeUnit64{INITIAL_XRP.drops()};
hookExecutionFee = XRPAmount{INITIAL_XRP.drops()};
else
hookExecutionFee += toAdd;
}
@@ -336,7 +336,7 @@ Transactor::calculateBaseFee(ReadView const& view, STTx const& tx)
// The calculation is (baseFee * burden) + (signerCount * baseFee) + hookExecutionFee
// To ensure there are no overflows or illegal negatives we will do each operation with an overflow check
// between and if there is a problem then return the highest possible fee to fail to the transaction.
FeeUnit64 accumulator = baseFee;
XRPAmount accumulator = baseFee;
do
{
if (accumulator * burden < accumulator)
@@ -357,7 +357,7 @@ Transactor::calculateBaseFee(ReadView const& view, STTx const& tx)
return accumulator;
}
while (0);
return FeeUnit64{INITIAL_XRP.drops()};
return XRPAmount{INITIAL_XRP.drops()};
}
XRPAmount
@@ -1389,14 +1389,13 @@ doTSH(
continue;
// compute and deduct fees for the TSH if applicable
FeeUnit64 tshFee =
XRPAmount tshFeeDrops =
calculateHookChainFee(view, ctx_.tx, klTshHook, !canRollback);
// no hooks to execute, skip tsh
if (tshFee == 0)
if (tshFeeDrops == 0)
continue;
XRPAmount tshFeeDrops = view.fees().toDrops(tshFee);
assert(tshFeeDrops >= beast::zero);
STAmount priorBalance = tshAcc->getFieldAmount(sfBalance);

View File

@@ -179,7 +179,7 @@ public:
// Hooks
static FeeUnit64
static XRPAmount
calculateHookChainFee(ReadView const& view, STTx const& tx, Keylet const& hookKeylet,
bool collectCallsOnly = false);

View File

@@ -284,7 +284,7 @@ invoke_preclaim(PreclaimContext const& ctx)
}
}
static XRPAmount
XRPAmount
invoke_calculateBaseFee(ReadView const& view, STTx const& tx)
{
switch (tx.getTxnType())

View File

@@ -263,7 +263,7 @@ enum LedgerSpecificFlags {
0x00800000, // True, trust lines allow rippling by default
lsfDepositAuth = 0x01000000, // True, all deposits require authorization
lsfTshCollect = 0x02000000, // True, allow TSH collect-calls to acc hooks
lsfDisallowIncomingNFTOffer =
lsfDisallowIncomingNFTokenOffer =
0x04000000, // True, reject new incoming NFT offers
lsfDisallowIncomingCheck =
0x08000000, // True, reject new checks

View File

@@ -60,7 +60,7 @@ LedgerFormats::LedgerFormats()
{sfRewardLgrFirst, soeOPTIONAL},
{sfRewardLgrLast, soeOPTIONAL},
{sfRewardTime, soeOPTIONAL},
{sfRewardAccumulator, soeOPTIONAL}
{sfRewardAccumulator, soeOPTIONAL},
{sfFirstNFTokenSequence, soeOPTIONAL},
},
commonFields);

View File

@@ -33,7 +33,7 @@ namespace ripple {
inline
std::optional<FeeUnit64>
std::optional<XRPAmount>
getHookFees(RPC::JsonContext const& context)
{
auto const& params(context.params);
@@ -65,7 +65,7 @@ Json::Value
doFee(RPC::JsonContext& context)
{
// get hook fees, if any
std::optional<FeeUnit64> hookFees;
std::optional<XRPAmount> hookFees;
try
{
hookFees = getHookFees(context);

View File

@@ -20,9 +20,6 @@
#include <ripple/basics/Expected.h>
#include <ripple/beast/unit_test.h>
#include <ripple/protocol/TER.h>
#if BOOST_VERSION >= 107500
#include <boost/json.hpp> // Not part of boost before version 1.75
#endif // BOOST_VERSION
#include <array>
#include <cstdint>
@@ -206,16 +203,6 @@ struct Expected_test : beast::unit_test::suite
std::string const s(std::move(expected.error()));
BEAST_EXPECT(s == "Not what is expected!");
}
// Test a case that previously unintentionally returned an array.
#if BOOST_VERSION >= 107500
{
auto expected = []() -> Expected<boost::json::value, std::string> {
return boost::json::object{{"oops", "me array now"}};
}();
BEAST_EXPECT(expected);
BEAST_EXPECT(!expected.value().is_array());
}
#endif // BOOST_VERSION
}
};

View File

@@ -237,7 +237,7 @@ class LedgerRPC_test : public beast::unit_test::suite
env.rpc("json", "ledger", to_string(jvParams))[jss::result];
BEAST_EXPECT(jrr[jss::ledger].isMember(jss::accountState));
BEAST_EXPECT(jrr[jss::ledger][jss::accountState].isArray());
BEAST_EXPECT(jrr[jss::ledger][jss::accountState].size() == 3u);
BEAST_EXPECT(jrr[jss::ledger][jss::accountState].size() == 2u);
}
void
@@ -276,7 +276,7 @@ class LedgerRPC_test : public beast::unit_test::suite
env.rpc("json", "ledger", to_string(jvParams))[jss::result];
BEAST_EXPECT(jrr[jss::ledger].isMember(jss::accountState));
BEAST_EXPECT(jrr[jss::ledger][jss::accountState].isArray());
BEAST_EXPECT(jrr[jss::ledger][jss::accountState].size() == 3u);
BEAST_EXPECT(jrr[jss::ledger][jss::accountState].size() == 2u);
}
void
@@ -1364,12 +1364,11 @@ class LedgerRPC_test : public beast::unit_test::suite
}
{
std::string const hash3{
"E86DE7F3D7A4D9CE17EF7C8BA08A8F4D"
"8F643B9552F0D895A31CDA78F541DE4E"};
// access via the ledger_hash field
Json::Value jvParams;
jvParams[jss::ledger_hash] = hash3;
jvParams[jss::ledger_hash] =
"2E81FC6EC0DD943197E0C7E3FBE9AE30"
"7F2775F2F7485BB37307984C3C0F2340";
auto jrr = env.rpc(
"json",
"ledger",
@@ -1378,8 +1377,11 @@ class LedgerRPC_test : public beast::unit_test::suite
BEAST_EXPECT(jrr.isMember(jss::ledger_hash));
BEAST_EXPECT(jrr[jss::ledger][jss::ledger_index] == "3");
// extra leading hex chars in hash are not allowed
jvParams[jss::ledger_hash] = "DEADBEEF" + hash3;
// extra leading hex chars in hash will be ignored
jvParams[jss::ledger_hash] =
"DEADBEEF"
"2E81FC6EC0DD943197E0C7E3FBE9AE30"
"7F2775F2F7485BB37307984C3C0F2340";
jrr = env.rpc(
"json",
"ledger",
@@ -1582,7 +1584,7 @@ class LedgerRPC_test : public beast::unit_test::suite
env.close();
jrr = env.rpc("json", "ledger", to_string(jv))[jss::result];
const std::string txid0 = [&]() {
const std::string txid1 = [&]() {
auto const& parentHash = env.current()->info().parentHash;
if (BEAST_EXPECT(jrr[jss::queue_data].size() == 2))
{
@@ -1641,7 +1643,7 @@ class LedgerRPC_test : public beast::unit_test::suite
BEAST_EXPECT(txj["retries_remaining"] == 9);
BEAST_EXPECT(txj["last_result"] == "terPRE_SEQ");
BEAST_EXPECT(txj.isMember(jss::tx));
BEAST_EXPECT(txj[jss::tx] == txid0);
BEAST_EXPECT(txj[jss::tx] == txid1);
uint256 tx0, tx1;
BEAST_EXPECT(tx0.parseHex(txid0));
BEAST_EXPECT(tx1.parseHex(txid1));
@@ -1694,7 +1696,7 @@ class LedgerRPC_test : public beast::unit_test::suite
BEAST_EXPECT(txj["retries_remaining"] == 1);
BEAST_EXPECT(txj["last_result"] == "terPRE_SEQ");
BEAST_EXPECT(txj.isMember(jss::tx));
BEAST_EXPECT(txj[jss::tx] != txid0);
BEAST_EXPECT(txj[jss::tx] != txid1);
return txj[jss::tx].asString();
}
return std::string{};