From d884efea29d4fcc9bfb01c0b153e31c6c46a98ae Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 14 Jan 2017 17:52:05 -0800 Subject: [PATCH] lnwire+lnd: Make Logging Messages Great Again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- fundingmanager.go | 20 +++++--- lnwire/channel_announcement.go | 18 ------- lnwire/channel_id.go | 3 +- lnwire/channel_update_announcement.go | 17 ------- lnwire/close_complete.go | 17 ------- lnwire/close_request.go | 20 +------- lnwire/commit_revocation.go | 16 ------ lnwire/commit_signature.go | 17 ------- lnwire/error_generic.go | 12 ----- lnwire/htlc_addreject.go | 11 ---- lnwire/htlc_addrequest.go | 26 +--------- lnwire/htlc_cancel.go | 11 ---- lnwire/htlc_settlerequest.go | 19 ------- lnwire/lnwire_test.go | 72 --------------------------- lnwire/message.go | 1 - lnwire/node_announcement.go | 15 ------ lnwire/ping.go | 12 +---- lnwire/pong.go | 12 +---- lnwire/single_funding_complete.go | 18 ------- lnwire/single_funding_open_proof.go | 15 +----- lnwire/single_funding_request.go | 25 ---------- lnwire/single_funding_response.go | 28 ----------- lnwire/single_funding_signcomplete.go | 10 ---- peer.go | 45 ++++++++++++++--- 24 files changed, 60 insertions(+), 400 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index c793e2217..b45c712b4 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -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, } @@ -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 { @@ -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() @@ -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, + } +} diff --git a/lnwire/channel_announcement.go b/lnwire/channel_announcement.go index 646865120..238c49d6a 100644 --- a/lnwire/channel_announcement.go +++ b/lnwire/channel_announcement.go @@ -2,7 +2,6 @@ package lnwire import ( "bytes" - "fmt" "io" "github.com/go-errors/errors" @@ -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) { diff --git a/lnwire/channel_id.go b/lnwire/channel_id.go index 030cbcf0e..a31b01fbf 100644 --- a/lnwire/channel_id.go +++ b/lnwire/channel_id.go @@ -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 } diff --git a/lnwire/channel_update_announcement.go b/lnwire/channel_update_announcement.go index a4358bc17..5705d67ee 100644 --- a/lnwire/channel_update_announcement.go +++ b/lnwire/channel_update_announcement.go @@ -3,7 +3,6 @@ package lnwire import ( "bytes" "errors" - "fmt" "io" "github.com/roasbeef/btcd/btcec" @@ -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) { diff --git a/lnwire/close_complete.go b/lnwire/close_complete.go index 2908e57e0..c12461988 100644 --- a/lnwire/close_complete.go +++ b/lnwire/close_complete.go @@ -1,8 +1,6 @@ package lnwire import ( - "fmt" - "github.com/roasbeef/btcd/btcec" "github.com/roasbeef/btcd/wire" @@ -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") -} diff --git a/lnwire/close_request.go b/lnwire/close_request.go index 4765b9a97..b5f52142a 100644 --- a/lnwire/close_request.go +++ b/lnwire/close_request.go @@ -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 } @@ -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") -} diff --git a/lnwire/commit_revocation.go b/lnwire/commit_revocation.go index 55f1ab61d..dc759009e 100644 --- a/lnwire/commit_revocation.go +++ b/lnwire/commit_revocation.go @@ -1,7 +1,6 @@ package lnwire import ( - "fmt" "io" "github.com/roasbeef/btcd/btcec" @@ -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") -} diff --git a/lnwire/commit_signature.go b/lnwire/commit_signature.go index 42902de28..f3ed4e444 100644 --- a/lnwire/commit_signature.go +++ b/lnwire/commit_signature.go @@ -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") -} diff --git a/lnwire/error_generic.go b/lnwire/error_generic.go index 412c976a2..cddf61ee8 100644 --- a/lnwire/error_generic.go +++ b/lnwire/error_generic.go @@ -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") -} diff --git a/lnwire/htlc_addreject.go b/lnwire/htlc_addreject.go index 4b8661005..25ab46a76 100644 --- a/lnwire/htlc_addreject.go +++ b/lnwire/htlc_addreject.go @@ -1,7 +1,6 @@ package lnwire import ( - "fmt" "io" "github.com/roasbeef/btcd/wire" @@ -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") -} diff --git a/lnwire/htlc_addrequest.go b/lnwire/htlc_addrequest.go index f2ec49bc4..4111b98dd 100644 --- a/lnwire/htlc_addrequest.go +++ b/lnwire/htlc_addrequest.go @@ -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 @@ -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") -} diff --git a/lnwire/htlc_cancel.go b/lnwire/htlc_cancel.go index 447fea236..0aed4021e 100644 --- a/lnwire/htlc_cancel.go +++ b/lnwire/htlc_cancel.go @@ -1,7 +1,6 @@ package lnwire import ( - "fmt" "io" "github.com/roasbeef/btcd/wire" @@ -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") -} diff --git a/lnwire/htlc_settlerequest.go b/lnwire/htlc_settlerequest.go index 265343015..3a7d98bbc 100644 --- a/lnwire/htlc_settlerequest.go +++ b/lnwire/htlc_settlerequest.go @@ -1,7 +1,6 @@ package lnwire import ( - "fmt" "io" "github.com/roasbeef/btcd/wire" @@ -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") -} diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index feca9d257..bec12a0b2 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -1,11 +1,7 @@ package lnwire import ( - "bytes" "encoding/hex" - "io/ioutil" - "reflect" - "testing" "net" @@ -117,71 +113,3 @@ var ( blue: 255, } ) - -func SerializeTest(t *testing.T, message Message, expectedString string, filename string) *bytes.Buffer { - var err error - - b := new(bytes.Buffer) - err = message.Encode(b, 0) - - if err != nil { - t.Errorf(err.Error()) - } else { - t.Logf("Encoded Bytes: %x\n", b.Bytes()) - // Check if we serialized correctly - if expectedString != hex.EncodeToString(b.Bytes()) { - t.Error("Serialization does not match expected") - } - - // So I can do: hexdump -C /dev/shm/fundingRequest.raw - if WRITE_FILE { - err = ioutil.WriteFile(filename, b.Bytes(), 0644) - if err != nil { - t.Error(err.Error()) - } - } - } - return b -} - -func DeserializeTest(t *testing.T, buf *bytes.Buffer, message Message, originalMessage Message) { - var err error - // Make a new buffer just to be clean - c := new(bytes.Buffer) - c.Write(buf.Bytes()) - - err = message.Decode(c, 0) - if err != nil { - t.Error("Decoding Error") - t.Error(err.Error()) - } else { - if !reflect.DeepEqual(message, originalMessage) { - t.Error("Decoding does not match!") - } - // Show the struct - t.Log(message.String()) - } -} - -func MessageSerializeDeserializeTest(t *testing.T, message Message, expectedString string) { - var err error - - b := new(bytes.Buffer) - _, err = WriteMessage(b, message, uint32(1), wire.TestNet3) - t.Logf("%x\n", b.Bytes()) - if hex.EncodeToString(b.Bytes()) != expectedString { - t.Error("Message encoding error") - } - // Deserialize/Decode - c := new(bytes.Buffer) - c.Write(b.Bytes()) - _, newMsg, _, err := ReadMessage(c, uint32(1), wire.TestNet3) - if err != nil { - t.Errorf(err.Error()) - } else { - if !reflect.DeepEqual(newMsg, message) { - t.Error("Message decoding does not match!") - } - t.Logf(newMsg.String()) - } -} diff --git a/lnwire/message.go b/lnwire/message.go index d0040f100..9eca6740c 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -66,7 +66,6 @@ type Message interface { Command() uint32 MaxPayloadLength(uint32) uint32 Validate() error - String() string } // makeEmptyMessage creates a new empty message of the proper concrete type diff --git a/lnwire/node_announcement.go b/lnwire/node_announcement.go index aecb26618..fca467f6d 100644 --- a/lnwire/node_announcement.go +++ b/lnwire/node_announcement.go @@ -2,7 +2,6 @@ package lnwire import ( "bytes" - "fmt" "io" "net" @@ -212,20 +211,6 @@ func (c *NodeAnnouncement) MaxPayloadLength(pver uint32) uint32 { return length } -// String returns the string representation of the target NodeAnnouncement. -// -// This is part of the lnwire.Message interface. -func (c *NodeAnnouncement) String() string { - return fmt.Sprintf("\n--- Begin NodeAnnouncement ---\n") + - fmt.Sprintf("Signature:\t\t%v\n", c.Signature) + - fmt.Sprintf("Timestamp:\t\t%v\n", c.Timestamp) + - fmt.Sprintf("Address:\t\t%v\n", c.Address.String()) + - fmt.Sprintf("NodeID:\t\t%v\n", c.NodeID) + - fmt.Sprintf("RGBColor:\t\t%v\n", c.RGBColor) + - fmt.Sprintf("Alias:\t\t%v\n", c.Alias) + - fmt.Sprintf("--- End NodeAnnouncement ---\n") -} - // dataToSign... func (c *NodeAnnouncement) DataToSign() ([]byte, error) { diff --git a/lnwire/ping.go b/lnwire/ping.go index 24061379e..a8b03a6e9 100644 --- a/lnwire/ping.go +++ b/lnwire/ping.go @@ -1,9 +1,6 @@ package lnwire -import ( - "fmt" - "io" -) +import "io" // Pong defines a message which is the direct response to a received Ping // message. A Pong reply indicates that a connection is still active. The Pong @@ -78,10 +75,3 @@ func (p *Pong) MaxPayloadLength(uint32) uint32 { func (p *Pong) Validate() error { return nil } - -// String returns the string representation of the target Pong. -// -// This is part of the lnwire.Message interface. -func (p *Pong) String() string { - return fmt.Sprintf("Pong(%v)", p.Nonce) -} diff --git a/lnwire/pong.go b/lnwire/pong.go index 1aeee3580..acfb89e95 100644 --- a/lnwire/pong.go +++ b/lnwire/pong.go @@ -1,9 +1,6 @@ package lnwire -import ( - "fmt" - "io" -) +import "io" // Ping defines a message which is sent by peers periodically to determine if // the connection is still valid. Each ping message should carry a unique nonce @@ -77,10 +74,3 @@ func (p Ping) MaxPayloadLength(uint32) uint32 { func (p *Ping) Validate() error { return nil } - -// String returns the string representation of the target Ping. -// -// This is part of the lnwire.Message interface. -func (p *Ping) String() string { - return fmt.Sprintf("Ping(%v)", p.Nonce) -} diff --git a/lnwire/single_funding_complete.go b/lnwire/single_funding_complete.go index 1a158a617..d91d18a13 100644 --- a/lnwire/single_funding_complete.go +++ b/lnwire/single_funding_complete.go @@ -142,21 +142,3 @@ func (s *SingleFundingComplete) Validate() error { // We're good! return nil } - -// String returns the string representation of the SingleFundingResponse. -// -// This is part of the lnwire.Message interface. -func (s *SingleFundingComplete) String() string { - var rk []byte - if s.RevocationKey != nil { - rk = s.RevocationKey.SerializeCompressed() - } - - return fmt.Sprintf("\n--- Begin SingleFundingComplete ---\n") + - fmt.Sprintf("ChannelID:\t\t\t%d\n", s.ChannelID) + - fmt.Sprintf("FundingOutPoint:\t\t\t%x\n", s.FundingOutPoint) + - fmt.Sprintf("CommitSignature\t\t\t\t%x\n", s.CommitSignature) + - fmt.Sprintf("RevocationKey\t\t\t\t%x\n", rk) + - fmt.Sprintf("StateHintObsfucator\t\t\t%x\n", s.StateHintObsfucator) + - fmt.Sprintf("--- End SingleFundingComplete ---\n") -} diff --git a/lnwire/single_funding_open_proof.go b/lnwire/single_funding_open_proof.go index 653fd865c..1700e9f90 100644 --- a/lnwire/single_funding_open_proof.go +++ b/lnwire/single_funding_open_proof.go @@ -1,9 +1,6 @@ package lnwire -import ( - "fmt" - "io" -) +import "io" // SingleFundingOpenProof is the message sent by the channel initiator to the // responder after the previously constructed funding transaction has achieved @@ -93,13 +90,3 @@ func (s *SingleFundingOpenProof) Validate() error { // We're good! return nil } - -// String returns the string representation of the SingleFundingOpenProof. -// -// This is part of the lnwire.Message interface. -func (s *SingleFundingOpenProof) String() string { - return fmt.Sprintf("\n--- Begin SingleFundingOpenProof ---\n") + - fmt.Sprintf("ChannelID:\t\t%d\n", s.ChannelID) + - fmt.Sprintf("ChanChainID\t\t%s\n", s.ChanChainID.ToUint64()) + - fmt.Sprintf("--- End SingleFundingOpenProof ---\n") -} diff --git a/lnwire/single_funding_request.go b/lnwire/single_funding_request.go index 86506adee..a9e3bce77 100644 --- a/lnwire/single_funding_request.go +++ b/lnwire/single_funding_request.go @@ -236,28 +236,3 @@ func (c *SingleFundingRequest) Validate() error { // We're good! return nil } - -// String returns the string representation of the SingleFundingRequest. -// -// This is part of the lnwire.Message interface. -func (c *SingleFundingRequest) String() string { - var serializedPubkey []byte - if &c.ChannelDerivationPoint != nil && c.ChannelDerivationPoint.X != nil { - serializedPubkey = c.ChannelDerivationPoint.SerializeCompressed() - } - - // TODO(roasbeef): remove string methods? - - return fmt.Sprintf("\n--- Begin SingleFundingRequest ---\n") + - fmt.Sprintf("ChannelID:\t\t\t%d\n", c.ChannelID) + - fmt.Sprintf("ChannelType:\t\t\t%x\n", c.ChannelType) + - fmt.Sprintf("CoinType:\t\t\t%d\n", c.CoinType) + - fmt.Sprintf("FeePerKb:\t\t\t%s\n", c.FeePerKb.String()) + - fmt.Sprintf("FundingAmount:\t\t\t%s\n", c.FundingAmount.String()) + - fmt.Sprintf("PushSatoshis:\t\t%v\n", c.PushSatoshis) + - fmt.Sprintf("CsvDelay:\t\t\t%d\n", c.CsvDelay) + - fmt.Sprintf("ChannelDerivationPoint:\t\t\t%x\n", serializedPubkey) + - fmt.Sprintf("DeliveryPkScript:\t\t\t%x\n", c.DeliveryPkScript) + - fmt.Sprintf("DustLimit:\t\t\t%d\n", c.DustLimit) + - fmt.Sprintf("--- End SingleFundingRequest ---\n") -} diff --git a/lnwire/single_funding_response.go b/lnwire/single_funding_response.go index b8f2027ab..90ab8ac48 100644 --- a/lnwire/single_funding_response.go +++ b/lnwire/single_funding_response.go @@ -180,31 +180,3 @@ func (c *SingleFundingResponse) Validate() error { // We're good! return nil } - -// String returns the string representation of the SingleFundingResponse. -// -// This is part of the lnwire.Message interface. -func (c *SingleFundingResponse) String() string { - var cdp []byte - var ck []byte - var rk []byte - if &c.ChannelDerivationPoint != nil { - cdp = c.ChannelDerivationPoint.SerializeCompressed() - } - if &c.CommitmentKey != nil { - ck = c.CommitmentKey.SerializeCompressed() - } - if &c.RevocationKey != nil { - rk = c.RevocationKey.SerializeCompressed() - } - - return fmt.Sprintf("\n--- Begin SingleFundingResponse ---\n") + - fmt.Sprintf("ChannelID:\t\t\t%d\n", c.ChannelID) + - fmt.Sprintf("ChannelDerivationPoint:\t\t\t\t%x\n", cdp) + - fmt.Sprintf("CommitmentKey:\t\t\t\t%x\n", ck) + - fmt.Sprintf("RevocationKey:\t\t\t\t%x\n", rk) + - fmt.Sprintf("CsvDelay:\t\t%d\n", c.CsvDelay) + - fmt.Sprintf("DeliveryPkScript:\t\t%x\n", c.DeliveryPkScript) + - fmt.Sprintf("DustLimit:\t\t\t%d\n", c.DustLimit) + - fmt.Sprintf("--- End SingleFundingResponse ---\n") -} diff --git a/lnwire/single_funding_signcomplete.go b/lnwire/single_funding_signcomplete.go index 15718b718..680a37108 100644 --- a/lnwire/single_funding_signcomplete.go +++ b/lnwire/single_funding_signcomplete.go @@ -96,13 +96,3 @@ func (s *SingleFundingSignComplete) Validate() error { // We're good! return nil } - -// String returns the string representation of the SingleFundingSignComplete. -// -// This is part of the lnwire.Message interface. -func (c *SingleFundingSignComplete) String() string { - return fmt.Sprintf("\n--- Begin FundingSignComplete ---\n") + - fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) + - fmt.Sprintf("CommitSignature\t\t%s\n", c.CommitSignature) + - fmt.Sprintf("--- End FundingSignComplete ---\n") -} diff --git a/peer.go b/peer.go index fcee224ab..85a721ded 100644 --- a/peer.go +++ b/peer.go @@ -345,9 +345,7 @@ func (p *peer) readNextMessage() (lnwire.Message, []byte, error) { } // TODO(roasbeef): add message summaries - peerLog.Tracef("readMessage from %v: %v", p, newLogClosure(func() string { - return spew.Sdump(nextMsg) - })) + p.logWireMessage(nextMsg, true) return nextMsg, rawPayload, nil } @@ -455,6 +453,43 @@ out: peerLog.Tracef("readHandler for peer %v done", p) } +// logWireMessage logs the receipt or sending of particular wire message. This +// function is used rather than just logging the message in order to produce +// less spammy log messages in trace mode by setting the 'Curve" parameter to +// nil. Doing this avoids printing out each of the field elements in the curve +// parameters for secp256k1. +func (p *peer) logWireMessage(msg lnwire.Message, read bool) { + switch m := msg.(type) { + case *lnwire.CommitRevocation: + m.NextRevocationKey.Curve = nil + case *lnwire.NodeAnnouncement: + m.NodeID.Curve = nil + case *lnwire.ChannelAnnouncement: + m.FirstNodeID.Curve = nil + m.SecondNodeID.Curve = nil + m.FirstBitcoinKey.Curve = nil + m.SecondBitcoinKey.Curve = nil + case *lnwire.SingleFundingComplete: + m.RevocationKey.Curve = nil + case *lnwire.SingleFundingRequest: + m.CommitmentKey.Curve = nil + m.ChannelDerivationPoint.Curve = nil + case *lnwire.SingleFundingResponse: + m.ChannelDerivationPoint.Curve = nil + m.CommitmentKey.Curve = nil + m.RevocationKey.Curve = nil + } + + prefix := "readMessage" + if !read { + prefix = "writeMessage" + } + + peerLog.Tracef(prefix+" to %v: %v", p, newLogClosure(func() string { + return spew.Sdump(msg) + })) +} + // writeMessage writes the target lnwire.Message to the remote peer. func (p *peer) writeMessage(msg lnwire.Message) error { // Simply exit if we're shutting down. @@ -463,9 +498,7 @@ func (p *peer) writeMessage(msg lnwire.Message) error { } // TODO(roasbeef): add message summaries - peerLog.Tracef("writeMessage to %v: %v", p, newLogClosure(func() string { - return spew.Sdump(msg) - })) + p.logWireMessage(msg, false) n, err := lnwire.WriteMessage(p.conn, msg, 0, p.addr.ChainNet) atomic.AddUint64(&p.bytesSent, uint64(n))