refactor(trie): remove unused RLP utilities - #21
Open
Sunny6889 wants to merge 1 commit into
Open
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Removes the RLP utilities under
framework/src/main/java/org/tron/core/capsule/utilsthat nothing calls, and reduces the one that is still needed to the part that is actually used.RLP (Recursive Length Prefix) is Ethereum's serialization format. It arrived with the original ethereumJ fork; TRON serializes its own transactions, blocks and accounts with protobuf, so RLP has no place in consensus or state. The only remaining consumer is
org.tron.core.trie.TrieImpl, which needs it because the trie node layout it implements is defined in terms of RLP-encoded lists.RLPElement,RLPItem,RLPList,DecodeResult(reachable only from the removedRLPmethods), andTxInputUtil/TxOutputUtil(leftovers from the UTXO-era code), plus their four tests.RLP.javafrom 1216 lines to 284.TrieImpluses four entry points out of 34 public methods; taking the reachability closure from those leaves six constants,decodeLazyList,verifyLength, bothencodeListoverloads and the nestedLList. The other 30 methods go.FastByteComparisons.org.tron.common.utils.FastByteComparisonsalready exists and is what nine other files use; the copy undercapsule/utilshad two consumers.TrieImplnow calls the common one.capsule/utilsgoes from eight files to one. 15 files changed, +52 / −1509.Why are these changes required?
Most of this code has never had a caller in TRON. Carrying a full RLP codec — a second serialization format, in a package named for capsule utilities — costs review attention on every audit, keeps test surface alive for code that cannot run, and blurs where the trie's dependencies actually begin.
Behaviour: unchanged.
The change is a deletion, not a rewrite. Two properties were checked rather than assumed:
RLP.javais byte-identical to the previous version. The parameter lists and bodies of all nine retained methods (including all four overloads) and the values of the six retained constants were compared against the pre-change file; none was rewritten. The encoder therefore produces the same bytes, and account-state root hashes cannot move.FastByteComparisonsare the same implementation. Normalising away package, imports and the method name (equalBytevsisEqual), the two files are identical, comparer holder included. This matters becauseTrieImpluses it to compare root hashes.The trie itself sits behind
allowAccountStateRoot, which defaults to0and has never been enabled on mainnet — but it still runs when the flag is on, which is why the change had to be equivalence-preserving rather than merely compiling.This PR has been tested by:
TrieTest(7) — the trie's own behaviour test, including root-hash order independence and proof verification.ManagerTest(36) andHistoryBlockHashIntegrationTest(16) — cover theAccountStateCallBack/AccountStateStoreTriepath that reachesRLP.SupplementTest(3) — the coverage test that called the removed decode methods../gradlew :framework:checkstyleMain :framework:checkstyleTest.Follow up
org.tron.core.trieand theaccountStateRootmachinery above it are deliberately out of scope. Removing them would touchManager,ChainBaseManagerand the DB stores, which is a different risk class, and the historical-state work under design covers the same area — this PR leaves that decision open rather than pre-empting it.Extra details
Two things worth knowing for review:
encodeListoverloads are needed.TrieImplpassesObject[](Node.children,hashArray), which bindsencodeList(Object...); the retainedLList.getEncoded()passesbyte[][], which bindsencodeList(byte[]...). Keeping only one changes which method the trie calls.TrieTestusedRLP.encodeIntonly to build keys, but not any replacement works. Line 49 putsnew byte[]{1}and the next line reads it back;encodeInt(1)returns the single byte[1], which is what made that pair match. It is nowByteUtil.intToBytesNoLeadZeroes, whose output is identical toRLP.encodeIntfor every key the test uses (all in 1..111), so the keys — and the root hashes asserted from them — are unchanged.