Skip to content

Commit

Permalink
Merge pull request #529 from lightninglabs/backoff-multi-send-bug
Browse files Browse the repository at this point in the history
Backoff procedure erroneously resumed between two different send events
  • Loading branch information
Roasbeef authored Sep 25, 2023
2 parents e81e803 + 30b333d commit 16b6c6f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
13 changes: 11 additions & 2 deletions proof/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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[:])
Expand All @@ -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
Expand Down
23 changes: 19 additions & 4 deletions tapdb/assets_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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[:],
)
Expand Down Expand Up @@ -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")
Expand Down
11 changes: 10 additions & 1 deletion tapfreighter/chain_porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 16b6c6f

Please sign in to comment.