Skip to content

Conversation

@imalygin
Copy link
Contributor

@imalygin imalygin commented Oct 31, 2025

Description:

This PR introduces StateLifecycleManager, a class responsible for managing the lifecycle of a state:

  • Making copies of the state.
  • Keeping references to a mutable state and the last immutable state, updating these references if necessary.
  • Creating snapshots.
  • Loading the state from the snapshot.

Highlights of changes:

  • The VirtualMapState.newInstance method was replaced with a factory function (stateSupplier) passed as a constructor argument to StateLifecycleManagerImpl.
  • State.loadSnapshot and State.createSnapshot were migrated to StateLifecycleManager.
  • StateLifecycleManager is a drop-in replacement for SwirldsStateManager.

Related issue(s):

Fixes #21915

Notes for reviewer:

Even though StateLifecycleManager comes with a copyMutableState method, and this method assumes that it's the ONLY way to create a copy of the state, usages of State.copy are not yet eliminated to limit the scope of this PR. This will be done in the follow-up task: #21949

@lfdt-bot
Copy link

lfdt-bot commented Oct 31, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@imalygin imalygin force-pushed the 21915-StateLifecycleManager branch from 025556f to 11ae127 Compare November 3, 2025 15:01
@imalygin imalygin self-assigned this Nov 3, 2025
@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 70.37037% with 40 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...wirlds/state/merkle/StateLifecycleManagerImpl.java 84.05% 6 Missing and 5 partials ⚠️
...ain/java/com/swirlds/platform/SwirldsPlatform.java 0.00% 5 Missing ⚠️
...rlds/platform/cli/GenesisPlatformStateCommand.java 0.00% 4 Missing ⚠️
...swirlds/platform/state/editor/StateEditorSave.java 0.00% 4 Missing ⚠️
...irlds/platform/recovery/EventRecoveryWorkflow.java 0.00% 3 Missing ⚠️
...ava/com/hedera/node/app/HederaVirtualMapState.java 33.33% 2 Missing ⚠️
...rlds/demo/migration/MigrationTestingToolState.java 0.00% 2 Missing ⚠️
.../com/swirlds/platform/builder/PlatformBuilder.java 0.00% 2 Missing ⚠️
...lds/platform/builder/PlatformComponentBuilder.java 33.33% 2 Missing ⚠️
.../demo/consistency/ConsistencyTestingToolState.java 50.00% 1 Missing ⚠️
... and 4 more

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #21958      +/-   ##
============================================
+ Coverage     70.82%   70.98%   +0.15%     
- Complexity    24382    24471      +89     
============================================
  Files          2667     2674       +7     
  Lines        104170   104397     +227     
  Branches      10941    10957      +16     
============================================
+ Hits          73778    74104     +326     
+ Misses        26355    26248     -107     
- Partials       4037     4045       +8     
Files with missing lines Coverage Δ Complexity Δ
...wirlds/demo/platform/PlatformTestingToolState.java 8.53% <ø> (ø) 3.00 <0.00> (ø)
...ommon/merkle/utility/MerkleTreeSnapshotWriter.java 84.21% <100.00%> (+3.25%) 5.00 <1.00> (ø)
...tform/eventhandling/DefaultTransactionHandler.java 73.01% <100.00%> (+0.21%) 13.00 <4.00> (ø)
...m/network/protocol/ReconnectStateSyncProtocol.java 100.00% <100.00%> (ø) 3.00 <0.00> (ø)
...wirlds/platform/reconnect/ReconnectController.java 89.55% <100.00%> (ø) 18.00 <0.00> (ø)
...rm/state/snapshot/DefaultStateSnapshotManager.java 78.78% <100.00%> (+0.21%) 11.00 <1.00> (ø)
...platform/state/snapshot/SignedStateFileWriter.java 91.78% <100.00%> (+1.50%) 10.00 <3.00> (ø)
...c/main/java/com/swirlds/state/MerkleNodeState.java 66.66% <ø> (ø) 2.00 <0.00> (ø)
...ate-api/src/main/java/com/swirlds/state/State.java 37.50% <ø> (+7.50%) 3.00 <0.00> (ø)
...java/com/swirlds/state/merkle/VirtualMapState.java 85.33% <100.00%> (+0.16%) 38.00 <0.00> (-1.00) ⬆️
... and 14 more

... and 86 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codacy-production
Copy link

codacy-production bot commented Nov 3, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.15% (target: -1.00%) 74.07%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (008b99b) 104075 77770 74.72%
Head commit (cce3cef) 104163 (+88) 77992 (+222) 74.87% (+0.15%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#21958) 135 100 74.07%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@imalygin imalygin force-pushed the 21915-StateLifecycleManager branch 2 times, most recently from cbc5f95 to a7221b5 Compare November 3, 2025 21:46
@imalygin imalygin force-pushed the 21915-StateLifecycleManager branch from a7221b5 to 855bf5a Compare November 3, 2025 22:15
@imalygin imalygin marked this pull request as ready for review November 3, 2025 22:17
@imalygin imalygin requested review from a team as code owners November 3, 2025 22:17
@imalygin imalygin requested a review from lpetrovic05 November 3, 2025 22:17
mhess-swl
mhess-swl previously approved these changes Nov 3, 2025
Copy link
Contributor

@mhess-swl mhess-swl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (Execution) 🙂

mxtartaglia-sl
mxtartaglia-sl previously approved these changes Nov 4, 2025
mxtartaglia-sl
mxtartaglia-sl previously approved these changes Nov 4, 2025
mhess-swl
mhess-swl previously approved these changes Nov 4, 2025
- got rid of `getRound` method
- improved javadoc
- added missing nullity annotations

Signed-off-by: Ivan Malygin <[email protected]>
Signed-off-by: Ivan Malygin <[email protected]>
Signed-off-by: Ivan Malygin <[email protected]>
artemananiev
artemananiev previously approved these changes Nov 6, 2025
Addressed review comments:
- improved javadocs
- removed `synchronized` modifier from `initState` and `copyMutableState`

Signed-off-by: Ivan Malygin <[email protected]>
artemananiev
artemananiev previously approved these changes Nov 6, 2025
- improved javadoc

Signed-off-by: Ivan Malygin <[email protected]>
- improved javadoc
- improved handling of destroyed states

Signed-off-by: Ivan Malygin <[email protected]>
Signed-off-by: Ivan Malygin <[email protected]>
Copy link
Contributor

@mhess-swl mhess-swl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for Execution

@imalygin imalygin merged commit dcef6ef into main Nov 8, 2025
61 of 63 checks passed
@imalygin imalygin deleted the 21915-StateLifecycleManager branch November 8, 2025 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor SwirldsStateManager into StateLifecycleManagerImpl

8 participants