Repository navigation
feat(api): bound field occurrences of all gRPC API requests #7052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
waynercheung
wants to merge
9
commits into
tronprotocol:release_v4.8.3
Choose a base branch
from
waynercheung:feat/grpc-request-admission
base: release_v4.8.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,562
−36
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8c846e1
feat(api): bound transaction field occurrences before parsing
waynercheung 6c0f647
perf(api): preserve KnownLength in transaction admission
waynercheung 3cb0b5a
feat(api): bound field occurrences across gRPC API requests
waynercheung e36e8c9
fix(api): reject oversized compressed requests without an error log
waynercheung 6aeaee0
refactor(api): fail at wiring time without a request prototype
waynercheung bd21475
refactor(api): register gRPC services through RpcService
waynercheung 0d81b23
refactor(api): tighten gRPC service wiring and admission helpers
waynercheung 90f150f
refactor(api): rename the admission guard to ProtobufAdmissionGuard
waynercheung 2c1cde4
refactor(api): clarify admission sentinel naming and buffer growth
waynercheung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
84 changes: 84 additions & 0 deletions
84
framework/src/main/java/org/tron/core/admission/AdmissionCheckedHandler.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package org.tron.core.admission; | ||
|
|
||
| import io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener; | ||
| import io.grpc.Grpc; | ||
| import io.grpc.Metadata; | ||
| import io.grpc.ServerCall; | ||
| import io.grpc.ServerCallHandler; | ||
| import io.grpc.Status; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.tron.common.prometheus.MetricKeys; | ||
| import org.tron.common.prometheus.Metrics; | ||
| import org.tron.core.admission.ProtobufAdmissionException.Reason; | ||
|
|
||
| /** | ||
| * Closes the call with {@code INVALID_ARGUMENT}, or {@code RESOURCE_EXHAUSTED} for a request over | ||
| * the size limit, when {@link GuardedRequestMarshaller} hands over a rejection sentinel; the | ||
| * service method is never invoked. | ||
| */ | ||
| @Slf4j(topic = "rpc") | ||
| public final class AdmissionCheckedHandler<ReqT, RespT> implements ServerCallHandler<ReqT, RespT> { | ||
|
|
||
| private final ServerCallHandler<ReqT, RespT> delegate; | ||
| private final GuardedRequestMarshaller<ReqT> marshaller; | ||
|
|
||
| AdmissionCheckedHandler(ServerCallHandler<ReqT, RespT> delegate, | ||
| GuardedRequestMarshaller<ReqT> marshaller) { | ||
| this.delegate = delegate; | ||
| this.marshaller = marshaller; | ||
| } | ||
|
|
||
| public ServerCallHandler<ReqT, RespT> getDelegate() { | ||
| return delegate; | ||
| } | ||
|
|
||
| public GuardedRequestMarshaller<ReqT> getMarshaller() { | ||
| return marshaller; | ||
| } | ||
|
|
||
| @Override | ||
| public ServerCall.Listener<ReqT> startCall(ServerCall<ReqT, RespT> call, Metadata headers) { | ||
| ServerCall.Listener<ReqT> next = delegate.startCall(call, headers); | ||
| return new SimpleForwardingServerCallListener<ReqT>(next) { | ||
| // Listener callbacks of one call are serialized by grpc. | ||
| private boolean rejected; | ||
|
|
||
| @Override | ||
| public void onMessage(ReqT message) { | ||
| if (rejected) { | ||
| return; | ||
| } | ||
| Reason reason = marshaller.rejectionReason(message); | ||
| if (reason != null) { | ||
| rejected = true; | ||
| String method = call.getMethodDescriptor().getFullMethodName(); | ||
| if (logger.isDebugEnabled()) { | ||
| logger.debug("gRPC {} from {} rejected by admission check: {}", method, | ||
| call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR), reason); | ||
| } | ||
| Metrics.counterInc(MetricKeys.Counter.GRPC_ADMISSION_REJECT, 1, method, reason.name()); | ||
| // The same status grpc gives an uncompressed message over the size limit. | ||
| Status status = reason == Reason.TOO_LARGE | ||
| ? Status.RESOURCE_EXHAUSTED : Status.INVALID_ARGUMENT; | ||
| call.close(status.withDescription(marshaller.rejectionMessage()), new Metadata()); | ||
| return; | ||
| } | ||
| super.onMessage(message); | ||
| } | ||
|
|
||
| @Override | ||
| public void onHalfClose() { | ||
| if (!rejected) { | ||
| super.onHalfClose(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onReady() { | ||
| if (!rejected) { | ||
| super.onReady(); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[DISCUSS] I would prefer to drop
GRPC_ADMISSION_REJECTunless there is a concrete operational use case for it. Adding a dedicated metric for this exceptional request-validation path increases the monitoring surface and long-term maintenance cost. Could you clarify what operators are expected to detect or act on using this counter, beyond the error responses and diagnostic logging already provided?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The operational use case is reviewing the fixed limit after rollout. Sustained
OVER_BUDGETrejections on a method would prompt an investigation of client compatibility, not establish that the requests were valid. The existing latency histogram is labeled only by method, so rejections are not visible there; DEBUG logs provide diagnostic details but no built-in aggregate rejection series.This follows the bounded-counter pattern used by
tron:tx_reject{source, reason}, while covering pre-parse admission for all wrapped gRPC request types. Labels come from registered methods and four fixed reasons. The counter uses the existing Prometheus switch, which is disabled by default.It cannot identify otherwise-valid requests or show accepted requests near the budget, and it excludes
/wallet/broadcasthexand transport-level rejections before unmarshalling. A general status metric could provide broader error visibility, but would not distinguishOVER_BUDGETfrom otherINVALID_ARGUMENTfailures. I propose retaining this counter for rollout diagnostics, but can remove it if we prefer a narrower monitoring scope.