feat(framework): support solidity conditional shutdown#6734
Open
317787106 wants to merge 1 commit intotronprotocol:developfrom
Open
feat(framework): support solidity conditional shutdown#6734317787106 wants to merge 1 commit intotronprotocol:developfrom
317787106 wants to merge 1 commit intotronprotocol:developfrom
Conversation
…shutdown - Convert SolidityNode from static utility to @conditional @component so it only registers when --solidity is passed - Implement ApplicationListener<ContextClosedEvent> to set flag=false before any @PreDestroy method fires, stopping worker threads promptly - Add pushVerifiedBlock() to TronNetDelegate to route solidity sync blocks through the conditional-shutdown check (<=, not ==, because a single batch write can advance the DB header past the target number) - Guard saveLatestSolidifiedBlockNum in loopProcessBlock: skip the write when hitDown is true, preventing a phantom block-num from persisting when the block was never actually pushed to BlockStore - Add unit tests covering lifecycle hooks, all retry paths, interrupt handling, and the hitDown save-guard; SolidityNode line coverage 28% -> 81% Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #6610.
Refactors
SolidityNodeinto a Spring-managed component with proper lifecycle support, enabling it to respond to conditional shutdown signals (block height, block time, block count) already implemented inTronNetDelegate.processBlock. The previous staticstart()approach bypassed Spring entirely, so the shutdown conditions could never be reached during solidity sync.Problem
SolidityNodepreviously initialized its ownTronApplicationContext, created aSolidityNodeinstance manually, and calledappT.blockUntilShutdown()in a separate JVM entry path. This architecture had two consequences:TronNetDelegate.processBlock(checkinglatestSolidityNumShutDown), butSolidityNodecalledManager.pushVerifiedBlock -> Manager.pushBlock— a path that never passes throughTronNetDelegate. The shutdown signal was therefore silently ignored.@PreDestroylifecycle.Changes
SolidityNode(framework)@Componentwith@Conditional(SolidityCondition.class)— only registered when--solidityflag is set.ApplicationListener<ContextClosedEvent>: setsflag = falseat the very start of context close, before any@PreDestroymethods run on other beans, preventing block pushes into a partially-shut-down system.@PostConstruct init(): initialises namedExecutorServicethread pools viaExecutorServiceManager. gRPC client andremoteBlockNumare initialised inrun()to keep init lightweight.@PreDestroy shutdown(): setsflag = false(safety net), shuts down both executors viaExecutorServiceManager.shutdownAndAwaitTermination, and closes the gRPC client cleanly.processSolidityBlock()usesblockQueue.poll(timeout)instead oftake(), and handlesInterruptedExceptionexplicitly so thread interruption during executor shutdown is clean.getBlockByNum(): loop changed towhile (flag); throwsRuntimeException("SolidityNode is closing.")when flag is false — avoidsNullPointerExceptionfromblockQueue.put(null).getLastSolidityBlockNum(): loop changed towhile (flag); returns0when flag is false — lets the caller'swhile (flag)loop exit quietly without a misleading error log.loopProcessBlock()now callstronNetDelegate.pushVerifiedBlock()instead ofdbManager.pushVerifiedBlock(), routing blocks through the shutdown-condition check inprocessBlock.TronNetDelegate(framework)pushVerifiedBlock(BlockCapsule): setsgeneratedByMyself = trueand delegates toprocessBlock(block, true), which already contains the conditional-shutdown logic. Includes timing log consistent with the removedManagermethod.processBlockuses<=instead of==becausepushBlockmay commit multiple blocks in a single batch write, causing the DB header number to jump past the target block number and never equal it exactly.Manager(framework)pushVerifiedBlock(). Block push for solidity sync now goes throughTronNetDelegate.FullNode(framework)trustNodeAddrvalidation andp2pDisable = trueare now enforced before the Spring context is created.appT.startup(), retrieves theSolidityNodebean from the context and callsrun()— reusing the same application lifecycle rather than spawning a second context.Tests
testSolidityGrpcCall— verifies gRPC connectivity through the runningRpcApiService.testSolidityNodeHttpApiService— verifies HTTP service start/stop idempotency.testExecutorsInitializedOnStartup—@PostConstructcreates both executors beforerun()is called.testOnApplicationEventSetsFlagFalse—ContextClosedEventsetsflag = falsebefore any@PreDestroyruns.testGetBlockByNumThrowsWhenClosed—RuntimeException(notnull) is thrown whenflag = false.testGetLastSolidityBlockNumReturnsZeroWhenClosed— returns0whenflag = falsefor a quiet loop exit.testSolidityConditionMatchesWhenSolidityFlagSet—SolidityCondition.matches()returnstruewith--solidity.