Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOUIssuerWeakTSH [DO NOT MERGE] #388

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ git-subtree. See those directories' README files for more details.
- [explorer.xahau.network](https://explorer.xahau.network)
- **Testnet & Faucet**: Test applications and obtain test XAH at [xahau-test.net](https://xahau-test.net) and use the testnet explorer at [explorer.xahau.network](https://explorer.xahau.network).
- **Supporting Wallets**: A list of wallets that support XAH and Xahau-based assets.
- [Xumm](https://xumm.app)
- [Xaman](https://xaman.app)
- [Crossmark](https://crossmark.io)
92 changes: 90 additions & 2 deletions 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 @@ -111,6 +112,21 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)
}
}
}

if (iouIssuerWeakTSH && tx.isFieldPresent(sfAmounts))
{
STArray const& sEntries(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 @@ -363,16 +398,36 @@ getTransactionalStakeHolders(STTx const& tx, ReadView const& rv)

// simple two party transactions
case ttPAYMENT:
case ttESCROW_CREATE:
case ttCHECK_CREATE:
case ttACCOUNT_DELETE:
case ttPAYCHAN_CREATE:
case ttINVOKE: {
if (destAcc)
ADD_TSH(*destAcc, tshSTRONG);
break;
}

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

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 +476,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 +501,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 +523,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 +544,18 @@ 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)
{
// ttCHECK_CASH have sfAmount optionally but only check
// check object
auto const amount = check->getFieldAmount(sfSendMax);
if (!isXRP(amount))
ADD_TSH(amount.getIssuer(), tshWEAK);
}
}
break;
}

Expand Down
8 changes: 7 additions & 1 deletion src/ripple/app/tx/impl/Transactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,8 +1465,14 @@ 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);
AccountID const& holder = amt >= beast::zero ? lowAcc : highAcc;
AccountID const& issuer = amt >= beast::zero ? highAcc : lowAcc;

additionalWeakTSH_.emplace(holder);
if (ctx_.view().rules().enabled(featureIOUIssuerWeakTSH))
additionalWeakTSH_.emplace(issuer);
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/ripple/nodestore/impl/Shard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,7 @@ Shard::finalize(bool writeSQLite, std::optional<uint256> const& referenceHash)
if (writeSQLite && !storeSQLite(ledger))
return fail("failed storing to SQLite databases");

assert(
ledger->info().seq == ledgerSeq &&
(ledger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
ledger->read(keylet::fees())));
assert(ledger->info().seq == ledgerSeq && ledger->read(keylet::fees()));

hash = ledger->info().parentHash;
next = std::move(ledger);
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 = 74;
static constexpr std::size_t numFeatures = 75;

/** 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 @@ -362,6 +362,7 @@ extern uint256 const fix240819;
extern uint256 const fixPageCap;
extern uint256 const fix240911;
extern uint256 const fixFloatDivide;
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 @@ -468,6 +468,7 @@ REGISTER_FIX (fix240819, Supported::yes, VoteBehavior::De
REGISTER_FIX (fixPageCap, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fix240911, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fixFloatDivide, 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
Loading
Loading