From b05a66f634d38ab3a038aed69ae078e182887d75 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Tue, 17 Jun 2025 10:45:56 -0400 Subject: [PATCH] Only calculate root hash when needed to verify an STH --- monitor/monitor.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/monitor/monitor.go b/monitor/monitor.go index ab62715..ccbae94 100644 --- a/monitor/monitor.go +++ b/monitor/monitor.go @@ -504,12 +504,11 @@ func saveStateWorker(ctx context.Context, config *Config, ctlog *loglist.Log, st if batch.begin != state.DownloadPosition.Size() { panic(fmt.Errorf("saveStateWorker: expected batch to start at %d but got %d instead", state.DownloadPosition.Size(), batch.begin)) } - rootHash := state.DownloadPosition.CalculateRoot() for { for len(batch.sths) > 0 && batch.sths[0].TreeSize == state.DownloadPosition.Size() { sth := batch.sths[0] batch.sths = batch.sths[1:] - if sth.RootHash != rootHash { + if rootHash := state.DownloadPosition.CalculateRoot(); sth.RootHash != rootHash { return &verifyEntriesError{ sth: &sth.SignedTreeHead, entriesRootHash: rootHash, @@ -536,7 +535,6 @@ func saveStateWorker(ctx context.Context, config *Config, ctlog *loglist.Log, st batch.entries = batch.entries[1:] leafHash := merkletree.HashLeaf(entry.LeafInput()) state.DownloadPosition.Add(leafHash) - rootHash = state.DownloadPosition.CalculateRoot() } if err := config.State.StoreLogState(ctx, ctlog.LogID, state); err != nil {