diff --git a/proof/archive.go b/proof/archive.go index 95ca9b967..9d255c8f9 100644 --- a/proof/archive.go +++ b/proof/archive.go @@ -17,6 +17,7 @@ import ( "github.com/lightninglabs/taproot-assets/asset" "github.com/lightninglabs/taproot-assets/fn" "github.com/lightningnetwork/lnd/lnrpc" + "github.com/lightningnetwork/lnd/lnwire" ) const ( @@ -64,7 +65,7 @@ type Locator struct { } // Hash returns a SHA256 hash of the bytes serialized locator. -func (l *Locator) Hash() [32]byte { +func (l *Locator) Hash() ([32]byte, error) { var buf bytes.Buffer if l.AssetID != nil { buf.Write(l.AssetID[:]) @@ -74,8 +75,16 @@ func (l *Locator) Hash() [32]byte { } buf.Write(l.ScriptKey.SerializeCompressed()) + if l.OutPoint != nil { + err := lnwire.WriteOutPoint(&buf, *l.OutPoint) + if err != nil { + return [32]byte{}, fmt.Errorf("unable to write "+ + "outpoint: %w", err) + } + } + // Hash the buffer. - return sha256.Sum256(buf.Bytes()) + return sha256.Sum256(buf.Bytes()), nil } // AnnotatedProof an annotated proof contains the raw proof blob along with a diff --git a/tapdb/assets_store.go b/tapdb/assets_store.go index 3e7c2931d..400377aff 100644 --- a/tapdb/assets_store.go +++ b/tapdb/assets_store.go @@ -2347,8 +2347,13 @@ func (a *AssetStore) StoreProofDeliveryAttempt(ctx context.Context, return a.db.ExecTx(ctx, &writeTxOpts, func(q ActiveAssetsStore) error { // Log proof delivery attempt and timestamp using the current // time. - proofLocatorHash := locator.Hash() - err := q.InsertReceiverProofTransferAttempt( + proofLocatorHash, err := locator.Hash() + if err != nil { + return fmt.Errorf("unable to hash proof locator: %w", + err) + } + + err = q.InsertReceiverProofTransferAttempt( ctx, InsertRecvProofTxAttemptParams{ ProofLocatorHash: proofLocatorHash[:], TimeUnix: a.clock.Now().UTC(), @@ -2375,7 +2380,12 @@ func (a *AssetStore) QueryProofDeliveryLog(ctx context.Context, readOpts := NewAssetStoreReadTx() err = a.db.ExecTx(ctx, &readOpts, func(q ActiveAssetsStore) error { - proofLocatorHash := locator.Hash() + proofLocatorHash, err := locator.Hash() + if err != nil { + return fmt.Errorf("unable to hash proof locator: %w", + err) + } + timestamps, err = q.QueryReceiverProofTransferAttempt( ctx, proofLocatorHash[:], ) @@ -2624,7 +2634,12 @@ func (a *AssetStore) reAnchorPassiveAssets(ctx context.Context, AssetID: &assetID, ScriptKey: *scriptKey, } - proofFile := proofFiles[locator.Hash()] + locatorHash, err := locator.Hash() + if err != nil { + return fmt.Errorf("failed to hash locator: %w", err) + } + + proofFile := proofFiles[locatorHash] if proofFile == nil { return fmt.Errorf("failed to find proof file for " + "passive asset") diff --git a/tapfreighter/chain_porter.go b/tapfreighter/chain_porter.go index c9c4d87eb..5d47e9c7d 100644 --- a/tapfreighter/chain_porter.go +++ b/tapfreighter/chain_porter.go @@ -451,6 +451,7 @@ func (p *ChainPorter) storeProofs(sendPkg *sendPackage) error { outputProofLocator := proof.Locator{ AssetID: &firstInput.ID, ScriptKey: *out.ScriptKey.PubKey, + OutPoint: &firstInput.OutPoint, } outputProof := &proof.AnnotatedProof{ Locator: outputProofLocator, @@ -695,7 +696,15 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error { return fmt.Errorf("error fetching passive asset "+ "proof file: %w", err) } - passiveAssetProofFiles[proofLocator.Hash()] = proofFileBlob + + // Hash proof locator. + hash, err := proofLocator.Hash() + if err != nil { + return fmt.Errorf("error hashing proof locator: %w", + err) + } + + passiveAssetProofFiles[hash] = proofFileBlob } // At this point we have the confirmation signal, so we can mark the