Repository navigation
feat(API): refactor merge rpc #6977
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
Merged
kuny0707
merged 6 commits into
tronprotocol:release_v4.8.3
from
Little-Peony:refactor_merge_rpc
Oct 13, 2026
+892
−1,264
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0449395
refactor(rpc): serve solidity and pbft grpc via shared service instances
Little-Peony ebc664a
test(rpc): check the cursor reset on the handler thread and wait for it
Little-Peony 240f094
refactor(rpc): fix the cursor per interceptor and document port parity
Little-Peony d280440
test(rpc): drive registered services and checked error paths
Little-Peony 082d99b
test(rpc): drop redundant cursor and error-path test cases
Little-Peony 89c5584
Merge branch 'release_v4.8.3' into refactor_merge_rpc
Little-Peony 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
425 changes: 88 additions & 337 deletions
425
framework/src/main/java/org/tron/core/services/RpcApiService.java
Large diffs are not rendered by default.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
framework/src/main/java/org/tron/core/services/filter/CursorServerInterceptor.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,62 @@ | ||
| package org.tron.core.services.filter; | ||
|
|
||
| import io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener; | ||
| import io.grpc.Metadata; | ||
| import io.grpc.ServerCall; | ||
| import io.grpc.ServerCallHandler; | ||
| import io.grpc.ServerInterceptor; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.tron.core.db.Manager; | ||
| import org.tron.core.db2.core.Chainbase; | ||
|
|
||
| /** | ||
| * Switches the current thread's read cursor around the synchronous handler callback and restores it | ||
| * afterwards, so the handler reads from the snapshot its subclass selects (HEAD / SOLIDITY / PBFT); | ||
| * the services behind it never touch the cursor. | ||
| * | ||
| * <p>Two invariants it relies on: | ||
| * <ul> | ||
| * <li>The bracket wraps {@code onHalfClose()} — where gRPC runs the unary handler inline — not | ||
| * {@code interceptCall}, which may land on another pool thread; the cursor is a | ||
| * {@link ThreadLocal}, so setting it elsewhere fails silently and the port serves HEAD. | ||
| * <li>Handlers must be synchronous: the cursor is reset when {@code onHalfClose} returns, so a read | ||
| * deferred to another thread would read HEAD. | ||
| * </ul> | ||
| * | ||
| * <p>The {@code finally} reset is mandatory: the fixed thread pool is reused, so a leftover cursor | ||
| * leaks into the next call on that thread. | ||
| * | ||
| * <p>The SOLIDITY and PBFT ports register the shared {@code protocol.Database} and | ||
| * {@code protocol.WalletSolidity} services through this interceptor, so their method sets are | ||
| * defined by those proto services alone: a method added to {@code protocol.Database} is served on | ||
| * the HEAD, SOLIDITY and PBFT ports, and one added to {@code protocol.WalletSolidity} on both the | ||
| * SOLIDITY and PBFT ports. Keeping a method off one of these ports must be implemented explicitly. | ||
| */ | ||
| public abstract class CursorServerInterceptor implements ServerInterceptor { | ||
|
|
||
| @Autowired | ||
| protected Manager dbManager; | ||
|
|
||
| /** Snapshot every call on this server reads from; fixed for the interceptor's lifetime. */ | ||
| private final Chainbase.Cursor cursor; | ||
|
|
||
| protected CursorServerInterceptor(Chainbase.Cursor cursor) { | ||
| this.cursor = cursor; | ||
| } | ||
|
|
||
| @Override | ||
| public <Q, A> ServerCall.Listener<Q> interceptCall( | ||
| ServerCall<Q, A> call, Metadata headers, ServerCallHandler<Q, A> next) { | ||
| return new SimpleForwardingServerCallListener<Q>(next.startCall(call, headers)) { | ||
| @Override | ||
| public void onHalfClose() { | ||
| try { | ||
| dbManager.setCursor(cursor); | ||
| super.onHalfClose(); | ||
| } finally { | ||
| dbManager.resetCursor(); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
framework/src/main/java/org/tron/core/services/filter/PbftCursorInterceptor.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,15 @@ | ||
| package org.tron.core.services.filter; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
| import org.tron.core.db2.core.Chainbase; | ||
|
|
||
| /** | ||
| * Makes every call on the PBFT gRPC server read the PBFT-confirmed state view. | ||
| */ | ||
| @Component | ||
| public class PbftCursorInterceptor extends CursorServerInterceptor { | ||
|
|
||
| public PbftCursorInterceptor() { | ||
| super(Chainbase.Cursor.PBFT); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
framework/src/main/java/org/tron/core/services/filter/SolidityCursorInterceptor.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,15 @@ | ||
| package org.tron.core.services.filter; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
| import org.tron.core.db2.core.Chainbase; | ||
|
|
||
| /** | ||
| * Makes every call on the Solidity gRPC server read the solidified state view. | ||
| */ | ||
| @Component | ||
| public class SolidityCursorInterceptor extends CursorServerInterceptor { | ||
|
|
||
| public SolidityCursorInterceptor() { | ||
| super(Chainbase.Cursor.SOLIDITY); | ||
| } | ||
| } |
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.