Sitelet https://github.com/tronprotocol/java-tron/pull/6991
Skip to content

refactor(trie): remove unused RLP utilities - #6991

Open
SeriousCoding789 wants to merge 3 commits into
tronprotocol:release_v4.8.3from
SeriousCoding789:clear_rlp
Open

SeriousCoding789 wants to merge 3 commits into
tronprotocol:release_v4.8.3from
SeriousCoding789:clear_rlp

Conversation

@SeriousCoding789

Copy link
Copy Markdown
Contributor

What does this PR do?

Removes the RLP utilities under framework/src/main/java/org/tron/core/capsule/utils that nothing calls, and trims the one file still in use down to what is actually reachable.

RLP is Ethereum's serialization format, inherited from the original ethereumJ fork. TRON serializes transactions, blocks and accounts with protobuf, so RLP has no role in them — a block's txTrieRoot is a plain SHA-256 Merkle tree (BlockCapsule.calcMerkleRoot → MerkleTree), which never touches RLP.

The one thing RLP is still needed for is accountStateRoot(not activated). That root is produced by org.tron.core.trie.TrieImpl, a Merkle Patricia Trie whose node layout is defined in terms of RLP-encoded lists, so the encoder has to stay to keep that format intact.

  • Deletes six unreferenced files: RLPElement, RLPItem, RLPList, DecodeResult (reachable only from the removed RLP methods), and TxInputUtil / TxOutputUtil (UTXO-era leftovers), plus their four tests.
  • Trims RLP.java from 1216 to 284 lines. TrieImpl uses four entry points; the reachability closure from those keeps six constants, EMPTY_ELEMENT_RLP, both encodeList overloads, decodeLazyList, verifyLength and the nested LList. The other 34 methods go.
  • Drops the duplicate FastByteComparisons. org.tron.common.utils.FastByteComparisons already exists and is what nine other files use; TrieImpl now calls it.

capsule/utils goes 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 second serialization codec, in a package named for capsule utilities, costs review attention on every audit and blurs where the trie's real dependencies begin.

Behaviour: unchanged.

Everything retained is what accountStateRoot depends on, so two properties were verified rather than assumed:

  • All retained members of RLP.java are byte-identical to the previous version. Both encodeList overloads, both decodeLazyList overloads, verifyLength, LList and its five methods, and all six constants were compared against the pre-change file; none was rewritten. The encoder emits the same bytes, so account-state root hashes cannot move.
  • The two FastByteComparisons are the same implementation. equalByte and isEqual are both b1.length == b2.length && compareTo(b1, 0, b1.length, b2, 0, b2.length) == 0, delegating to the same LexicographicalComparerHolder.BEST_COMPARER.

Tests: the four deleted tests covered only deleted classes. TrieTest gains a case for TrieImpl.equals, which is the one changed line the previous revision left uncovered.

@317787106

Copy link
Copy Markdown
Collaborator

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Tracking: code refactor and cleanup

3 participants