hiero-ledger / hiero-ledger/hiero-consensus-node

PCLI state genesis tool fails with immutable copy error

Open
#10,430 0 comments 0 reactions 0 assignees View on GitHub
Platform
Dominant language
Java
Stars
406
Forks
226
Avg merge
3d 4h
Merged PRs (30d)
210

Description

We attempted to run `pcli --load "" state genesis "/SignedState.swh" ` on a mainnet state file (specifically round `151988064` from the dell node), but encountered an error. Console output was:

```
Replacing platform data
Hashing state
Writing modified state to /Users/matthess/Downloads/repo/hedera-services/hedera-node/45state
java.lang.IllegalStateException: detach is only allowed on immutable copies
at com.swirlds.virtualmap.internal.merkle.VirtualRootNode.detach(VirtualRootNode.java:1304)
at com.swirlds.virtualmap.internal.pipeline.VirtualPipeline.lambda$detachCopy$2(VirtualPipeline.java:426)
at com.swirlds.virtualmap.internal.pipeline.VirtualPipeline.pausePipelineAndExecute(VirtualPipeline.java:637)
at com.swirlds.virtualmap.internal.pipeline.VirtualPipeline.detachCopy(VirtualPipeline.java:426)
at com.swirlds.virtualmap.internal.merkle.VirtualRootNode.serialize(VirtualRootNode.java:1172)
at com.swirlds.virtualmap.VirtualMap.serialize(VirtualMap.java:324)
at com.swirlds.common.io.streams.MerkleDataOutputStream.writeSerializableNode(MerkleDataOutputStream.java:64)
at com.swirlds.common.io.streams.MerkleDataOutputStream.writeInternal(MerkleDataOutputStream.java:81)
at com.swirlds.common.io.streams.MerkleDataOutputStream.lambda$writeMerkleTree$1(MerkleDataOutputStream.java:172)
at com.swirlds.common.merkle.iterators.MerkleIterator.forEachRemainingWithIO(MerkleIterator.java:410)
at com.swirlds.common.io.streams.MerkleDataOutputStream.writeMerkleTree(MerkleDataOutputStream.java:166)
at com.swirlds.platform.state.signed.SignedStateFileWriter.writeStateFileToStream(SignedStateFileWriter.java:120)
at com.swirlds.platform.state.signed.SignedStateFileWriter.lambda$writeStateFile$0(SignedStateFileWriter.java:133)
at com.swirlds.common.io.utility.FileUtils.writeAndFlush(FileUtils.java:281)
at com.swirlds.platform.state.signed.SignedStateFileWriter.writeStateFile(SignedStateFileWriter.java:132)
at com.swirlds.platform.state.signed.SignedStateFileWriter.writeSignedStateFilesToDirectory(SignedStateFileWriter.java:154)
at com.swirlds.platform.cli.GenesisPlatformStateCommand.call(GenesisPlatformStateCommand.java:98)
at com.swirlds.platform.cli.GenesisPlatformStateCommand.call(GenesisPlatformStateCommand.java:43)
at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
at picocli.CommandLine.access$1300(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
at picocli.CommandLine.execute(CommandLine.java:2078)
at com.swirlds.cli.PlatformCli.main(PlatformCli.java:195)
```
A possible cause is that this code was not tried on a state that contained any VirtualMaps.

For now, there's a quick hack to get around this error in `GenesisPlatformStateCommand` by inserting a call to copy the state:

```java
System.out.printf("Writing modified state to %s %n", outputDir.toAbsolutePath());
reservedSignedState.get().getState().copy(); // <--- inserted line here
writeSignedStateFilesToDirectory(platformContext, NO_NODE_ID, outputDir, reservedSignedState.get());
```

Contributor guide

Open the contributing guide

Research direction

Start with GenesisPlatformStateCommand.call and reproduce the pcli state genesis command using a signed state containing a VirtualMap. Read the VirtualRootNode serialization and VirtualPipeline detach path shown in the stack trace, comparing it with the existing state.copy() workaround. Done means writing the modified signed state succeeds without the immutable-copy error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.