Skip to content

Commit f0fc2e7

Browse files
nsacfromknecht
authored andcommitted
formatting: correctly pass DecayedLog, changed Put
This commit fixes previously incorrect passing of DecayedLog to newTestRoute in bench_test.go, sphinx_test.go, and in sphinx.go. A pointer to DecayedLog is used instead. Additionally, serialization of the CLTV value is moved out of the Put function's boltdb.Batch call.
1 parent 5aef6ab commit f0fc2e7

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

bench_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"bytes"
55
"testing"
66

7-
"github.com/roasbeef/btcd/btcec"
87
"github.com/lightningnetwork/lightning-onion/persistlog"
8+
"github.com/roasbeef/btcd/btcec"
99
)
1010

1111
var (
@@ -58,7 +58,7 @@ func BenchmarkProcessPacket(b *testing.B) {
5858
b.StopTimer()
5959

6060
// Create the DecayedLog object
61-
d := persistlog.DecayedLog{}
61+
d := &persistlog.DecayedLog{}
6262
if err := d.Start(); err != nil {
6363
b.Fatalf("unable to start channeldb")
6464
}

persistlog/decayedlog.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,19 @@ func (d *DecayedLog) Get(hash []byte) (
176176
// sharedHashBucket.
177177
func (d *DecayedLog) Put(hash []byte,
178178
value uint32) error {
179-
return d.db.Batch(func(tx *bolt.Tx) error {
180-
var scratch [4]byte
181179

180+
var scratch [4]byte
181+
182+
// Store value into scratch
183+
binary.BigEndian.PutUint32(scratch[:], value)
184+
185+
return d.db.Batch(func(tx *bolt.Tx) error {
182186
sharedHashes, err := tx.CreateBucketIfNotExists(sharedHashBucket)
183187
if err != nil {
184188
return fmt.Errorf("Unable to create bucket sharedHashes:"+
185189
" %v", err)
186190
}
187191

188-
// Store value into scratch
189-
binary.BigEndian.PutUint32(scratch[:], value)
190-
191192
return sharedHashes.Put(hash, scratch[:])
192193
})
193194
}

sphinx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ type Router struct {
621621

622622
onionKey *btcec.PrivateKey
623623

624-
d persistlog.DecayedLog
624+
d *persistlog.DecayedLog
625625
}
626626

627627
// NewRouter creates a new instance of a Sphinx onion Router given the node's
@@ -634,7 +634,7 @@ func NewRouter(nodeKey *btcec.PrivateKey, net *chaincfg.Params,
634634
// Safe to ignore the error here, nodeID is 20 bytes.
635635
nodeAddr, _ := btcutil.NewAddressPubKeyHash(nodeID[:], net)
636636

637-
d := persistlog.DecayedLog{
637+
d := &persistlog.DecayedLog{
638638
Notifier: chainNotifier,
639639
}
640640

sphinx_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ var (
8787
"baaa7d63ad64199f4664813b955cff954949076dcf"
8888
)
8989

90-
func newTestRoute(numHops int, d persistlog.DecayedLog) ([]*Router, *[]HopData, *OnionPacket, error) {
90+
func newTestRoute(numHops int, d *persistlog.DecayedLog) ([]*Router, *[]HopData, *OnionPacket, error) {
9191
nodes := make([]*Router, numHops)
9292

9393
// Create numHops random sphinx nodes.
@@ -182,7 +182,7 @@ func TestBolt4Packet(t *testing.T) {
182182
}
183183

184184
func TestSphinxCorrectness(t *testing.T) {
185-
d := persistlog.DecayedLog{}
185+
d := &persistlog.DecayedLog{}
186186
if err := d.Start(); err != nil {
187187
t.Fatalf("unable to start channeldb")
188188
}
@@ -248,7 +248,7 @@ func TestSphinxSingleHop(t *testing.T) {
248248
// We'd like to test the proper behavior of the correctness of onion
249249
// packet processing for "single-hop" payments which bare a full onion
250250
// packet.
251-
d := persistlog.DecayedLog{}
251+
d := &persistlog.DecayedLog{}
252252
if err := d.Start(); err != nil {
253253
t.Fatalf("unable to start channeldb")
254254
}
@@ -275,7 +275,7 @@ func TestSphinxSingleHop(t *testing.T) {
275275
func TestSphinxNodeRelpay(t *testing.T) {
276276
// We'd like to ensure that the sphinx node itself rejects all replayed
277277
// packets which share the same shared secret.
278-
d := persistlog.DecayedLog{}
278+
d := &persistlog.DecayedLog{}
279279
if err := d.Start(); err != nil {
280280
t.Fatalf("unable to start channeldb")
281281
}
@@ -301,7 +301,7 @@ func TestSphinxNodeRelpay(t *testing.T) {
301301
func TestSphinxAssocData(t *testing.T) {
302302
// We want to make sure that the associated data is considered in the
303303
// HMAC creation
304-
d := persistlog.DecayedLog{}
304+
d := &persistlog.DecayedLog{}
305305
if err := d.Start(); err != nil {
306306
t.Fatalf("unable to start channeldb")
307307
}
@@ -319,7 +319,7 @@ func TestSphinxAssocData(t *testing.T) {
319319
func TestSphinxEncodeDecode(t *testing.T) {
320320
// Create some test data with a randomly populated, yet valid onion
321321
// forwarding message.
322-
d := persistlog.DecayedLog{}
322+
d := &persistlog.DecayedLog{}
323323
if err := d.Start(); err != nil {
324324
t.Fatalf("unable to start channeldb")
325325
}

0 commit comments

Comments
 (0)