Skip to content

Commit 08d04c0

Browse files
authored
Print total tree size, including inactive shards in rekor-cli loginfo (sigstore#864)
* Print total tree size, including inactive shards Signed-off-by: Priya Wadhwa <priya@chainguard.dev> * Rename TreeSize to ActiveTreeSize Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
1 parent 143e9ec commit 08d04c0

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

cmd/rekor-cli/app/log_info.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import (
4343
)
4444

4545
type logInfoCmdOutput struct {
46-
TreeSize int64
46+
ActiveTreeSize int64
47+
TotalTreeSize int64
4748
RootHash string
4849
TimestampNanos uint64
4950
TreeID string
@@ -54,11 +55,12 @@ func (l *logInfoCmdOutput) String() string {
5455
ts := time.Unix(0, int64(l.TimestampNanos)).UTC().Format(time.RFC3339)
5556

5657
return fmt.Sprintf(`Verification Successful!
57-
Tree Size: %v
58-
Root Hash: %s
59-
Timestamp: %s
60-
TreeID: %s
61-
`, l.TreeSize, l.RootHash, ts, l.TreeID)
58+
Active Tree Size: %v
59+
Total Tree Size: %v
60+
Root Hash: %s
61+
Timestamp: %s
62+
TreeID: %s
63+
`, l.ActiveTreeSize, l.TotalTreeSize, l.RootHash, ts, l.TreeID)
6264
}
6365

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

102104
cmdOutput := &logInfoCmdOutput{
103-
TreeSize: swag.Int64Value(logInfo.TreeSize),
105+
ActiveTreeSize: swag.Int64Value(logInfo.TreeSize),
106+
TotalTreeSize: totalTreeSize(logInfo, logInfo.InactiveShards),
104107
RootHash: swag.StringValue(logInfo.RootHash),
105108
TimestampNanos: sth.GetTimestamp(),
106109
TreeID: swag.StringValue(logInfo.TreeID),
@@ -222,6 +225,14 @@ func loadVerifier(rekorClient *rclient.Rekor) (signature.Verifier, error) {
222225
return signature.LoadVerifier(pub, crypto.SHA256)
223226
}
224227

228+
func totalTreeSize(activeShard *models.LogInfo, inactiveShards []*models.InactiveShardLogInfo) int64 {
229+
total := swag.Int64Value(activeShard.TreeSize)
230+
for _, i := range inactiveShards {
231+
total += swag.Int64Value(i.TreeSize)
232+
}
233+
return total
234+
}
235+
225236
func init() {
226237
initializePFlagMap()
227238
rootCmd.AddCommand(logInfoCmd)

tests/sharding-e2e-test.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ popd
194194
# Pass in the universal log_index & make sure it resolves
195195
check_log_index 3
196196

197+
# Make sure the shard tree size is 1 and the total tree size is 4
198+
rm $HOME/.rekor/state.json # We have to remove this since we can't prove consistency between entry 0 and entry 1
199+
TREE_SIZE=$($REKOR_CLI loginfo --rekor_server http://localhost:3000 --format json | jq -r .ActiveTreeSize)
200+
stringsMatch $TREE_SIZE "1"
201+
202+
TOTAL_TREE_SIZE=$($REKOR_CLI loginfo --rekor_server http://localhost:3000 --format json | jq -r .TotalTreeSize)
203+
stringsMatch $TOTAL_TREE_SIZE "4"
204+
205+
197206
# Make sure we can still get logproof for the now-inactive shard
198207
$REKOR_CLI logproof --last-size 2 --tree-id $INITIAL_TREE_ID --rekor_server http://localhost:3000
199208
# And the logproof for the now active shard
@@ -215,7 +224,6 @@ if [[ "$ENCODED_PUBLIC_KEY" == "$NEW_PUB_KEY" ]]; then
215224
exit 1
216225
fi
217226

218-
219227
# TODO: Try to get the entry via Entry ID (Tree ID in hex + UUID)
220228
echo
221229
echo "Testing /api/v1/log/entries/retrieve endpoint..."

0 commit comments

Comments
 (0)