Skip to content

Commit 6844040

Browse files
authored
Merge pull request #62 from ellemouton/rmvNetParam
sphinx: remove unused members of Router
2 parents 06182b1 + ebe0b43 commit 6844040

File tree

5 files changed

+13
-40
lines changed

5 files changed

+13
-40
lines changed

bench_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ func BenchmarkProcessPacket(b *testing.B) {
8888
router := path[0]
8989
router.log.Stop()
9090
path[0] = &Router{
91-
nodeID: router.nodeID,
92-
nodeAddr: router.nodeAddr,
9391
onionKey: router.onionKey,
9492
log: NewMemoryReplayLog(),
9593
}

cmd/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"os"
1010

1111
"github.com/btcsuite/btcd/btcec/v2"
12-
"github.com/btcsuite/btcd/chaincfg"
1312
sphinx "github.com/lightningnetwork/lightning-onion"
1413
"github.com/urfave/cli"
1514
)
@@ -300,7 +299,7 @@ func peel(ctx *cli.Context) error {
300299

301300
s := sphinx.NewRouter(
302301
&sphinx.PrivKeyECDH{PrivKey: sessionKey},
303-
&chaincfg.TestNet3Params, sphinx.NewMemoryReplayLog(),
302+
sphinx.NewMemoryReplayLog(),
304303
)
305304
s.Start()
306305
defer s.Stop()

path_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"testing"
99

1010
"github.com/btcsuite/btcd/btcec/v2"
11-
"github.com/btcsuite/btcd/chaincfg"
1211
"github.com/stretchr/testify/require"
1312
)
1413

@@ -149,8 +148,7 @@ func TestOnionRouteBlinding(t *testing.T) {
149148
blindingPoint *btcec.PublicKey) *ProcessedPacket {
150149

151150
r := NewRouter(
152-
&PrivKeyECDH{PrivKey: key}, &chaincfg.MainNetParams,
153-
NewMemoryReplayLog(),
151+
&PrivKeyECDH{PrivKey: key}, NewMemoryReplayLog(),
154152
)
155153

156154
require.NoError(t, r.Start())

sphinx.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"sync"
1010

1111
"github.com/btcsuite/btcd/btcec/v2"
12-
"github.com/btcsuite/btcd/btcutil"
13-
"github.com/btcsuite/btcd/chaincfg"
1412
)
1513

1614
const (
@@ -484,26 +482,14 @@ type ProcessedPacket struct {
484482
// of processing incoming Sphinx onion packets thereby "peeling" a layer off
485483
// the onion encryption which the packet is wrapped with.
486484
type Router struct {
487-
nodeID [AddressSize]byte
488-
nodeAddr *btcutil.AddressPubKeyHash
489-
490485
onionKey SingleKeyECDH
491-
492-
log ReplayLog
486+
log ReplayLog
493487
}
494488

495489
// NewRouter creates a new instance of a Sphinx onion Router given the node's
496490
// currently advertised onion private key, and the target Bitcoin network.
497-
func NewRouter(nodeKey SingleKeyECDH, net *chaincfg.Params, log ReplayLog) *Router {
498-
var nodeID [AddressSize]byte
499-
copy(nodeID[:], btcutil.Hash160(nodeKey.PubKey().SerializeCompressed()))
500-
501-
// Safe to ignore the error here, nodeID is 20 bytes.
502-
nodeAddr, _ := btcutil.NewAddressPubKeyHash(nodeID[:], net)
503-
491+
func NewRouter(nodeKey SingleKeyECDH, log ReplayLog) *Router {
504492
return &Router{
505-
nodeID: nodeID,
506-
nodeAddr: nodeAddr,
507493
onionKey: nodeKey,
508494
log: log,
509495
}

sphinx_test.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"testing"
1212

1313
"github.com/btcsuite/btcd/btcec/v2"
14-
"github.com/btcsuite/btcd/chaincfg"
1514
"github.com/davecgh/go-spew/spew"
1615
"github.com/stretchr/testify/require"
1716
)
@@ -52,8 +51,7 @@ func newTestRoute(numHops int) ([]*Router, *PaymentPath, *[]HopData, *OnionPacke
5251
}
5352

5453
nodes[i] = NewRouter(
55-
&PrivKeyECDH{PrivKey: privKey}, &chaincfg.MainNetParams,
56-
NewMemoryReplayLog(),
54+
&PrivKeyECDH{PrivKey: privKey}, NewMemoryReplayLog(),
5755
)
5856
}
5957

@@ -219,12 +217,7 @@ func TestSphinxCorrectness(t *testing.T) {
219217
// The next hop should have been parsed as node[i+1].
220218
parsedNextHop := onionPacket.ForwardingInstructions.NextAddress[:]
221219
expected := bytes.Repeat([]byte{byte(i)}, AddressSize)
222-
if !bytes.Equal(parsedNextHop, expected) {
223-
t.Fatalf("Processing error, next hop parsed incorrectly."+
224-
" next hop should be %v, was instead parsed as %v",
225-
hex.EncodeToString(nodes[i+1].nodeID[:]),
226-
hex.EncodeToString(parsedNextHop))
227-
}
220+
require.Equal(t, expected, parsedNextHop)
228221

229222
fwdMsg = onionPacket.NextPacket
230223
}
@@ -303,14 +296,14 @@ func TestSphinxNodeRelpaySameBatch(t *testing.T) {
303296

304297
// Allow the node to process the initial packet, this should proceed
305298
// without any failures.
306-
if err := tx.ProcessOnionPacket(0, fwdMsg, nil, 1, nil); err != nil {
299+
if err := tx.ProcessOnionPacket(0, fwdMsg, nil, 1); err != nil {
307300
t.Fatalf("unable to process sphinx packet: %v", err)
308301
}
309302

310303
// Now, force the node to process the packet a second time, this call
311304
// should not fail, even though the batch has internally recorded this
312305
// as a duplicate.
313-
err = tx.ProcessOnionPacket(1, fwdMsg, nil, 1, nil)
306+
err = tx.ProcessOnionPacket(1, fwdMsg, nil, 1)
314307
if err != nil {
315308
t.Fatalf("adding duplicate sphinx packet to batch should not "+
316309
"result in an error, instead got: %v", err)
@@ -349,7 +342,7 @@ func TestSphinxNodeRelpayLaterBatch(t *testing.T) {
349342

350343
// Allow the node to process the initial packet, this should proceed
351344
// without any failures.
352-
err = tx.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1, nil)
345+
err = tx.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1)
353346
if err != nil {
354347
t.Fatalf("unable to process sphinx packet: %v", err)
355348
}
@@ -363,7 +356,7 @@ func TestSphinxNodeRelpayLaterBatch(t *testing.T) {
363356

364357
// Now, force the node to process the packet a second time, this should
365358
// fail with a detected replay error.
366-
err = tx2.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1, nil)
359+
err = tx2.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1)
367360
if err != nil {
368361
t.Fatalf("sphinx packet replay should not have been rejected, "+
369362
"instead error is %v", err)
@@ -395,7 +388,7 @@ func TestSphinxNodeReplayBatchIdempotency(t *testing.T) {
395388

396389
// Allow the node to process the initial packet, this should proceed
397390
// without any failures.
398-
err = tx.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1, nil)
391+
err = tx.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1)
399392
if err != nil {
400393
t.Fatalf("unable to process sphinx packet: %v", err)
401394
}
@@ -409,7 +402,7 @@ func TestSphinxNodeReplayBatchIdempotency(t *testing.T) {
409402

410403
// Now, force the node to process the packet a second time, this should
411404
// not fail with a detected replay error.
412-
err = tx2.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1, nil)
405+
err = tx2.ProcessOnionPacket(uint16(0), fwdMsg, nil, 1)
413406
if err != nil {
414407
t.Fatalf("sphinx packet replay should not have been rejected, "+
415408
"instead error is %v", err)
@@ -499,8 +492,7 @@ func newEOBRoute(numHops uint32,
499492
}
500493

501494
nodes[i] = NewRouter(
502-
&PrivKeyECDH{PrivKey: privKey}, &chaincfg.MainNetParams,
503-
NewMemoryReplayLog(),
495+
&PrivKeyECDH{PrivKey: privKey}, NewMemoryReplayLog(),
504496
)
505497
}
506498

0 commit comments

Comments
 (0)