[Feature] decouple json-rpc filter processing from Manager
Maintainers usually reply within 1 day
A pull request for this has already been merged.
- #6990 by @0xbigapple — merged
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 48/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- java
- Domain
- backend, backend-api-design
Research direction
Start in the framework module by reading Manager, TronJsonRpcImpl, and ApplicationImpl.shutdown(), then trace the existing filter queue and consumer lifecycle. Introduce the specified FilterCapsuleQueue boundary and preserve filter delivery while ensuring the consumer stops before database shutdown and the core layer no longer references the API layer.
Written by the indexing model from the issue text.
Description
Summary
The json-rpc filter event-processing thread currently is located within Manager (core layer), forcing it to hold TronJsonRpcImpl (API layer) via a @Lazy injection — a reverse circular dependency. This proposal moves that thread into TronJsonRpcImpl; Manager only posts filter events into a standalone queue bean, and the reverse edge disappears.
Problem
Motivation
#6732 turned handleLogsFilter/handleBLockFilter from static into instance methods, so Manager's event-processing thread needs a TronJsonRpcImpl instance; the review deferred the resulting @Lazy cycle to a follow-up (discussion) — this issue serves as the dedicated follow-up to address that technical debt.
Current State
Manager ──@Lazy @Autowired field──▶ TronJsonRpcImpl ──@Autowired field──▶ Manager
Each arrow reads "depends on"; the labels are injection styles. TronJsonRpcImpl's constructor parameters Wallet/NodeInfoService each depend on Manager as well, closing the same cycle indirectly.
Manager owns the filter queue, the consumer thread, and its shutdown; the consumer calls back into the API layer.
Limitations or Risks
FullNodesetsallowCircularReferences(false), so a directly injected cycle is rejected at startup;@Lazy(likeObjectProvideror a runtimegetBean()) only makes Spring tolerate the cycle — the reverse edge stays, obscuring the component graph and complicating lifecycle changes.- The reverse core → API edge risks encouraging future changes to repeat the same
@Lazypattern, widening the breach. - One latent defect remains in the current implementation: the consumer stop flag is a non-volatile boolean (the shutdown-time write has no visibility guarantee for that thread), and the loop does not exit on
InterruptedException— under the Java memory model, neither the normal nor the forced stop path is reliable.
Proposed Solution
Proposed Design
Eliminate the reverse dependency entirely rather than suppressing it via @Lazy: a standalone FilterCapsuleQueue bean is introduced as an intermediary between the two layers — Manager only produces into it; TronJsonRpcImpl owns the consumer thread (start on @PostConstruct, stop via idempotent close()). ApplicationImpl.shutdown() calls close() explicitly after producers stop and before dbManager.close() — Spring destroys beans only after the database closes, so bean destruction alone would let the consumer outlive it (ApplicationImpl is already the shutdown-orchestrating composition root). Filter API behavior stays unchanged (unbounded queue; pending entries are not drained on shutdown, while an in-flight capsule may complete).
Key Changes
- Module:
frameworkonly org.tron.common.logsfilter.queue.FilterCapsuleQueue(new bean, beside the existingorg.tron.common.logsfilter.capsulepackage)Manager: drop the@Lazyfield, the consumer loop, and its thread lifecycleTronJsonRpcImpl: constructor gains aManagerparameter, consumer lifecycle, rewrittenclose()ordering (stop and await the consumer first, then shut downlogsFilterPool)ApplicationImpl.shutdown(): explicit consumer stop- No configuration or API changes
Impact
- Stability: fixes the latent stop-path defect above along the way; graceful shutdown stops the consumer before the database closes.
- Performance: no steady-state change expected — processing path, queue, and thread count are unchanged.
- Developer Experience: the core layer no longer references the API layer;
framework/src/mainbecomes@Lazy-free.
Compatibility
- Breaking Change: No
- Default Behavior Change: No — filter delivery, queue semantics, and shutdown semantics are preserved
- Migration Required: No
Additional Notes
- Do you have ideas regarding implementation? Yes
- Are you willing to implement this feature? Yes
- Dominant language
- Java
- Stars
- 4.2k
- Forks
- 1.8k
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 51
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tronprotocol/java-tron
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
tronprotocol/java-tron#7044 · 4 comments ·
Maintainers usually reply within 1 day
-
[Feature] Remove unused discovery message definitionsPossibly taken A pull request linked to this issue is open or already merged. Opentype:feature
Difficulty 4/5 3-5 days Newbie friendliness 35/100
tronprotocol/java-tron#7013 · 3 comments ·
Maintainers usually reply within 1 day
-
[Feature] Validate ECKey inputs and improve key handlingPossibly taken A pull request linked to this issue is open or already merged. Opentype:feature
Difficulty 4/5 3-5 days Newbie friendliness 40/100
tronprotocol/java-tron#6994 · 5 comments ·
Maintainers usually reply within 1 day
-
type:feature
Difficulty 5/5 Over a week Newbie friendliness 25/100
tronprotocol/java-tron#6989 · 7 comments ·
Maintainers usually reply within 1 day
-
[Feature] Remove unused SM2/SM3 crypto enginePossibly taken A pull request linked to this issue is open or already merged. Opentype:feature
Difficulty 5/5 Over a week Newbie friendliness 28/100
tronprotocol/java-tron#6959 · 3 comments ·
Maintainers usually reply within 1 day
All issues in tronprotocol/java-tron
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
citrusframework/citrus#2044 ·
Maintainers usually reply within 1 day
-
[bug]打火石不能被放在厨具架上Open
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
KaleidoscopeMods/KaleidoscopeCookery#237 · 1 comment ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
molgenis/molgenis-emx2#7059 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
quarkiverse/quarkus-flow#1169 ·
Maintainers usually reply within 1 day