Skip to content

[Storehouse] 010 Util convert v6 -> v7 checkpoint - #8583

Open
zhangchiqing wants to merge 5 commits into
leo/payloadless-remote-ledger-servicefrom
leo/payloadless-util-convert-checkpoint
Open

[Storehouse] 010 Util convert v6 -> v7 checkpoint#8583
zhangchiqing wants to merge 5 commits into
leo/payloadless-remote-ledger-servicefrom
leo/payloadless-util-convert-checkpoint

Conversation

@zhangchiqing

@zhangchiqing zhangchiqing commented Jun 18, 2026

Copy link
Copy Markdown
Member

To bootstrap a payloadless EN, a v7 root checkpoint file is needed. This PR adds a util to convert a v6 root checkpoint into a v7 root checkpoint.

It adds two ways to convert:

  1. original way (less code, but use more memory), it loads the entire v6 checkpoint into memory, and then convert it into v7
  2. steam way (more new code, but much less memory), it iterate each node in the v6 checkpoint file, if it's a leaf node, convert it into v7 format.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a3b7dcc-61e9-4564-b361-fcd9462cfec2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch leo/payloadless-util-convert-checkpoint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zhangchiqing
zhangchiqing marked this pull request as ready for review June 18, 2026 03:04
@zhangchiqing
zhangchiqing requested a review from a team as a code owner June 18, 2026 03:04
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-remote-ledger-service branch from 08074ba to 4f1f09d Compare June 18, 2026 23:19
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-util-convert-checkpoint branch 3 times, most recently from ce39b24 to 287bfbb Compare June 18, 2026 23:34
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-remote-ledger-service branch from 0955ccb to 8177757 Compare June 19, 2026 00:00
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-util-convert-checkpoint branch from 287bfbb to a9c6645 Compare June 19, 2026 00:01
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-remote-ledger-service branch from 8177757 to efd0192 Compare July 2, 2026 18:43
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-util-convert-checkpoint branch from a9c6645 to ca39b1a Compare July 2, 2026 19:11
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-remote-ledger-service branch from efd0192 to fba2a36 Compare July 13, 2026 17:26
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-util-convert-checkpoint branch from ca39b1a to 4d5c8bf Compare July 13, 2026 17:26
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-remote-ledger-service branch from fba2a36 to dd25d6c Compare July 14, 2026 19:25
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-util-convert-checkpoint branch from 4d5c8bf to 91eb0a7 Compare July 14, 2026 19:56
) error {
err := convertCheckpointV6ToV7Stream(inputDir, inputFileName, outputDir, outputFileName, logger, nWorker)
if err != nil {
cleanupErr := deleteCheckpointFiles(outputDir, outputFileName)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-running the conversion deletes the previously converted output. The "V7 output already exists" rejection from convertCheckpointV6ToV7Stream reaches this cleanup, and deleteCheckpointFiles removes every <outputFile>* file.

streamFiles := filePaths(dir, streamName, subtrieLevel)
require.Equal(t, len(nonStreamFiles), len(streamFiles))
for i, nf := range nonStreamFiles {
require.NoError(t, compareFiles(nf, streamFiles[i]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

compareFiles has a bug! It opens file1 twice (checkpoint_v6_test.go:451), so it can never fail. Fix the helper to os.Open(file2).

if err != nil {
return 0, fmt.Errorf("could not read subtrie footer: %w", err)
}
if embeddedSum != expectedSum {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only compares two stored checksums; the bytes actually read are never CRC-verified, so input corruption is copied into a V7 file that then carries a fresh valid checksum. The non-stream path verifies content CRC via readCheckpointSubTrie. Same applies to the top-trie path below.

checksums := make([]uint32, subtrieCount)
for k := 0; k < subtrieCount; k++ {
r := <-results
if r.err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Returning on the first error leaves the other workers running. Their deferred Close renames temp files to final part files, possibly after the wrapper's deleteCheckpointFiles has run, leaving stray output that contradicts the godoc and blocks retries. Drain all subtrieCount results, then return the first error, aggregate the errors or/and build a stopping mechanism into the workers.

go func() {
for i := range jobs {
sum, err := convertSubTrieFileV6ToV7Stream(
inputDir, inputFileName, outputDir, outputFileName, i, subtrieChecksums[i], logger)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

subtrieChecksums is sized from the header while this loop hard-codes subtrieCount, so a checksum-valid header declaring fewer than 16 subtries panics in a worker goroutine. You could validate len(subtrieChecksums) == subtrieCount up front.

flagNWorker,
)
var err error
if flagStream {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

stream could be a boolean input into ConvertCheckpointV6ToV7 so that you don't need to expose 2 methods with identical inputs.

@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-remote-ledger-service branch from dd25d6c to 3e9115e Compare July 31, 2026 03:38
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-util-convert-checkpoint branch 2 times, most recently from f871ac3 to 91eb0a7 Compare July 31, 2026 03:58
@zhangchiqing
zhangchiqing force-pushed the leo/payloadless-util-convert-checkpoint branch from 91eb0a7 to 1c62fec Compare July 31, 2026 04:08
…l V7 conversion cleanup at bootstrap, logger and godoc fixes, and tests for the leaf-hash flag and V7 subtrie paths
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.

2 participants