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
24 changed files with 60 additions and 400 deletions

View File

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