Repository navigation
feat(api): improve request handling and validation - #7022
Conversation
waynercheung
left a comment
There was a problem hiding this comment.
[SHOULD] The Compatibility section is still generic. Please list the concrete client-visible changes so operators and SDK maintainers can check their integrations:
- JsonFormat enforces a 100,000-token budget per parsed document, including the ABI strings parsed by
deploycontractand JSON-RPCbuildTransaction. - Form-encoded bodies have a fixed 1,000-entry limit, including repeated keys.
- Multi-contract requests are rejected earlier. Some HTTP arrays containing a valid contract and an unparseable or untyped contract previously had the latter silently dropped. Rejected multi-contract sign-weight/approval replies omit
transaction. When rejection happens inpackTransaction, HTTPbroadcasttransactionreturns an emptytxid. - gRPC
createCommonTransactionnow returnsCONTRACT_VALIDATE_ERRORfor zero or multiple contracts, instead of failing on an empty list or using only the first contract. Wallet.broadcastTransactionchecks the contract count before the expiration check and beforeManager's signature/permission validation. Its existing signature-length check still runs first.
I tested a local merge of f17a200 with release_v4.8.3 at 4c9b5f4 on JDK 17: no conflicts, and all 537 selected tests (the PR's test classes plus the JSON-RPC test packages) passed. The PR's listed CI checks also pass. Consensus validation rules and Manager's existing error message are unchanged, so no hard fork is required.
I recommend fixing the form-counting boundary before merging; the rest looks good to me.
[NIT] DecodeUtil.java:21 reports 42 as the expected byte length; please log ADDRESS_SIZE / 2 (21 bytes). If the shielded servlet re-wrap stays, a short comment explaining that clientMessage matches the exact exception class would help.
f17a200 to
6913441
Compare
|
@waynercheung
|
waynercheung
left a comment
There was a problem hiding this comment.
Thanks for the updates. The address-length log fix and the re-wrap comment look good. I accept the intentional raw-segment cap, and the remaining documentation and regression-test suggestions are non-blocking.
I tested a local merge of 6913441 with release_v4.8.3 at a901f85 on JDK 17: all 537 selected tests (the PR's test classes plus the JSON-RPC test packages) and framework Checkstyle pass.
There was a problem hiding this comment.
Two small simplification ideas:
- The inner try/catch blocks seem to exist because Util.clientMessage matches exact classes, so
ContractSizeNotEqualToOneExceptionwould otherwise become internal server error. Adding it to the clientMessage allow-list would let these servlets drop the innertry/catchand rely on the existingUtil.processError(e, response). - The same contract-count check and message formatting now appear in about six places (
packTransaction,broadcastTransaction,getTransactionApprovedList,getTransactionSignWeight,getShieldTransactionHash,createCommonTransaction). A shared helper, e.g.TransactionUtil.checkSingleContract(Transaction)plus a factory onContractSizeNotEqualToOneExceptionfor the message, could keep one definition of the rule; Manager can stay as is.
Thanks, I looked at both and would keep the current form:
|
1609c2d to
3fc7c35
Compare
|
Refactor only: the pack-and-catch for |
6506222 to
fd035ff
Compare
fd035ff to
81b51b2
Compare
| public static final String TX_RESULT_NULL = "TransactionResultCapsule is null"; | ||
| public static final String CONTRACT_NOT_EXIST = "No contract!"; | ||
| public static final String CONTRACT_SIZE_NOT_EQUAL_TO_ONE = | ||
| "contract size should be exactly 1, this is extend feature ,actual :%d"; |
There was a problem hiding this comment.
format error, modify it to contract size should be exactly 1. This is extend feature, actual :%d
There was a problem hiding this comment.
I think we should keep it as before in Manager.processTransaction
On This is a breaking change for HTTP clients. Up to v4.8.2.3 there was no switch and single-digit keys were always resolved, and #7028 added the switch a day earlier with I understand the concern behind the change: a numeric key can override a value that the named-field checks would have filtered, as the So I wouldn't recommend flipping the default directly in this PR, and would keep |
|
@SeriousCoding789
Agreed on the release notes: 4.8.3 will list this as a behavior change for HTTP clients, with |
| TransactionSignWeight.Builder tswBuilder = TransactionSignWeight.newBuilder(); | ||
| Result.Builder resultBuilder = Result.newBuilder(); | ||
| int contractCount = trx.getRawData().getContractCount(); | ||
| if (contractCount > 1) { |
There was a problem hiding this comment.
[NIT] Why not change to contractCount != 1 ?
There was a problem hiding this comment.
> 1 is on purpose: zero contracts keep the existing handling further down (Invalid transaction: no valid contract, with transaction in the reply, after the signature-count check), so this PR only adds the rejection for more than one contract and leaves the zero-contract response unchanged. A zero count also usually means packTransaction dropped contracts it couldn't parse, where "no valid contract" is the more accurate message. Wallet.getTransactionApprovedList follows the same split.
|
Follow-up (P2P side): this PR adds up-front contract count checks on the API paths and, as noted under Compatibility, leaves P2P unchanged. On P2P,
Admission only: block validation and consensus are unchanged. The API-visible change will be listed in the 4.8.3 release notes together with the compatibility changes of this PR. |
|
The P2P-side follow-up described above is open in #7064 . Once it is merged, |
Summary
node.allowNumericFieldAlias = false).Compatibility
Some previously accepted inputs may now be rejected. Earlier validation may change error precedence and returned fields, using endpoint-specific error responses. A transaction that cannot be parsed now returns the parse error instead of
internal server error, and single-digit JSON keys are no longer resolved to protobuf field numbers unlessnode.allowNumericFieldAliasis enabled.Block processing, P2P, and consensus behavior remain unchanged apart from address-validation logging.
TODO