hiero-ledger / hiero-ledger/hiero-consensus-node
Refactor single-field update check in our codebase.
- Dominant language
- Java
- Stars
- 406
- Forks
- 226
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 210
Description
### Background
Currently, there are code sections that check if only a single field in the `transactionBody` is updated by explicitly verifying that one target field is non-null and all other known fields are null, e.g. `NodeUpdateHandler.onlyUpdatesAccountID()`
```
private boolean onlyUpdatesAccountID(@NonNull final NodeUpdateTransactionBody op) {
return op.hasAccountId()
&& !op.hasDescription()
&& !op.hasAdminKey()
&& op.gossipEndpoint().isEmpty()
&& op.serviceEndpoint().isEmpty()
&& !op.hasGossipCaCertificate()
&& !op.hasGrpcCertificateHash()
&& !op.hasDeclineReward()
&& !op.hasGrpcProxyEndpoint();
}
```
This approach requires updating the condition every time a new field is added to the `transactionBody`, which is error-prone and often missed.
Currently identified places where this should be fixed
1. `NodeUpdateHandler::onlyUpdatesAccountID`
2. `FileUpdateHandler::wantsToMutateNonExpiryField`
3. `ConsensusUpdateTopicHandler::wantsToMutateNonExpiryField`
Example for a fix: https://github.com/hiero-ledger/hiero-consensus-node/pull/22471
### Acceptance Criteria
- Replace all existing single-field update checks with a centralized method that dynamically verifies exactly one field is updated.
- The new method must automatically account for any new fields added to the `transactionBody` without requiring manual updates.
- Unit tests covering existing and new field scenarios are added or updated to verify correct single-field detection.
### Dependencies
_No response_
### Definition of Ready (DoR) Checklist
- [ ] Clear acceptance criteria
- [ ] Clear and detailed description
- [ ] Dependencies identified
- [ ] Links to documentation
- [ ] Should be completable in 2-3 Days
- [ ] Initial draft of Low-level design document
- [ ] At least high level test plan
- [ ] Groomed/Estimated
### Definition of Done (DoD) Checklist
- [ ] Acceptance Criteria complete
- [ ] No Codacy issues greater than minor (in new code)
- [ ] JavaDocs updated/created
- [ ] Code commented
- [ ] Unit tests created/updated
- [ ] 80% test code coverage (in new code)
- [ ] Happy Path and major negative cases in HAPI tests as applicable
Contributor guide
Assessment
This issue has not been assessed yet.