Skip to content

Commit

Permalink
IOUIssuerWeakTSH
Browse files Browse the repository at this point in the history
  • Loading branch information
tequdev committed Oct 29, 2024
1 parent 6b26045 commit 0031e2e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
80 changes: 79 additions & 1 deletion src/ripple/app/hook/impl/applyHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)

bool const fixV1 = rv.rules().enabled(fixXahauV1);
bool const fixV2 = rv.rules().enabled(fixXahauV2);
bool const iouIssuerWeakTSH = rv.rules().enabled(featureIOUIssuerWeakTSH);

switch (tt)
{
Expand Down Expand Up @@ -110,6 +111,21 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)
: tshWEAK);
}
}

if (iouIssuerWeakTSH)
{
STArray const& sEntries(ctx.tx.getFieldArray(sfAmounts));
for (STObject const& sEntry : sEntries)
{
STAmount const amount = sEntry.getFieldAmount(sfAmount);

if (!isXRP(amount))
{
ADD_TSH(amount.getIssuer(), tshWEAK);
continue;
}
}
}
}
break;
}
Expand Down Expand Up @@ -197,6 +213,13 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)
issuer,
(ut->getFlags() & lsfBurnable) ? tshSTRONG : tshWEAK);

if (iouIssuerWeakTSH)
{
STAmount const amount = ut->getFieldAmount(sfAmount);
if (!isXRP(amount))
ADD_TSH(amount.getIssuer(), tshWEAK);
}

break;
}

Expand Down Expand Up @@ -301,13 +324,25 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)
ADD_TSH(bo->getAccountID(sfOwner), tshSTRONG);
if (bo->isFieldPresent(sfDestination))
ADD_TSH(bo->getAccountID(sfDestination), tshSTRONG);
if (iouIssuerWeakTSH)
{
STAmount const amount = bo->getFieldAmount(sfAmount);
if (!isXRP(amount))
ADD_TSH(amount.getIssuer(), tshWEAK);
}
}

if (so)
{
ADD_TSH(so->getAccountID(sfOwner), tshSTRONG);
if (so->isFieldPresent(sfDestination))
ADD_TSH(so->getAccountID(sfDestination), tshSTRONG);
if (iouIssuerWeakTSH)
{
STAmount const amount = so->getFieldAmount(sfAmount);
if (!isXRP(amount))
ADD_TSH(amount.getIssuer(), tshWEAK);
}
}

break;
Expand Down Expand Up @@ -366,13 +401,25 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)
case ttESCROW_CREATE:
case ttCHECK_CREATE:
case ttACCOUNT_DELETE:
case ttPAYCHAN_CREATE:
case ttINVOKE: {
if (destAcc)
ADD_TSH(*destAcc, tshSTRONG);
break;
}

case ttPAYCHAN_CREATE: {
if (destAcc)
ADD_TSH(*destAcc, tshSTRONG);

if (iouIssuerWeakTSH)
{
auto const amount = tx.getFieldAmount(sfAmount);
if (!isXRP(amount))
ADD_TSH(amount.getIssuer(), tshWEAK);
}
break;
}

case ttTRUST_SET: {
if (!tx.isFieldPresent(sfLimitAmount))
return {};
Expand Down Expand Up @@ -421,6 +468,13 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)
if (src != dst)
ADD_TSH(dst, tt == ttESCROW_FINISH ? tshSTRONG : tshWEAK);

if (iouIssuerWeakTSH)
{
auto const amount = escrow->getFieldAmount(sfAmount);
if (!isXRP(amount))
ADD_TSH(amount.getIssuer(), tshWEAK);
}

break;
}
// old logic
Expand All @@ -439,6 +493,13 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)
ADD_TSH(
escrow->getAccountID(sfDestination),
tt == ttESCROW_FINISH ? tshSTRONG : tshWEAK);

if (iouIssuerWeakTSH)
{
auto const amount = escrow->getFieldAmount(sfAmount);
if (!isXRP(amount))
ADD_TSH(amount.getIssuer(), tshWEAK);
}
break;
}
}
Expand All @@ -454,6 +515,13 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)

ADD_TSH(chan->getAccountID(sfAccount), tshSTRONG);
ADD_TSH(chan->getAccountID(sfDestination), tshWEAK);

if (iouIssuerWeakTSH)
{
auto const amount = chan->getFieldAmount(sfAmount);
if (!isXRP(amount))
ADD_TSH(amount.getIssuer(), tshWEAK);
}
break;
}

Expand All @@ -468,6 +536,16 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)

ADD_TSH(check->getAccountID(sfAccount), tshSTRONG);
ADD_TSH(check->getAccountID(sfDestination), tshWEAK);

if (tt == ttCHECK_CASH)
{
if (iouIssuerWeakTSH)
{
auto const amount = tx.getFieldAmount(sfSendMax);
if (!isXRP(amount))
ADD_TSH(amount.getIssuer(), tshWEAK);
}
}
break;
}

Expand Down
11 changes: 9 additions & 2 deletions src/ripple/app/tx/impl/Transactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,8 +1465,15 @@ Transactor::addWeakTSHFromSandbox(detail::ApplyViewBase const& pv)

AccountID const& lowAcc = std::get<0>(tpl);
AccountID const& highAcc = std::get<1>(tpl);
STAmount const& amt = entry.second;
additionalWeakTSH_.emplace(amt >= beast::zero ? lowAcc : highAcc);
if (ctx_.view().rules().enabled(featureIOUIssuerWeakTSH)){
additionalWeakTSH_.emplace(lowAcc);
additionalWeakTSH_.emplace(highAcc);
}
else
{
STAmount const& amt = entry.second;
additionalWeakTSH_.emplace(amt >= beast::zero ? lowAcc : highAcc);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 73;
static constexpr std::size_t numFeatures = 74;

/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
Expand Down Expand Up @@ -361,6 +361,7 @@ extern uint256 const fixNSDelete;
extern uint256 const fix240819;
extern uint256 const fixPageCap;
extern uint256 const fix240911;
extern uint256 const featureIOUIssuerWeakTSH;

} // namespace ripple

Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/impl/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ REGISTER_FIX (fixNSDelete, Supported::yes, VoteBehavior::De
REGISTER_FIX (fix240819, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fixPageCap, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fix240911, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FEATURE(IOUIssuerWeakTSH, Supported::yes, VoteBehavior::DefaultNo);

// The following amendments are obsolete, but must remain supported
// because they could potentially get enabled.
Expand Down

0 comments on commit 0031e2e

Please sign in to comment.