add server logging (#7645)

This commit is contained in:
Peter Chen
2026-06-26 09:40:16 -07:00
committed by GitHub
parent 734811d1dd
commit f96d50b487
8 changed files with 126 additions and 20 deletions

View File

@@ -207,8 +207,8 @@ TYPED_SFIELD(sfParentBatchID, UINT256, 36)
TYPED_SFIELD(sfLoanBrokerID, UINT256, 37,
SField::kSmdPseudoAccount | SField::kSmdDefault)
TYPED_SFIELD(sfLoanID, UINT256, 38)
TYPED_SFIELD(sfBlindingFactor, UINT256, 39)
TYPED_SFIELD(sfReferenceHolding, UINT256, 40)
TYPED_SFIELD(sfReferenceHolding, UINT256, 39)
TYPED_SFIELD(sfBlindingFactor, UINT256, 40)
// number (common)
TYPED_SFIELD(sfNumber, NUMBER, 1)

View File

@@ -131,7 +131,9 @@ public:
* lsfMPTCanHoldConfidentialBalance is set on the issuance.
* - Encrypted field existence consistency:
* If sfConfidentialBalanceSpending/sfConfidentialBalanceInbox exists, then
* sfIssuerEncryptedBalance must also exist (and vice versa).
* sfIssuerEncryptedBalance must also exist (and vice versa). If
* sfAuditorEncryptedBalance exists, then those core encrypted balance fields
* must also exist.
* - COA <= OutstandingAmount:
* Confidential outstanding balance cannot exceed total outstanding.
* - Verifies sfConfidentialBalanceVersion is changed whenever sfConfidentialBalanceSpending is

View File

@@ -543,7 +543,8 @@ ValidConfidentialMPToken::visitEntry(
bool const hasPublicBalance = before->getFieldU64(sfMPTAmount) > 0;
bool const hasEncryptedFields = before->isFieldPresent(sfConfidentialBalanceSpending) ||
before->isFieldPresent(sfConfidentialBalanceInbox) ||
before->isFieldPresent(sfIssuerEncryptedBalance);
before->isFieldPresent(sfIssuerEncryptedBalance) ||
before->isFieldPresent(sfAuditorEncryptedBalance);
if (hasPublicBalance || hasEncryptedFields)
changes_[id].deletedWithEncrypted = true;
@@ -561,10 +562,12 @@ ValidConfidentialMPToken::visitEntry(
bool const hasIssuerBalance = after->isFieldPresent(sfIssuerEncryptedBalance);
bool const hasHolderInbox = after->isFieldPresent(sfConfidentialBalanceInbox);
bool const hasHolderSpending = after->isFieldPresent(sfConfidentialBalanceSpending);
bool const hasAuditorBalance = after->isFieldPresent(sfAuditorEncryptedBalance);
// sfIssuerEncryptedBalance, sfConfidentialBalanceInbox, and sfConfidentialBalanceSpending
// must all exist or not exist same time.
if (hasHolderInbox != hasHolderSpending || hasHolderInbox != hasIssuerBalance)
// The core encrypted balances must all exist or not exist at the same time. The auditor
// balance is optional, but cannot exist without the core fields.
if (hasHolderInbox != hasHolderSpending || hasHolderInbox != hasIssuerBalance ||
(hasAuditorBalance && !hasIssuerBalance))
changes_[id].badConsistency = true;
auto const confidentialBalanceFieldChanged = [&before, &after](auto const& field) {

View File

@@ -1,5 +1,6 @@
#include <xrpl/tx/transactors/token/ConfidentialMPTConvert.h>
#include <xrpl/basics/Log.h>
#include <xrpl/basics/Slice.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/core/ServiceRegistry.h>
@@ -246,7 +247,13 @@ ConfidentialMPTConvert::doApply()
{
auto sum = homomorphicAdd(holderEc, (*sleMptoken)[sfConfidentialBalanceInbox]);
if (!sum)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTConvert failed homomorphic add for holder inbox.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleMptoken)[sfConfidentialBalanceInbox] = std::move(*sum);
}
@@ -255,7 +262,13 @@ ConfidentialMPTConvert::doApply()
{
auto sum = homomorphicAdd(issuerEc, (*sleMptoken)[sfIssuerEncryptedBalance]);
if (!sum)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTConvert failed homomorphic add for issuer balance.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleMptoken)[sfIssuerEncryptedBalance] = std::move(*sum);
}
@@ -268,7 +281,13 @@ ConfidentialMPTConvert::doApply()
auto sum = homomorphicAdd(*auditorEc, (*sleMptoken)[sfAuditorEncryptedBalance]);
if (!sum)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTConvert failed homomorphic add for auditor balance.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleMptoken)[sfAuditorEncryptedBalance] = std::move(*sum);
}

View File

@@ -1,5 +1,6 @@
#include <xrpl/tx/transactors/token/ConfidentialMPTConvertBack.h>
#include <xrpl/basics/Log.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ReadView.h>
@@ -245,7 +246,14 @@ ConfidentialMPTConvertBack::doApply()
auto res = homomorphicSubtract(
(*sleMptoken)[sfConfidentialBalanceSpending], ctx_.tx[sfHolderEncryptedAmount]);
if (!res)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTConvertBack failed homomorphic subtract for holder spending "
"balance.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleMptoken)[sfConfidentialBalanceSpending] = std::move(*res);
}
@@ -255,7 +263,13 @@ ConfidentialMPTConvertBack::doApply()
auto res = homomorphicSubtract(
(*sleMptoken)[sfIssuerEncryptedBalance], ctx_.tx[sfIssuerEncryptedAmount]);
if (!res)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTConvertBack failed homomorphic subtract for issuer balance.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleMptoken)[sfIssuerEncryptedBalance] = std::move(*res);
}
@@ -265,7 +279,13 @@ ConfidentialMPTConvertBack::doApply()
auto res = homomorphicSubtract(
(*sleMptoken)[sfAuditorEncryptedBalance], ctx_.tx[sfAuditorEncryptedAmount]);
if (!res)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTConvertBack failed homomorphic subtract for auditor balance.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleMptoken)[sfAuditorEncryptedBalance] = std::move(*res);
}

View File

@@ -1,5 +1,6 @@
#include <xrpl/tx/transactors/token/ConfidentialMPTMergeInbox.h>
#include <xrpl/basics/Log.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ReadView.h>
@@ -101,7 +102,13 @@ ConfidentialMPTMergeInbox::doApply()
auto sum = homomorphicAdd(
(*sleMptoken)[sfConfidentialBalanceSpending], (*sleMptoken)[sfConfidentialBalanceInbox]);
if (!sum)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTMergeInbox failed homomorphic add for inbox merge.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleMptoken)[sfConfidentialBalanceSpending] = std::move(*sum);

View File

@@ -1,5 +1,6 @@
#include <xrpl/tx/transactors/token/ConfidentialMPTSend.h>
#include <xrpl/basics/Log.h>
#include <xrpl/basics/Slice.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ReadView.h>
@@ -306,7 +307,13 @@ ConfidentialMPTSend::doApply()
auto const curSpending = (*sleSenderMPToken)[sfConfidentialBalanceSpending];
auto newSpending = homomorphicSubtract(curSpending, senderEc);
if (!newSpending)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTSend failed homomorphic subtract for sender spending balance.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleSenderMPToken)[sfConfidentialBalanceSpending] = std::move(*newSpending);
}
@@ -316,7 +323,13 @@ ConfidentialMPTSend::doApply()
auto const curIssuerEnc = (*sleSenderMPToken)[sfIssuerEncryptedBalance];
auto newIssuerEnc = homomorphicSubtract(curIssuerEnc, issuerEc);
if (!newIssuerEnc)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTSend failed homomorphic subtract for sender issuer balance.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleSenderMPToken)[sfIssuerEncryptedBalance] = std::move(*newIssuerEnc);
}
@@ -327,7 +340,13 @@ ConfidentialMPTSend::doApply()
auto const curAuditorEnc = (*sleSenderMPToken)[sfAuditorEncryptedBalance];
auto newAuditorEnc = homomorphicSubtract(curAuditorEnc, *auditorEc);
if (!newAuditorEnc)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTSend failed homomorphic subtract for sender auditor balance.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleSenderMPToken)[sfAuditorEncryptedBalance] = std::move(*newAuditorEnc);
}
@@ -342,7 +361,13 @@ ConfidentialMPTSend::doApply()
auto const curInbox = (*sleDestinationMPToken)[sfConfidentialBalanceInbox];
auto newInbox = homomorphicAdd(curInbox, *rerandomizedDestEc);
if (!newInbox)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTSend failed homomorphic add for destination inbox.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleDestinationMPToken)[sfConfidentialBalanceInbox] = std::move(*newInbox);
}
@@ -357,7 +382,13 @@ ConfidentialMPTSend::doApply()
auto const curIssuerEnc = (*sleDestinationMPToken)[sfIssuerEncryptedBalance];
auto newIssuerEnc = homomorphicAdd(curIssuerEnc, *rerandomizedIssuerEc);
if (!newIssuerEnc)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTSend failed homomorphic add for destination issuer balance.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleDestinationMPToken)[sfIssuerEncryptedBalance] = std::move(*newIssuerEnc);
}
@@ -373,7 +404,13 @@ ConfidentialMPTSend::doApply()
auto const curAuditorEnc = (*sleDestinationMPToken)[sfAuditorEncryptedBalance];
auto newAuditorEnc = homomorphicAdd(curAuditorEnc, *rerandomizedAuditorEc);
if (!newAuditorEnc)
return tecINTERNAL; // LCOV_EXCL_LINE
{
// LCOV_EXCL_START
JLOG(ctx_.journal.error())
<< "ConfidentialMPTSend failed homomorphic add for destination auditor balance.";
return tecINTERNAL;
// LCOV_EXCL_STOP
}
(*sleDestinationMPToken)[sfAuditorEncryptedBalance] = std::move(*newAuditorEnc);
}

View File

@@ -5029,6 +5029,24 @@ class Invariants_test : public beast::unit_test::Suite
{tecINVARIANT_FAILED, tecINVARIANT_FAILED},
precloseConfidential);
doInvariantCheck(
{"MPToken encrypted field existence inconsistency"},
[&mptID](Account const& a1, Account const& a2, ApplyContext& ac) {
auto sleToken = ac.view().peek(keylet::mptoken(mptID, a2.id()));
if (!sleToken)
return false;
sleToken->makeFieldAbsent(sfIssuerEncryptedBalance);
sleToken->makeFieldAbsent(sfConfidentialBalanceInbox);
sleToken->makeFieldAbsent(sfConfidentialBalanceSpending);
sleToken->setFieldVL(sfAuditorEncryptedBalance, Blob{0x00});
ac.view().update(sleToken);
return true;
},
XRPAmount{},
STTx{ttMPTOKEN_AUTHORIZE, [](STObject&) {}},
{tecINVARIANT_FAILED, tecINVARIANT_FAILED},
precloseConfidential);
// requiresPrivacyFlag
auto const precloseNoPrivacy = [&mptID](
Account const& a1, Account const& a2, Env& env) -> bool {