Skip to content

Commit 61f26f4

Browse files
committed
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`.
1 parent 165ed77 commit 61f26f4

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

tapdb/assets_store.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,25 +2434,14 @@ func insertAssetTransferOutput(ctx context.Context, q ActiveAssetsStore,
24342434
return fmt.Errorf("unable to insert script key: %w", err)
24352435
}
24362436

2437-
// Now we will mark the output proof as undelivered if it is intended
2438-
// for a counterpart.
2439-
//
2440-
// If the transfer output proof is not intended for a counterpart the
2441-
// `proofDeliveryComplete` field will be left as NULL. Otherwise, we set
2442-
// it to false to indicate that the proof has not been delivered yet.
2443-
shouldDeliverProof, err := output.ShouldDeliverProof()
2444-
if err != nil {
2445-
return fmt.Errorf("unable to determine if proof should be "+
2446-
"delivery for given transfer output: %w", err)
2447-
}
2448-
2437+
// Marshal the proof delivery complete field to a nullable boolean.
24492438
var proofDeliveryComplete sql.NullBool
2450-
if shouldDeliverProof {
2439+
output.ProofDeliveryComplete.WhenSome(func(deliveryComplete bool) {
24512440
proofDeliveryComplete = sql.NullBool{
2452-
Bool: false,
2441+
Bool: deliveryComplete,
24532442
Valid: true,
24542443
}
2455-
}
2444+
})
24562445

24572446
// Check if position value can be stored in a 32-bit integer. Type cast
24582447
// if possible, otherwise return an error.

tapfreighter/chain_porter.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,10 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error {
656656
}
657657

658658
if !shouldDeliverProof {
659-
log.Debugf("Not delivering proof for output with "+
660-
"script key %x", key.SerializeCompressed())
659+
log.Debugf("Not delivering transfer ouput proof "+
660+
"(proof_delivery_status=%v, script_key=%x)",
661+
out.ProofDeliveryComplete,
662+
key.SerializeCompressed())
661663
return nil
662664
}
663665

tapfreighter/interface.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ type TransferOutput struct {
252252
// ShouldDeliverProof returns true if a proof corresponding to the subject
253253
// transfer output should be delivered to a peer.
254254
func (out *TransferOutput) ShouldDeliverProof() (bool, error) {
255+
// If any proof delivery is already complete (some true), no further
256+
// delivery is needed. However, if the proof delivery status is
257+
// unset (none), we won't use that status in determining whether proof
258+
// delivery is necessary. The field may not be set yet.
259+
if out.ProofDeliveryComplete.UnwrapOr(false) {
260+
return false, nil
261+
}
262+
255263
// If the proof courier address is unspecified, we don't need to deliver
256264
// a proof.
257265
if len(out.ProofCourierAddr) == 0 {

tapfreighter/parcel.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ func transferOutput(vPkt *tappsbt.VPacket, vOutIdx int, position uint64,
604604
return nil, fmt.Errorf("unable to create anchor: %w", err)
605605
}
606606

607-
return &TransferOutput{
607+
out := TransferOutput{
608608
Anchor: *anchor,
609609
Type: vOut.Type,
610610
ScriptKey: vOut.ScriptKey,
@@ -618,7 +618,28 @@ func transferOutput(vPkt *tappsbt.VPacket, vOutIdx int, position uint64,
618618
ProofCourierAddr: proofCourierAddrBytes,
619619
ScriptKeyLocal: isLocalKey(vOut.ScriptKey),
620620
Position: position,
621-
}, nil
621+
}
622+
623+
// Determine whether an associated proof needs to be delivered to a peer
624+
// based on the currently set fields.
625+
shouldDeliverProof, err := out.ShouldDeliverProof()
626+
if err != nil {
627+
return nil, fmt.Errorf("unable to determine if transfer "+
628+
"output proof should be delivery to a peer: %w", err)
629+
}
630+
631+
if shouldDeliverProof {
632+
// Set the `ProofDeliveryComplete` field to `Some(false)` to
633+
// indicate that proof delivery is pending. Once the proof has
634+
// been successfully delivered, this field will be updated to
635+
// `Some(true)`.
636+
//
637+
// If it was determined that the proof should not be delivered,
638+
// the `ProofDeliveryComplete` field would remain `None`.
639+
out.ProofDeliveryComplete = fn.Some(false)
640+
}
641+
642+
return &out, nil
622643
}
623644

624645
// outputAnchor creates an Anchor from an anchor transaction and a virtual

0 commit comments

Comments
 (0)