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
Open
SeriousCoding789
wants to merge
4
commits into
tronprotocol:release_v4.8.3
Choose a base branch
from
Little-Peony:refactor_merge_rpc
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.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bc7b5f7
refactor(rpc): serve solidity and pbft grpc via shared service instances
Little-Peony 75fb525
Merge branch 'release_v4.8.3' into refactor_merge_rpc
Little-Peony 51f6f79
test(rpc): check the cursor reset on the handler thread and wait for it
Little-Peony 90db120
Merge branch 'release_v4.8.3' into refactor_merge_rpc
SeriousCoding789 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
422 changes: 85 additions & 337 deletions
422
framework/src/main/java/org/tron/core/services/RpcApiService.java
Large diffs are not rendered by default.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
| 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. | ||
| */ | ||
| public abstract class CursorServerInterceptor implements ServerInterceptor { | ||
|
|
||
| @Autowired | ||
| protected Manager dbManager; | ||
|
|
||
| /** Snapshot every call on this server reads from; set by the subclass. */ | ||
| protected Chainbase.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() { | ||
| this.cursor = 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() { | ||
| this.cursor = 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.
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.
[NIT] Method-set parity is now implicit — record the new contract semantics
After this dedup, any method added to
protocol.WalletSolidity/protocol.Databasein the future automatically appears on all three ports (HEAD / SOLIDITY / PBFT). The per-port opt-out that the mirrored delegations provided — intentionally or not, e.g. the two methods the PBFT port lacked until now — no longer exists; each port's method set is now defined solely by the proto service. That is a reasonable semantics, but it should be recorded: one sentence in this class's javadoc or the PR description, e.g. "new proto methods default to all-port parity; per-port exclusion must be implemented explicitly".Suggestion: add the one-line contract note to the class javadoc (or PR description); no code change needed.