Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
tapfreighter: set ProofDeliveryComplete field on transfer output init
- Set the `ProofDeliveryComplete` field in the transfer output struct
during its initialization.

- The `insertAssetTransferOutput` function now only marshals the
`ProofDeliveryComplete` status for database storage. It does not
determine the status at the time of storing in the database.

- `TransferOutput.ShouldDeliverProof` will return `false` if
`ProofDeliveryComplete == fn.Some(true)`.

- Improved logging for scenarios where proof delivery is skipped,
specifically when `out.ShouldDeliverProof()` returns `false`.
  • Loading branch information
ffranr committed Aug 7, 2024
commit 61f26f40494d0ffc684df73af7df75433c2ba320
19 changes: 4 additions & 15 deletions tapdb/assets_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2434,25 +2434,14 @@ func insertAssetTransferOutput(ctx context.Context, q ActiveAssetsStore,
return fmt.Errorf("unable to insert script key: %w", err)
}

// Now we will mark the output proof as undelivered if it is intended
// for a counterpart.
//
// If the transfer output proof is not intended for a counterpart the
// `proofDeliveryComplete` field will be left as NULL. Otherwise, we set
// it to false to indicate that the proof has not been delivered yet.
shouldDeliverProof, err := output.ShouldDeliverProof()
if err != nil {
return fmt.Errorf("unable to determine if proof should be "+
"delivery for given transfer output: %w", err)
}

// Marshal the proof delivery complete field to a nullable boolean.
var proofDeliveryComplete sql.NullBool
if shouldDeliverProof {
output.ProofDeliveryComplete.WhenSome(func(deliveryComplete bool) {
proofDeliveryComplete = sql.NullBool{
Bool: false,
Bool: deliveryComplete,
Valid: true,
}
}
})

// Check if position value can be stored in a 32-bit integer. Type cast
// if possible, otherwise return an error.
Expand Down
6 changes: 4 additions & 2 deletions tapfreighter/chain_porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,10 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error {
}

if !shouldDeliverProof {
log.Debugf("Not delivering proof for output with "+
"script key %x", key.SerializeCompressed())
log.Debugf("Not delivering transfer ouput proof "+
"(proof_delivery_status=%v, script_key=%x)",
out.ProofDeliveryComplete,
key.SerializeCompressed())
return nil
}

Expand Down
8 changes: 8 additions & 0 deletions tapfreighter/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ type TransferOutput struct {
// ShouldDeliverProof returns true if a proof corresponding to the subject
// transfer output should be delivered to a peer.
func (out *TransferOutput) ShouldDeliverProof() (bool, error) {
// If any proof delivery is already complete (some true), no further
// delivery is needed. However, if the proof delivery status is
// unset (none), we won't use that status in determining whether proof
// delivery is necessary. The field may not be set yet.
if out.ProofDeliveryComplete.UnwrapOr(false) {
return false, nil
}

// If the proof courier address is unspecified, we don't need to deliver
// a proof.
if len(out.ProofCourierAddr) == 0 {
Expand Down
25 changes: 23 additions & 2 deletions tapfreighter/parcel.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func transferOutput(vPkt *tappsbt.VPacket, vOutIdx int, position uint64,
return nil, fmt.Errorf("unable to create anchor: %w", err)
}

return &TransferOutput{
out := TransferOutput{
Anchor: *anchor,
Type: vOut.Type,
ScriptKey: vOut.ScriptKey,
Expand All @@ -618,7 +618,28 @@ func transferOutput(vPkt *tappsbt.VPacket, vOutIdx int, position uint64,
ProofCourierAddr: proofCourierAddrBytes,
ScriptKeyLocal: isLocalKey(vOut.ScriptKey),
Position: position,
}, nil
}

// Determine whether an associated proof needs to be delivered to a peer
// based on the currently set fields.
shouldDeliverProof, err := out.ShouldDeliverProof()
if err != nil {
return nil, fmt.Errorf("unable to determine if transfer "+
"output proof should be delivery to a peer: %w", err)
}

if shouldDeliverProof {
// Set the `ProofDeliveryComplete` field to `Some(false)` to
// indicate that proof delivery is pending. Once the proof has
// been successfully delivered, this field will be updated to
// `Some(true)`.
//
// If it was determined that the proof should not be delivered,
// the `ProofDeliveryComplete` field would remain `None`.
out.ProofDeliveryComplete = fn.Some(false)
}

return &out, nil
}

// outputAnchor creates an Anchor from an anchor transaction and a virtual
Expand Down