mirror of
https://github.com/Xahau/xahaud.git
synced 2026-01-19 14:15:16 +00:00
Compare commits
8 Commits
remit_squa
...
attestatio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
738a4c1e87 | ||
|
|
df9ed403ad | ||
|
|
deb4b34b9b | ||
|
|
d0baeab32f | ||
|
|
72016c3e0e | ||
|
|
54211fb63b | ||
|
|
27f43ba9ee | ||
|
|
7881b7f69f |
@@ -455,6 +455,7 @@ 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/Attest.cpp
|
||||
src/ripple/app/tx/impl/SetSignerList.cpp
|
||||
src/ripple/app/tx/impl/SetTrust.cpp
|
||||
src/ripple/app/tx/impl/SignerEntries.cpp
|
||||
@@ -755,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
|
||||
@@ -896,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
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ echo "START BUILDING (HOST)"
|
||||
echo "Cleaning previously built binary"
|
||||
rm -f release-build/xahaud
|
||||
|
||||
BUILD_CORES=$(echo "scale=0 ; `nproc` / 3" | bc)
|
||||
BUILD_CORES=$(echo "scale=0 ; `nproc` / 1.337" | bc)
|
||||
|
||||
if [[ "$GITHUB_REPOSITORY" == "" ]]; then
|
||||
#Default
|
||||
|
||||
182
src/ripple/app/tx/impl/Attest.cpp
Normal file
182
src/ripple/app/tx/impl/Attest.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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/Attest.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/ledger/View.h>
|
||||
#include <ripple/protocol/Feature.h>
|
||||
#include <ripple/protocol/Indexes.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
TxConsequences
|
||||
Attest::makeTxConsequences(PreflightContext const& ctx)
|
||||
{
|
||||
return TxConsequences{ctx.tx, TxConsequences::normal};
|
||||
}
|
||||
|
||||
NotTEC
|
||||
Attest::preflight(PreflightContext const& ctx)
|
||||
{
|
||||
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
|
||||
return ret;
|
||||
|
||||
auto const flags = ctx.tx.getFlags();
|
||||
|
||||
if (flags & tfAttestMask)
|
||||
return temINVALID_FLAG;
|
||||
|
||||
bool const hasTxnID = ctx.tx.isFieldPresent(sfAttestedTxnID);
|
||||
bool const hasAccID = ctx.tx.isFieldPresent(sfAttestedAccID);
|
||||
|
||||
if ((hasTxnID && hasAccID) || (!hasTxnID && !hasAccID))
|
||||
{
|
||||
JLOG(ctx.j.warn())
|
||||
<< "Attest: must specify exactly one of: AttestedTxnID, AttestedAccID";
|
||||
return temMALFORMED;
|
||||
}
|
||||
|
||||
return preflight2(ctx);
|
||||
}
|
||||
|
||||
TER
|
||||
Attest::preclaim(PreclaimContext const& ctx)
|
||||
{
|
||||
if (!ctx.view.rules().enabled(featureAttestations))
|
||||
return temDISABLED;
|
||||
|
||||
auto const id = ctx.tx[sfAccount];
|
||||
|
||||
auto const sle = ctx.view.read(keylet::account(id));
|
||||
if (!sle)
|
||||
return terNO_ACCOUNT;
|
||||
|
||||
Keylet kl =
|
||||
ctx.tx.isFieldPresent(sfAttestedTxnID)
|
||||
? keylet::attestationTxn(id, ctx.tx.getFieldH256(sfAttestedTxnID))
|
||||
: keylet::attestationAcc(id, ctx.tx.getAccountID(sfAttestedAccID));
|
||||
|
||||
uint32_t flags = ctx.tx.getFlags();
|
||||
|
||||
bool const isDelete = (flags & tfDeleteAttestation) == tfDeleteAttestation;
|
||||
bool const exists = ctx.view.exists(kl);
|
||||
|
||||
if (exists && !isDelete)
|
||||
return tecDUPLICATE;
|
||||
else if (!exists && isDelete)
|
||||
return tecNO_ENTRY;
|
||||
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
TER
|
||||
Attest::doApply()
|
||||
{
|
||||
auto j = ctx_.app.journal("View");
|
||||
|
||||
auto const sle = view().peek(keylet::account(account_));
|
||||
if (!sle)
|
||||
return tefINTERNAL;
|
||||
|
||||
Keylet kl =
|
||||
ctx_.tx.isFieldPresent(sfAttestedTxnID)
|
||||
? keylet::attestationTxn(account_, ctx_.tx.getFieldH256(sfAttestedTxnID))
|
||||
: keylet::attestationAcc(account_, ctx_.tx.getAccountID(sfAttestedAccID));
|
||||
|
||||
uint32_t flags = ctx_.tx.getFlags();
|
||||
|
||||
bool const isDelete = (flags & tfDeleteAttestation) == tfDeleteAttestation;
|
||||
bool const exists = view().exists(kl);
|
||||
|
||||
// check for sufficient reserves
|
||||
if (!isDelete)
|
||||
{
|
||||
STAmount const reserve{
|
||||
view().fees().accountReserve(sle->getFieldU32(sfOwnerCount) + 1)};
|
||||
|
||||
STAmount const afterFee =
|
||||
mPriorBalance - ctx_.tx.getFieldAmount(sfFee).xrp();
|
||||
|
||||
if (afterFee > mPriorBalance || afterFee < reserve)
|
||||
return tecINSUFFICIENT_RESERVE;
|
||||
}
|
||||
|
||||
// delete mode
|
||||
if (exists && isDelete)
|
||||
{
|
||||
auto sleA = view().peek(kl);
|
||||
|
||||
AccountID owner = sleA->getAccountID(sfOwner);
|
||||
|
||||
auto const page = (*sleA)[sfOwnerNode];
|
||||
if (!view().dirRemove(
|
||||
keylet::ownerDir(owner), page, kl.key, true))
|
||||
{
|
||||
JLOG(j.fatal())
|
||||
<< "Could not remove Attestation from owner directory";
|
||||
return tefBAD_LEDGER;
|
||||
}
|
||||
|
||||
view().erase(sleA);
|
||||
adjustOwnerCount(view(), sle, -1, j);
|
||||
return tesSUCCESS;
|
||||
}
|
||||
// create mode
|
||||
else if (!exists && !isDelete)
|
||||
{
|
||||
auto sleA = std::make_shared<SLE>(kl);
|
||||
|
||||
sleA->setFieldU16(sfLedgerEntryType, ltATTESTATION);
|
||||
sleA->setAccountID(sfOwner, account_);
|
||||
|
||||
if (ctx_.tx.isFieldPresent(sfAttestedTxnID))
|
||||
sleA->setFieldH256(sfAttestedTxnID, ctx_.tx.getFieldH256(sfAttestedTxnID));
|
||||
else
|
||||
sleA->setAccountID(sfAttestedAccID, ctx_.tx.getAccountID(sfAttestedAccID));
|
||||
|
||||
|
||||
auto const page = view().dirInsert(
|
||||
keylet::ownerDir(account_), kl, describeOwnerDir(account_));
|
||||
|
||||
JLOG(j_.trace())
|
||||
<< "Adding Attestation to owner directory " << to_string(kl.key)
|
||||
<< ": " << (page ? "success" : "failure");
|
||||
|
||||
if (!page)
|
||||
return tecDIR_FULL;
|
||||
|
||||
sleA->setFieldU64(sfOwnerNode, *page);
|
||||
view().insert(sleA);
|
||||
|
||||
adjustOwnerCount(view(), sle, 1, j);
|
||||
return tesSUCCESS;
|
||||
}
|
||||
// everything else is invalid
|
||||
else
|
||||
return tecINTERNAL;
|
||||
}
|
||||
|
||||
XRPAmount
|
||||
Attest::calculateBaseFee(ReadView const& view, STTx const& tx)
|
||||
{
|
||||
return Transactor::calculateBaseFee(view, tx);
|
||||
}
|
||||
|
||||
} // namespace ripple
|
||||
57
src/ripple/app/tx/impl/Attest.h
Normal file
57
src/ripple/app/tx/impl/Attest.h
Normal file
@@ -0,0 +1,57 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_TX_ATTEST_H_INCLUDED
|
||||
#define RIPPLE_TX_ATTEST_H_INCLUDED
|
||||
|
||||
#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 Attest : public Transactor
|
||||
{
|
||||
public:
|
||||
static constexpr ConsequencesFactoryType ConsequencesFactory{Custom};
|
||||
|
||||
explicit Attest(ApplyContext& ctx) : Transactor(ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static XRPAmount
|
||||
calculateBaseFee(ReadView const& view, STTx const& tx);
|
||||
|
||||
static TxConsequences
|
||||
makeTxConsequences(PreflightContext const& ctx);
|
||||
|
||||
static NotTEC
|
||||
preflight(PreflightContext const& ctx);
|
||||
|
||||
static TER
|
||||
preclaim(PreclaimContext const& ctx);
|
||||
|
||||
TER
|
||||
doApply() override;
|
||||
};
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
#endif
|
||||
@@ -492,6 +492,7 @@ LedgerEntryTypesMatch::visitEntry(
|
||||
case ltURI_TOKEN:
|
||||
case ltIMPORT_VLSEQ:
|
||||
case ltUNL_REPORT:
|
||||
case ltATTESTATION:
|
||||
break;
|
||||
default:
|
||||
invalidTypeAdded_ = true;
|
||||
|
||||
@@ -85,6 +85,54 @@ preflight0(PreflightContext const& ctx)
|
||||
return temINVALID;
|
||||
}
|
||||
|
||||
// don't allow attestations unless enabled
|
||||
if (ctx.tx.isFieldPresent(sfAttesters))
|
||||
{
|
||||
if (!ctx.rules.enabled(featureAttestations))
|
||||
return temDISABLED;
|
||||
|
||||
// make sure they can't spam millions of attesters
|
||||
auto const& attesters = ctx.tx.getFieldArray(sfAttesters);
|
||||
if (attesters.empty() || attesters.size() > 32)
|
||||
{
|
||||
JLOG(ctx.j.warn())
|
||||
<< "applyTransaction: attesters array too big (max 32) or empty.";
|
||||
return temMALFORMED;
|
||||
}
|
||||
|
||||
|
||||
// enforce that it must specify a last ledger seq
|
||||
if (!ctx.tx.isFieldPresent(sfLastLedgerSequence))
|
||||
{
|
||||
JLOG(ctx.j.warn())
|
||||
<< "applyTransaction: txns with attesters must specify a last ledger sequence <= cur + 256";
|
||||
return temMALFORMED;
|
||||
}
|
||||
|
||||
// sanity check entries
|
||||
std::set<AccountID> used;
|
||||
for (auto const& attester: attesters)
|
||||
{
|
||||
if (attester.getFName() != sfAttesterEntry)
|
||||
{
|
||||
JLOG(ctx.j.warn())
|
||||
<< "applyTransaction: attesters array contained non AttesterEntry object.";
|
||||
return temMALFORMED;
|
||||
}
|
||||
|
||||
AccountID const& id = attester.getAccountID(sfAccount);
|
||||
|
||||
if (used.find(id) != used.end())
|
||||
{
|
||||
JLOG(ctx.j.warn())
|
||||
<< "applyTransaction: attesters array contained duplicate attester ID.";
|
||||
return temMALFORMED;
|
||||
}
|
||||
|
||||
used.emplace(id);
|
||||
}
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
@@ -1928,6 +1976,62 @@ Transactor::operator()()
|
||||
}
|
||||
}
|
||||
|
||||
if (applied && ctx_.tx.isFieldPresent(sfAttesters) && view().rules().enabled(featureAttestations))
|
||||
{
|
||||
// delete used attestation objects
|
||||
|
||||
auto const& attesters = ctx_.tx.getFieldArray(sfAttesters);
|
||||
auto const txid = ctx_.tx.getTransactionID();
|
||||
|
||||
auto const& j = ctx_.app.journal("View");
|
||||
|
||||
for (auto const& attester : attesters)
|
||||
{
|
||||
Keylet kl = keylet::attestationTxn(attester.getAccountID(sfAccount), txid);
|
||||
if (!view().exists(kl))
|
||||
{
|
||||
JLOG(j.warn())
|
||||
<< "Transactor: Warning!!! Attestation does not exist at end of attested txn "
|
||||
<< txid;
|
||||
continue;
|
||||
}
|
||||
|
||||
// remove from dir
|
||||
auto sleA = view().peek(kl);
|
||||
|
||||
if (!sleA->isFieldPresent(sfAttestedTxnID))
|
||||
{
|
||||
JLOG(j.warn())
|
||||
<< "Transactor: Warning!!! Attestation is of the wrong type at end of attested txn "
|
||||
<< txid;
|
||||
continue;
|
||||
}
|
||||
|
||||
AccountID owner = sleA->getAccountID(sfOwner);
|
||||
auto sle = view().peek(keylet::account(owner));
|
||||
|
||||
if (!sle)
|
||||
{
|
||||
JLOG(j.warn())
|
||||
<< "Transactor: Warning!!! Attester account does not exist at the end of attested txn "
|
||||
<< txid;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto const page = (*sleA)[sfOwnerNode];
|
||||
if (!view().dirRemove(
|
||||
keylet::ownerDir(owner), page, kl.key, true))
|
||||
{
|
||||
JLOG(j.warn())
|
||||
<< "Could not remove Attestation from owner directory";
|
||||
continue;
|
||||
}
|
||||
|
||||
view().erase(sleA);
|
||||
adjustOwnerCount(view(), sle, -1, j);
|
||||
}
|
||||
}
|
||||
|
||||
// Post-application (Weak TSH/AAW) Hooks are executed here.
|
||||
// These TSH do not have the ability to rollback.
|
||||
// The callback, if any, is also executed here.
|
||||
|
||||
@@ -160,6 +160,7 @@ public:
|
||||
{
|
||||
// Most transactors do nothing
|
||||
// after checkSeq/Fee/Sign.
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <ripple/app/tx/impl/GenesisMint.h>
|
||||
#include <ripple/app/tx/impl/Import.h>
|
||||
#include <ripple/app/tx/impl/Invoke.h>
|
||||
#include <ripple/app/tx/impl/Attest.h>
|
||||
#include <ripple/app/tx/impl/NFTokenAcceptOffer.h>
|
||||
#include <ripple/app/tx/impl/NFTokenBurn.h>
|
||||
#include <ripple/app/tx/impl/NFTokenCancelOffer.h>
|
||||
@@ -164,6 +165,8 @@ invoke_preflight(PreflightContext const& ctx)
|
||||
return invoke_preflight_helper<Import>(ctx);
|
||||
case ttINVOKE:
|
||||
return invoke_preflight_helper<Invoke>(ctx);
|
||||
case ttATTEST:
|
||||
return invoke_preflight_helper<Attest>(ctx);
|
||||
case ttURITOKEN_MINT:
|
||||
case ttURITOKEN_BURN:
|
||||
case ttURITOKEN_BUY:
|
||||
@@ -209,6 +212,27 @@ invoke_preclaim(PreclaimContext const& ctx)
|
||||
|
||||
if (result != tesSUCCESS)
|
||||
return result;
|
||||
|
||||
if (ctx.tx.isFieldPresent(sfAttesters) && ctx.view.rules().enabled(featureAttestations))
|
||||
{
|
||||
// check last ledger sequence
|
||||
if (!ctx.tx.isFieldPresent(sfLastLedgerSequence))
|
||||
return tecINTERNAL;
|
||||
|
||||
if (ctx.tx.getFieldU32(sfLastLedgerSequence) > ctx.view.seq() + 256)
|
||||
return tecLAST_LEDGER_SEQ_TOO_HIGH;
|
||||
|
||||
// check if the required attestations are present on ledger
|
||||
auto const& attesters = ctx.tx.getFieldArray(sfAttesters);
|
||||
|
||||
auto const txid = ctx.tx.getTransactionID();
|
||||
|
||||
// each required attestation must exist on the ledger to allow the txn through
|
||||
// otherwise it gets marked retry
|
||||
for (auto const& attester : attesters)
|
||||
if (!ctx.view.exists(keylet::attestationTxn(attester.getAccountID(sfAccount), txid)))
|
||||
return terAWAITING_ATTESTATION;
|
||||
}
|
||||
}
|
||||
|
||||
return T::preclaim(ctx);
|
||||
@@ -283,6 +307,8 @@ invoke_preclaim(PreclaimContext const& ctx)
|
||||
return invoke_preclaim<Import>(ctx);
|
||||
case ttINVOKE:
|
||||
return invoke_preclaim<Invoke>(ctx);
|
||||
case ttATTEST:
|
||||
return invoke_preclaim<Attest>(ctx);
|
||||
case ttURITOKEN_MINT:
|
||||
case ttURITOKEN_BURN:
|
||||
case ttURITOKEN_BUY:
|
||||
@@ -364,6 +390,8 @@ invoke_calculateBaseFee(ReadView const& view, STTx const& tx)
|
||||
return Import::calculateBaseFee(view, tx);
|
||||
case ttINVOKE:
|
||||
return Invoke::calculateBaseFee(view, tx);
|
||||
case ttATTEST:
|
||||
return Attest::calculateBaseFee(view, tx);
|
||||
case ttURITOKEN_MINT:
|
||||
case ttURITOKEN_BURN:
|
||||
case ttURITOKEN_BUY:
|
||||
@@ -544,6 +572,10 @@ invoke_apply(ApplyContext& ctx)
|
||||
Invoke p(ctx);
|
||||
return p();
|
||||
}
|
||||
case ttATTEST: {
|
||||
Attest p(ctx);
|
||||
return p();
|
||||
}
|
||||
case ttURITOKEN_MINT:
|
||||
case ttURITOKEN_BURN:
|
||||
case ttURITOKEN_BUY:
|
||||
|
||||
@@ -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 = 66;
|
||||
static constexpr std::size_t numFeatures = 67;
|
||||
|
||||
/** 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,7 @@ extern uint256 const featureImport;
|
||||
extern uint256 const featureXahauGenesis;
|
||||
extern uint256 const featureHooksUpdate1;
|
||||
extern uint256 const fixURITokenV1;
|
||||
|
||||
extern uint256 const featureAttestations;
|
||||
} // namespace ripple
|
||||
|
||||
#endif
|
||||
|
||||
@@ -295,7 +295,13 @@ Keylet
|
||||
import_vlseq(PublicKey const& key) noexcept;
|
||||
|
||||
Keylet
|
||||
uritoken(AccountID const& issuer, Blob const& uri);
|
||||
uritoken(AccountID const& issuer, Blob const& uri) noexcept;
|
||||
|
||||
Keylet
|
||||
attestationTxn(AccountID const& issuer, uint256 const& txnid) noexcept;
|
||||
|
||||
Keylet
|
||||
attestationAcc(AccountID const& issuer, AccountID const& issuee) noexcept;
|
||||
|
||||
} // namespace keylet
|
||||
|
||||
|
||||
@@ -52,6 +52,12 @@ namespace ripple {
|
||||
// clang-format off
|
||||
enum LedgerEntryType : std::uint16_t
|
||||
{
|
||||
/** A ledger object which describes an attested txn
|
||||
|
||||
\sa kelet::attestation
|
||||
*/
|
||||
ltATTESTATION = 0x0041,
|
||||
|
||||
/** A ledger object which describes an account.
|
||||
|
||||
\sa keylet::account
|
||||
|
||||
@@ -483,6 +483,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 sfAttestedTxnID;
|
||||
|
||||
// currency amount (common)
|
||||
extern SF_AMOUNT const sfAmount;
|
||||
@@ -552,6 +553,8 @@ 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 sfAttestedAccID;
|
||||
|
||||
// path set
|
||||
extern SField const sfPaths;
|
||||
@@ -562,6 +565,7 @@ 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
|
||||
@@ -590,6 +594,9 @@ extern SField const sfHookGrant;
|
||||
extern SField const sfActiveValidator;
|
||||
extern SField const sfImportVLKey;
|
||||
extern SField const sfHookEmission;
|
||||
extern SField const sfMintURIToken;
|
||||
extern SField const sfAmountEntry;
|
||||
extern SField const sfAttesterEntry;
|
||||
|
||||
// array of objects (common)
|
||||
// ARRAY/1 is reserved for end of array
|
||||
@@ -617,6 +624,8 @@ extern SField const sfGenesisMints;
|
||||
extern SField const sfActiveValidators;
|
||||
extern SField const sfImportVLKeys;
|
||||
extern SField const sfHookEmissions;
|
||||
extern SField const sfAmounts;
|
||||
extern SField const sfAttesters;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -223,8 +223,9 @@ enum TERcodes : TERUnderlyingType {
|
||||
terQUEUED, // Transaction is being held in TxQ until fee drops
|
||||
terPRE_TICKET, // Ticket is not yet in ledger but might be on its way
|
||||
terNO_AMM, // RESERVED - AMM
|
||||
terNO_HOOK // Transaction requires a non-existent hook definition
|
||||
terNO_HOOK, // Transaction requires a non-existent hook definition
|
||||
// (referenced by sfHookHash)
|
||||
terAWAITING_ATTESTATION,
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -337,6 +338,7 @@ enum TECcodes : TERUnderlyingType {
|
||||
tecXCHAIN_PAYMENT_FAILED = 184, // RESERVED - XCHAIN
|
||||
tecXCHAIN_SELF_COMMIT = 185, // RESERVED - XCHAIN
|
||||
tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR = 186, // RESERVED - XCHAIN
|
||||
tecLAST_LEDGER_SEQ_TOO_HIGH = 187,
|
||||
tecLAST_POSSIBLE_ENTRY = 255,
|
||||
};
|
||||
|
||||
|
||||
@@ -132,6 +132,10 @@ constexpr std::uint32_t const tfStrongTSH = 0x00008000;
|
||||
constexpr std::uint32_t const tfNFTokenMintOldMask =
|
||||
~(tfUniversal | tfBurnable | tfOnlyXRP | tfTrustLine | tfTransferable | tfStrongTSH);
|
||||
|
||||
// Attest flags:
|
||||
constexpr std::uint32_t tfDeleteAttestation = 0x00000001;
|
||||
constexpr std::uint32_t tfAttestMask = ~tfDeleteAttestation;
|
||||
|
||||
// Prior to fixRemoveNFTokenAutoTrustLine, transfer of an NFToken between
|
||||
// accounts allowed a TrustLine to be added to the issuer of that token
|
||||
// without explicit permission from that issuer. This was enabled by
|
||||
|
||||
@@ -146,6 +146,13 @@ enum TxType : std::uint16_t
|
||||
ttURITOKEN_CREATE_SELL_OFFER = 48,
|
||||
ttURITOKEN_CANCEL_SELL_OFFER = 49,
|
||||
|
||||
/** This transaction acts as an attestation for another txn currently in the TxQ */
|
||||
ttATTEST = 94,
|
||||
|
||||
/* 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 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,
|
||||
* according to reward schedule */
|
||||
|
||||
@@ -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(Attestations, Supported::yes, VoteBehavior::DefaultNo);
|
||||
|
||||
// The following amendments are obsolete, but must remain supported
|
||||
// because they could potentially get enabled.
|
||||
|
||||
@@ -45,6 +45,8 @@ namespace ripple {
|
||||
*/
|
||||
enum class LedgerNameSpace : std::uint16_t {
|
||||
ACCOUNT = 'a',
|
||||
ATTESTATION_ACC = 'A',
|
||||
ATTESTATION_TXN = 't',
|
||||
DIR_NODE = 'd',
|
||||
TRUST_LINE = 'r',
|
||||
OFFER = 'o',
|
||||
@@ -435,7 +437,7 @@ nft_sells(uint256 const& id) noexcept
|
||||
}
|
||||
|
||||
Keylet
|
||||
uritoken(AccountID const& issuer, Blob const& uri)
|
||||
uritoken(AccountID const& issuer, Blob const& uri) noexcept
|
||||
{
|
||||
return {
|
||||
ltURI_TOKEN,
|
||||
@@ -443,6 +445,16 @@ uritoken(AccountID const& issuer, Blob const& uri)
|
||||
LedgerNameSpace::URI_TOKEN, issuer, Slice{uri.data(), uri.size()})};
|
||||
}
|
||||
|
||||
Keylet attestationTxn(AccountID const& issuer, uint256 const& txnid) noexcept
|
||||
{
|
||||
return {ltATTESTATION, indexHash(LedgerNameSpace::ATTESTATION_TXN, issuer, txnid)};
|
||||
}
|
||||
|
||||
Keylet attestationAcc(AccountID const& issuer, AccountID const& issuee) noexcept
|
||||
{
|
||||
return {ltATTESTATION, indexHash(LedgerNameSpace::ATTESTATION_ACC, issuer, issuee)};
|
||||
}
|
||||
|
||||
} // namespace keylet
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
@@ -141,6 +141,27 @@ 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},
|
||||
});
|
||||
|
||||
add(sfAttesterEntry.jsonName.c_str(),
|
||||
sfAttesterEntry.getCode(),
|
||||
{
|
||||
{sfAccount, soeREQUIRED},
|
||||
});
|
||||
}
|
||||
|
||||
InnerObjectFormats const&
|
||||
|
||||
@@ -363,6 +363,18 @@ LedgerFormats::LedgerFormats()
|
||||
},
|
||||
commonFields);
|
||||
|
||||
add(jss::Attestation,
|
||||
ltATTESTATION,
|
||||
{
|
||||
{sfOwner, soeREQUIRED},
|
||||
{sfOwnerNode, soeREQUIRED},
|
||||
{sfAttestedTxnID, soeOPTIONAL},
|
||||
{sfAttestedAccID, soeOPTIONAL},
|
||||
{sfPreviousTxnID, soeREQUIRED},
|
||||
{sfPreviousTxnLgrSeq, soeREQUIRED},
|
||||
},
|
||||
commonFields);
|
||||
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
|
||||
@@ -236,6 +236,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(sfAttestedTxnID, "AttestedTxnID", UINT256, 96);
|
||||
|
||||
// currency amount (common)
|
||||
CONSTRUCT_TYPED_SFIELD(sfAmount, "Amount", AMOUNT, 1);
|
||||
@@ -305,6 +306,8 @@ 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(sfAttestedAccID, "AttestedAccID", ACCOUNT, 98);
|
||||
|
||||
// vector of 256-bit
|
||||
CONSTRUCT_TYPED_SFIELD(sfIndexes, "Indexes", VECTOR256, 1, SField::sMD_Never);
|
||||
@@ -312,6 +315,7 @@ 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);
|
||||
@@ -346,6 +350,9 @@ 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);
|
||||
CONSTRUCT_UNTYPED_SFIELD(sfAttesterEntry, "AttesterEntry", OBJECT, 90);
|
||||
|
||||
// array of objects
|
||||
// ARRAY/1 is reserved for end of array
|
||||
@@ -370,6 +377,8 @@ 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);
|
||||
CONSTRUCT_UNTYPED_SFIELD(sfAttesters, "Attesters", ARRAY, 91);
|
||||
|
||||
// clang-format on
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ transResults()
|
||||
MAKE_ERROR(tecHOOK_REJECTED, "Rejected by hook on sending or receiving account."),
|
||||
MAKE_ERROR(tecREQUIRES_FLAG, "The transaction or part-thereof requires a flag that wasn't set."),
|
||||
MAKE_ERROR(tecPRECISION_LOSS, "The amounts used by the transaction cannot interact."),
|
||||
MAKE_ERROR(tecLAST_LEDGER_SEQ_TOO_HIGH, "The sfLastLedgerSequence was higher than seq + 256."),
|
||||
MAKE_ERROR(tefALREADY, "The exact transaction was already in this ledger."),
|
||||
MAKE_ERROR(tefBAD_ADD_AUTH, "Not authorized to add account."),
|
||||
MAKE_ERROR(tefBAD_AUTH, "Transaction's public key is not authorized."),
|
||||
@@ -188,6 +189,7 @@ transResults()
|
||||
MAKE_ERROR(terQUEUED, "Held until escalated fee drops."),
|
||||
MAKE_ERROR(terPRE_TICKET, "Ticket is not yet in ledger."),
|
||||
MAKE_ERROR(terNO_HOOK, "No hook with that hash exists on the ledger."),
|
||||
MAKE_ERROR(terAWAITING_ATTESTATION, "Transaction is waiting for attesters to attest."),
|
||||
|
||||
MAKE_ERROR(tesSUCCESS, "The transaction was applied. Only final in a validated ledger."),
|
||||
};
|
||||
|
||||
@@ -44,6 +44,7 @@ TxFormats::TxFormats()
|
||||
{sfNetworkID, soeOPTIONAL},
|
||||
{sfHookParameters, soeOPTIONAL},
|
||||
{sfOperationLimit, soeOPTIONAL},
|
||||
{sfAttesters, soeOPTIONAL},
|
||||
};
|
||||
|
||||
add(jss::AccountSet,
|
||||
@@ -116,6 +117,21 @@ 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,
|
||||
{
|
||||
@@ -441,6 +457,15 @@ TxFormats::TxFormats()
|
||||
{sfTicketSequence, soeOPTIONAL},
|
||||
},
|
||||
commonFields);
|
||||
|
||||
add(jss::Attest,
|
||||
ttATTEST,
|
||||
{
|
||||
{sfAttestedTxnID, soeOPTIONAL},
|
||||
{sfAttestedAccID, soeOPTIONAL},
|
||||
{sfTicketSequence, soeOPTIONAL},
|
||||
},
|
||||
commonFields);
|
||||
}
|
||||
|
||||
TxFormats const&
|
||||
|
||||
@@ -50,6 +50,9 @@ JSS(AccountSet); // transaction type.
|
||||
JSS(Amendments); // ledger type.
|
||||
JSS(Amount); // in: TransactionSign; field.
|
||||
JSS(Authorize); // field
|
||||
JSS(Attest);
|
||||
JSS(AttesterEntry);
|
||||
JSS(Attestation);
|
||||
JSS(Blob);
|
||||
JSS(Check); // ledger type.
|
||||
JSS(CheckCancel); // transaction type.
|
||||
@@ -117,6 +120,7 @@ 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.
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
4815
src/test/app/SetHookTSH_test.cpp
Normal file
4815
src/test/app/SetHookTSH_test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -42,35 +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
|
||||
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);
|
||||
|
||||
/**
|
||||
* Verify the content of negative UNL entries (public key and ledger sequence)
|
||||
* of a ledger
|
||||
@@ -85,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
|
||||
*
|
||||
@@ -103,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
|
||||
{
|
||||
/**
|
||||
@@ -245,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));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -266,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)
|
||||
{
|
||||
@@ -292,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]);
|
||||
@@ -304,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)
|
||||
{
|
||||
@@ -312,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)
|
||||
{
|
||||
@@ -341,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)
|
||||
{
|
||||
@@ -357,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)
|
||||
{
|
||||
@@ -385,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)
|
||||
{
|
||||
@@ -400,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)
|
||||
{
|
||||
@@ -410,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)
|
||||
{
|
||||
@@ -434,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)
|
||||
{
|
||||
@@ -450,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)
|
||||
{
|
||||
@@ -459,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)
|
||||
{
|
||||
@@ -478,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)
|
||||
{
|
||||
@@ -492,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());
|
||||
}
|
||||
@@ -507,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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -542,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
|
||||
@@ -634,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;
|
||||
}
|
||||
@@ -643,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;
|
||||
}
|
||||
}
|
||||
@@ -659,7 +625,7 @@ struct NetworkHistory
|
||||
}
|
||||
l->updateSkipList();
|
||||
}
|
||||
return negUnlSizeTest(
|
||||
return unl::negUnlSizeTest(
|
||||
l, param.negUNLSize, param.hasToDisable, param.hasToReEnable);
|
||||
}
|
||||
|
||||
@@ -759,7 +725,7 @@ voteAndCheck(
|
||||
vote.doVoting(
|
||||
history.lastLedger(), history.UNLKeySet, history.validations, txSet);
|
||||
|
||||
return countTx(txSet) >= expect;
|
||||
return unl::countTx(txSet) >= expect;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -782,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
|
||||
}
|
||||
@@ -1912,31 +1878,6 @@ BEAST_DEFINE_TESTSUITE(NegativeUNLVoteFilterValidations, consensus, ripple);
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
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;
|
||||
}
|
||||
|
||||
bool
|
||||
VerifyPubKeyAndSeq(
|
||||
@@ -1975,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)
|
||||
{
|
||||
@@ -2019,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
|
||||
|
||||
@@ -51,23 +51,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
|
||||
// */
|
||||
inline 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
|
||||
// *
|
||||
@@ -110,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
|
||||
*
|
||||
@@ -165,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
|
||||
@@ -345,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,
|
||||
@@ -374,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,
|
||||
@@ -413,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)
|
||||
@@ -674,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())
|
||||
@@ -728,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;
|
||||
}
|
||||
@@ -737,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;
|
||||
}
|
||||
}
|
||||
@@ -753,7 +711,7 @@ struct URNetworkHistory
|
||||
}
|
||||
l->updateSkipList();
|
||||
}
|
||||
return negUnlSizeTest(
|
||||
return unl::negUnlSizeTest(
|
||||
l, param.negUNLSize, param.hasToDisable, param.hasToReEnable);
|
||||
}
|
||||
|
||||
@@ -854,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;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1235,22 +1194,6 @@ BEAST_DEFINE_TESTSUITE(UNLReportVoteNewValidator, consensus, ripple);
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline 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
|
||||
applyAndTestUNLRResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass)
|
||||
{
|
||||
@@ -1313,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)
|
||||
{
|
||||
@@ -1412,54 +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)
|
||||
{
|
||||
/*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;
|
||||
};
|
||||
|
||||
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
|
||||
@@ -70,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>
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <test/jtx/acctdelete.h>
|
||||
|
||||
|
||||
95
src/test/jtx/impl/unl.cpp
Normal file
95
src/test/jtx/impl/unl.cpp
Normal 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
|
||||
86
src/test/jtx/unl.h
Normal file
86
src/test/jtx/unl.h
Normal 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
|
||||
Reference in New Issue
Block a user