Skip to content

Commit 8342d3c

Browse files
committed
sphinx: remove unused members of Router
By removing the unused members of the Router, we can remove the network parameter from NewRouter which will make it easier to instantiate the Router in other packages.
1 parent 06182b1 commit 8342d3c

File tree

4 files changed

+6
-32
lines changed

4 files changed

+6
-32
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
}

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: 3 additions & 11 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
}
@@ -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)