mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-21 14:20:56 +00:00
The bound passed to the pseudo-account credential cleanup limits how many owner-directory entries the walk visits, not how many credentials it deletes: entries the walk leaves alone are charged against the same budget. Both comments claimed the latter, so say what the code actually does. Narrow the tecINCOMPLETE relaxation in the MPT issuance invariant to VaultDelete. That is the only transaction carrying the DestroyMptIssuance privilege that can return tecINCOMPLETE, and the comment above the branch already said as much, so the code now matches it and any future transaction with the same privilege stays under the strict rule. Rename removeExpiredCredentials to removeDeletedCredentials. It now also deletes credentials removed by a bounded cleanup rather than by expiry, which is the same reason removeDeletedTrustLines carries that name.
557 lines
15 KiB
C++
557 lines
15 KiB
C++
#pragma once
|
|
|
|
#include <xrpl/basics/ByteUtilities.h>
|
|
#include <xrpl/basics/Number.h>
|
|
#include <xrpl/basics/base_uint.h>
|
|
#include <xrpl/basics/safe_cast.h>
|
|
#include <xrpl/protocol/Units.h>
|
|
|
|
#include <mpt_protocol.h>
|
|
#include <secp256k1_mpt.h>
|
|
|
|
#include <chrono>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
namespace xrpl {
|
|
|
|
/**
|
|
* Protocol specific constants.
|
|
*
|
|
* This information is, implicitly, part of the protocol.
|
|
*
|
|
* @note Changing these values without adding code to the
|
|
* server to detect "pre-change" and "post-change"
|
|
* will result in a hard fork.
|
|
*
|
|
* @ingroup protocol
|
|
*/
|
|
/**
|
|
* Smallest legal byte size of a transaction.
|
|
*/
|
|
constexpr std::size_t kTxMinSizeBytes = 32;
|
|
|
|
/**
|
|
* Largest legal byte size of a transaction.
|
|
*/
|
|
constexpr std::size_t kTxMaxSizeBytes = megabytes(1);
|
|
|
|
/**
|
|
* The maximum number of unfunded offers to delete at once
|
|
*/
|
|
constexpr std::size_t kUnfundedOfferRemoveLimit = 1000;
|
|
|
|
/**
|
|
* The maximum number of expired offers to delete at once
|
|
*/
|
|
constexpr std::size_t kExpiredOfferRemoveLimit = 256;
|
|
|
|
/**
|
|
* The maximum number of metadata entries allowed in one transaction
|
|
*/
|
|
constexpr std::size_t kOversizeMetaDataCap = 5200;
|
|
|
|
/**
|
|
* The maximum number of entries per directory page
|
|
*/
|
|
constexpr std::size_t kDirNodeMaxEntries = 32;
|
|
|
|
/**
|
|
* The maximum number of pages allowed in a directory
|
|
*
|
|
* Made obsolete by fixDirectoryLimit amendment.
|
|
*/
|
|
constexpr std::uint64_t kDirNodeMaxPages = 262144;
|
|
|
|
/**
|
|
* The maximum number of items in an NFT page
|
|
*/
|
|
constexpr std::size_t kDirMaxTokensPerPage = 32;
|
|
|
|
/**
|
|
* The maximum number of owner directory entries for account to be deletable
|
|
*/
|
|
constexpr std::size_t kMaxDeletableDirEntries = 1000;
|
|
|
|
/**
|
|
* The maximum number of token offers that can be canceled at once
|
|
*/
|
|
constexpr std::size_t kMaxTokenOfferCancelCount = 500;
|
|
|
|
/**
|
|
* The maximum number of offers in an offer directory for NFT to be burnable
|
|
*/
|
|
constexpr std::size_t kMaxDeletableTokenOfferEntries = 500;
|
|
|
|
/**
|
|
* The maximum token transfer fee allowed.
|
|
*
|
|
* Token transfer fees can range from 0% to 50% and are specified in tenths of
|
|
* a basis point; that is a value of 1000 represents a transfer fee of 1% and
|
|
* a value of 10000 represents a transfer fee of 10%.
|
|
*
|
|
* Note that for extremely low transfer fees values, it is possible that the
|
|
* calculated fee will be 0.
|
|
*/
|
|
constexpr std::uint16_t kMaxTransferFee = 50000;
|
|
|
|
/**
|
|
* There are 10,000 basis points (bips) in 100%.
|
|
*
|
|
* Basis points represent 0.01%.
|
|
*
|
|
* Given a value X, to find the amount for B bps,
|
|
* use X * B / bipsPerUnity
|
|
*
|
|
* Example: If a loan broker has 999 XRP of debt, and must maintain 1,000 bps of
|
|
* that debt as cover (10%), then the minimum cover amount is 999,000,000 drops
|
|
* * 1000 / bipsPerUnity = 99,900,00 drops or 99.9 XRP.
|
|
*
|
|
* Given a percentage P, to find the number of bps that percentage represents,
|
|
* use P * bipsPerUnity.
|
|
*
|
|
* Example: 50% is 0.50 * bipsPerUnity = 5,000 bps.
|
|
*/
|
|
constexpr Bips32 kBipsPerUnity(100 * 100);
|
|
static_assert(kBipsPerUnity == Bips32{10'000});
|
|
constexpr TenthBips32 kTenthBipsPerUnity(kBipsPerUnity.value() * 10);
|
|
static_assert(kTenthBipsPerUnity == TenthBips32(100'000));
|
|
|
|
constexpr Bips32
|
|
percentageToBips(std::uint32_t percentage)
|
|
{
|
|
return Bips32(percentage * kBipsPerUnity.value() / 100);
|
|
}
|
|
constexpr TenthBips32
|
|
percentageToTenthBips(std::uint32_t percentage)
|
|
{
|
|
return TenthBips32(percentage * kTenthBipsPerUnity.value() / 100);
|
|
}
|
|
template <typename T, class TBips>
|
|
constexpr T
|
|
bipsOfValue(T value, Bips<TBips> bips)
|
|
{
|
|
return value * bips.value() / kBipsPerUnity.value();
|
|
}
|
|
template <typename T, class TBips>
|
|
constexpr T
|
|
tenthBipsOfValue(T value, TenthBips<TBips> bips)
|
|
{
|
|
return value * bips.value() / kTenthBipsPerUnity.value();
|
|
}
|
|
|
|
namespace lending {
|
|
/**
|
|
* The maximum management fee rate allowed by a loan broker in 1/10 bips.
|
|
*
|
|
* Valid values are between 0 and 10% inclusive.
|
|
*/
|
|
constexpr TenthBips16 kMaxManagementFeeRate(
|
|
unsafeCast<std::uint16_t>(percentageToTenthBips(10).value()));
|
|
static_assert(kMaxManagementFeeRate == TenthBips16(std::uint16_t(10'000u)));
|
|
|
|
/**
|
|
* The maximum coverage rate required of a loan broker in 1/10 bips.
|
|
*
|
|
* Valid values are between 0 and 100% inclusive.
|
|
*/
|
|
constexpr TenthBips32 kMaxCoverRate = percentageToTenthBips(100);
|
|
static_assert(kMaxCoverRate == TenthBips32(100'000u));
|
|
|
|
/**
|
|
* The maximum overpayment fee on a loan in 1/10 bips.
|
|
*
|
|
* Valid values are between 0 and 100% inclusive.
|
|
*/
|
|
constexpr TenthBips32 kMaxOverpaymentFee = percentageToTenthBips(100);
|
|
static_assert(kMaxOverpaymentFee == TenthBips32(100'000u));
|
|
|
|
/**
|
|
* Annualized interest rate of the Loan in 1/10 bips.
|
|
*
|
|
* Valid values are between 0 and 100% inclusive.
|
|
*/
|
|
constexpr TenthBips32 kMaxInterestRate = percentageToTenthBips(100);
|
|
static_assert(kMaxInterestRate == TenthBips32(100'000u));
|
|
|
|
/**
|
|
* The maximum premium added to the interest rate for late payments on a loan
|
|
* in 1/10 bips.
|
|
*
|
|
* Valid values are between 0 and 100% inclusive.
|
|
*/
|
|
constexpr TenthBips32 kMaxLateInterestRate = percentageToTenthBips(100);
|
|
static_assert(kMaxLateInterestRate == TenthBips32(100'000u));
|
|
|
|
/**
|
|
* The maximum close interest rate charged for repaying a loan early in 1/10
|
|
* bips.
|
|
*
|
|
* Valid values are between 0 and 100% inclusive.
|
|
*/
|
|
constexpr TenthBips32 kMaxCloseInterestRate = percentageToTenthBips(100);
|
|
static_assert(kMaxCloseInterestRate == TenthBips32(100'000u));
|
|
|
|
/**
|
|
* The maximum overpayment interest rate charged on loan overpayments in 1/10
|
|
* bips.
|
|
*
|
|
* Valid values are between 0 and 100% inclusive.
|
|
*/
|
|
constexpr TenthBips32 kMaxOverpaymentInterestRate = percentageToTenthBips(100);
|
|
static_assert(kMaxOverpaymentInterestRate == TenthBips32(100'000u));
|
|
|
|
/**
|
|
* LoanPay transaction cost will be one base fee per X combined payments
|
|
*
|
|
* The number of payments is estimated based on the Amount paid and the Loan's
|
|
* Fixed Payment size. Overpayments (indicated with the tfLoanOverpayment flag)
|
|
* count as one more payment.
|
|
*
|
|
* This number was chosen arbitrarily, but should not be changed once released
|
|
* without an amendment
|
|
*/
|
|
static constexpr int kLoanPaymentsPerFeeIncrement = 5;
|
|
|
|
/**
|
|
* Maximum number of combined payments that a LoanPay transaction will process
|
|
*
|
|
* This limit is enforced during the loan payment process, and thus is not
|
|
* estimated. If the limit is hit, no further payments or overpayments will be
|
|
* processed, no matter how much of the transaction Amount is left, but the
|
|
* transaction will succeed with the payments that have been processed up to
|
|
* that point.
|
|
*
|
|
* This limit is independent of loanPaymentsPerFeeIncrement, so a transaction
|
|
* could potentially be charged for many more payments than actually get
|
|
* processed. Users should take care not to submit a transaction paying more
|
|
* than loanMaximumPaymentsPerTransaction * Loan.PeriodicPayment. Because
|
|
* overpayments are charged as a payment, if submitting
|
|
* loanMaximumPaymentsPerTransaction * Loan.PeriodicPayment, users should not
|
|
* set the tfLoanOverpayment flag.
|
|
*
|
|
* Even though they're independent, loanMaximumPaymentsPerTransaction should be
|
|
* a multiple of loanPaymentsPerFeeIncrement.
|
|
*
|
|
* This number was chosen arbitrarily, but should not be changed once released
|
|
* without an amendment
|
|
*/
|
|
static constexpr int kLoanMaximumPaymentsPerTransaction = 100;
|
|
} // namespace lending
|
|
|
|
/**
|
|
* The maximum length of a URI inside an NFT
|
|
*/
|
|
constexpr std::size_t kMaxTokenUriLength = 256;
|
|
|
|
/**
|
|
* The maximum length of a Data element inside a DID
|
|
*/
|
|
constexpr std::size_t kMaxDidDocumentLength = 256;
|
|
|
|
/**
|
|
* The maximum length of a URI inside a DID
|
|
*/
|
|
constexpr std::size_t kMaxDidUriLength = 256;
|
|
|
|
/**
|
|
* The maximum length of an Attestation inside a DID
|
|
*/
|
|
constexpr std::size_t kMaxDidDataLength = 256;
|
|
|
|
/**
|
|
* The maximum length of a domain
|
|
*/
|
|
constexpr std::size_t kMaxDomainLength = 256;
|
|
|
|
/**
|
|
* The maximum length of a URI inside a Credential
|
|
*/
|
|
constexpr std::size_t kMaxCredentialUriLength = 256;
|
|
|
|
/**
|
|
* The maximum length of a CredentialType inside a Credential
|
|
*/
|
|
constexpr std::size_t kMaxCredentialTypeLength = 64;
|
|
|
|
/**
|
|
* The maximum number of credentials can be passed in array
|
|
*/
|
|
constexpr std::size_t kMaxCredentialsArraySize = 8;
|
|
|
|
/**
|
|
* The maximum number of credentials can be passed in array for permissioned
|
|
* domain
|
|
*/
|
|
constexpr std::size_t kMaxPermissionedDomainCredentialsArraySize = 10;
|
|
|
|
/**
|
|
* The maximum length of MPTokenMetadata
|
|
*/
|
|
constexpr std::size_t kMaxMpTokenMetadataLength = 1024;
|
|
|
|
/**
|
|
* The maximum amount of MPTokenIssuance
|
|
*/
|
|
constexpr std::uint64_t kMaxMpTokenAmount = 0x7FFF'FFFF'FFFF'FFFFull;
|
|
static_assert(Number::kMaxRep >= kMaxMpTokenAmount);
|
|
|
|
/**
|
|
* The maximum length of Data payload
|
|
*/
|
|
constexpr std::size_t kMaxDataPayloadLength = 256;
|
|
|
|
/**
|
|
* Vault withdrawal policies
|
|
*/
|
|
constexpr std::uint8_t kVaultStrategyFirstComeFirstServe = 1;
|
|
|
|
/**
|
|
* Default IOU scale factor for a Vault
|
|
*/
|
|
constexpr std::uint8_t kVaultDefaultIouScale = 6;
|
|
/**
|
|
* Maximum scale factor for a Vault. The number is chosen to ensure that
|
|
* 1 IOU can be always converted to shares.
|
|
* 10^19 > maxMPTokenAmount (2^64-1) > 10^18
|
|
*/
|
|
constexpr std::uint8_t kVaultMaximumIouScale = 18;
|
|
|
|
/**
|
|
* Vault ledger-entry schema versions. Assigned to newly created
|
|
* Vaults once featureLendingProtocolV1_1 is enabled. Vaults created before
|
|
* activation are left without LEVersion (implicit legacy version 0,
|
|
* accrual-basis accounting).
|
|
*/
|
|
enum class VaultVersion : uint8_t {
|
|
Legacy = 0,
|
|
CashBasis,
|
|
};
|
|
|
|
/**
|
|
* Vault kind. Distinguishes closed-ended vaults from the default open-ended
|
|
* kind. Persisted as sfVaultKind (UINT8); absent means OpenEnded.
|
|
*/
|
|
enum class VaultKind : std::uint8_t {
|
|
OpenEnded = 0,
|
|
ClosedEnded = 1,
|
|
};
|
|
|
|
/**
|
|
* Lifecycle phase of a vault. Open-ended vaults are always NoPhase; the other
|
|
* three values are the phases of a closed-ended vault.
|
|
*/
|
|
enum class VaultPhase : std::uint8_t {
|
|
NoPhase = 0,
|
|
Subscription,
|
|
Investment,
|
|
Redemption,
|
|
};
|
|
|
|
/**
|
|
* Bounds on the length of a closed-ended vault's Investment phase
|
|
* (RedemptionDate - SubscriptionDate). At vault creation the gap must satisfy
|
|
* kMinInvestmentPeriod <= gap < kMaxInvestmentPeriod.
|
|
*/
|
|
constexpr std::uint32_t kMinInvestmentPeriod =
|
|
std::chrono::seconds{std::chrono::minutes{1}}.count();
|
|
// This is 946708560 seconds which 30 x 365.2425 days (the average length of a Gregorian year).
|
|
constexpr std::uint32_t kMaxInvestmentPeriod = std::chrono::seconds{std::chrono::years{30}}.count();
|
|
|
|
/**
|
|
* Maximum recursion depth for vault shares being put as an asset inside
|
|
* another vault; counted from 0
|
|
*/
|
|
constexpr std::uint8_t kMaxAssetCheckDepth = 5;
|
|
|
|
/**
|
|
* A ledger index.
|
|
*/
|
|
using LedgerIndex = std::uint32_t;
|
|
|
|
constexpr std::uint32_t kFlagLedgerInterval = 256;
|
|
|
|
/**
|
|
* Returns true if the given ledgerIndex is a voting ledgerIndex
|
|
*/
|
|
bool
|
|
isVotingLedger(LedgerIndex seq);
|
|
|
|
/**
|
|
* Returns true if the given ledgerIndex is a flag ledgerIndex
|
|
*/
|
|
bool
|
|
isFlagLedger(LedgerIndex seq);
|
|
|
|
/**
|
|
* A transaction identifier.
|
|
* The value is computed as the hash of the
|
|
* canonicalized, serialized transaction object.
|
|
*/
|
|
using TxID = uint256;
|
|
|
|
/**
|
|
* The maximum number of trustlines to delete as part of AMM account
|
|
* deletion cleanup.
|
|
*/
|
|
constexpr std::uint16_t kMaxDeletableAmmTrustLines = 512;
|
|
|
|
/**
|
|
* The maximum number of owner-directory entries to walk when clearing
|
|
* credentials pinned to a pseudo-account, in a single transaction.
|
|
*
|
|
* The walk stops after this many entries whether or not each one turns out to
|
|
* be a credential, so a directory that also holds other objects yields fewer
|
|
* deletions per transaction.
|
|
*/
|
|
constexpr std::uint16_t kMaxDeletablePseudoAccountCredentials = 512;
|
|
|
|
/**
|
|
* The maximum length of a URI inside an Oracle
|
|
*/
|
|
constexpr std::size_t kMaxOracleUri = 256;
|
|
|
|
/**
|
|
* The maximum length of a Provider inside an Oracle
|
|
*/
|
|
constexpr std::size_t kMaxOracleProvider = 256;
|
|
|
|
/**
|
|
* The maximum size of a data series array inside an Oracle
|
|
*/
|
|
constexpr std::size_t kMaxOracleDataSeries = 10;
|
|
|
|
/**
|
|
* The maximum length of a SymbolClass inside an Oracle
|
|
*/
|
|
constexpr std::size_t kMaxOracleSymbolClass = 16;
|
|
|
|
/**
|
|
* The maximum allowed time difference between lastUpdateTime and the time
|
|
* of the last closed ledger
|
|
*/
|
|
constexpr std::size_t kMaxLastUpdateTimeDelta = 300;
|
|
|
|
/**
|
|
* The maximum price scaling factor
|
|
*/
|
|
constexpr std::size_t kMaxPriceScale = 20;
|
|
|
|
/**
|
|
* The maximum percentage of outliers to trim
|
|
*/
|
|
constexpr std::size_t kMaxTrim = 25;
|
|
|
|
/**
|
|
* The maximum number of delegate permissions an account can grant
|
|
*/
|
|
constexpr std::size_t kPermissionMaxSize = 10;
|
|
|
|
/**
|
|
* The maximum number of transactions that can be in a batch.
|
|
*/
|
|
constexpr std::size_t kMaxBatchTxCount = 8;
|
|
|
|
/**
|
|
* The maximum number of batch signers.
|
|
*/
|
|
constexpr std::size_t kMaxBatchSigners = kMaxBatchTxCount * 3;
|
|
|
|
/**
|
|
* Length of a secp256k1 scalar in bytes.
|
|
*/
|
|
constexpr std::size_t kEcScalarLength = kMPT_SCALAR_SIZE;
|
|
|
|
/**
|
|
* Length of EC point (compressed)
|
|
*/
|
|
constexpr std::size_t kCompressedEcPointLength = 33;
|
|
|
|
/**
|
|
* Length of one compressed EC point component in an EC ElGamal ciphertext.
|
|
*/
|
|
constexpr std::size_t kEcCiphertextComponentLength = kMPT_ELGAMAL_CIPHER_SIZE;
|
|
|
|
/**
|
|
* EC ElGamal ciphertext length: two compressed EC points concatenated.
|
|
*/
|
|
constexpr std::size_t kEcGamalEncryptedTotalLength = kMPT_ELGAMAL_TOTAL_SIZE;
|
|
|
|
/**
|
|
* Length of EC public key (compressed)
|
|
*/
|
|
constexpr std::size_t kEcPubKeyLength = kMPT_PUBKEY_SIZE;
|
|
|
|
/**
|
|
* Length of EC private key in bytes
|
|
*/
|
|
constexpr std::size_t kEcPrivKeyLength = kMPT_PRIVKEY_SIZE;
|
|
|
|
/**
|
|
* Length of the EC blinding factor in bytes
|
|
*/
|
|
constexpr std::size_t kEcBlindingFactorLength = kMPT_BLINDING_FACTOR_SIZE;
|
|
|
|
/**
|
|
* Length of Schnorr ZKProof for public key registration (compact form) in bytes
|
|
*/
|
|
constexpr std::size_t kEcSchnorrProofLength = kMPT_SCHNORR_PROOF_SIZE;
|
|
|
|
/**
|
|
* Length of Pedersen Commitment (compressed)
|
|
*/
|
|
constexpr std::size_t kEcPedersenCommitmentLength = kMPT_PEDERSEN_COMMIT_SIZE;
|
|
|
|
/**
|
|
* Length of single bulletproof (range proof for 1 commitment) in bytes
|
|
*/
|
|
constexpr std::size_t kEcSingleBulletproofLength = kMPT_SINGLE_BULLETPROOF_SIZE;
|
|
|
|
/**
|
|
* Length of double bulletproof (range proof for 2 commitments) in bytes
|
|
*/
|
|
constexpr std::size_t kEcDoubleBulletproofLength = kMPT_DOUBLE_BULLETPROOF_SIZE;
|
|
|
|
/**
|
|
* Length of the compact sigma proof component for ConfidentialMPTSend.
|
|
*/
|
|
constexpr std::size_t kEcSendSigmaProofLength = SECP256K1_COMPACT_STANDARD_PROOF_SIZE;
|
|
|
|
/**
|
|
* 192 bytes compact sigma proof + 754 bytes double bulletproof.
|
|
*/
|
|
constexpr std::size_t kEcSendProofLength = kEcSendSigmaProofLength + kEcDoubleBulletproofLength;
|
|
|
|
/**
|
|
* Length of the compact sigma proof component for ConfidentialMPTConvertBack.
|
|
*/
|
|
constexpr std::size_t kEcConvertBackSigmaProofLength = SECP256K1_COMPACT_CONVERTBACK_PROOF_SIZE;
|
|
|
|
/**
|
|
* 128 bytes compact sigma proof + 688 bytes single bulletproof.
|
|
*/
|
|
constexpr std::size_t kEcConvertBackProofLength =
|
|
kEcConvertBackSigmaProofLength + kEcSingleBulletproofLength;
|
|
|
|
/**
|
|
* Length of the ZKProof for ConfidentialMPTClawback.
|
|
*/
|
|
constexpr std::size_t kEcClawbackProofLength = SECP256K1_COMPACT_CLAWBACK_PROOF_SIZE;
|
|
|
|
/**
|
|
* Extra base fee multiplier charged to confidential MPT transactions.
|
|
*/
|
|
constexpr std::uint32_t kConfidentialFeeMultiplier = 9;
|
|
|
|
/**
|
|
* Compressed EC point prefix for even y-coordinate
|
|
*/
|
|
constexpr std::uint8_t kEcCompressedPrefixEvenY = 0x02;
|
|
|
|
/**
|
|
* Compressed EC point prefix for odd y-coordinate
|
|
*/
|
|
constexpr std::uint8_t kEcCompressedPrefixOddY = 0x03;
|
|
|
|
} // namespace xrpl
|