Skip to content

Commit bd32f90

Browse files
committed
universe: improve robustness of proof leaf sync
During syncing, the universe root is fetched before the proof leaves, which are then verified against that root. Occasionally, the fetched root may become stale before a proof leaf is verified. In such cases, the proof leaf may belong to a newer version of the universe tree. This isn't critical, as the syncer will eventually resolve the mismatch during subsequent universe root queries. To improve robustness, this change modifies how proof leaves are fetched. While queries remain parallel, failed query or verification attempts no longer prevent other attempts from proceeding. The syncer now uses whatever proof leaves it can verify with the universe root it has.
1 parent 053a88a commit bd32f90

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

universe/syncer.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func (s *SimpleSyncer) syncRoot(ctx context.Context, remoteRoot Root,
304304

305305
// Now that we know where the divergence is, we can fetch the issuance
306306
// proofs from the remote party.
307-
err = fn.ParSlice(
307+
fetchErrs, err := fn.ParSliceErrCollect(
308308
ctx, keysToFetch, func(ctx context.Context, key LeafKey) error {
309309
newProof, err := diffEngine.FetchProofLeaf(
310310
ctx, uniID, key,
@@ -320,8 +320,9 @@ func (s *SimpleSyncer) syncRoot(ctx context.Context, remoteRoot Root,
320320
// given.
321321
validRoot := leafProof.VerifyRoot(remoteRoot)
322322
if !validRoot {
323-
return fmt.Errorf("proof for key=%v is "+
324-
"invalid", spew.Sdump(key))
323+
return fmt.Errorf("proof leaf failed "+
324+
"universe root verification "+
325+
"(leaf_key=%v)", spew.Sdump(key))
325326
}
326327

327328
// If this is an issuance proof, then we can send
@@ -379,6 +380,13 @@ func (s *SimpleSyncer) syncRoot(ctx context.Context, remoteRoot Root,
379380
return err
380381
}
381382

383+
// Report any errors encountered while fetching the leaves.
384+
for idx, fetchErr := range fetchErrs {
385+
leafKey := keysToFetch[idx]
386+
log.Errorf("Error fetching leaf (leaf_key=%x): %v",
387+
leafKey.UniverseKey(), fetchErr)
388+
}
389+
382390
// We use an error group to simply the error handling of a goroutine.
383391
// This goroutine will handle reading in batches of new leaves to
384392
// insert into the DB. We'll fee the output of the goroutines below

0 commit comments

Comments
 (0)