Skip to content

Commit

Permalink
Merge pull request #484 from lightninglabs/proof-courier-ntfn
Browse files Browse the repository at this point in the history
Fix proof courier in integration test
  • Loading branch information
jharveyb authored Sep 5, 2023
2 parents 603894b + eb415c3 commit f87d176
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
7 changes: 0 additions & 7 deletions itest/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ func testBasicSendUnidirectional(t *harnessTest) {
t, t.tapd, sendResp, genInfo.AssetId,
[]uint64{currentUnits, numUnits}, i, i+1,
)
_ = sendProof(
t, t.tapd, secondTapd, bobAddr.ScriptKey, genInfo,
)
AssertNonInteractiveRecvComplete(t.t, secondTapd, i+1)
}

Expand Down Expand Up @@ -212,10 +209,6 @@ func testResumePendingPackageSend(t *harnessTest) {
t.lndHarness.MineBlocks(6)
}

_ = sendProof(
t, sendTapd, recvTapd, recvAddr.ScriptKey, genInfo,
)

// Confirm with the receiver node that the asset was fully
// received.
AssertNonInteractiveRecvComplete(t.t, recvTapd, i+1)
Expand Down
2 changes: 1 addition & 1 deletion itest/tapd_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func newTapdHarness(ht *harnessTest, cfg tapdConfig,
case *ApertureHarness:
// Use passed in backoff config or default config.
backoffCfg := &proof.BackoffCfg{
BackoffResetWait: 20 * time.Second,
BackoffResetWait: 2 * time.Second,
NumTries: 3,
InitialBackoff: 2 * time.Second,
MaxBackoff: 2 * time.Second,
Expand Down
2 changes: 1 addition & 1 deletion proof/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (h *HashMailCourier) DeliverProof(ctx context.Context,
proof *AnnotatedProof) error {

log.Infof("Attempting to deliver receiver proof for send of "+
"asset_id=%x, amt=%v", h.recipient.AssetID, h.recipient.Amount)
"asset_id=%v, amt=%v", h.recipient.AssetID, h.recipient.Amount)

// Compute the stream IDs for the sender and receiver.
senderStreamID := deriveSenderStreamID(h.recipient)
Expand Down
9 changes: 9 additions & 0 deletions proof/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ type Proof struct {
ChallengeWitness wire.TxWitness
}

// OutPoint returns the outpoint that commits to the asset associated with this
// proof.
func (p *Proof) OutPoint() wire.OutPoint {
return wire.OutPoint{
Hash: p.AnchorTx.TxHash(),
Index: p.InclusionProof.OutputIndex,
}
}

// EncodeRecords returns the set of known TLV records to encode a Proof.
func (p *Proof) EncodeRecords() []tlv.Record {
records := make([]tlv.Record, 0, 9)
Expand Down
21 changes: 17 additions & 4 deletions tapgarden/custodian.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,16 @@ func (c *Custodian) inspectWalletTx(walletTx *lndclient.Transaction) error {
return err
}

// We are not interested in the outpoint if we don't know of a
// pre-stored address associated with it.
if addr == nil {
continue
}

// TODO(ffranr): This proof courier disabled check should be
// removed. It was implemented because some integration test do
// not setup and use a proof courier.
skipProofCourier := c.cfg.ProofCourierCfg == nil || addr == nil
if skipProofCourier {
if c.cfg.ProofCourierCfg == nil {
continue
}

Expand Down Expand Up @@ -580,12 +585,20 @@ func (c *Custodian) mapProofToEvent(p proof.Blob) error {

// Check if any of our in-flight events match the last proof's state.
for _, event := range c.events {
if AddrMatchesAsset(event.Addr, &lastProof.Asset) {
if AddrMatchesAsset(event.Addr, &lastProof.Asset) &&
event.Outpoint == lastProof.OutPoint() {

// Importing a proof already creates the asset in the
// database. Therefore, all we need to do is update the
// state of the address event to mark it as completed
// successfully.
return c.setReceiveCompleted(event, lastProof, file)
err = c.setReceiveCompleted(event, lastProof, file)
if err != nil {
return fmt.Errorf("error updating event: %w",
err)
}

delete(c.events, event.Outpoint)
}
}

Expand Down

0 comments on commit f87d176

Please sign in to comment.