Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backoff procedure erroneously resumed between two different send events #529

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, forgot about the error return type. Since we ignore any errors returned by buf.Write() above (which AFAIK can never return an actual error on a bytes.Buffer but is part of the io.Writer interface anyway), we probably can do the same here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The was merged before I saw your comment! Let me know if you want me to open another PR to go back on the err handling (I'm guessing this is fine as is?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no problem, let's leave it the way it is now.

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,
ffranr marked this conversation as resolved.
Show resolved Hide resolved
}
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