From 152db53a4fba6dcb7fa7503addbb0f2e736a8631 Mon Sep 17 00:00:00 2001 From: tequ Date: Wed, 22 Oct 2025 15:43:35 +0900 Subject: [PATCH] address reviews --- src/ripple/app/tx/impl/SetAccount.cpp | 16 ++++++++++------ src/ripple/protocol/impl/TER.cpp | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ripple/app/tx/impl/SetAccount.cpp b/src/ripple/app/tx/impl/SetAccount.cpp index 712192100..a489a7840 100644 --- a/src/ripple/app/tx/impl/SetAccount.cpp +++ b/src/ripple/app/tx/impl/SetAccount.cpp @@ -658,15 +658,15 @@ SetAccount::doApply() // HookStateScale if (tx.isFieldPresent(sfHookStateScale)) { - uint16_t const scale = tx.getFieldU16(sfHookStateScale); + uint16_t const newScale = tx.getFieldU16(sfHookStateScale); uint16_t const oldScale = sle->isFieldPresent(sfHookStateScale) ? sle->getFieldU16(sfHookStateScale) : 1; - if (scale == oldScale) + if (newScale == oldScale) { // do nothing } - else if (scale == 1) + else if (newScale == 1) { sle->makeFieldAbsent(sfHookStateScale); } @@ -676,8 +676,12 @@ SetAccount::doApply() uint32_t const stateCount = sle->getFieldU32(sfHookStateCount); uint32_t const oldOwnerCount = sle->getFieldU32(sfOwnerCount); - uint32_t const newOwnerCount = - oldOwnerCount - (oldScale * stateCount) + (scale * stateCount); + uint32_t const newOwnerCount = oldOwnerCount - + (oldScale * stateCount) + (newScale * stateCount); + + // sanity check + // if stateCount == 0, then newOwnerCount == oldOwnerCount + assert(newOwnerCount >= oldOwnerCount); STAmount const balance = STAmount((*sle)[sfBalance]).xrp(); XRPAmount const reserve = @@ -689,7 +693,7 @@ SetAccount::doApply() adjustOwnerCount( view(), sle, newOwnerCount - oldOwnerCount, j_); - sle->setFieldU16(sfHookStateScale, scale); + sle->setFieldU16(sfHookStateScale, newScale); } } diff --git a/src/ripple/protocol/impl/TER.cpp b/src/ripple/protocol/impl/TER.cpp index 3edea1147..08992c6a3 100644 --- a/src/ripple/protocol/impl/TER.cpp +++ b/src/ripple/protocol/impl/TER.cpp @@ -94,7 +94,7 @@ transResults() MAKE_ERROR(tecINSUF_RESERVE_SELLER, "The seller of an object has insufficient reserves, and thus cannot complete the sale."), MAKE_ERROR(tecIMMUTABLE, "The remark is marked immutable on the object, and therefore cannot be updated."), MAKE_ERROR(tecTOO_MANY_REMARKS, "The number of remarks on the object would exceed the limit of 32."), - MAKE_ERROR(tecHAS_HOOK_STATE, "The account has hook state. Delete all existing state first."), + MAKE_ERROR(tecHAS_HOOK_STATE, "Delete all hook state before reducing scale"), MAKE_ERROR(tefALREADY, "The exact transaction was already in this ledger."), MAKE_ERROR(tefBAD_ADD_AUTH, "Not authorized to add account."),