lnwire+lnd: Make Logging Messages Great Again

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-01-14 17:52:05 -08:00
parent 0bfdcde969
commit d884efea29
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
24 changed files with 60 additions and 400 deletions

@ -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,
}
}

@ -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) {

@ -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
}

@ -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) {

@ -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")
}

@ -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")
}

@ -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")
}

@ -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")
}

@ -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")
}

@ -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")
}

@ -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")
}

@ -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")
}

@ -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")
}

@ -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())
}
}

@ -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

@ -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) {

@ -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)
}

@ -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)
}

@ -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")
}

@ -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")
}

@ -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")
}

@ -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")
}

@ -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")
}

45
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))