-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(framework): decouple Manager from TronJsonRpcImpl #20
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package org.tron.common.logsfilter.queue; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import java.util.concurrent.BlockingQueue; | ||
| import java.util.concurrent.LinkedBlockingQueue; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.stream.Stream; | ||
| import org.springframework.stereotype.Component; | ||
| import org.tron.common.logsfilter.capsule.FilterTriggerCapsule; | ||
|
|
||
| /** | ||
| * Queue between the block-processing producer (Manager) and the json-rpc filter | ||
| * consumer (TronJsonRpcImpl), so that neither side references the other. | ||
| */ | ||
| @Component | ||
| public class FilterCapsuleQueue { | ||
|
|
||
| private final BlockingQueue<FilterTriggerCapsule> queue = new LinkedBlockingQueue<>(); | ||
|
|
||
| public boolean offer(FilterTriggerCapsule capsule) { | ||
| return queue.offer(capsule); | ||
| } | ||
|
|
||
| public FilterTriggerCapsule poll(long timeout, TimeUnit unit) throws InterruptedException { | ||
| return queue.poll(timeout, unit); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public Stream<FilterTriggerCapsule> stream() { | ||
| return queue.stream(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,6 @@ | |
| import org.apache.commons.collections4.CollectionUtils; | ||
| import org.bouncycastle.util.encoders.Hex; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.context.annotation.Lazy; | ||
| import org.springframework.stereotype.Component; | ||
| import org.tron.api.GrpcAPI; | ||
| import org.tron.api.GrpcAPI.TransactionInfoList; | ||
|
|
@@ -62,11 +61,11 @@ | |
| import org.tron.common.logsfilter.capsule.BlockFilterCapsule; | ||
| import org.tron.common.logsfilter.capsule.BlockLogTriggerCapsule; | ||
| import org.tron.common.logsfilter.capsule.ContractTriggerCapsule; | ||
| import org.tron.common.logsfilter.capsule.FilterTriggerCapsule; | ||
| import org.tron.common.logsfilter.capsule.LogsFilterCapsule; | ||
| import org.tron.common.logsfilter.capsule.SolidityTriggerCapsule; | ||
| import org.tron.common.logsfilter.capsule.TransactionLogTriggerCapsule; | ||
| import org.tron.common.logsfilter.capsule.TriggerCapsule; | ||
| import org.tron.common.logsfilter.queue.FilterCapsuleQueue; | ||
| import org.tron.common.logsfilter.trigger.ContractEventTrigger; | ||
| import org.tron.common.logsfilter.trigger.ContractLogTrigger; | ||
| import org.tron.common.logsfilter.trigger.ContractTrigger; | ||
|
|
@@ -143,7 +142,6 @@ | |
| import org.tron.core.service.MortgageService; | ||
| import org.tron.core.service.RewardViCalService; | ||
| import org.tron.core.services.event.exception.EventException; | ||
| import org.tron.core.services.jsonrpc.TronJsonRpcImpl; | ||
| import org.tron.core.store.AccountAssetStore; | ||
| import org.tron.core.store.AccountIdIndexStore; | ||
| import org.tron.core.store.AccountIndexStore; | ||
|
|
@@ -253,8 +251,8 @@ public class Manager { | |
| @Getter | ||
| private BlockingQueue<TriggerCapsule> triggerCapsuleQueue; | ||
| // log filter | ||
| private boolean isRunFilterProcessThread = true; | ||
| private BlockingQueue<FilterTriggerCapsule> filterCapsuleQueue; | ||
| @Autowired | ||
| private FilterCapsuleQueue filterCapsuleQueue; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Manager.close() previously stopped the json-rpc filter consumer (stopFilterProcessThread). After this change the consumer is stopped only by ApplicationImpl.shutdown() -> TronJsonRpcImpl.close(); direct callers of the public Manager.close() with json-rpc filters enabled no longer terminate the consumer thread or its executor. Keep the leak-safe behavior by documenting/centralizing the shutdown contract, or have Manager.close() delegate the consumer shutdown so no code path leaves the daemon thread running. Prompt for AI agents |
||
|
|
||
| @Getter | ||
| private volatile long latestSolidityNumShutDown; | ||
|
|
@@ -273,16 +271,10 @@ public class Manager { | |
| private static final String rePushEsName = "repush"; | ||
| private ExecutorService triggerEs; | ||
| private static final String triggerEsName = "event-trigger"; | ||
| private ExecutorService filterEs; | ||
| private static final String filterEsName = "filter"; | ||
|
|
||
| @Autowired | ||
| private RewardViCalService rewardViCalService; | ||
|
|
||
| @Lazy | ||
| @Autowired | ||
| private TronJsonRpcImpl tronJsonRpcImpl; | ||
|
|
||
| /** | ||
| * Cycle thread to rePush Transactions | ||
| */ | ||
|
|
@@ -334,26 +326,6 @@ public class Manager { | |
| } | ||
| }; | ||
|
|
||
| private Runnable filterProcessLoop = | ||
| () -> { | ||
| while (isRunFilterProcessThread) { | ||
| try { | ||
| FilterTriggerCapsule filterCapsule = filterCapsuleQueue.poll(1, TimeUnit.SECONDS); | ||
| if (filterCapsule instanceof LogsFilterCapsule) { | ||
| tronJsonRpcImpl.handleLogsFilter((LogsFilterCapsule) filterCapsule); | ||
| } else if (filterCapsule instanceof BlockFilterCapsule) { | ||
| tronJsonRpcImpl.handleBLockFilter((BlockFilterCapsule) filterCapsule); | ||
| } | ||
| } catch (InterruptedException e) { | ||
| logger.error("FilterProcessLoop get InterruptedException, error is {}.", | ||
| e.getMessage()); | ||
| Thread.currentThread().interrupt(); | ||
| } catch (Throwable throwable) { | ||
| logger.error("Unknown throwable happened in filterProcessLoop. ", throwable); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| private Comparator downComparator = (Comparator<TransactionCapsule>) (o1, o2) -> Long | ||
| .compare(o2.getOrder(), o1.getOrder()); | ||
|
|
||
|
|
@@ -476,11 +448,6 @@ public void stopRePushTriggerThread() { | |
| ExecutorServiceManager.shutdownAndAwaitTermination(triggerEs, triggerEsName); | ||
| } | ||
|
|
||
| public void stopFilterProcessThread() { | ||
| isRunFilterProcessThread = false; | ||
| ExecutorServiceManager.shutdownAndAwaitTermination(filterEs, filterEsName); | ||
| } | ||
|
|
||
| public void stopValidateSignThread() { | ||
| ExecutorServiceManager.shutdownAndAwaitTermination(validateSignService, "validate-sign"); | ||
| } | ||
|
|
@@ -510,7 +477,6 @@ public void init() { | |
| this.rePushTransactions = new LinkedBlockingQueue<>(); | ||
| } | ||
| this.triggerCapsuleQueue = new LinkedBlockingQueue<>(); | ||
| this.filterCapsuleQueue = new LinkedBlockingQueue<>(); | ||
| chainBaseManager.setMerkleContainer(getMerkleContainer()); | ||
| chainBaseManager.setMortgageService(mortgageService); | ||
| this.initGenesis(); | ||
|
|
@@ -584,12 +550,6 @@ public void init() { | |
| ExecutorServiceManager.submit(triggerEs, triggerCapsuleProcessLoop); | ||
| } | ||
|
|
||
| // start json rpc filter process | ||
| if (CommonParameter.getInstance().isJsonRpcFilterEnabled()) { | ||
| filterEs = ExecutorServiceManager.newSingleThreadExecutor(filterEsName); | ||
| ExecutorServiceManager.submit(filterEs, filterProcessLoop); | ||
| } | ||
|
|
||
| //initStoreFactory | ||
| prepareStoreFactory(); | ||
| //initActuatorCreator | ||
|
|
@@ -2344,9 +2304,7 @@ private void reApplyBlockEvents(List<KhaosBlock> newBranch) { | |
| private void postBlockFilter(final BlockCapsule blockCapsule, boolean solidified) { | ||
| BlockFilterCapsule blockFilterCapsule = | ||
| new BlockFilterCapsule(blockCapsule, solidified); | ||
| if (!filterCapsuleQueue.offer(blockFilterCapsule)) { | ||
| logger.info("Too many filters, block filter lost: {}.", blockCapsule.getBlockId()); | ||
| } | ||
| filterCapsuleQueue.offer(blockFilterCapsule); | ||
| } | ||
|
|
||
| private void postLogsFilter(final BlockCapsule blockCapsule, boolean solidified, | ||
|
|
@@ -2359,9 +2317,7 @@ private void postLogsFilter(final BlockCapsule blockCapsule, boolean solidified, | |
| blockCapsule.getBlockId().toString(), blockCapsule.getBloom(), transactionInfoList, | ||
| solidified, removed); | ||
|
|
||
| if (!filterCapsuleQueue.offer(logsFilterCapsule)) { | ||
| logger.info("Too many filters, logs filter lost: {}.", blockNumber); | ||
| } | ||
| filterCapsuleQueue.offer(logsFilterCapsule); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2658,7 +2614,6 @@ public void close() { | |
| stopRePushThread(); | ||
| stopRePushTriggerThread(); | ||
| EventPluginLoader.getInstance().stopPlugin(); | ||
| stopFilterProcessThread(); | ||
| stopValidateSignThread(); | ||
| chainBaseManager.shutdown(); | ||
| revokingStore.shutdown(); | ||
|
|
||
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.
P2: The queue is an unbounded LinkedBlockingQueue, so offer() always returns true for a non-null capsule. The producer call-sites in Manager.postBlockFilter/postLogsFilter treat a false return as a full queue and log "Too many filters, block filter lost", but that branch is unreachable, and there is no bound protecting memory if the consumer lags or stops. If loss/dropping on overflow is intended, give the queue a bounded capacity; otherwise the "lost filter" handling in Manager is dead code and the queue can grow without limit.
Prompt for AI agents