routing: new newLogClosure to delay spew evaluation until log print time

In this commit, we update the generateSphinxPacket to use newLogClosure
to delay the spew evaluation until log print time. Before this commit,
even if we weren't on the trace logging level, the spew call would
always be evaluated.
This commit is contained in:
Olaoluwa Osuntokun 2018-06-30 17:14:22 -05:00
parent b3bb65ea43
commit 39c1f46f85
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -1458,7 +1458,10 @@ func generateSphinxPacket(route *Route, paymentHash []byte) ([]byte,
hopPayloads := route.ToHopPayloads()
log.Tracef("Constructed per-hop payloads for payment_hash=%x: %v",
paymentHash[:], spew.Sdump(hopPayloads))
paymentHash[:], newLogClosure(func() string {
return spew.Sdump(hopPayloads)
}),
)
sessionKey, err := btcec.NewPrivateKey(btcec.S256())
if err != nil {
@ -1467,8 +1470,9 @@ func generateSphinxPacket(route *Route, paymentHash []byte) ([]byte,
// Next generate the onion routing packet which allows us to perform
// privacy preserving source routing across the network.
sphinxPacket, err := sphinx.NewOnionPacket(nodes, sessionKey,
hopPayloads, paymentHash)
sphinxPacket, err := sphinx.NewOnionPacket(
nodes, sessionKey, hopPayloads, paymentHash,
)
if err != nil {
return nil, nil, err
}