Skip to content
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

Reduce checkpoint file size by using fewer bytes to encode length of encoded payload value #2165

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package extract

import (
"encoding/binary"
"encoding/hex"
"fmt"
"os"
Expand All @@ -11,6 +12,7 @@ import (

"github.com/onflow/flow-go/cmd/util/cmd/common"
"github.com/onflow/flow-go/ledger/common/hash"
"github.com/onflow/flow-go/ledger/complete/wal"
"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/metrics"
Expand Down Expand Up @@ -117,13 +119,43 @@ func run(*cobra.Command, []string) {
if err != nil {
log.Fatal().Err(err).Msg("invalid root checkpoint")
}
const crcLength = 4
_, err = f.Seek(-(hash.HashLen + crcLength), 2 /* relative from end */)
if err != nil {
log.Fatal().Err(err).Msg("invalid root checkpoint")

const (
encMagicSize = 2
encVersionSize = 2
crcLength = 4
encNodeCountSize = 8
encTrieCountSize = 2
headerSize = encMagicSize + encVersionSize
)

// read checkpoint version
header := make([]byte, headerSize)
n, err := f.Read(header)
if err != nil || n != headerSize {
log.Fatal().Err(err).Msg("failed to read version from root checkpoint")
}

magic := binary.BigEndian.Uint16(header)
version := binary.BigEndian.Uint16(header[encMagicSize:])

if magic != wal.MagicBytes {
log.Fatal().Err(err).Msg("invalid magic bytes in root checkpoint")
}

if version <= 3 {
_, err = f.Seek(-(hash.HashLen + crcLength), 2 /* relative from end */)
if err != nil {
log.Fatal().Err(err).Msg("invalid root checkpoint")
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I left this comment on other PR - I would check if version is below one we explicitly support

Copy link
Member Author

Choose a reason for hiding this comment

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

Great suggestion! 👍 Opened issue #2205 to track this and done in PR #2206.

_, err = f.Seek(-(hash.HashLen + encNodeCountSize + encTrieCountSize + crcLength), 2 /* relative from end */)
if err != nil {
log.Fatal().Err(err).Msg("invalid root checkpoint")
}
}

n, err := f.Read(stateCommitment[:])
n, err = f.Read(stateCommitment[:])
if err != nil || n != hash.HashLen {
log.Fatal().Err(err).Msg("failed to read state commitment from root checkpoint")
}
Expand Down
Loading