Compare commits

..

9 Commits

Author SHA1 Message Date
Richard Holland
45411750cf cadastre preflight 2023-12-18 14:15:45 +00:00
Richard Holland
b42be37d78 move utf8 checking to header file 2023-12-18 13:57:06 +00:00
Richard Holland
9215b87511 . 2023-12-18 13:57:02 +00:00
Richard Holland
2817f848e8 . 2023-12-09 13:10:08 +00:00
Richard Holland
557ad3d18e cadastre txn types 2023-12-09 13:08:28 +00:00
Richard Holland
e05d7e783c initial cadastre fields 2023-12-07 15:01:18 +00:00
Richard Holland
49798b1792 make server_definitions caching thread_local 2023-12-05 13:47:54 +00:00
Denis Angell
27f43ba9ee TSH Tests (#222) 2023-12-03 10:13:05 +01:00
Wietse Wind
7881b7f69f Build on most cores (nproc / 3 » nproc / 1.337) (#226)
Use those resources! 🎉🚀
2023-12-01 12:47:50 +01:00
34 changed files with 5524 additions and 2436 deletions

View File

@@ -455,13 +455,13 @@ target_sources (rippled PRIVATE
src/ripple/app/tx/impl/GenesisMint.cpp
src/ripple/app/tx/impl/Import.cpp
src/ripple/app/tx/impl/Invoke.cpp
src/ripple/app/tx/impl/Remit.cpp
src/ripple/app/tx/impl/SetSignerList.cpp
src/ripple/app/tx/impl/SetTrust.cpp
src/ripple/app/tx/impl/SignerEntries.cpp
src/ripple/app/tx/impl/Taker.cpp
src/ripple/app/tx/impl/Transactor.cpp
src/ripple/app/tx/impl/URIToken.cpp
src/ripple/app/tx/impl/Cadastre.cpp
src/ripple/app/tx/impl/apply.cpp
src/ripple/app/tx/impl/applySteps.cpp
src/ripple/app/hook/impl/applyHook.cpp
@@ -741,7 +741,6 @@ if (tests)
src/test/app/RCLCensorshipDetector_test.cpp
src/test/app/RCLValidations_test.cpp
src/test/app/Regression_test.cpp
src/test/app/Remit_test.cpp
src/test/app/SHAMapStore_test.cpp
src/test/app/SetAuth_test.cpp
src/test/app/SetRegularKey_test.cpp
@@ -757,6 +756,7 @@ if (tests)
src/test/app/ValidatorList_test.cpp
src/test/app/ValidatorSite_test.cpp
src/test/app/SetHook_test.cpp
src/test/app/SetHookTSH_test.cpp
src/test/app/Wildcard_test.cpp
src/test/app/XahauGenesis_test.cpp
src/test/app/tx/apply_test.cpp
@@ -890,7 +890,6 @@ if (tests)
src/test/jtx/impl/rate.cpp
src/test/jtx/impl/regkey.cpp
src/test/jtx/impl/reward.cpp
src/test/jtx/impl/remit.cpp
src/test/jtx/impl/sendmax.cpp
src/test/jtx/impl/seq.cpp
src/test/jtx/impl/sig.cpp
@@ -899,6 +898,7 @@ if (tests)
src/test/jtx/impl/token.cpp
src/test/jtx/impl/trust.cpp
src/test/jtx/impl/txflags.cpp
src/test/jtx/impl/unl.cpp
src/test/jtx/impl/uritoken.cpp
src/test/jtx/impl/utility.cpp

View File

@@ -891,13 +891,19 @@ hook::removeHookNamespaceEntry(ripple::SLE& sleAccount, ripple::uint256 ns)
bool
hook::canHook(ripple::TxType txType, ripple::uint256 hookOn)
{
uint16_t tt = safe_cast<uint16_t>(txType);
// only the low order byte is used to determine HookOn
tt &= 0xFFU;
// invert ttHOOK_SET bit
hookOn ^= UINT256_BIT[ttHOOK_SET];
// invert entire field
hookOn = ~hookOn;
return (hookOn & UINT256_BIT[txType]) != beast::zero;
return (hookOn & UINT256_BIT[tt]) != beast::zero;
}
// Update HookState ledger objects for the hook... only called after accept()

View File

@@ -0,0 +1,207 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/app/tx/impl/Cadastre.h>
#include <ripple/basics/Log.h>
#include <ripple/ledger/View.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/app/tx/impl/URIToken.h>
namespace ripple {
TxConsequences
Cadastre::makeTxConsequences(PreflightContext const& ctx)
{
return TxConsequences{ctx.tx, TxConsequences::normal};
}
/*
add(jss::Cadastre,
ltCADASTRE,
{
{sfOwner, soeREQUIRED},
{sfOwnerNode, soeREQUIRED},
{sfAssociation, soeOPTIONAL},
{sfAssociationNode, soeOPTIONAL},
{sfLocationX, soeREQUIRED},
{sfLocationY, soeREQUIRED},
{sfUniverse, soeREQUIRED},
{sfDisplayURI, soeOPTIONAL},
{sfBroadcastURI, soeOPTIONAL},
{sfCadastreCount, soeOPTIONAL}, // for 0x8000,0x8000 tile only
},
commonFields);
ttCADASTRE_MINT = 0x005D, // HookOn = 93
ttCADASTRE_BURN = 0x015D,
ttCADASTRE_CREATE_SELL_OFFER = 0x025D,
ttCADASTRE_CANCEL_SELL_OFFER = 0x035D,
ttCADASTRE_BUY = 0x045D,
ttCADASTRE_SET = 0x055D,
*/
NotTEC
Cadastre::preflight(PreflightContext const& ctx)
{
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;
auto& tx = ctx.tx;
// the validation for amount is the same regardless of which txn is appears
// on
if (ctx.tx.isFieldPresent(sfAmount))
{
auto amt = ctx.tx.getFieldAmount(sfAmount);
if (!isLegalNet(amt) || amt.signum() < 0)
{
JLOG(ctx.j.warn()) << "Malformed transaction. Negative or "
"invalid amount/currency specified.";
return temBAD_AMOUNT;
}
if (isBadCurrency(amt.getCurrency()))
{
JLOG(ctx.j.warn()) << "Malformed transaction. Bad currency.";
return temBAD_CURRENCY;
}
if (amt == beast::zero && !ctx.tx.isFieldPresent(sfDestination))
{
if (tt == ttCADASTRE_BUY)
{
// buy operation does not specify a destination, and can have a
// zero amount pass
}
else
{
JLOG(ctx.j.warn()) << "Malformed transaction. "
<< "If no sell-to destination is specified "
"then a non-zero price must be set.";
return temMALFORMED;
}
}
}
if (ctx.tx.isFieldPresent(sfDestination) &&
!ctx.tx.isFieldPresent(sfAmount))
return temMALFORMED;
auto checkURI = [&ctx](SField const& f) -> TER
{
if (ctx.tx.isFieldPresent(f))
{
auto const& vl = ctx.tx.getFieldVL(f);
if (vl.size() < 1 || vl.size() > 256)
{
JLOG(ctx.j.warn())
<< "Cadastre: Malformed transaction, "
<< f.getName()
<< " was invalid size (too big/small)";
return temMALFORMED;
}
if (!URIToken::validateUTF8(ctx.tx.getFieldVL(sfDisplayURI)))
{
JLOG(ctx.j.warn())
<< "Cadastre: Malformed transaction, "
<< f.getName()
<< " was not valid utf-8";
return temMALFORMED;
}
}
return tesSUCCESS;
};
checkURI(sfDisplayURI);
checkURI(sfBroadcastURI);
return preflight2(ctx);
}
TER
Cadastre::preclaim(PreclaimContext const& ctx)
{
if (!ctx.view.rules().enabled(featureHooks))
return temDISABLED;
auto const id = ctx.tx[sfAccount];
auto const sle = ctx.view.read(keylet::account(id));
if (!sle)
return terNO_ACCOUNT;
if (ctx.tx.isFieldPresent(sfDestination))
{
if (!ctx.view.exists(keylet::account(ctx.tx[sfDestination])))
return tecNO_TARGET;
}
auto const tt = tx.getTxnType();
switch(tt)
{
case ttCADASTRE_MINT:
case ttCADASTRE_SET:
{
break;
}
case ttCADASTRE_BURN:
{
break;
}
case ttCADASTRE_CREATE_SELL_OFFER:
{
break;
}
case ttCADASTRE_CANCEL_SELL_OFFER:
{
break;
}
case ttCADASTRE_BUY:
{
break;
}
}
return tesSUCCESS;
}
TER
Cadastre::doApply()
{
// everything happens in the hooks!
return tesSUCCESS;
}
XRPAmount
Cadastre::calculateBaseFee(ReadView const& view, STTx const& tx)
{
XRPAmount extraFee{0};
return Transactor::calculateBaseFee(view, tx) + extraFee;
}
} // namespace ripple

View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Copyright (c) 2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -17,22 +17,22 @@
*/
//==============================================================================
#ifndef RIPPLE_TX_SIMPLE_PAYMENT_H_INCLUDED
#define RIPPLE_TX_SIMPLE_PAYMENT_H_INCLUDED
#ifndef RIPPLE_TX_CADASTRE_H_INCLUDED
#define RIPPLE_TX_CADASTRE_H_INCLUDED
#include <ripple/app/ledger/Ledger.h>
#include <ripple/app/tx/impl/Transactor.h>
#include <ripple/basics/Log.h>
#include <ripple/core/Config.h>
#include <ripple/protocol/Indexes.h>
namespace ripple {
class Remit : public Transactor
class Cadastre : public Transactor
{
public:
static constexpr ConsequencesFactoryType ConsequencesFactory{Custom};
static constexpr ConsequencesFactoryType ConsequencesFactory{Normal};
explicit Remit(ApplyContext& ctx) : Transactor(ctx)
explicit Cadastre(ApplyContext& ctx) : Transactor(ctx)
{
}
@@ -45,6 +45,9 @@ public:
static NotTEC
preflight(PreflightContext const& ctx);
static TER
preclaim(PreclaimContext const& ctx);
TER
doApply() override;
};

View File

@@ -492,6 +492,7 @@ LedgerEntryTypesMatch::visitEntry(
case ltURI_TOKEN:
case ltIMPORT_VLSEQ:
case ltUNL_REPORT:
case ltCADASTRE:
break;
default:
invalidTypeAdded_ = true;
@@ -597,8 +598,7 @@ ValidNewAccountRoot::finalize(
return false;
}
if ((tt == ttPAYMENT || tt == ttIMPORT || tt == ttGENESIS_MINT ||
tt == ttREMIT) &&
if ((tt == ttPAYMENT || tt == ttIMPORT || tt == ttGENESIS_MINT) &&
result == tesSUCCESS)
{
std::uint32_t const startingSeq{

View File

@@ -1,501 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/app/tx/impl/Remit.h>
#include <ripple/app/tx/impl/URIToken.h>
#include <ripple/basics/Log.h>
#include <ripple/ledger/View.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Indexes.h>
namespace ripple {
TxConsequences
Remit::makeTxConsequences(PreflightContext const& ctx)
{
return TxConsequences{ctx.tx, TxConsequences::normal};
}
NotTEC
Remit::preflight(PreflightContext const& ctx)
{
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;
if (ctx.tx.getFlags() & tfUniversalMask)
{
// There are no flags (other than universal).
JLOG(ctx.j.warn()) << "Malformed transaction: Invalid flags set.";
return temINVALID_FLAG;
}
AccountID const dstID = ctx.tx.getAccountID(sfDestination);
AccountID const srcID = ctx.tx.getAccountID(sfAccount);
if (dstID == srcID)
{
JLOG(ctx.j.warn()) << "Malformed transaction: Remit to self.";
return temREDUNDANT;
}
// sanity check amounts
if (ctx.tx.isFieldPresent(sfAmounts))
{
std::map<Currency, std::set<AccountID>> already;
bool nativeAlready = false;
STArray const& sEntries(ctx.tx.getFieldArray(sfAmounts));
for (STObject const& sEntry : sEntries)
{
// Validate the AmountEntry.
if (sEntry.getFName() != sfAmountEntry)
{
JLOG(ctx.j.warn()) << "Malformed: Expected AmountEntry.";
return temMALFORMED;
}
STAmount const amount = sEntry.getFieldAmount(sfAmount);
if (!isLegalNet(amount) || amount.signum() <= 0)
{
JLOG(ctx.j.warn()) << "Malformed transaction: bad amount: "
<< amount.getFullText();
return temBAD_AMOUNT;
}
if (isBadCurrency(amount.getCurrency()))
{
JLOG(ctx.j.warn()) << "Malformed transaction: Bad currency.";
return temBAD_CURRENCY;
}
if (isXRP(amount))
{
if (nativeAlready)
{
JLOG(ctx.j.warn()) << "Malformed transaction: Native "
"Currency appears more than once.";
return temMALFORMED;
}
nativeAlready = true;
continue;
}
auto found = already.find(amount.getCurrency());
if (found == already.end())
{
already.emplace(
amount.getCurrency(),
std::set<AccountID>{amount.getIssuer()});
continue;
}
if (found->second.find(amount.getIssuer()) != found->second.end())
{
JLOG(ctx.j.warn()) << "Malformed transaction: Issued Currency "
"appears more than once.";
return temMALFORMED;
}
found->second.emplace(amount.getIssuer());
}
}
// sanity check minturitoken
if (ctx.tx.isFieldPresent(sfMintURIToken))
{
STObject const& mint = const_cast<ripple::STTx&>(ctx.tx)
.getField(sfMintURIToken)
.downcast<STObject>();
// RH TODO: iterate mint fields detect any that shouldnt be there
Blob const uri = mint.getFieldVL(sfURI);
if (uri.size() < 1 || uri.size() > 256)
{
JLOG(ctx.j.warn())
<< "Malformed transaction: URI was too short/long.";
return temMALFORMED;
}
if (!URIToken::validateUTF8(mint.getFieldVL(sfURI)))
{
JLOG(ctx.j.warn())
<< "Malformed transaction: Invalid UTF8 inside MintURIToken.";
return temMALFORMED;
}
if (mint.isFieldPresent(sfFlags))
{
if (mint.getFieldU32(sfFlags) & tfURITokenMintMask)
return temINVALID_FLAG;
}
}
// check uritokenids for duplicates
if (ctx.tx.isFieldPresent(sfURITokenIDs))
{
STVector256 ids = ctx.tx.getFieldV256(sfURITokenIDs);
std::sort(ids.begin(), ids.end());
if (std::adjacent_find(ids.begin(), ids.end()) != ids.end())
{
JLOG(ctx.j.warn())
<< "Malformed transaction: Duplicate URITokenID.";
return temMALFORMED;
}
}
return preflight2(ctx);
}
TER
Remit::doApply()
{
if (!view().rules().enabled(featureRemit) || !view().rules().enabled(featureURIToken))
return temDISABLED;
Sandbox sb(&ctx_.view());
beast::Journal const& j = ctx_.journal;
auto const srcAccID = ctx_.tx[sfAccount];
auto sleSrcAcc = sb.peek(keylet::account(srcAccID));
if (!sleSrcAcc)
return terNO_ACCOUNT;
XRPAmount const accountReserve{sb.fees().accountReserve(0)};
XRPAmount const objectReserve{sb.fees().accountReserve(1) - accountReserve};
// amount of native tokens we will transfer to cover reserves for the
// tls/acc/uritokens created, and native tokens listed in amounts
XRPAmount nativeRemit{0};
AccountID const dstAccID{ctx_.tx[sfDestination]};
auto sleDstAcc = sb.peek(keylet::account(dstAccID));
auto const flags = !sleDstAcc ? 0 : sleDstAcc->getFlags();
// Check if the destination has disallowed incoming
if (sb.rules().enabled(featureDisallowIncoming) &&
(flags & lsfDisallowIncomingRemit))
return tecNO_PERMISSION;
// the destination may require a dest tag
if ((flags & lsfRequireDestTag) &&
!ctx_.tx.isFieldPresent(sfDestinationTag))
{
JLOG(j.warn())
<< "Remit: DestinationTag required for this destination.";
return tecDST_TAG_NEEDED;
}
// if the destination doesn't exist, create it.
bool const createDst = !sleDstAcc;
if (createDst)
{
// sender will pay the reserve
nativeRemit += accountReserve;
// Create the account.
std::uint32_t const seqno{
sb.rules().enabled(featureXahauGenesis)
? sb.info().parentCloseTime.time_since_epoch().count()
: sb.rules().enabled(featureDeletableAccounts) ? sb.seq() : 1};
sleDstAcc = std::make_shared<SLE>(keylet::account(dstAccID));
sleDstAcc->setAccountID(sfAccount, dstAccID);
sleDstAcc->setFieldU32(sfSequence, seqno);
sleDstAcc->setFieldU32(sfOwnerCount, 0);
if (sb.exists(keylet::fees()) && sb.rules().enabled(featureXahauGenesis))
{
auto sleFees = sb.peek(keylet::fees());
uint64_t accIdx = sleFees->isFieldPresent(sfAccountCount)
? sleFees->getFieldU64(sfAccountCount)
: 0;
sleDstAcc->setFieldU64(sfAccountIndex, accIdx);
sleFees->setFieldU64(sfAccountCount, accIdx + 1);
sb.update(sleFees);
}
// we'll fix this up at the end
sleDstAcc->setFieldAmount(sfBalance, STAmount{XRPAmount{0}});
sb.insert(sleDstAcc);
}
// if theres a minted uritoken the sender pays for that
if (ctx_.tx.isFieldPresent(sfMintURIToken))
{
nativeRemit += objectReserve;
STObject const& mint = const_cast<ripple::STTx&>(ctx_.tx)
.getField(sfMintURIToken)
.downcast<STObject>();
Blob const& mintURI = mint.getFieldVL(sfURI);
std::optional<uint256> mintDigest;
if (mint.isFieldPresent(sfDigest))
mintDigest = mint.getFieldH256(sfDigest);
Keylet kl = keylet::uritoken(srcAccID, mintURI);
// check that it doesn't already exist
if (sb.exists(kl))
{
JLOG(j.trace()) << "Remit: tried to creat duplicate URIToken. Tx: "
<< ctx_.tx.getTransactionID();
return tecDUPLICATE;
}
auto sleMint = std::make_shared<SLE>(kl);
sleMint->setAccountID(sfOwner, dstAccID);
sleMint->setAccountID(sfIssuer, srcAccID);
sleMint->setFieldVL(sfURI, mintURI);
if (mint.isFieldPresent(sfDigest))
sleMint->setFieldH256(sfDigest, mint.getFieldH256(sfDigest));
sleMint->setFieldU32(
sfFlags,
mint.isFieldPresent(sfFlags) ? mint.getFieldU32(sfFlags) : 0);
auto const page = view().dirInsert(
keylet::ownerDir(dstAccID), kl, describeOwnerDir(dstAccID));
JLOG(j_.trace()) << "Adding URIToken to owner directory "
<< to_string(kl.key) << ": "
<< (page ? "success" : "failure");
if (!page)
return tecDIR_FULL;
sleMint->setFieldU64(sfOwnerNode, *page);
sb.insert(sleMint);
// ensure there is a deletion blocker against the issuer now
sleSrcAcc->setFieldU32(
sfFlags, sleSrcAcc->getFlags() | lsfURITokenIssuer);
adjustOwnerCount(sb, sleDstAcc, 1, j);
}
// iterate uritokens
if (ctx_.tx.isFieldPresent(sfURITokenIDs))
{
STVector256 ids = ctx_.tx.getFieldV256(sfURITokenIDs);
for (uint256 const klRaw : ids)
{
Keylet kl = keylet::unchecked(klRaw);
auto sleU = sb.peek(kl);
// does it exist
if (!sleU)
{
JLOG(j.warn()) << "Remit: one or more uritokens did not exist "
"on the source account.";
return tecUNFUNDED_PAYMENT;
}
// is it a uritoken?
if (sleU->getFieldU16(sfLedgerEntryType) != ltURI_TOKEN)
{
JLOG(j.warn()) << "Remit: one or more supplied URITokenIDs was "
"not actually a uritoken.";
return tecNO_ENTRY;
}
// is it our uritoken?
if (sleU->getAccountID(sfOwner) != srcAccID)
{
JLOG(j.warn()) << "Remit: one or more supplied URITokenIDs was "
"not owned by sender.";
return tecNO_PERMISSION;
}
// erase current sale offers, if any
if (sleU->isFieldPresent(sfAmount))
sleU->makeFieldAbsent(sfAmount);
if (sleU->isFieldPresent(sfDestination))
sleU->makeFieldAbsent(sfDestination);
// pay the reserve
nativeRemit += objectReserve;
// remove from sender dir
{
auto const page = (*sleU)[sfOwnerNode];
if (!sb.dirRemove(
keylet::ownerDir(srcAccID), page, kl.key, true))
{
JLOG(j.fatal())
<< "Could not remove URIToken from owner directory";
return tefBAD_LEDGER;
}
adjustOwnerCount(sb, sleSrcAcc, -1, j);
}
// add to dest dir
{
auto const page = sb.dirInsert(
keylet::ownerDir(dstAccID), kl, describeOwnerDir(dstAccID));
JLOG(j_.trace()) << "Adding URIToken to owner directory "
<< to_string(kl.key) << ": "
<< (page ? "success" : "failure");
if (!page)
return tecDIR_FULL;
sleU->setFieldU64(sfOwnerNode, *page);
adjustOwnerCount(sb, sleDstAcc, 1, j);
}
// change the owner
sleU->setAccountID(sfOwner, dstAccID);
sb.update(sleU);
}
}
// iterate trustlines
if (ctx_.tx.isFieldPresent(sfAmounts))
{
// process trustline remits
STArray const& sEntries(ctx_.tx.getFieldArray(sfAmounts));
for (STObject const& sEntry : sEntries)
{
STAmount const amount = sEntry.getFieldAmount(sfAmount);
if (isXRP(amount))
{
// since we have to pay for all the created objects including
// possibly the account itself this is paid right at the end,
// and only if there is balance enough to cover.
nativeRemit += amount.xrp();
continue;
}
AccountID const issuerAccID = amount.getIssuer();
// check permissions
if (issuerAccID == srcAccID || issuerAccID == dstAccID)
{
// no permission check needed when the issuer sends out or a
// subscriber sends back RH TODO: move this condition into
// trustTransferAllowed, guarded by an amendment
}
else if (TER canXfer = trustTransferAllowed(
sb,
std::vector<AccountID>{srcAccID, dstAccID},
amount.issue(),
j);
canXfer != tesSUCCESS)
return canXfer;
// compute the amount the source will need to send
// in remit the sender pays all transfer fees, so that
// the destination can always be assured they got the exact amount
// specified. therefore we need to compute the amount + transfer fee
auto const srcAmt =
issuerAccID != srcAccID && issuerAccID != dstAccID
? multiply(amount, transferRate(sb, issuerAccID))
: amount;
auto const dstAmt = amount;
STAmount availableFunds{
accountFunds(sb, srcAccID, srcAmt, fhZERO_IF_FROZEN, j)};
if (availableFunds < srcAmt)
return tecUNFUNDED_PAYMENT;
// if the target trustline doesn't exist we need to create it and
// pay its reserve
if (!sb.exists(keylet::line(
issuerAccID == dstAccID ? srcAccID : dstAccID,
issuerAccID,
amount.getCurrency())))
nativeRemit += objectReserve;
// action the transfer
STAmount sentAmt;
if (TER result =
rippleSend(sb, srcAccID, dstAccID, dstAmt, sentAmt, j);
result != tesSUCCESS)
return result;
if (sentAmt != srcAmt)
return tecINTERNAL;
}
}
if (nativeRemit < beast::zero)
return tecINTERNAL;
if (nativeRemit > beast::zero)
{
// ensure the account can cover the native remit
if (mSourceBalance < nativeRemit)
return tecUNFUNDED_PAYMENT;
// subtract the balance from the sender
{
STAmount bal = mSourceBalance;
bal -= nativeRemit;
if (bal < beast::zero || bal > mSourceBalance)
return tecINTERNAL;
sleSrcAcc->setFieldAmount(sfBalance, bal);
}
// add the balance to the destination
{
STAmount bal = sleDstAcc->getFieldAmount(sfBalance);
STAmount prior = bal;
bal += nativeRemit;
if (bal < beast::zero || bal < prior)
return tecINTERNAL;
sleDstAcc->setFieldAmount(sfBalance, bal);
}
}
// apply
sb.update(sleSrcAcc);
sb.update(sleDstAcc);
sb.apply(ctx_.rawView());
return tesSUCCESS;
}
XRPAmount
Remit::calculateBaseFee(ReadView const& view, STTx const& tx)
{
XRPAmount extraFee{0};
if (tx.isFieldPresent(sfBlob))
extraFee +=
XRPAmount{static_cast<XRPAmount>(tx.getFieldVL(sfBlob).size())};
// RH TODO: add fees
return Transactor::calculateBaseFee(view, tx) + extraFee;
}
} // namespace ripple

View File

@@ -577,14 +577,6 @@ SetAccount::doApply()
uFlagsOut |= lsfDisallowIncomingTrustline;
else if (uClearFlag == asfDisallowIncomingTrustline)
uFlagsOut &= ~lsfDisallowIncomingTrustline;
if (ctx_.view().rules().enabled(featureRemit))
{
if (uSetFlag == asfDisallowIncomingRemit)
uFlagsOut |= lsfDisallowIncomingRemit;
else if (uClearFlag == asfDisallowIncomingRemit)
uFlagsOut &= ~lsfDisallowIncomingRemit;
}
}
if (uFlagsIn != uFlagsOut)

View File

@@ -45,6 +45,7 @@
#include <ripple/app/tx/impl/SetSignerList.h>
#include <ripple/app/tx/impl/SetTrust.h>
#include <ripple/app/tx/impl/URIToken.h>
#include <ripple/app/tx/impl/Cadastre.h>
namespace ripple {
@@ -164,14 +165,19 @@ invoke_preflight(PreflightContext const& ctx)
return invoke_preflight_helper<Import>(ctx);
case ttINVOKE:
return invoke_preflight_helper<Invoke>(ctx);
case ttREMIT:
return invoke_preflight_helper<Remit>(ctx);
case ttURITOKEN_MINT:
case ttURITOKEN_BURN:
case ttURITOKEN_BUY:
case ttURITOKEN_CREATE_SELL_OFFER:
case ttURITOKEN_CANCEL_SELL_OFFER:
return invoke_preflight_helper<URIToken>(ctx);
case ttCADASTRE_MINT:
case ttCADASTRE_BURN:
case ttCADASTRE_CREATE_SELL_OFFER:
case ttCADASTRE_CANCEL_SELL_OFFER:
case ttCADASTRE_BUY:
case ttCADASTRE_SET:
return invoke_preflight_helper<Cadastre>(ctx);
default:
assert(false);
return {temUNKNOWN, TxConsequences{temUNKNOWN}};
@@ -285,14 +291,19 @@ invoke_preclaim(PreclaimContext const& ctx)
return invoke_preclaim<Import>(ctx);
case ttINVOKE:
return invoke_preclaim<Invoke>(ctx);
case ttREMIT:
return invoke_preclaim<Remit>(ctx);
case ttURITOKEN_MINT:
case ttURITOKEN_BURN:
case ttURITOKEN_BUY:
case ttURITOKEN_CREATE_SELL_OFFER:
case ttURITOKEN_CANCEL_SELL_OFFER:
return invoke_preclaim<URIToken>(ctx);
case ttCADASTRE_MINT:
case ttCADASTRE_BURN:
case ttCADASTRE_CREATE_SELL_OFFER:
case ttCADASTRE_CANCEL_SELL_OFFER:
case ttCADASTRE_BUY:
case ttCADASTRE_SET:
return invoke_preclaim<Cadastre>(ctx);
default:
assert(false);
return temUNKNOWN;
@@ -368,14 +379,19 @@ invoke_calculateBaseFee(ReadView const& view, STTx const& tx)
return Import::calculateBaseFee(view, tx);
case ttINVOKE:
return Invoke::calculateBaseFee(view, tx);
case ttREMIT:
return Remit::calculateBaseFee(view, tx);
case ttURITOKEN_MINT:
case ttURITOKEN_BURN:
case ttURITOKEN_BUY:
case ttURITOKEN_CREATE_SELL_OFFER:
case ttURITOKEN_CANCEL_SELL_OFFER:
return URIToken::calculateBaseFee(view, tx);
case ttCADASTRE_MINT:
case ttCADASTRE_BURN:
case ttCADASTRE_CREATE_SELL_OFFER:
case ttCADASTRE_CANCEL_SELL_OFFER:
case ttCADASTRE_BUY:
case ttCADASTRE_SET:
return Cadastre::calculateBaseFee(view, tx);
default:
assert(false);
return XRPAmount{0};
@@ -550,10 +566,6 @@ invoke_apply(ApplyContext& ctx)
Invoke p(ctx);
return p();
}
case ttREMIT: {
Remit p(ctx);
return p();
}
case ttURITOKEN_MINT:
case ttURITOKEN_BURN:
case ttURITOKEN_BUY:
@@ -562,6 +574,15 @@ invoke_apply(ApplyContext& ctx)
URIToken p(ctx);
return p();
}
case ttCADASTRE_MINT:
case ttCADASTRE_BURN:
case ttCADASTRE_CREATE_SELL_OFFER:
case ttCADASTRE_CANCEL_SELL_OFFER:
case ttCADASTRE_BUY:
case ttCADASTRE_SET: {
Cadastre p(ctx);
return p();
}
default:
assert(false);
return {temUNKNOWN, false};

View File

@@ -27,7 +27,6 @@
#include <ripple/ledger/OpenView.h>
#include <ripple/ledger/RawView.h>
#include <ripple/ledger/ReadView.h>
#include <ripple/ledger/Sandbox.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Protocol.h>
#include <ripple/protocol/Rate.h>
@@ -389,18 +388,6 @@ rippleCredit(
bool bCheckIssuer,
beast::Journal j);
// Send regardless of limits.
// --> saAmount: Amount/currency/issuer to deliver to receiver.
// <-- saActual: Amount actually cost. Sender pays fees.
TER
rippleSend(
ApplyView& view,
AccountID const& uSenderID,
AccountID const& uReceiverID,
STAmount const& saAmount,
STAmount& saActual,
beast::Journal j);
[[nodiscard]] TER
accountSend(
ApplyView& view,
@@ -640,12 +627,12 @@ trustTransferAllowed(
{
static_assert(
std::is_same<V, ReadView const>::value ||
std::is_same<V, ApplyView>::value || std::is_same<V, Sandbox>::value);
std::is_same<V, ApplyView>::value);
typedef typename std::conditional<
std::is_same<V, ReadView const>::value,
std::shared_ptr<SLE const>,
std::shared_ptr<SLE>>::type SLEPtr;
std::is_same<V, ApplyView>::value,
std::shared_ptr<SLE>,
std::shared_ptr<SLE const>>::type SLEPtr;
if (isBadCurrency(issue.currency))
return tecNO_PERMISSION;

View File

@@ -1150,7 +1150,7 @@ rippleCredit(
// Send regardless of limits.
// --> saAmount: Amount/currency/issuer to deliver to receiver.
// <-- saActual: Amount actually cost. Sender pays fees.
TER
static TER
rippleSend(
ApplyView& view,
AccountID const& uSenderID,

View File

@@ -74,7 +74,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
// the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 67;
static constexpr std::size_t numFeatures = 66;
/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
@@ -354,7 +354,6 @@ extern uint256 const featureImport;
extern uint256 const featureXahauGenesis;
extern uint256 const featureHooksUpdate1;
extern uint256 const fixURITokenV1;
extern uint256 const featureRemit;
} // namespace ripple

View File

@@ -297,6 +297,10 @@ import_vlseq(PublicKey const& key) noexcept;
Keylet
uritoken(AccountID const& issuer, Blob const& uri);
Keylet
cadastre(uint256 const& universe, uint16_t locx, uint16_t locy);
} // namespace keylet
// Everything below is deprecated and should be removed in favor of keylets:

View File

@@ -179,6 +179,15 @@ enum LedgerEntryType : std::uint16_t
*/
ltUNL_REPORT = 0x0052,
/** A ledger object that contains cadastral information about a unit of virtual land
* in a given universe. The block at 0x8000, 0x8000 is the center of the universe
* and has special rights and privileges, namely it is the god block whose hooks are
* strongly executed whenever dealings with land in that universe occur.
*
* \sa keylet::cadastre
*/
ltCADASTRE = 0x004B,
//---------------------------------------------------------------------------
/** A special type, matching any ledger entry type.
@@ -285,8 +294,6 @@ enum LedgerSpecificFlags {
0x20000000, // True, reject new trustlines (only if no issued assets)
lsfURITokenIssuer =
0x40000000, // True, has minted tokens in the past
lsfDisallowIncomingRemit = // True, no remits allowed to this account
0x80000000,
// ltOFFER
lsfPassive = 0x00010000,

View File

@@ -354,6 +354,8 @@ extern SF_UINT16 const sfHookStateChangeCount;
extern SF_UINT16 const sfHookEmitCount;
extern SF_UINT16 const sfHookExecutionIndex;
extern SF_UINT16 const sfHookApiVersion;
extern SF_UINT16 const sfLocationX;
extern SF_UINT16 const sfLocationY;
// 32-bit integers (common)
extern SF_UINT32 const sfNetworkID;
@@ -433,6 +435,8 @@ extern SF_UINT64 const sfReferenceCount;
extern SF_UINT64 const sfRewardAccumulator;
extern SF_UINT64 const sfAccountCount;
extern SF_UINT64 const sfAccountIndex;
extern SF_UINT64 const sfAssociationNode;
extern SF_UINT64 const sfCadastreCount;
// 128-bit
extern SF_UINT128 const sfEmailHash;
@@ -483,6 +487,7 @@ extern SF_UINT256 const sfURITokenID;
extern SF_UINT256 const sfGovernanceFlags;
extern SF_UINT256 const sfGovernanceMarks;
extern SF_UINT256 const sfEmittedTxnID;
extern SF_UINT256 const sfUniverse;
// currency amount (common)
extern SF_AMOUNT const sfAmount;
@@ -537,6 +542,8 @@ extern SF_VL const sfHookReturnString;
extern SF_VL const sfHookParameterName;
extern SF_VL const sfHookParameterValue;
extern SF_VL const sfBlob;
extern SF_VL const sfBroadcastURI;
extern SF_VL const sfDisplayURI;
// account
extern SF_ACCOUNT const sfAccount;
@@ -552,7 +559,7 @@ extern SF_ACCOUNT const sfEmitCallback;
// account (uncommon)
extern SF_ACCOUNT const sfHookAccount;
extern SF_ACCOUNT const sfNFTokenMinter;
extern SF_ACCOUNT const sfInform;
extern SF_ACCOUNT const sfAssociation;
// path set
extern SField const sfPaths;
@@ -563,7 +570,6 @@ extern SF_VECTOR256 const sfHashes;
extern SF_VECTOR256 const sfAmendments;
extern SF_VECTOR256 const sfNFTokenOffers;
extern SF_VECTOR256 const sfHookNamespaces;
extern SF_VECTOR256 const sfURITokenIDs;
// inner object
// OBJECT/1 is reserved for end of object
@@ -592,8 +598,6 @@ extern SField const sfHookGrant;
extern SField const sfActiveValidator;
extern SField const sfImportVLKey;
extern SField const sfHookEmission;
extern SField const sfMintURIToken;
extern SField const sfAmountEntry;
// array of objects (common)
// ARRAY/1 is reserved for end of array
@@ -621,7 +625,6 @@ extern SField const sfGenesisMints;
extern SField const sfActiveValidators;
extern SField const sfImportVLKeys;
extern SField const sfHookEmissions;
extern SField const sfAmounts;
//------------------------------------------------------------------------------

View File

@@ -86,7 +86,6 @@ constexpr std::uint32_t asfDisallowIncomingNFTokenOffer = 12;
constexpr std::uint32_t asfDisallowIncomingCheck = 13;
constexpr std::uint32_t asfDisallowIncomingPayChan = 14;
constexpr std::uint32_t asfDisallowIncomingTrustline = 15;
constexpr std::uint32_t asfDisallowIncomingRemit = 16;
// OfferCreate flags:
constexpr std::uint32_t tfPassive = 0x00010000;

View File

@@ -146,9 +146,14 @@ enum TxType : std::uint16_t
ttURITOKEN_CREATE_SELL_OFFER = 48,
ttURITOKEN_CANCEL_SELL_OFFER = 49,
/* A payment transactor that delivers only the exact amounts specified, creating accounts and TLs as needed
* that the sender pays for. */
ttREMIT = 95,
/* This transaction mints, burns or updates cadastral tiles. */
ttCADASTRE_MINT = 0x005D, // HookOn = 93
ttCADASTRE_BURN = 0x015D,
ttCADASTRE_CREATE_SELL_OFFER = 0x025D,
ttCADASTRE_CANCEL_SELL_OFFER = 0x035D,
ttCADASTRE_BUY = 0x045D,
ttCADASTRE_SET = 0x055D,
/** This transaction can only be used by the genesis account, which is controlled exclusively by
* rewards/governance hooks, to print new XRP to be delivered directly to an array of destinations,

View File

@@ -460,7 +460,7 @@ REGISTER_FEATURE(Import, Supported::yes, VoteBehavior::De
REGISTER_FEATURE(XahauGenesis, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FEATURE(HooksUpdate1, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fixURITokenV1, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(Remit, Supported::yes, VoteBehavior::DefaultNo);
// The following amendments are obsolete, but must remain supported
// because they could potentially get enabled.

View File

@@ -72,6 +72,7 @@ enum class LedgerNameSpace : std::uint16_t {
URI_TOKEN = 'U',
IMPORT_VLSEQ = 'I',
UNL_REPORT = 'R',
CADASTRE = 'K',
// No longer used or supported. Left here to reserve the space
// to avoid accidental reuse.
@@ -443,6 +444,15 @@ uritoken(AccountID const& issuer, Blob const& uri)
LedgerNameSpace::URI_TOKEN, issuer, Slice{uri.data(), uri.size()})};
}
Keylet
cadastre(uint256 const& universe, uint16_t locx, uint16_t locy)
{
return {
ltCADASTRE,
indexHash(
LedgerNameSpace::CADASTRE, universe, locx, locy)};
}
} // namespace keylet
} // namespace ripple

View File

@@ -141,21 +141,6 @@ InnerObjectFormats::InnerObjectFormats()
{sfPublicKey, soeREQUIRED},
{sfAccount, soeOPTIONAL},
});
add(sfAmountEntry.jsonName.c_str(),
sfAmountEntry.getCode(),
{
{sfAmount, soeREQUIRED},
{sfFlags, soeOPTIONAL},
});
add(sfMintURIToken.jsonName.c_str(),
sfMintURIToken.getCode(),
{
{sfURI, soeREQUIRED},
{sfDigest, soeOPTIONAL},
{sfFlags, soeOPTIONAL},
});
}
InnerObjectFormats const&

View File

@@ -363,6 +363,22 @@ LedgerFormats::LedgerFormats()
},
commonFields);
add(jss::Cadastre,
ltCADASTRE,
{
{sfOwner, soeREQUIRED},
{sfOwnerNode, soeREQUIRED},
{sfAssociation, soeOPTIONAL},
{sfAssociationNode, soeOPTIONAL},
{sfLocationX, soeREQUIRED},
{sfLocationY, soeREQUIRED},
{sfUniverse, soeREQUIRED},
{sfDisplayURI, soeOPTIONAL},
{sfBroadcastURI, soeOPTIONAL},
{sfCadastreCount, soeOPTIONAL}, // for 0x8000,0x8000 tile only
},
commonFields);
// clang-format on
}

View File

@@ -102,6 +102,8 @@ CONSTRUCT_TYPED_SFIELD(sfHookStateChangeCount, "HookStateChangeCount", UINT16,
CONSTRUCT_TYPED_SFIELD(sfHookEmitCount, "HookEmitCount", UINT16, 18);
CONSTRUCT_TYPED_SFIELD(sfHookExecutionIndex, "HookExecutionIndex", UINT16, 19);
CONSTRUCT_TYPED_SFIELD(sfHookApiVersion, "HookApiVersion", UINT16, 20);
CONSTRUCT_TYPED_SFIELD(sfLocationX, "LocationX", UINT16, 99);
CONSTRUCT_TYPED_SFIELD(sfLocationY, "LocationY", UINT16, 98);
// 32-bit integers (common)
CONSTRUCT_TYPED_SFIELD(sfNetworkID, "NetworkID", UINT32, 1);
@@ -183,6 +185,8 @@ CONSTRUCT_TYPED_SFIELD(sfEmitBurden, "EmitBurden", UINT64,
CONSTRUCT_TYPED_SFIELD(sfHookInstructionCount, "HookInstructionCount", UINT64, 17);
CONSTRUCT_TYPED_SFIELD(sfHookReturnCode, "HookReturnCode", UINT64, 18);
CONSTRUCT_TYPED_SFIELD(sfReferenceCount, "ReferenceCount", UINT64, 19);
CONSTRUCT_TYPED_SFIELD(sfCadastreCount, "CadastreCount", UINT64, 96);
CONSTRUCT_TYPED_SFIELD(sfAssociationNode, "AssociationNode", UINT64, 97);
CONSTRUCT_TYPED_SFIELD(sfAccountIndex, "AccountIndex", UINT64, 98);
CONSTRUCT_TYPED_SFIELD(sfAccountCount, "AccountCount", UINT64, 99);
CONSTRUCT_TYPED_SFIELD(sfRewardAccumulator, "RewardAccumulator", UINT64, 100);
@@ -236,6 +240,7 @@ CONSTRUCT_TYPED_SFIELD(sfURITokenID, "URITokenID", UINT256,
CONSTRUCT_TYPED_SFIELD(sfGovernanceFlags, "GovernanceFlags", UINT256, 99);
CONSTRUCT_TYPED_SFIELD(sfGovernanceMarks, "GovernanceMarks", UINT256, 98);
CONSTRUCT_TYPED_SFIELD(sfEmittedTxnID, "EmittedTxnID", UINT256, 97);
CONSTRUCT_TYPED_SFIELD(sfUniverse, "Universe", UINT256, 96);
// currency amount (common)
CONSTRUCT_TYPED_SFIELD(sfAmount, "Amount", AMOUNT, 1);
@@ -290,6 +295,8 @@ CONSTRUCT_TYPED_SFIELD(sfHookReturnString, "HookReturnString", VL,
CONSTRUCT_TYPED_SFIELD(sfHookParameterName, "HookParameterName", VL, 24);
CONSTRUCT_TYPED_SFIELD(sfHookParameterValue, "HookParameterValue", VL, 25);
CONSTRUCT_TYPED_SFIELD(sfBlob, "Blob", VL, 26);
CONSTRUCT_TYPED_SFIELD(sfBroadcastURI, "BroadcastURI", VL, 99);
CONSTRUCT_TYPED_SFIELD(sfDisplayURI, "DisplayURI", VL, 98);
// account
CONSTRUCT_TYPED_SFIELD(sfAccount, "Account", ACCOUNT, 1);
@@ -305,7 +312,7 @@ CONSTRUCT_TYPED_SFIELD(sfEmitCallback, "EmitCallback", ACCOUNT,
// account (uncommon)
CONSTRUCT_TYPED_SFIELD(sfHookAccount, "HookAccount", ACCOUNT, 16);
CONSTRUCT_TYPED_SFIELD(sfInform, "Inform", ACCOUNT, 99);
CONSTRUCT_TYPED_SFIELD(sfAssociation, "Association", ACCOUNT, 99);
// vector of 256-bit
CONSTRUCT_TYPED_SFIELD(sfIndexes, "Indexes", VECTOR256, 1, SField::sMD_Never);
@@ -313,7 +320,6 @@ CONSTRUCT_TYPED_SFIELD(sfHashes, "Hashes", VECTOR25
CONSTRUCT_TYPED_SFIELD(sfAmendments, "Amendments", VECTOR256, 3);
CONSTRUCT_TYPED_SFIELD(sfNFTokenOffers, "NFTokenOffers", VECTOR256, 4);
CONSTRUCT_TYPED_SFIELD(sfHookNamespaces, "HookNamespaces", VECTOR256, 5);
CONSTRUCT_TYPED_SFIELD(sfURITokenIDs, "URITokenIDs", VECTOR256, 99);
// path set
CONSTRUCT_UNTYPED_SFIELD(sfPaths, "Paths", PATHSET, 1);
@@ -348,8 +354,6 @@ CONSTRUCT_UNTYPED_SFIELD(sfGenesisMint, "GenesisMint", OBJECT,
CONSTRUCT_UNTYPED_SFIELD(sfActiveValidator, "ActiveValidator", OBJECT, 95);
CONSTRUCT_UNTYPED_SFIELD(sfImportVLKey, "ImportVLKey", OBJECT, 94);
CONSTRUCT_UNTYPED_SFIELD(sfHookEmission, "HookEmission", OBJECT, 93);
CONSTRUCT_UNTYPED_SFIELD(sfMintURIToken, "MintURIToken", OBJECT, 92);
CONSTRUCT_UNTYPED_SFIELD(sfAmountEntry, "AmountEntry", OBJECT, 91);
// array of objects
// ARRAY/1 is reserved for end of array
@@ -374,7 +378,6 @@ CONSTRUCT_UNTYPED_SFIELD(sfGenesisMints, "GenesisMints", ARRAY,
CONSTRUCT_UNTYPED_SFIELD(sfActiveValidators, "ActiveValidators", ARRAY, 95);
CONSTRUCT_UNTYPED_SFIELD(sfImportVLKeys, "ImportVLKeys", ARRAY, 94);
CONSTRUCT_UNTYPED_SFIELD(sfHookEmissions, "HookEmissions", ARRAY, 93);
CONSTRUCT_UNTYPED_SFIELD(sfAmounts, "Amounts", ARRAY, 92);
// clang-format on

View File

@@ -116,21 +116,6 @@ TxFormats::TxFormats()
},
commonFields);
add(jss::Remit,
ttREMIT,
{
{sfDestination, soeREQUIRED},
{sfAmounts, soeOPTIONAL},
{sfURITokenIDs, soeOPTIONAL},
{sfMintURIToken, soeOPTIONAL},
{sfInvoiceID, soeOPTIONAL},
{sfDestinationTag, soeOPTIONAL},
{sfTicketSequence, soeOPTIONAL},
{sfBlob, soeOPTIONAL},
{sfInform, soeOPTIONAL},
},
commonFields);
add(jss::EscrowCreate,
ttESCROW_CREATE,
{
@@ -456,6 +441,71 @@ TxFormats::TxFormats()
{sfTicketSequence, soeOPTIONAL},
},
commonFields);
add(jss::CadastreMint,
ttCADASTRE_MINT,
{
{sfDestination, soeOPTIONAL},
{sfAmount, soeOPTIONAL},
{sfAssociation, soeOPTIONAL},
{sfBroadcastURI, soeOPTIONAL},
{sfDisplayURI, soeOPTIONAL},
{sfLocationX, soeREQUIRED},
{sfLocationY, soeREQUIRED},
{sfUniverse, soeREQUIRED},
},
commonFields);
add(jss::CadastreBurn,
ttCADASTRE_BURN,
{
{sfLocationX, soeREQUIRED},
{sfLocationY, soeREQUIRED},
{sfUniverse, soeREQUIRED},
},
commonFields);
add(jss::CadastreCreateSellOffer,
ttCADASTRE_CREATE_SELL_OFFER,
{
{sfDestination, soeOPTIONAL},
{sfAmount, soeREQUIRED},
{sfLocationX, soeREQUIRED},
{sfLocationY, soeREQUIRED},
{sfUniverse, soeREQUIRED},
},
commonFields);
add(jss::CadastreCancelSellOffer,
ttCADASTRE_CANCEL_SELL_OFFER,
{
{sfLocationX, soeREQUIRED},
{sfLocationY, soeREQUIRED},
{sfUniverse, soeREQUIRED},
},
commonFields);
add(jss::CadastreBuy,
ttCADASTRE_BUY,
{
{sfAmount, soeREQUIRED},
{sfLocationX, soeREQUIRED},
{sfLocationY, soeREQUIRED},
{sfUniverse, soeREQUIRED},
},
commonFields);
add(jss::CadastreSet,
ttCADASTRE_SET,
{
{sfAssociation, soeOPTIONAL},
{sfBroadcastURI, soeOPTIONAL},
{sfDisplayURI, soeOPTIONAL},
{sfLocationX, soeREQUIRED},
{sfLocationY, soeREQUIRED},
{sfUniverse, soeREQUIRED},
},
commonFields);
}
TxFormats const&

View File

@@ -51,6 +51,13 @@ JSS(Amendments); // ledger type.
JSS(Amount); // in: TransactionSign; field.
JSS(Authorize); // field
JSS(Blob);
JSS(Cadastre); // ledger type
JSS(CadastreMint); // txn type
JSS(CadastreBurn); // txn type
JSS(CadastreCreateSellOffer); // txn type
JSS(CadastreCancelSellOffer); // txn type
JSS(CadastreBuy); // txn type
JSS(CadastreSet); // txn type
JSS(Check); // ledger type.
JSS(CheckCancel); // transaction type.
JSS(CheckCash); // transaction type.
@@ -117,7 +124,6 @@ JSS(Payment); // transaction type.
JSS(PaymentChannelClaim); // transaction type.
JSS(PaymentChannelCreate); // transaction type.
JSS(PaymentChannelFund); // transaction type.
JSS(Remit); // transaction type.
JSS(RippleState); // ledger type.
JSS(SLE_hit_rate); // out: GetCounts.
JSS(SetFee); // transaction type.

View File

@@ -5549,73 +5549,6 @@ class Import_test : public beast::unit_test::suite
}
}
// std::unique_ptr<Config>
// network::makeGenesisConfig(
// FeatureBitset features,
// uint32_t networkID,
// std::string fee,
// std::string a_res,
// std::string o_res,
// uint32_t ledgerID)
// {
// using namespace jtx;
// // IMPORT VL KEY
// std::vector<std::string> const keys = {
// "ED74D4036C6591A4BDF9C54CEFA39B996A"
// "5DCE5F86D11FDA1874481CE9D5A1CDC1"};
// Json::Value jsonValue;
// Json::Reader reader;
// reader.parse(ImportTCHalving::base_genesis, jsonValue);
// foreachFeature(features, [&](uint256 const& feature) {
// std::string featureName = featureToName(feature);
// std::optional<uint256> featureHash =
// getRegisteredFeature(featureName);
// if (featureHash.has_value())
// {
// std::string hashString = to_string(featureHash.value());
// jsonValue["ledger"]["accountState"][1]["Amendments"].append(
// hashString);
// }
// });
// jsonValue["ledger_current_index"] = ledgerID;
// jsonValue["ledger"]["ledger_index"] = to_string(ledgerID);
// jsonValue["ledger"]["seqNum"] = to_string(ledgerID);
// return envconfig([&](std::unique_ptr<Config> cfg) {
// cfg->NETWORK_ID = networkID;
// cfg->START_LEDGER = jsonValue.toStyledString();
// cfg->START_UP = Config::LOAD_JSON;
// Section config;
// config.append(
// {"reference_fee = " + fee,
// "account_reserve = " + a_res,
// "owner_reserve = " + o_res});
// auto setup = setup_FeeVote(config);
// cfg->FEES = setup;
// for (auto const& strPk : keys)
// {
// auto pkHex = strUnHex(strPk);
// if (!pkHex)
// Throw<std::runtime_error>(
// "Import VL Key '" + strPk + "' was not valid hex.");
// auto const pkType = publicKeyType(makeSlice(*pkHex));
// if (!pkType)
// Throw<std::runtime_error>(
// "Import VL Key '" + strPk +
// "' was not a valid key type.");
// cfg->IMPORT_VL_KEYS.emplace(strPk, makeSlice(*pkHex));
// }
// return cfg;
// });
// }
void
testHalving(FeatureBitset features)
{

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -42,52 +42,6 @@ namespace test {
* are put in their existing unit test files.
*/
/**
* Test the size of the negative UNL in a ledger,
* also test if the ledger has ToDisalbe and/or ToReEnable
*
* @param l the ledger
* @param size the expected negative UNL size
* @param hasToDisable if expect ToDisable in ledger
* @param hasToReEnable if expect ToDisable in ledger
* @return true if meet all three expectation
*/
bool inline negUnlSizeTest(
std::shared_ptr<ripple::Ledger const> const& l,
size_t size,
bool hasToDisable,
bool hasToReEnable)
{
bool sameSize = l->negativeUNL().size() == size;
bool sameToDisable =
(l->validatorToDisable() != std::nullopt) == hasToDisable;
bool sameToReEnable =
(l->validatorToReEnable() != std::nullopt) == hasToReEnable;
return sameSize && sameToDisable && sameToReEnable;
}
/**
* Try to apply a ttUNL_MODIFY Tx, and test the apply result
*
* @param env the test environment
* @param view the OpenView of the ledger
* @param tx the ttUNL_MODIFY Tx
* @param pass if the Tx should be applied successfully
* @return true if meet the expectation of apply result
*/
bool inline applyAndTestResult(
jtx::Env& env,
ripple::OpenView& view,
ripple::STTx const& tx,
bool pass)
{
auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
if (pass)
return res.first == tesSUCCESS;
else
return res.first == tefFAILURE || res.first == temDISABLED;
}
/**
* Verify the content of negative UNL entries (public key and ledger sequence)
* of a ledger
@@ -102,15 +56,6 @@ VerifyPubKeyAndSeq(
std::shared_ptr<Ledger const> const& l,
hash_map<PublicKey, std::uint32_t> nUnlLedgerSeq);
/**
* Count the number of Tx in a TxSet
*
* @param txSet the TxSet
* @return the number of Tx
*/
std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet);
/**
* Create fake public keys
*
@@ -120,17 +65,6 @@ countTx(std::shared_ptr<SHAMap> const& txSet);
std::vector<PublicKey>
createPublicKeys(std::size_t n);
/**
* Create ttUNL_MODIFY Tx
*
* @param disabling disabling or re-enabling a validator
* @param seq current ledger seq
* @param txKey the public key of the validator
* @return the ttUNL_MODIFY Tx
*/
STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey);
class NegativeUNL_test : public beast::unit_test::suite
{
/**
@@ -262,14 +196,16 @@ class NegativeUNL_test : public beast::unit_test::suite
l = std::make_shared<Ledger>(
*l, env.app().timeKeeper().closeTime());
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]);
auto txReEnable_1 = createTx(false, l->seq(), publicKeys[1]);
auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
auto txReEnable_1 = unl::createTx(false, l->seq(), publicKeys[1]);
OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, false));
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_1, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txDisable_0, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_1, false));
accum.apply(*l);
BEAST_EXPECT(negUnlSizeTest(l, 0, false, false));
BEAST_EXPECT(unl::negUnlSizeTest(l, 0, false, false));
}
{
@@ -283,18 +219,21 @@ class NegativeUNL_test : public beast::unit_test::suite
BEAST_EXPECT(l->isFlagLedger());
l->updateNegativeUNL();
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]);
auto txDisable_1 = createTx(true, l->seq(), publicKeys[1]);
auto txReEnable_2 = createTx(false, l->seq(), publicKeys[2]);
auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
auto txDisable_1 = unl::createTx(true, l->seq(), publicKeys[1]);
auto txReEnable_2 = unl::createTx(false, l->seq(), publicKeys[2]);
// can apply 1 and only 1 ToDisable Tx,
// cannot apply ToReEnable Tx, since negative UNL is empty
OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, true));
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_1, false));
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_2, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txDisable_0, true));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txDisable_1, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_2, false));
accum.apply(*l);
auto good_size = negUnlSizeTest(l, 0, true, false);
auto good_size = unl::negUnlSizeTest(l, 0, true, false);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -309,7 +248,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(3) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i)
{
auto good_size = negUnlSizeTest(l, 0, true, false);
auto good_size = unl::negUnlSizeTest(l, 0, true, false);
BEAST_EXPECT(good_size);
if (good_size)
BEAST_EXPECT(l->validatorToDisable() == publicKeys[0]);
@@ -321,7 +260,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(4) next flag ledger
// test if the ledger updated correctly
auto good_size = negUnlSizeTest(l, 1, false, false);
auto good_size = unl::negUnlSizeTest(l, 1, false, false);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -329,20 +268,25 @@ class NegativeUNL_test : public beast::unit_test::suite
nUnlLedgerSeq.emplace(publicKeys[0], l->seq());
}
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]);
auto txDisable_1 = createTx(true, l->seq(), publicKeys[1]);
auto txReEnable_0 = createTx(false, l->seq(), publicKeys[0]);
auto txReEnable_1 = createTx(false, l->seq(), publicKeys[1]);
auto txReEnable_2 = createTx(false, l->seq(), publicKeys[2]);
auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
auto txDisable_1 = unl::createTx(true, l->seq(), publicKeys[1]);
auto txReEnable_0 = unl::createTx(false, l->seq(), publicKeys[0]);
auto txReEnable_1 = unl::createTx(false, l->seq(), publicKeys[1]);
auto txReEnable_2 = unl::createTx(false, l->seq(), publicKeys[2]);
OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, false));
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_1, true));
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_1, false));
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_2, false));
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_0, true));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txDisable_0, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txDisable_1, true));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_1, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_2, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_0, true));
accum.apply(*l);
good_size = negUnlSizeTest(l, 1, true, true);
good_size = unl::negUnlSizeTest(l, 1, true, true);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -358,7 +302,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(5) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i)
{
auto good_size = negUnlSizeTest(l, 1, true, true);
auto good_size = unl::negUnlSizeTest(l, 1, true, true);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -374,19 +318,20 @@ class NegativeUNL_test : public beast::unit_test::suite
//(6) next flag ledger
// test if the ledger updated correctly
auto good_size = negUnlSizeTest(l, 1, false, false);
auto good_size = unl::negUnlSizeTest(l, 1, false, false);
BEAST_EXPECT(good_size);
if (good_size)
{
BEAST_EXPECT(l->negativeUNL().count(publicKeys[1]));
}
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]);
auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, true));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txDisable_0, true));
accum.apply(*l);
good_size = negUnlSizeTest(l, 1, true, false);
good_size = unl::negUnlSizeTest(l, 1, true, false);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -402,7 +347,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(7) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i)
{
auto good_size = negUnlSizeTest(l, 1, true, false);
auto good_size = unl::negUnlSizeTest(l, 1, true, false);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -417,7 +362,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(8) next flag ledger
// test if the ledger updated correctly
auto good_size = negUnlSizeTest(l, 2, false, false);
auto good_size = unl::negUnlSizeTest(l, 2, false, false);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -427,16 +372,19 @@ class NegativeUNL_test : public beast::unit_test::suite
BEAST_EXPECT(VerifyPubKeyAndSeq(l, nUnlLedgerSeq));
}
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]);
auto txReEnable_0 = createTx(false, l->seq(), publicKeys[0]);
auto txReEnable_1 = createTx(false, l->seq(), publicKeys[1]);
auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
auto txReEnable_0 = unl::createTx(false, l->seq(), publicKeys[0]);
auto txReEnable_1 = unl::createTx(false, l->seq(), publicKeys[1]);
OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_0, true));
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_1, false));
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_0, true));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_1, false));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txDisable_0, false));
accum.apply(*l);
good_size = negUnlSizeTest(l, 2, false, true);
good_size = unl::negUnlSizeTest(l, 2, false, true);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -451,7 +399,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(9) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i)
{
auto good_size = negUnlSizeTest(l, 2, false, true);
auto good_size = unl::negUnlSizeTest(l, 2, false, true);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -467,7 +415,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(10) next flag ledger
// test if the ledger updated correctly
auto good_size = negUnlSizeTest(l, 1, false, false);
auto good_size = unl::negUnlSizeTest(l, 1, false, false);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -476,12 +424,13 @@ class NegativeUNL_test : public beast::unit_test::suite
BEAST_EXPECT(VerifyPubKeyAndSeq(l, nUnlLedgerSeq));
}
auto txReEnable_1 = createTx(false, l->seq(), publicKeys[1]);
auto txReEnable_1 = unl::createTx(false, l->seq(), publicKeys[1]);
OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txReEnable_1, true));
BEAST_EXPECT(
unl::applyAndTestResult(env, accum, txReEnable_1, true));
accum.apply(*l);
good_size = negUnlSizeTest(l, 1, false, true);
good_size = unl::negUnlSizeTest(l, 1, false, true);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -495,7 +444,7 @@ class NegativeUNL_test : public beast::unit_test::suite
//(11) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i)
{
auto good_size = negUnlSizeTest(l, 1, false, true);
auto good_size = unl::negUnlSizeTest(l, 1, false, true);
BEAST_EXPECT(good_size);
if (good_size)
{
@@ -509,14 +458,14 @@ class NegativeUNL_test : public beast::unit_test::suite
l->updateNegativeUNL();
//(12) next flag ledger
BEAST_EXPECT(negUnlSizeTest(l, 0, false, false));
BEAST_EXPECT(unl::negUnlSizeTest(l, 0, false, false));
}
{
//(13) ledgers before the next flag ledger
for (auto i = 0; i < 256; ++i)
{
BEAST_EXPECT(negUnlSizeTest(l, 0, false, false));
BEAST_EXPECT(unl::negUnlSizeTest(l, 0, false, false));
l = std::make_shared<Ledger>(
*l, env.app().timeKeeper().closeTime());
}
@@ -524,7 +473,7 @@ class NegativeUNL_test : public beast::unit_test::suite
l->updateNegativeUNL();
//(14) next flag ledger
BEAST_EXPECT(negUnlSizeTest(l, 0, false, false));
BEAST_EXPECT(unl::negUnlSizeTest(l, 0, false, false));
}
}
@@ -559,11 +508,11 @@ class NegativeUNLNoAmendment_test : public beast::unit_test::suite
*l, env.app().timeKeeper().closeTime());
}
BEAST_EXPECT(l->seq() == 256);
auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]);
auto txDisable_0 = unl::createTx(true, l->seq(), publicKeys[0]);
OpenView accum(&*l);
BEAST_EXPECT(applyAndTestResult(env, accum, txDisable_0, false));
BEAST_EXPECT(unl::applyAndTestResult(env, accum, txDisable_0, false));
accum.apply(*l);
BEAST_EXPECT(negUnlSizeTest(l, 0, false, false));
BEAST_EXPECT(unl::negUnlSizeTest(l, 0, false, false));
}
void
@@ -651,8 +600,8 @@ struct NetworkHistory
OpenView accum(&*l);
if (l->negativeUNL().size() < param.negUNLSize)
{
auto tx = createTx(true, l->seq(), UNLKeys[nidx]);
if (!applyAndTestResult(env, accum, tx, true))
auto tx = unl::createTx(true, l->seq(), UNLKeys[nidx]);
if (!unl::applyAndTestResult(env, accum, tx, true))
break;
++nidx;
}
@@ -660,15 +609,15 @@ struct NetworkHistory
{
if (param.hasToDisable)
{
auto tx = createTx(true, l->seq(), UNLKeys[nidx]);
if (!applyAndTestResult(env, accum, tx, true))
auto tx = unl::createTx(true, l->seq(), UNLKeys[nidx]);
if (!unl::applyAndTestResult(env, accum, tx, true))
break;
++nidx;
}
if (param.hasToReEnable)
{
auto tx = createTx(false, l->seq(), UNLKeys[0]);
if (!applyAndTestResult(env, accum, tx, true))
auto tx = unl::createTx(false, l->seq(), UNLKeys[0]);
if (!unl::applyAndTestResult(env, accum, tx, true))
break;
}
}
@@ -676,7 +625,7 @@ struct NetworkHistory
}
l->updateSkipList();
}
return negUnlSizeTest(
return unl::negUnlSizeTest(
l, param.negUNLSize, param.hasToDisable, param.hasToReEnable);
}
@@ -776,7 +725,7 @@ voteAndCheck(
vote.doVoting(
history.lastLedger(), history.UNLKeySet, history.validations, txSet);
return countTx(txSet) >= expect;
return unl::countTx(txSet) >= expect;
}
/**
@@ -799,11 +748,11 @@ class NegativeUNLVoteInternal_test : public beast::unit_test::suite
PublicKey toDisableKey;
PublicKey toReEnableKey;
LedgerIndex seq(1234);
BEAST_EXPECT(countTx(txSet) == 0);
BEAST_EXPECT(unl::countTx(txSet) == 0);
vote.addTx(seq, toDisableKey, NegativeUNLVote::ToDisable, txSet);
BEAST_EXPECT(countTx(txSet) == 1);
BEAST_EXPECT(unl::countTx(txSet) == 1);
vote.addTx(seq, toReEnableKey, NegativeUNLVote::ToReEnable, txSet);
BEAST_EXPECT(countTx(txSet) == 2);
BEAST_EXPECT(unl::countTx(txSet) == 2);
// content of a tx is implicitly tested after applied to a ledger
// in later test cases
}
@@ -1967,34 +1916,6 @@ VerifyPubKeyAndSeq(
return nUnlLedgerSeq.size() == 0;
}
std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet)
{
/*uint64_t counter = 0;
if (txSet)
for (auto const& item : *txSet)
{
SerialIter sit(item.slice());
auto tx = std::make_shared<STTx
const>(SerialIter{sit.getSlice(sit.getVLDataLength())});
if (tx->getFieldU16(sfTransactionType) == ttUNL_MODIFY)
counter++;
}
*/
std::size_t count = 0;
for (auto i = txSet->begin(); i != txSet->end(); ++i)
{
// RH TODO: why does the above parse??
auto raw = i->slice();
if (raw[0] == 0x12U && raw[1] == 0 && raw[2] == 0x66U)
count++;
}
return count;
};
std::vector<PublicKey>
createPublicKeys(std::size_t n)
{
@@ -2011,16 +1932,5 @@ createPublicKeys(std::size_t n)
return keys;
}
STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey)
{
auto fill = [&](auto& obj) {
obj.setFieldU8(sfUNLModifyDisabling, disabling ? 1 : 0);
obj.setFieldU32(sfLedgerSequence, seq);
obj.setFieldVL(sfUNLModifyValidator, txKey);
};
return STTx(ttUNL_MODIFY, fill);
}
} // namespace test
} // namespace ripple

View File

@@ -52,66 +52,20 @@ namespace test {
// */
// /**
// * Test the size of the negative UNL in a ledger,
// * also test if the ledger has ToDisalbe and/or ToReEnable
// * Try to apply a ttUNL_MODIFY Tx, and test the apply result
// *
// * @param l the ledger
// * @param size the expected negative UNL size
// * @param hasToDisable if expect ToDisable in ledger
// * @param hasToReEnable if expect ToDisable in ledger
// * @return true if meet all three expectation
// * @param env the test environment
// * @param view the OpenView of the ledger
// * @param tx the ttUNL_MODIFY Tx
// * @param pass if the Tx should be applied successfully
// * @return true if meet the expectation of apply result
// */
/*
bool
inline
negUnlSizeTest(
std::shared_ptr<ripple::Ledger const> const& l,
size_t size,
bool hasToDisable,
bool hasToReEnable)
{
bool sameSize = l->negativeUNL().size() == size;
bool sameToDisable =
(l->validatorToDisable() != std::nullopt) == hasToDisable;
bool sameToReEnable =
(l->validatorToReEnable() != std::nullopt) == hasToReEnable;
return sameSize && sameToDisable && sameToReEnable;
}
*/
/**
* Try to apply a ttUNL_MODIFY Tx, and test the apply result
*
* @param env the test environment
* @param view the OpenView of the ledger
* @param tx the ttUNL_MODIFY Tx
* @param pass if the Tx should be applied successfully
* @return true if meet the expectation of apply result
*/
/*
bool
inline
applyAndTestResult(jtx::Env& env, ripple::OpenView& view, ripple::STTx const&
tx, bool pass)
{
auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
if (pass)
return res.first == tesSUCCESS;
else
return res.first == tefFAILURE || res.first == temDISABLED;
}
*/
inline bool
applyAndTestUNLRResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass)
{
auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
if (pass)
return res.first == tesSUCCESS;
else
return res.first == tefFAILURE || res.first == temDISABLED ||
res.first == temMALFORMED ||
res.first == telIMPORT_VL_KEY_NOT_RECOGNISED;
}
applyAndTestUNLRResult(
jtx::Env& env,
OpenView& view,
STTx const& tx,
bool pass);
/**
* Verify the content of UNL Report entries (public key and ledger sequence)
@@ -139,9 +93,6 @@ countUNLRTx(std::shared_ptr<SHAMap> const& txSet);
std::vector<std::string> const keys = {
"ED74D4036C6591A4BDF9C54CEFA39B996A5DCE5F86D11FDA1874481CE9D5A1CDC1"};
std::unique_ptr<Config>
makeNetworkVLConfig(uint32_t networkID, std::vector<std::string> keys);
/**
* Verify if the UNL report exists
*
@@ -194,38 +145,6 @@ createUNLRTx(
PublicKey const& importKey,
PublicKey const& valKey);
/**
* Count the number of Tx in a TxSet
*
* @param txSet the TxSet
* @return the number of Tx
*/
inline std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet);
/**
* Create ttUNL_MODIFY Tx
*
* @param disabling disabling or re-enabling a validator
* @param seq current ledger seq
* @param txKey the public key of the validator
* @return the ttUNL_MODIFY Tx
*/
inline STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey);
/**
* Try to apply a ttUNL_MODIFY Tx, and test the apply result
*
* @param env the test environment
* @param view the OpenView of the ledger
* @param tx the ttUNL_MODIFY Tx
* @param pass if the Tx should be applied successfully
* @return true if meet the expectation of apply result
*/
inline bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass);
class UNLReport_test : public beast::unit_test::suite
{
// Import VL Keys
@@ -374,7 +293,10 @@ class UNLReport_test : public beast::unit_test::suite
// telIMPORT_VL_KEY_NOT_RECOGNISED
{
test::jtx::Env env{
*this, makeNetworkVLConfig(21337, keys), features, nullptr};
*this,
jtx::network::makeNetworkVLConfig(21337, keys),
features,
nullptr};
auto l = std::make_shared<Ledger>(
create_genesis,
@@ -403,7 +325,10 @@ class UNLReport_test : public beast::unit_test::suite
// SUCCESS
{
test::jtx::Env env{
*this, makeNetworkVLConfig(21337, keys), features, nullptr};
*this,
jtx::network::makeNetworkVLConfig(21337, keys),
features,
nullptr};
auto l = std::make_shared<Ledger>(
create_genesis,
@@ -442,7 +367,10 @@ class UNLReport_test : public beast::unit_test::suite
using namespace jtx;
test::jtx::Env env{
*this, makeNetworkVLConfig(21337, keys), features, nullptr};
*this,
jtx::network::makeNetworkVLConfig(21337, keys),
features,
nullptr};
std::vector<PublicKey> ivlKeys;
for (auto const& strPk : _ivlKeys)
@@ -703,7 +631,8 @@ struct URNetworkHistory
URNetworkHistory(beast::unit_test::suite& suite, Parameter const& p)
: env(suite,
p.withVL ? makeNetworkVLConfig(21337, keys) : jtx::envconfig(),
p.withVL ? jtx::network::makeNetworkVLConfig(21337, keys)
: jtx::envconfig(),
jtx::supported_amendments() | featureNegativeUNL)
, param(p)
, validations(env.app().getValidations())
@@ -757,8 +686,8 @@ struct URNetworkHistory
OpenView accum(&*l);
if (l->negativeUNL().size() < param.negUNLSize)
{
auto tx = createTx(true, l->seq(), UNLKeys[nidx]);
if (!applyAndTestResult(env, accum, tx, true))
auto tx = unl::createTx(true, l->seq(), UNLKeys[nidx]);
if (!unl::applyAndTestResult(env, accum, tx, true))
break;
++nidx;
}
@@ -766,15 +695,15 @@ struct URNetworkHistory
{
if (param.hasToDisable)
{
auto tx = createTx(true, l->seq(), UNLKeys[nidx]);
if (!applyAndTestResult(env, accum, tx, true))
auto tx = unl::createTx(true, l->seq(), UNLKeys[nidx]);
if (!unl::applyAndTestResult(env, accum, tx, true))
break;
++nidx;
}
if (param.hasToReEnable)
{
auto tx = createTx(false, l->seq(), UNLKeys[0]);
if (!applyAndTestResult(env, accum, tx, true))
auto tx = unl::createTx(false, l->seq(), UNLKeys[0]);
if (!unl::applyAndTestResult(env, accum, tx, true))
break;
}
}
@@ -782,7 +711,7 @@ struct URNetworkHistory
}
l->updateSkipList();
}
return negUnlSizeTest(
return unl::negUnlSizeTest(
l, param.negUNLSize, param.hasToDisable, param.hasToReEnable);
}
@@ -883,7 +812,8 @@ voteAndCheckUNLR(
vote.doVoting(
history.lastLedger(), history.UNLKeySet, history.validations, txSet);
return countUNLRTx(txSet) == expectReport && countTx(txSet) >= expectModify;
return countUNLRTx(txSet) == expectReport &&
unl::countTx(txSet) >= expectModify;
}
/*
@@ -1264,6 +1194,18 @@ BEAST_DEFINE_TESTSUITE(UNLReportVoteNewValidator, consensus, ripple);
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
bool
applyAndTestUNLRResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass)
{
auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
if (pass)
return res.first == tesSUCCESS;
else
return res.first == tefFAILURE || res.first == temDISABLED ||
res.first == temMALFORMED ||
res.first == telIMPORT_VL_KEY_NOT_RECOGNISED;
}
bool
VerifyUNLRPubKeyAndSeq(
std::shared_ptr<Ledger const> const& l,
@@ -1314,38 +1256,6 @@ countUNLRTx(std::shared_ptr<SHAMap> const& txSet)
return count;
};
std::unique_ptr<Config>
makeNetworkVLConfig(uint32_t networkID, std::vector<std::string> keys)
{
using namespace jtx;
return envconfig([&](std::unique_ptr<Config> cfg) {
cfg->NETWORK_ID = networkID;
Section config;
config.append(
{"reference_fee = 10",
"account_reserve = 1000000",
"owner_reserve = 200000"});
auto setup = setup_FeeVote(config);
cfg->FEES = setup;
for (auto const& strPk : keys)
{
auto pkHex = strUnHex(strPk);
if (!pkHex)
Throw<std::runtime_error>(
"Import VL Key '" + strPk + "' was not valid hex.");
auto const pkType = publicKeyType(makeSlice(*pkHex));
if (!pkType)
Throw<std::runtime_error>(
"Import VL Key '" + strPk + "' was not a valid key type.");
cfg->IMPORT_VL_KEYS.emplace(strPk, makeSlice(*pkHex));
}
return cfg;
});
}
bool
hasUNLReport(jtx::Env const& env)
{
@@ -1413,45 +1323,5 @@ createUNLRTx(
return STTx(ttUNL_REPORT, fill);
}
/*
inline STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey)
{
auto fill = [&](auto& obj) {
obj.setFieldU8(sfUNLModifyDisabling, disabling ? 1 : 0);
obj.setFieldU32(sfLedgerSequence, seq);
obj.setFieldVL(sfUNLModifyValidator, txKey);
};
return STTx(ttUNL_MODIFY, fill);
}
*/
/*
inline std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet)
{
std::size_t count = 0;
for (auto i = txSet->begin(); i != txSet->end(); ++i)
{
auto raw = i->slice();
if (raw[0] == 0x12U && raw[1] == 0 && raw[2] == 0x66U)
count++;
}
return count;
};
*/
/*
inline bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass)
{
auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
if (pass)
return res.first == tesSUCCESS;
else
return res.first == tefFAILURE || res.first == temDISABLED;
}
*/
} // namespace test
} // namespace ripple
} // namespace ripple

View File

@@ -60,7 +60,6 @@
#include <test/jtx/require.h>
#include <test/jtx/requires.h>
#include <test/jtx/reward.h>
#include <test/jtx/remit.h>
#include <test/jtx/sendmax.h>
#include <test/jtx/seq.h>
#include <test/jtx/sig.h>
@@ -71,6 +70,7 @@
#include <test/jtx/token.h>
#include <test/jtx/trust.h>
#include <test/jtx/txflags.h>
#include <test/jtx/unl.h>
#include <test/jtx/uritoken.h>
#include <test/jtx/utility.h>

View File

@@ -18,6 +18,7 @@
//==============================================================================
#include <test/jtx/Env.h>
#include <ripple/protocol/jss.h>
#include <test/jtx/acctdelete.h>
namespace ripple {

View File

@@ -1,84 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 XRPL Labs
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/protocol/jss.h>
#include <test/jtx/remit.h>
namespace ripple {
namespace test {
namespace jtx {
namespace remit {
Json::Value
remit(jtx::Account const& account, jtx::Account const& dest)
{
using namespace jtx;
Json::Value jv;
jv[jss::TransactionType] = jss::Remit;
jv[jss::Account] = account.human();
jv[jss::Destination] = dest.human();
return jv;
}
void
amts::operator()(Env& env, JTx& jt) const
{
auto& ja = jt.jv[sfAmounts.getJsonName()];
for (std::size_t i = 0; i < amts_.size(); ++i)
{
ja[i][sfAmountEntry.jsonName] = Json::Value{};
ja[i][sfAmountEntry.jsonName][jss::Amount] =
amts_[i].getJson(JsonOptions::none);
}
jt.jv[sfAmounts.jsonName] = ja;
}
void
blob::operator()(Env& env, JTx& jt) const
{
jt.jv[sfBlob.jsonName] = blob_;
}
void
inform::operator()(Env& env, JTx& jt) const
{
jt.jv[sfInform.jsonName] = inform_.human();
}
void
token_ids::operator()(Env& env, JTx& jt) const
{
for (std::size_t i = 0; i < token_ids_.size(); ++i)
{
jt.jv[sfURITokenIDs.jsonName] = Json::arrayValue;
jt.jv[sfURITokenIDs.jsonName][i] = token_ids_[i];
}
}
void
uri::operator()(Env& env, JTx& jt) const
{
jt.jv[sfMintURIToken.jsonName] = Json::Value{};
jt.jv[sfMintURIToken.jsonName][sfURI.jsonName] = strHex(uri_);;
}
} // namespace remit
} // namespace jtx
} // namespace test
} // namespace ripple

95
src/test/jtx/impl/unl.cpp Normal file
View File

@@ -0,0 +1,95 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 XRPL Labs
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/app/tx/apply.h>
#include <ripple/protocol/jss.h>
#include <test/jtx/unl.h>
namespace ripple {
namespace test {
namespace unl {
bool
negUnlSizeTest(
std::shared_ptr<Ledger const> const& l,
size_t size,
bool hasToDisable,
bool hasToReEnable)
{
bool sameSize = l->negativeUNL().size() == size;
bool sameToDisable =
(l->validatorToDisable() != std::nullopt) == hasToDisable;
bool sameToReEnable =
(l->validatorToReEnable() != std::nullopt) == hasToReEnable;
return sameSize && sameToDisable && sameToReEnable;
}
bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass)
{
auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal);
if (pass)
return res.first == tesSUCCESS;
else
return res.first == tefFAILURE || res.first == temDISABLED;
}
std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet)
{
/*uint64_t counter = 0;
if (txSet)
for (auto const& item : *txSet)
{
SerialIter sit(item.slice());
auto tx = std::make_shared<STTx
const>(SerialIter{sit.getSlice(sit.getVLDataLength())});
if (tx->getFieldU16(sfTransactionType) == ttUNL_MODIFY)
counter++;
}
*/
std::size_t count = 0;
for (auto i = txSet->begin(); i != txSet->end(); ++i)
{
// RH TODO: why does the above parse??
auto raw = i->slice();
if (raw[0] == 0x12U && raw[1] == 0 && raw[2] == 0x66U)
count++;
}
return count;
};
STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey)
{
auto fill = [&](auto& obj) {
obj.setFieldU8(sfUNLModifyDisabling, disabling ? 1 : 0);
obj.setFieldU32(sfLedgerSequence, seq);
obj.setFieldVL(sfUNLModifyValidator, txKey);
};
return STTx(ttUNL_MODIFY, fill);
}
} // namespace unl
} // namespace test
} // namespace ripple

View File

@@ -1,118 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 XRPL Labs
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_TEST_JTX_REMIT_H_INCLUDED
#define RIPPLE_TEST_JTX_REMIT_H_INCLUDED
#include <ripple/protocol/STAmount.h>
#include <test/jtx/Account.h>
#include <test/jtx/Env.h>
namespace ripple {
namespace test {
namespace jtx {
namespace remit {
Json::Value
remit(jtx::Account const& account, jtx::Account const& dest);
/** Sets the optional Amount on a JTx. */
class amts
{
private:
std::vector<STAmount> amts_;
public:
explicit amts(std::vector<STAmount> const& amts) : amts_(amts)
{
}
void
operator()(Env&, JTx& jtx) const;
};
/** Set the optional "Blob" on a JTx */
class blob
{
private:
std::string blob_;
public:
explicit blob(std::string const& blob) : blob_(blob)
{
}
void
operator()(Env&, JTx& jtx) const;
};
/** Sets the optional "Inform" on a JTx. */
class inform
{
private:
jtx::Account inform_;
public:
explicit inform(jtx::Account const& inform) : inform_(inform)
{
}
void
operator()(Env&, JTx& jtx) const;
};
/** Sets the optional "URITokenIDs" on a JTx. */
class token_ids
{
private:
std::vector<std::string> token_ids_;
public:
explicit token_ids(std::vector<std::string> const& token_ids) : token_ids_(token_ids)
{
}
void
operator()(Env&, JTx& jtx) const;
};
/** Set the optional "sfMintURIToken" on a JTx */
class uri
{
private:
std::string uri_;
public:
explicit uri(std::string const& uri) : uri_(uri)
{
}
void
operator()(Env&, JTx& jtx) const;
};
} // namespace remit
} // namespace jtx
} // namespace test
} // namespace ripple
#endif // RIPPLE_TEST_JTX_REMIT_H_INCLUDED

86
src/test/jtx/unl.h Normal file
View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 XRPL Labs
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_TEST_JTX_UNL_H_INCLUDED
#define RIPPLE_TEST_JTX_UNL_H_INCLUDED
#include <ripple/protocol/STAmount.h>
#include <test/jtx/Account.h>
#include <test/jtx/Env.h>
namespace ripple {
namespace test {
namespace unl {
/**
* Test the size of the negative UNL in a ledger,
* also test if the ledger has ToDisalbe and/or ToReEnable
*
* @param l the ledger
* @param size the expected negative UNL size
* @param hasToDisable if expect ToDisable in ledger
* @param hasToReEnable if expect ToDisable in ledger
* @return true if meet all three expectation
*/
bool
negUnlSizeTest(
std::shared_ptr<Ledger const> const& l,
size_t size,
bool hasToDisable,
bool hasToReEnable);
/**
* Try to apply a ttUNL_MODIFY Tx, and test the apply result
*
* @param env the test environment
* @param view the OpenView of the ledger
* @param tx the ttUNL_MODIFY Tx
* @param pass if the Tx should be applied successfully
* @return true if meet the expectation of apply result
*/
bool
applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass);
/**
* Count the number of Tx in a TxSet
*
* @param txSet the TxSet
* @return the number of Tx
*/
std::size_t
countTx(std::shared_ptr<SHAMap> const& txSet);
/**
* Create ttUNL_MODIFY Tx
*
* @param disabling disabling or re-enabling a validator
* @param seq current ledger seq
* @param txKey the public key of the validator
* @return the ttUNL_MODIFY Tx
*/
STTx
createTx(bool disabling, LedgerIndex seq, PublicKey const& txKey);
} // namespace unl
} // namespace test
} // namespace ripple
#endif // RIPPLE_TEST_JTX_UNL_H_INCLUDED