Skip to content

Commit 632294a

Browse files
authored
Merge pull request #1866 from lightninglabs/wip/proof-validation-logging
proof: expand validation logging for inclusion/exclusion proofs
2 parents 3ba2cc0 + 7f7c8ce commit 632294a

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

proof/verifier.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"fmt"
77
"io"
88
"runtime"
9+
"sort"
10+
"strconv"
11+
"strings"
912
"sync"
1013

1114
"github.com/btcsuite/btcd/btcec/v2"
@@ -178,10 +181,10 @@ func verifyTaprootProof(anchor *wire.MsgTx, proof *TaprootProof,
178181
)
179182

180183
return nil, fmt.Errorf("%w: derived_keys=%s, expected_key=%x, "+
181-
"output_index=%d, internal_key=%x, method=%s",
184+
"output_index=%d, internal_key=%x, asset_id=%s, method=%s",
182185
commitment.ErrInvalidTaprootProof, keysForLog, expectedKey,
183186
proof.OutputIndex, proof.InternalKey.SerializeCompressed(),
184-
method)
187+
a.ID().String(), method)
185188
}
186189

187190
// verifyInclusionProof verifies the InclusionProof is valid.
@@ -373,9 +376,26 @@ func (p *Proof) verifyV0ExclusionProofs(
373376
// Correctly validated proofs are removed from the set. That means, if
374377
// there are any outputs left in the set, it means that there are
375378
// missing proofs for those outputs.
376-
if len(p2trOutputs) > 0 {
377-
return nil, fmt.Errorf("%w: missing exclusion proof(s)",
378-
ErrInvalidCommitmentProof)
379+
if len(p2trOutputs) != 0 {
380+
// Collect and sort the missing output indexes for stable
381+
// logging/errors.
382+
indexes := make([]int, 0, len(p2trOutputs))
383+
for i := range p2trOutputs {
384+
indexes = append(indexes, int(i))
385+
}
386+
sort.Ints(indexes)
387+
388+
// Format as "0, 3, 7".
389+
parts := make([]string, len(indexes))
390+
for i, v := range indexes {
391+
parts[i] = strconv.Itoa(v)
392+
}
393+
missing := strings.Join(parts, ", ")
394+
395+
log.Errorf("Missing exclusion proofs for p2tr output "+
396+
"indexes: %s", missing)
397+
return nil, fmt.Errorf("%w: missing exclusion proofs for "+
398+
"outputs", ErrInvalidCommitmentProof)
379399
}
380400

381401
return commitVersions, nil

tapgarden/caretaker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ func (b *BatchCaretaker) batchStreamUniverseItems(ctx context.Context,
13111311
err := uni.UpsertProofLeafBatch(ctx, batch)
13121312
if err != nil {
13131313
return fmt.Errorf("unable to register "+
1314-
"issuance batch: %w", err)
1314+
"proof leaf batch: %w", err)
13151315
}
13161316

13171317
log.Infof("Inserted %d new leaves (%d of %d) into "+

universe/archive.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ func extractBatchDeps(batch []*Item) map[UniverseKey]*asset.Asset {
428428
func (a *Archive) UpsertProofLeafBatch(ctx context.Context,
429429
items []*Item) error {
430430

431-
log.Infof("Verifying %d new proofs for insertion into Universe",
432-
len(items))
431+
log.InfoS(ctx, "Verifying new proofs for insertion into Universe",
432+
"count", len(items))
433433

434434
// Issuance proofs that also create an asset group (a.k.a. group
435435
// anchors) must be verified and stored before any issuance proofs that
@@ -529,25 +529,25 @@ func (a *Archive) UpsertProofLeafBatch(ctx context.Context,
529529
return err
530530
}
531531

532-
log.Infof("Inserting %d verified group anchor proofs into Universe",
533-
len(anchorItems))
532+
log.InfoS(ctx, "Inserting verified group anchor proofs into Universe",
533+
"count", len(anchorItems))
534534
err = a.cfg.Multiverse.UpsertProofLeafBatch(ctx, anchorItems)
535535
if err != nil {
536-
return fmt.Errorf("unable to register new group anchor "+
537-
"issuance proofs: %w", err)
536+
return fmt.Errorf("upsert group anchor proof leaf batch "+
537+
"(count=%d): %w", len(anchorItems), err)
538538
}
539539

540540
err = verifyBatch(nonAnchorItems)
541541
if err != nil {
542542
return err
543543
}
544544

545-
log.Infof("Inserting %d verified proofs into Universe",
546-
len(nonAnchorItems))
545+
log.InfoS(ctx, "Inserting verified proofs into Universe",
546+
"count", len(nonAnchorItems))
547547
err = a.cfg.Multiverse.UpsertProofLeafBatch(ctx, nonAnchorItems)
548548
if err != nil {
549-
return fmt.Errorf("unable to register new issuance proofs: %w",
550-
err)
549+
return fmt.Errorf("upsert proof leaf batch (count=%d): %w",
550+
len(nonAnchorItems), err)
551551
}
552552

553553
// Log a sync event for the newly inserted leaf in the background as an

0 commit comments

Comments
 (0)