Skip to content

Commit 80bbe42

Browse files
committed
proof: improve hashmail courier proof delivery log messages
Improve comments, log messages, and error messages.
1 parent 55c55c9 commit 80bbe42

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

proof/courier.go

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,19 @@ func (h *HashMailBox) RecvAck(ctx context.Context, sid streamID) error {
439439
return fmt.Errorf("unable to create read stream: %w", err)
440440
}
441441

442+
log.Debugf("Exec stream Recv for receiver ACK (sid=%x)", sid[:])
442443
msg, err := readStream.Recv()
443444
if err != nil {
444-
return err
445+
return fmt.Errorf("failed on stream Recv (sid=%x): %w", sid[:],
446+
err)
445447
}
446448

447449
if bytes.Equal(msg.Msg, ackMsg) {
450+
log.Debugf("Received ACK from sender (sid=%x)", sid[:])
448451
return nil
449452
}
450453

451-
return fmt.Errorf("expected ack, got %x", msg.Msg)
454+
return fmt.Errorf("expected ACK from hashmail service, got %x", msg.Msg)
452455
}
453456

454457
// CleanUp attempts to tear down the mailbox as specified by the passed sid.
@@ -867,13 +870,20 @@ func (h *HashMailCourier) ensureConnect(ctx context.Context) error {
867870
func (h *HashMailCourier) DeliverProof(ctx context.Context,
868871
recipient Recipient, proof *AnnotatedProof) error {
869872

870-
log.Infof("Attempting to deliver receiver proof for send of "+
871-
"asset_id=%v, amt=%v", recipient.AssetID, recipient.Amount)
872-
873-
// Compute the stream IDs for the sender and receiver.
873+
// Compute the stream IDs for the sender and receiver. Note that these
874+
// stream IDs are derived from the recipient's script key only. Which
875+
// means that stream IDs will be identical for multiple proofs sent to
876+
// the same recipient.
874877
senderStreamID := deriveSenderStreamID(recipient)
875878
receiverStreamID := deriveReceiverStreamID(recipient)
876879

880+
log.Infof("Delivering proof to asset transfer receiver "+
881+
"(amt=%v, asset_id=%v, script_pub_key=%x, "+
882+
"sender_sid=%x, receiver_sid=%x)",
883+
recipient.Amount, recipient.AssetID,
884+
recipient.ScriptKey.SerializeCompressed(), senderStreamID,
885+
receiverStreamID)
886+
877887
// Interact with the hashmail service using a backoff procedure to
878888
// ensure that we don't overwhelm the service with delivery attempts.
879889
deliveryExec := func() error {
@@ -901,8 +911,7 @@ func (h *HashMailCourier) DeliverProof(ctx context.Context,
901911
// TODO(roasbeef): do ecies here
902912
// (this ^ TODO relates to encrypting proofs for the receiver
903913
// before uploading to the courier)
904-
log.Infof("Sending receiver proof via sid=%x",
905-
senderStreamID)
914+
log.Infof("Writing proof to mailbox (sid=%x)", senderStreamID)
906915
err = h.mailbox.WriteProof(
907916
ctx, senderStreamID, proof.Blob,
908917
)
@@ -911,21 +920,27 @@ func (h *HashMailCourier) DeliverProof(ctx context.Context,
911920
"transfer receiver: %w", err)
912921
}
913922

914-
// Wait to receive the ACK from the remote party over
915-
// their stream.
916-
log.Infof("Waiting (%v) for receiver ACK via sid=%x",
917-
h.cfg.ReceiverAckTimeout, receiverStreamID)
923+
// Wait to receive ACK from proof transfer receiving peer over
924+
// hashmail service.
925+
log.Infof("Waiting for receiver ACK from hashmail service "+
926+
"(timeout=%v, sid=%x)", h.cfg.ReceiverAckTimeout,
927+
receiverStreamID)
918928

919929
ctxTimeout, cancel := context.WithTimeout(
920930
ctx, h.cfg.ReceiverAckTimeout,
921931
)
922932
defer cancel()
923933
err = h.mailbox.RecvAck(ctxTimeout, receiverStreamID)
924934
if err != nil {
925-
return fmt.Errorf("failed to receive ACK from "+
926-
"receiver within timeout: %w", err)
935+
return fmt.Errorf("failed to retrieve proof transfer "+
936+
"receiver ACK within timeout (sid=%x): %w",
937+
receiverStreamID, err)
927938
}
928939

940+
log.Infof("Retrieved proof transfer receiver ACK from "+
941+
"hashmail service (timeout=%v, sid=%x)",
942+
h.cfg.ReceiverAckTimeout, receiverStreamID)
943+
929944
return nil
930945
}
931946
err := h.backoffHandle.Exec(
@@ -937,12 +952,12 @@ func (h *HashMailCourier) DeliverProof(ctx context.Context,
937952
"failed: %w", err)
938953
}
939954

940-
log.Infof("Received ACK from receiver! Cleaning up mailboxes...")
941-
942955
defer h.Close()
943956

944-
// Once we receive this ACK, we can clean up our mailbox and also the
945-
// receiver's mailbox.
957+
// If the backoff handler's exec routine completes successfully, we can
958+
// remove our mailbox and the receiver's mailbox.
959+
log.Infof("Removing sender and recipient mailboxes from hashmail " +
960+
"service")
946961
if err := h.mailbox.CleanUp(ctx, senderStreamID); err != nil {
947962
return fmt.Errorf("failed to cleanup sender mailbox: %w", err)
948963
}

0 commit comments

Comments
 (0)