From 84425152c8567bf471d27a86ff06b0423fc00608 Mon Sep 17 00:00:00 2001 From: Martin Hutchinson Date: Wed, 22 Jul 2026 14:25:30 +0000 Subject: [PATCH] Safer locking semantics on lookup Previously this could return a proof for a newer tree. In the interest of making this prototype done and with as few loose ends as possible, this is fixed by simply keeping the read lock for the whole operation. Also added a .gitignore for the main files in this repo. --- .gitignore | 13 +++++++++++++ vindex/map.go | 13 ++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4711883 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# Go binaries +/cmd +/proxy +/client +/ct +/logandmap +/sumdbindex +/sumdbverify + +# Go test binaries and coverage/profile outputs +*.test +*.out +*.prof diff --git a/vindex/map.go b/vindex/map.go index a761a11..7909919 100644 --- a/vindex/map.go +++ b/vindex/map.go @@ -504,14 +504,8 @@ func (b *VerifiableIndex) Close() error { // Lookup returns the values stored for the given key. func (b *VerifiableIndex) Lookup(ctx context.Context, key [sha256.Size]byte) (api.LookupResponse, error) { - // Scope the lock to be as minimal as possible - // This looks up the indices from the in-memory map, and the proof from the vindex. - lookupLocked := func(key [sha256.Size]byte) (mpt.Proof, []uint64, error) { - b.indexMu.RLock() - defer b.indexMu.RUnlock() - _, _, proof, err := b.vindex.Prove(key) - return proof, b.data[key], err - } + b.indexMu.RLock() + defer b.indexMu.RUnlock() result := api.LookupResponse{} @@ -546,10 +540,11 @@ func (b *VerifiableIndex) Lookup(ctx context.Context, key [sha256.Size]byte) (ap result.OutputLogLeaf = data result.OutputLogProof = proof - viProof, allIndices, err := lookupLocked(key) + _, _, viProof, err := b.vindex.Prove(key) if err != nil { return result, fmt.Errorf("failed to get inclusion proof from vindex: %v", err) } + allIndices := b.data[key] cutoff := slices.IndexFunc(allIndices, func(idx uint64) bool { return idx >= size