Skip to content

Commit

Permalink
lnwire+lnd: Make Logging Messages Great Again
Browse files Browse the repository at this point in the history
This commit modifies the login of sent/recv’d wire messages in trace
mode in order utilize the more detailed, and automatically generated
logging statements using pure spew.Sdump.

In order to avoid the spammy messages due to spew printing the
btcec.S256() curve paramter within wire messages with public keys, we
introduce a new logging function to unset the curve paramter to it
isn’t printed in its entirety. To insure we don’t run into any panics
as a result of a nil pointer defense, we now copy the public keys
during the funding process so we don’t run into a panic due to
modifying a pointer to the same object.
  • Loading branch information
Roasbeef committed Jan 15, 2017
1 parent 0bfdcde commit d884efe
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 400 deletions.
20 changes: 14 additions & 6 deletions fundingmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ func (f *fundingManager) handleFundingRequest(fmsg *fundingRequestMsg) {
}
contribution := &lnwallet.ChannelContribution{
FundingAmount: amt,
MultiSigKey: msg.ChannelDerivationPoint,
CommitKey: msg.CommitmentKey,
MultiSigKey: copyPubKey(msg.ChannelDerivationPoint),
CommitKey: copyPubKey(msg.CommitmentKey),
DeliveryAddress: addrs[0],
CsvDelay: delay,
}
Expand Down Expand Up @@ -464,10 +464,10 @@ func (f *fundingManager) handleFundingResponse(fmsg *fundingResponseMsg) {
}
contribution := &lnwallet.ChannelContribution{
FundingAmount: 0,
MultiSigKey: msg.ChannelDerivationPoint,
CommitKey: msg.CommitmentKey,
MultiSigKey: copyPubKey(msg.ChannelDerivationPoint),
CommitKey: copyPubKey(msg.CommitmentKey),
DeliveryAddress: addrs[0],
RevocationKey: msg.RevocationKey,
RevocationKey: copyPubKey(msg.RevocationKey),
CsvDelay: msg.CsvDelay,
}
if err := resCtx.reservation.ProcessContribution(contribution); err != nil {
Expand Down Expand Up @@ -534,7 +534,7 @@ func (f *fundingManager) handleFundingComplete(fmsg *fundingCompleteMsg) {
chanID, fundingOut,
)

revokeKey := fmsg.msg.RevocationKey
revokeKey := copyPubKey(fmsg.msg.RevocationKey)
obsfucator := fmsg.msg.StateHintObsfucator
commitSig := fmsg.msg.CommitSignature.Serialize()

Expand Down Expand Up @@ -1034,3 +1034,11 @@ func (f *fundingManager) getReservationCtx(peerID int32,

return resCtx, nil
}

func copyPubKey(pub *btcec.PublicKey) *btcec.PublicKey {
return &btcec.PublicKey{
Curve: btcec.S256(),
X: pub.X,
Y: pub.Y,
}
}
18 changes: 0 additions & 18 deletions lnwire/channel_announcement.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package lnwire

import (
"bytes"
"fmt"
"io"

"github.com/go-errors/errors"
Expand Down Expand Up @@ -174,23 +173,6 @@ func (c *ChannelAnnouncement) MaxPayloadLength(pver uint32) uint32 {
return length
}

// String returns the string representation of the target ChannelAnnouncement.
//
// This is part of the lnwire.Message interface.
func (c *ChannelAnnouncement) String() string {
return fmt.Sprintf("\n--- Begin ChannelAnnouncement ---\n") +
fmt.Sprintf("FirstNodeSig:\t\t%v\n", c.FirstNodeSig) +
fmt.Sprintf("SecondNodeSig:\t\t%v\n", c.SecondNodeSig) +
fmt.Sprintf("ChannelID:\t\t%v\n", c.ChannelID.ToUint64()) +
fmt.Sprintf("FirstBitcoinSig:\t\t%v\n", c.FirstBitcoinSig) +
fmt.Sprintf("SecondBitcoinSig:\t\t%v\n", c.SecondBitcoinSig) +
fmt.Sprintf("FirstNodeSig:\t\t%v\n", c.FirstNodeSig) +
fmt.Sprintf("SecondNodeID:\t\t%v\n", c.SecondNodeID) +
fmt.Sprintf("FirstBitcoinKey:\t\t%v\n", c.FirstBitcoinKey) +
fmt.Sprintf("SecondBitcoinKey:\t\t%v\n", c.SecondBitcoinKey) +
fmt.Sprintf("--- End ChannelAnnouncement ---\n")
}

// DataToSign is used to retrieve part of the announcement message which
// should be signed.
func (c *ChannelAnnouncement) DataToSign() ([]byte, error) {
Expand Down
3 changes: 1 addition & 2 deletions lnwire/channel_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ type ChannelID struct {
// NOTE: This field is limited to 3 bytes.
TxIndex uint32

// TxPosition indicating transaction output which pays to the
// channel.
// TxPosition indicating transaction output which pays to the channel.
TxPosition uint16
}

Expand Down
17 changes: 0 additions & 17 deletions lnwire/channel_update_announcement.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package lnwire
import (
"bytes"
"errors"
"fmt"
"io"

"github.com/roasbeef/btcd/btcec"
Expand Down Expand Up @@ -152,22 +151,6 @@ func (c *ChannelUpdateAnnouncement) MaxPayloadLength(pver uint32) uint32 {
return length
}

// String returns the string representation of the target ChannelUpdateAnnouncement.
//
// This is part of the lnwire.Message interface.
func (c *ChannelUpdateAnnouncement) String() string {
return fmt.Sprintf("\n--- Begin ChannelUpdateAnnouncement ---\n") +
fmt.Sprintf("Signature:\t\t%v\n", c.Signature) +
fmt.Sprintf("ChannelID:\t\t%v\n", c.ChannelID.ToUint64()) +
fmt.Sprintf("Timestamp:\t\t%v\n", c.Timestamp) +
fmt.Sprintf("Flags:\t\t%v\n", c.Flags) +
fmt.Sprintf("Expiry:\t\t%v\n", c.Expiry) +
fmt.Sprintf("HtlcMinimumMstat:\t\t%v\n", c.HtlcMinimumMstat) +
fmt.Sprintf("FeeBaseMstat:\t\t%v\n", c.FeeBaseMstat) +
fmt.Sprintf("FeeProportionalMillionths:\t\t%v\n", c.FeeProportionalMillionths) +
fmt.Sprintf("--- End ChannelUpdateAnnouncement ---\n")
}

// DataToSign is used to retrieve part of the announcement message which
// should be signed.
func (c *ChannelUpdateAnnouncement) DataToSign() ([]byte, error) {
Expand Down
17 changes: 0 additions & 17 deletions lnwire/close_complete.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package lnwire

import (
"fmt"

"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/wire"

Expand Down Expand Up @@ -97,18 +95,3 @@ func (c *CloseComplete) Validate() error {
// We're good!
return nil
}

// String returns the string representation of the target CloseComplete.
//
// This is part of the lnwire.Message interface.
func (c *CloseComplete) String() string {
var serializedSig []byte
if c.ResponderCloseSig != nil {
serializedSig = c.ResponderCloseSig.Serialize()
}

return fmt.Sprintf("\n--- Begin CloseComplete ---\n") +
fmt.Sprintf("ReservationID:\t\t%d\n", c.ChannelPoint) +
fmt.Sprintf("ResponderCloseSig:\t%x\n", serializedSig) +
fmt.Sprintf("--- End CloseComplete ---\n")
}
20 changes: 2 additions & 18 deletions lnwire/close_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type CloseRequest struct {
RequesterCloseSig *btcec.Signature

// Fee is the required fee-per-KB the closing transaction must have.
// It is recommended that a "sufficient" fee be paid in order to achieve
// timely channel closure.
// It is recommended that a "sufficient" fee be paid in order to
// achieve timely channel closure.
// TODO(roasbeef): if initiator always pays fees, then no longer needed.
Fee btcutil.Amount
}
Expand Down Expand Up @@ -117,19 +117,3 @@ func (c *CloseRequest) Validate() error {
// We're good!
return nil
}

// String returns the string representation of the target CloseRequest.
//
// This is part of the lnwire.Message interface.
func (c *CloseRequest) String() string {
var serializedSig []byte
if c.RequesterCloseSig != nil && c.RequesterCloseSig.R != nil {
serializedSig = c.RequesterCloseSig.Serialize()
}

return fmt.Sprintf("\n--- Begin CloseRequest ---\n") +
fmt.Sprintf("ChannelPoint:\t\t%v\n", c.ChannelPoint) +
fmt.Sprintf("CloseSig\t\t%x\n", serializedSig) +
fmt.Sprintf("Fee:\t\t\t%d\n", c.Fee) +
fmt.Sprintf("--- End CloseRequest ---\n")
}
16 changes: 0 additions & 16 deletions lnwire/commit_revocation.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lnwire

import (
"fmt"
"io"

"github.com/roasbeef/btcd/btcec"
Expand Down Expand Up @@ -121,18 +120,3 @@ func (c *CommitRevocation) Validate() error {
// We're good!
return nil
}

// String returns the string representation of the target CommitRevocation.
//
// This is part of the lnwire.Message interface.
// TODO(roasbeef): remote all String() methods...spew should be used instead.
func (c *CommitRevocation) String() string {
keySer := c.NextRevocationKey.SerializeCompressed()

return fmt.Sprintf("\n--- Begin CommitRevocation ---\n") +
fmt.Sprintf("ChannelPoint:\t%v\n", c.ChannelPoint) +
fmt.Sprintf("Revocation:\t%x\n", c.Revocation) +
fmt.Sprintf("NextRevocationKey:\t%x\n", keySer) +
fmt.Sprintf("NextRevocationHash:\t%x\n", c.NextRevocationHash) +
fmt.Sprintf("--- End CommitRevocation ---\n")
}
17 changes: 0 additions & 17 deletions lnwire/commit_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,3 @@ func (c *CommitSignature) Validate() error {
// We're good!
return nil
}

// String returns the string representation of the target CommitSignature.
//
// This is part of the lnwire.Message interface.
func (c *CommitSignature) String() string {
var serializedSig []byte
if c.CommitSig != nil {
serializedSig = c.CommitSig.Serialize()
}

return fmt.Sprintf("\n--- Begin CommitSignature ---\n") +
fmt.Sprintf("ChannelPoint:\t%v\n", c.ChannelPoint) +
fmt.Sprintf("LogIndex:\t\t%v\n", c.LogIndex) +
fmt.Sprintf("Fee:\t\t\t%s\n", c.Fee.String()) +
fmt.Sprintf("CommitSig:\t\t%x\n", serializedSig) +
fmt.Sprintf("--- End CommitSignature ---\n")
}
12 changes: 0 additions & 12 deletions lnwire/error_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,3 @@ func (c *ErrorGeneric) Validate() error {
// We're good!
return nil
}

// String returns the string representation of the target ErrorGeneric.
//
// This is part of the lnwire.Message interface.
func (c *ErrorGeneric) String() string {
return fmt.Sprintf("\n--- Begin ErrorGeneric ---\n") +
fmt.Sprintf("ChannelPoint:\t%d\n", c.ChannelPoint) +
fmt.Sprintf("Code:\t%d\n", c.Code) +
fmt.Sprintf("Problem:\t%s\n", c.Problem) +
fmt.Sprintf("PendingChannelID:\t%s\n", c.PendingChannelID) +
fmt.Sprintf("--- End ErrorGeneric ---\n")
}
11 changes: 0 additions & 11 deletions lnwire/htlc_addreject.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lnwire

import (
"fmt"
"io"

"github.com/roasbeef/btcd/wire"
Expand Down Expand Up @@ -91,13 +90,3 @@ func (c *HTLCAddReject) Validate() error {
// We're good!
return nil
}

// String returns the string representation of the target HTLCAddReject.
//
// This is part of the lnwire.Message interface.
func (c *HTLCAddReject) String() string {
return fmt.Sprintf("\n--- Begin HTLCAddReject ---\n") +
fmt.Sprintf("ChannelPoint:\t\t%d\n", c.ChannelPoint) +
fmt.Sprintf("HTLCKey:\t\t%d\n", c.HTLCKey) +
fmt.Sprintf("--- End HTLCAddReject ---\n")
}
26 changes: 1 addition & 25 deletions lnwire/htlc_addrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ type HTLCAddRequest struct {
// sufficient expiry value to allow her to redeem the incmoing HTLC.
Expiry uint32

// Amount to pay in the hop
// Difference between hop and first item in blob is the fee to complete

// Amount is the number of credits this HTLC is worth.
// Amount of BTC that the HTLC is worth.
Amount btcutil.Amount

// RefundContext is for payment cancellation
Expand Down Expand Up @@ -148,24 +145,3 @@ func (c *HTLCAddRequest) Validate() error {
// We're good!
return nil
}

// String returns the string representation of the target HTLCAddRequest.
//
// This is part of the lnwire.Message interface.
func (c *HTLCAddRequest) String() string {
var redemptionHashes string
for i, rh := range c.RedemptionHashes {
redemptionHashes += fmt.Sprintf("\n\tSlice\t%d\n", i)
redemptionHashes += fmt.Sprintf("\t\tRedemption Hash: %x\n", rh)
}

return fmt.Sprintf("\n--- Begin HTLCAddRequest ---\n") +
fmt.Sprintf("ChannelPoint:\t%v\n", c.ChannelPoint) +
fmt.Sprintf("Expiry:\t\t%d\n", c.Expiry) +
fmt.Sprintf("Amount\t\t%d\n", c.Amount) +
fmt.Sprintf("ContractType:\t%d (%b)\n", c.ContractType, c.ContractType) +
fmt.Sprintf("RedemptionHashes:") +
redemptionHashes +
fmt.Sprintf("OnionBlob:\t\t\t\t%x\n", c.OnionBlob) +
fmt.Sprintf("--- End HTLCAddRequest ---\n")
}
11 changes: 0 additions & 11 deletions lnwire/htlc_cancel.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lnwire

import (
"fmt"
"io"

"github.com/roasbeef/btcd/wire"
Expand Down Expand Up @@ -160,13 +159,3 @@ func (c *CancelHTLC) Validate() error {
// We're good!
return nil
}

// String returns the string representation of the target CancelHTLC. This is
// part of the lnwire.Message interface.
func (c *CancelHTLC) String() string {
return fmt.Sprintf("\n--- Begin CancelHTLC ---\n") +
fmt.Sprintf("ChannelPoint:\t%d\n", c.ChannelPoint) +
fmt.Sprintf("HTLCKey:\t%d\n", c.HTLCKey) +
fmt.Sprintf("Reason:\t%v\n", c.Reason) +
fmt.Sprintf("--- End CancelHTLC ---\n")
}
19 changes: 0 additions & 19 deletions lnwire/htlc_settlerequest.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lnwire

import (
"fmt"
"io"

"github.com/roasbeef/btcd/wire"
Expand Down Expand Up @@ -107,21 +106,3 @@ func (c *HTLCSettleRequest) Validate() error {
// We're good!
return nil
}

// String returns the string representation of the target HTLCSettleRequest.
//
// This is part of the lnwire.Message interface.
func (c *HTLCSettleRequest) String() string {
var redemptionProofs string
for i, rh := range c.RedemptionProofs {
redemptionProofs += fmt.Sprintf("\n\tSlice\t%d\n", i)
redemptionProofs += fmt.Sprintf("\t\tRedemption Proof: %x\n", rh)
}

return fmt.Sprintf("\n--- Begin HTLCSettleRequest ---\n") +
fmt.Sprintf("ChannelPoint:\t%v\n", c.ChannelPoint) +
fmt.Sprintf("HTLCKey:\t%d\n", c.HTLCKey) +
fmt.Sprintf("RedemptionHashes:") +
redemptionProofs +
fmt.Sprintf("--- End HTLCSettleRequest ---\n")
}
Loading

0 comments on commit d884efe

Please sign in to comment.