Skip to content

Commit

Permalink
create fix amendment for adding sfPreviousTxnID/`sfPreviousTxnLgrSe…
Browse files Browse the repository at this point in the history
…q` everywhere
  • Loading branch information
mvadari committed Oct 5, 2023
1 parent f0a7861 commit e9c9c47
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/ripple/ledger/detail/ApplyStateTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ class ApplyStateTable
using Mods = hash_map<key_type, std::shared_ptr<SLE>>;

static void
threadItem(TxMeta& meta, std::shared_ptr<SLE> const& to);
threadItem(
TxMeta& meta,
std::shared_ptr<SLE> const& to,
ReadView const& view);

std::shared_ptr<SLE>
getForMod(
Expand Down
24 changes: 19 additions & 5 deletions src/ripple/ledger/impl/ApplyStateTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#include <ripple/json/to_string.h>
#include <ripple/ledger/detail/ApplyStateTable.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/LedgerFormats.h>
#include <ripple/protocol/st.h>
#include <cassert>
#include <set>

namespace ripple {
namespace detail {
Expand Down Expand Up @@ -191,7 +193,7 @@ ApplyStateTable::apply(

if (curNode->isThreadedType()) // thread transaction to node
// item modified
threadItem(meta, curNode);
threadItem(meta, curNode, to);

STObject prevs(sfPreviousFields);
for (auto const& obj : *origNode)
Expand Down Expand Up @@ -225,7 +227,7 @@ ApplyStateTable::apply(
threadOwners(to, meta, curNode, newMod, j);

if (curNode->isThreadedType()) // always thread to self
threadItem(meta, curNode);
threadItem(meta, curNode, to);

STObject news(sfNewFields);
for (auto const& obj : *curNode)
Expand Down Expand Up @@ -520,12 +522,24 @@ ApplyStateTable::destroyXRP(XRPAmount const& fee)

// Insert this transaction to the SLE's threading list
void
ApplyStateTable::threadItem(TxMeta& meta, std::shared_ptr<SLE> const& sle)
ApplyStateTable::threadItem(
TxMeta& meta,
std::shared_ptr<SLE> const& sle,
ReadView const& view)
{
key_type prevTxID;
LedgerIndex prevLgrID;

if (!sle->thread(meta.getTxID(), meta.getLgrSeq(), prevTxID, prevLgrID))
static std::set<LedgerEntryType> newPreviousTxnIDTypes = {
ltDIR_NODE, ltAMENDMENTS, ltFEE_SETTINGS, ltNEGATIVE_UNL, ltAMM};
bool const includePrevTxnID = view.rules().enabled(fixPreviousTxnID) ||
!newPreviousTxnIDTypes.count(sle->getType());
if (!sle->thread(
meta.getTxID(),
meta.getLgrSeq(),
prevTxID,
prevLgrID,
includePrevTxnID))
return;

if (!prevTxID.isZero())
Expand Down Expand Up @@ -610,7 +624,7 @@ ApplyStateTable::threadTx(
JLOG(j.warn()) << "Threading to non-existent account: " << toBase58(to);
return;
}
threadItem(meta, sle);
threadItem(meta, sle, base);
}

void
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 = 62;
static constexpr std::size_t numFeatures = 63;

/** 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 @@ -349,6 +349,7 @@ extern uint256 const fixNFTokenRemint;
extern uint256 const fixReducedOffersV1;
extern uint256 const featureClawback;
extern uint256 const featureXChainBridge;
extern uint256 const fixPreviousTxnID;

} // namespace ripple

Expand Down
3 changes: 2 additions & 1 deletion src/ripple/protocol/STLedgerEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class STLedgerEntry final : public STObject, public CountedObject<STLedgerEntry>
uint256 const& txID,
std::uint32_t ledgerSeq,
uint256& prevTxID,
std::uint32_t& prevLedgerID);
std::uint32_t& prevLedgerID,
bool const includePrevTxnID);

private:
/* Make STObject comply with the template for this SLE type
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 @@ -456,6 +456,7 @@ REGISTER_FIX (fixReducedOffersV1, Supported::yes, VoteBehavior::De
REGISTER_FEATURE(Clawback, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(AMM, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(XChainBridge, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixPreviousTxnID, Supported::yes, VoteBehavior::DefaultNo);

// The following amendments are obsolete, but must remain supported
// because they could potentially get enabled.
Expand Down
10 changes: 10 additions & 0 deletions src/ripple/protocol/impl/LedgerFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ LedgerFormats::LedgerFormats()
{sfIndexNext, soeOPTIONAL},
{sfIndexPrevious, soeOPTIONAL},
{sfNFTokenID, soeOPTIONAL},
{sfPreviousTxnID, soeOPTIONAL},
{sfPreviousTxnLgrSeq, soeOPTIONAL},
},
commonFields);

Expand Down Expand Up @@ -142,6 +144,8 @@ LedgerFormats::LedgerFormats()
{
{sfAmendments, soeOPTIONAL}, // Enabled
{sfMajorities, soeOPTIONAL},
{sfPreviousTxnID, soeOPTIONAL},
{sfPreviousTxnLgrSeq, soeOPTIONAL},
},
commonFields);

Expand All @@ -157,6 +161,8 @@ LedgerFormats::LedgerFormats()
{sfBaseFeeDrops, soeOPTIONAL},
{sfReserveBaseDrops, soeOPTIONAL},
{sfReserveIncrementDrops, soeOPTIONAL},
{sfPreviousTxnID, soeOPTIONAL},
{sfPreviousTxnLgrSeq, soeOPTIONAL},
},
commonFields);

Expand Down Expand Up @@ -240,6 +246,8 @@ LedgerFormats::LedgerFormats()
{sfDisabledValidators, soeOPTIONAL},
{sfValidatorToDisable, soeOPTIONAL},
{sfValidatorToReEnable, soeOPTIONAL},
{sfPreviousTxnID, soeOPTIONAL},
{sfPreviousTxnLgrSeq, soeOPTIONAL},
},
commonFields);

Expand Down Expand Up @@ -280,6 +288,8 @@ LedgerFormats::LedgerFormats()
{sfAsset, soeREQUIRED},
{sfAsset2, soeREQUIRED},
{sfOwnerNode, soeREQUIRED},
{sfPreviousTxnID, soeOPTIONAL},
{sfPreviousTxnLgrSeq, soeOPTIONAL},
},
commonFields);

Expand Down
10 changes: 7 additions & 3 deletions src/ripple/protocol/impl/STLedgerEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ STLedgerEntry::thread(
uint256 const& txID,
std::uint32_t ledgerSeq,
uint256& prevTxID,
std::uint32_t& prevLedgerID)
std::uint32_t& prevLedgerID,
bool const includePrevTxnID)
{
uint256 oldPrevTxID = getFieldH256(sfPreviousTxnID);

Expand All @@ -149,8 +150,11 @@ STLedgerEntry::thread(

prevTxID = oldPrevTxID;
prevLedgerID = getFieldU32(sfPreviousTxnLgrSeq);
setFieldH256(sfPreviousTxnID, txID);
setFieldU32(sfPreviousTxnLgrSeq, ledgerSeq);
if (includePrevTxnID)
{
setFieldH256(sfPreviousTxnID, txID);
setFieldU32(sfPreviousTxnLgrSeq, ledgerSeq);
}
return true;
}

Expand Down

0 comments on commit e9c9c47

Please sign in to comment.