From 247c17215c31eac034b7a1608a09100c6c6aa9ae Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Fri, 15 Mar 2024 03:02:02 +0000 Subject: [PATCH] inital version of touch amendment --- src/ripple/app/tx/impl/Transactor.cpp | 27 ++++++++++++++++++++++ src/ripple/protocol/Feature.h | 3 ++- src/ripple/protocol/SField.h | 1 + src/ripple/protocol/impl/Feature.cpp | 1 + src/ripple/protocol/impl/LedgerFormats.cpp | 1 + src/ripple/protocol/impl/SField.cpp | 1 + 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/ripple/app/tx/impl/Transactor.cpp b/src/ripple/app/tx/impl/Transactor.cpp index 0c35154e5..75b2d9a5c 100644 --- a/src/ripple/app/tx/impl/Transactor.cpp +++ b/src/ripple/app/tx/impl/Transactor.cpp @@ -1079,6 +1079,31 @@ Transactor::checkMultiSign(PreclaimContext const& ctx) //------------------------------------------------------------------------------ +// increment the touch counter on an account +static void +touchAccount( + ApplyView& view, + AccountID const& id, + std::optional> sle) +{ + if (!view.rules().enabled(featureTouch)) + return; + + if (!sle) + *sle = view.peek(keylet::account(id)); + + if (!(*sle)) + return; + + uint64_t tc = (*sle)->isFieldPresent(sfTouchCount) + ? (*sle)->getFieldU64(sfTouchCount) + : 0; + + (*sle)->setFieldU64(sfTouchCount, tc + 1); + + view.update(*sle); +} + static void removeUnfundedOffers( ApplyView& view, @@ -1511,6 +1536,8 @@ Transactor::doTSH( if ((!canRollback && strong) || (canRollback && !strong)) continue; + touchAccount(view, tshAccountID, {}); + auto klTshHook = keylet::hook(tshAccountID); auto tshHook = view.read(klTshHook); diff --git a/src/ripple/protocol/Feature.h b/src/ripple/protocol/Feature.h index d6e3c3eea..be5e920ee 100644 --- a/src/ripple/protocol/Feature.h +++ b/src/ripple/protocol/Feature.h @@ -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 = 68; +static constexpr std::size_t numFeatures = 69; /** Amendments that this server supports and the default voting behavior. Whether they are enabled depends on the Rules defined in the validated @@ -356,6 +356,7 @@ extern uint256 const featureHooksUpdate1; extern uint256 const fixXahauV1; extern uint256 const fixXahauV2; extern uint256 const featureRemit; +extern uint256 const featureTouch; } // namespace ripple diff --git a/src/ripple/protocol/SField.h b/src/ripple/protocol/SField.h index 1f9d15368..0fc34ce09 100644 --- a/src/ripple/protocol/SField.h +++ b/src/ripple/protocol/SField.h @@ -433,6 +433,7 @@ extern SF_UINT64 const sfReferenceCount; extern SF_UINT64 const sfRewardAccumulator; extern SF_UINT64 const sfAccountCount; extern SF_UINT64 const sfAccountIndex; +extern SF_UINT64 const sfTouchCount; // 128-bit extern SF_UINT128 const sfEmailHash; diff --git a/src/ripple/protocol/impl/Feature.cpp b/src/ripple/protocol/impl/Feature.cpp index 565aa0eab..8cd196bfc 100644 --- a/src/ripple/protocol/impl/Feature.cpp +++ b/src/ripple/protocol/impl/Feature.cpp @@ -462,6 +462,7 @@ REGISTER_FEATURE(HooksUpdate1, Supported::yes, VoteBehavior::De REGISTER_FIX (fixXahauV1, Supported::yes, VoteBehavior::DefaultNo); REGISTER_FIX (fixXahauV2, Supported::yes, VoteBehavior::DefaultNo); REGISTER_FEATURE(Remit, Supported::yes, VoteBehavior::DefaultNo); +REGISTER_FEATURE(Touch, Supported::yes, VoteBehavior::DefaultNo); // The following amendments are obsolete, but must remain supported // because they could potentially get enabled. diff --git a/src/ripple/protocol/impl/LedgerFormats.cpp b/src/ripple/protocol/impl/LedgerFormats.cpp index acb07c489..4fbcb961a 100644 --- a/src/ripple/protocol/impl/LedgerFormats.cpp +++ b/src/ripple/protocol/impl/LedgerFormats.cpp @@ -66,6 +66,7 @@ LedgerFormats::LedgerFormats() {sfGovernanceFlags, soeOPTIONAL}, {sfGovernanceMarks, soeOPTIONAL}, {sfAccountIndex, soeOPTIONAL}, + {sfTouchCount, soeOPTIONAL}, }, commonFields); diff --git a/src/ripple/protocol/impl/SField.cpp b/src/ripple/protocol/impl/SField.cpp index a72208607..3dee6b3a4 100644 --- a/src/ripple/protocol/impl/SField.cpp +++ b/src/ripple/protocol/impl/SField.cpp @@ -183,6 +183,7 @@ CONSTRUCT_TYPED_SFIELD(sfEmitBurden, "EmitBurden", UINT64, CONSTRUCT_TYPED_SFIELD(sfHookInstructionCount, "HookInstructionCount", UINT64, 17); CONSTRUCT_TYPED_SFIELD(sfHookReturnCode, "HookReturnCode", UINT64, 18); CONSTRUCT_TYPED_SFIELD(sfReferenceCount, "ReferenceCount", UINT64, 19); +CONSTRUCT_TYPED_SFIELD(sfTouchCount, "TouchCount", UINT64, 97); CONSTRUCT_TYPED_SFIELD(sfAccountIndex, "AccountIndex", UINT64, 98); CONSTRUCT_TYPED_SFIELD(sfAccountCount, "AccountCount", UINT64, 99); CONSTRUCT_TYPED_SFIELD(sfRewardAccumulator, "RewardAccumulator", UINT64, 100);