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

Print total tree size, including inactive shards in rekor-cli loginfo #864

Merged
merged 2 commits into from
Jun 7, 2022
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
25 changes: 18 additions & 7 deletions cmd/rekor-cli/app/log_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ import (
)

type logInfoCmdOutput struct {
TreeSize int64
ActiveTreeSize int64
TotalTreeSize int64
priyawadhwa marked this conversation as resolved.
Show resolved Hide resolved
RootHash string
TimestampNanos uint64
TreeID string
Expand All @@ -54,11 +55,12 @@ func (l *logInfoCmdOutput) String() string {
ts := time.Unix(0, int64(l.TimestampNanos)).UTC().Format(time.RFC3339)

return fmt.Sprintf(`Verification Successful!
Tree Size: %v
Root Hash: %s
Timestamp: %s
TreeID: %s
`, l.TreeSize, l.RootHash, ts, l.TreeID)
Active Tree Size: %v
Total Tree Size: %v
Root Hash: %s
Timestamp: %s
TreeID: %s
`, l.ActiveTreeSize, l.TotalTreeSize, l.RootHash, ts, l.TreeID)
}

// logInfoCmd represents the current information about the transparency log
Expand Down Expand Up @@ -100,7 +102,8 @@ var logInfoCmd = &cobra.Command{
}

cmdOutput := &logInfoCmdOutput{
TreeSize: swag.Int64Value(logInfo.TreeSize),
ActiveTreeSize: swag.Int64Value(logInfo.TreeSize),
TotalTreeSize: totalTreeSize(logInfo, logInfo.InactiveShards),
RootHash: swag.StringValue(logInfo.RootHash),
TimestampNanos: sth.GetTimestamp(),
TreeID: swag.StringValue(logInfo.TreeID),
Expand Down Expand Up @@ -222,6 +225,14 @@ func loadVerifier(rekorClient *rclient.Rekor) (signature.Verifier, error) {
return signature.LoadVerifier(pub, crypto.SHA256)
}

func totalTreeSize(activeShard *models.LogInfo, inactiveShards []*models.InactiveShardLogInfo) int64 {
total := swag.Int64Value(activeShard.TreeSize)
for _, i := range inactiveShards {
total += swag.Int64Value(i.TreeSize)
}
return total
}

func init() {
initializePFlagMap()
rootCmd.AddCommand(logInfoCmd)
Expand Down
10 changes: 9 additions & 1 deletion tests/sharding-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ popd
# Pass in the universal log_index & make sure it resolves
check_log_index 3

# Make sure the shard tree size is 1 and the total tree size is 4
rm $HOME/.rekor/state.json # We have to remove this since we can't prove consistency between entry 0 and entry 1
TREE_SIZE=$($REKOR_CLI loginfo --rekor_server http://localhost:3000 --format json | jq -r .ActiveTreeSize)
stringsMatch $TREE_SIZE "1"

TOTAL_TREE_SIZE=$($REKOR_CLI loginfo --rekor_server http://localhost:3000 --format json | jq -r .TotalTreeSize)
stringsMatch $TOTAL_TREE_SIZE "4"


# Make sure we can still get logproof for the now-inactive shard
$REKOR_CLI logproof --last-size 2 --tree-id $INITIAL_TREE_ID --rekor_server http://localhost:3000
# And the logproof for the now active shard
Expand All @@ -215,7 +224,6 @@ if [[ "$ENCODED_PUBLIC_KEY" == "$NEW_PUB_KEY" ]]; then
exit 1
fi


# TODO: Try to get the entry via Entry ID (Tree ID in hex + UUID)
UUID=$($REKOR_CLI get --log-index 2 --rekor_server http://localhost:3000 --format json | jq -r .UUID)

Expand Down