fix(jsonrpc): accept "input" as alias for "data" in call args#6722
Open
waynercheung wants to merge 1 commit intotronprotocol:developfrom
Open
fix(jsonrpc): accept "input" as alias for "data" in call args#6722waynercheung wants to merge 1 commit intotronprotocol:developfrom
waynercheung wants to merge 1 commit intotronprotocol:developfrom
Conversation
426eb5f to
0b55d1a
Compare
Closes tronprotocol#6517. JSON-RPC requests using the execution-apis field name `input` were rejected with UnrecognizedPropertyException, blocking spec-compliant clients -- notably go-ethereum's ethclient since ethereum/go-ethereum#28078, which only emits `input`. CallArguments and BuildArguments now declare both fields. A new resolveData() does pure precedence resolution -- `input` wins over `data` -- mirroring go-ethereum's TransactionArgs.data(). Five call sites in TronJsonRpcImpl use the resolver instead of getData(). The verb-prefix name (not getXxx) keeps Jackson and FastJSON's JavaBean introspection from picking the method up as a `resolveData` wire property; two serialisation tests pin this as a regression guard. Hex validation is mode-driven via JsonRpcApiUtil.requireValidHex (HexMode.STRICT / HexMode.LENIENT): - `input` (new field) is STRICT: follows the execution-apis BYTES schema -- requires `0x` prefix and even length; "" is accepted as empty bytes per geth's hexutil.Bytes.UnmarshalText. - `data` retains LENIENT parsing via ByteArray.fromHexString for backward compatibility with existing callers (e.g. BuildTransactionTest.testCreateSmartContract uses bare-hex bytecode). Conflict between `input` and `data` (both set, not equal) is detected on the build path at BuildArguments.getContractType(), mirroring geth's data() / setDefaults split. The error message matches go-ethereum's setDefaults wording verbatim. Comparison is byte-level so case differences are not flagged. The query path (CallArguments.resolveData()) stays lenient -- input wins silently. Tested by 52 unit tests including Jackson/FastJSON serialisation safety guards; BuildTransactionTest.testCreateSmartContract still passes; checkstyle clean.
0b55d1a to
8df76fe
Compare
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?
Accept
inputalongsidedataoneth_call,eth_estimateGas, andbuildTransactioncall arguments, matching the Ethereum execution-apis spec and resolving #6517.input(raw field) toCallArgumentsandBuildArguments.resolveData()- pure precedence resolution withinputwinning overdata, mirroring go-ethereum'sTransactionArgs.data().inputanddata(both set, not equal) are detected atBuildArguments.getContractType()- mirroring geth'sdata()/setDefaultssplit. The error message uses go-ethereum's wording verbatim. The query path stays lenient (inputwins silently).TronJsonRpcImplfromgetData()toresolveData().JsonRpcApiUtil.requireValidHex(HexMode.STRICT/HexMode.LENIENT):inputis STRICT: follows the execution-apis BYTES schema (^0x[0-9a-f]*$, even length;""is accepted as empty bytes per geth'shexutil.Bytes.UnmarshalText).datakeeps LENIENT parsing viaByteArray.fromHexString(accepts bare hex and odd length) for backward compatibility with existing callers - notablyBuildTransactionTest.testCreateSmartContract, which submits bare-hex bytecode.resolveData()- verb prefix, notgetXxx- so Jackson's and FastJSON's JavaBean introspection skips it with no per-serializer annotations needed.CallArguments7->8 args,BuildArguments16->17 args). The named-JSON deserialisation path is unaffected.Why are these changes required?
The Ethereum execution-apis spec uses
inputas the canonical calldata field;datais the legacy alias. go-ethereum accepts both, withinputwinning when equal and erroring when not. Notably, go-ethereum'sethclienthas emitted onlyinputsince ethereum/go-ethereum#28078, so any tron RPC user upgrading their geth client side hits this.Before this PR, java-tron only read
data. A spec-compliant client carrying onlyinputfailed two ways:FAIL_ON_UNKNOWN_PROPERTIES=true), returning-32603instead of executing the call.to) trippedinvalid json requestbecause calldata appeared absent.Both symptoms are captured in #6517.
This PR has been tested by:
CallArgumentsTest(23 tests) +BuildArgumentsTest(29 tests) = 52 total. Coverage:inputonly,dataonly, neither.CallArgumentsreturnsinputsilently;BuildArguments.getContractType()throws with geth-equivalent wording.""is presence (matches geth).0x(zero-length payload) is presence and never collapses to absent.0xDEAD == 0xdead).inputvalidation rejects bare hex, odd length, non-hex chars.datavalidation still accepts bare hex and odd length;BuildTransactionTest.testCreateSmartContractstill passes.datais rejected even wheninputis the precedence winner, and vice versa.resolveDatanever appears as a wire property and serialisation never throws even with conflictinginput/data(regression guard for the verb-prefix naming).inputfield foreth_call? #6517 reproductions: Jackson deserialisation of{"input": "0xdeadbeef"}succeeds; contract-creation viainput(noto) resolves toCreateSmartContract.Follow up
inputanddatapayloads. Useful but not blocking - the unit-level path is fully covered.ByteArray.fromHexStringto the execution-apis BYTES schema, then drop the asymmetric branch inrequireValidHex. Behaviour-changing for non-RPC callers, so deferred to a separate change.