Skip to content

Commit 751fb4d

Browse files
authored
Merge pull request #35 from Roasbeef/eob-refactoring-prep
multi: eob refactoring prep
2 parents 725fcf8 + 73f6bde commit 751fb4d

File tree

13 files changed

+597
-448
lines changed

13 files changed

+597
-448
lines changed

.travis.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
language: go
2+
cache:
3+
directories:
4+
- $GOCACHE
5+
- $GOPATH/pkg/mod
6+
- $GOPATH/src/github.com/btcsuite
7+
- $GOPATH/src/github.com/golang
8+
29
go:
3-
- 1.9.4
4-
- "1.10"
5-
sudo: false
6-
install:
7-
- go get -v github.com/lightningnetwork/lightning-onion
8-
- go get -v github.com/davecgh/go-spew/spew
10+
- "1.12.x"
11+
12+
sudo: required
13+
914
script:
1015
- export PATH=$PATH:$HOME/gopath/bin
16+
- export GO111MODULE=on
1117
- go test -v

bench_test.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,40 @@ var (
1414

1515
func BenchmarkPathPacketConstruction(b *testing.B) {
1616
b.StopTimer()
17-
route := make([]*btcec.PublicKey, NumMaxHops)
18-
for i := 0; i < NumMaxHops; i++ {
19-
privKey, err := btcec.NewPrivateKey(btcec.S256())
20-
if err != nil {
21-
b.Fatalf("unable to generate key: %v", privKey)
22-
}
23-
24-
route[i] = privKey.PubKey()
25-
}
2617

2718
var (
2819
err error
2920
sphinxPacket *OnionPacket
21+
route PaymentPath
3022
)
3123

32-
var hopsData []HopData
33-
for i := 0; i < len(route); i++ {
34-
hopsData = append(hopsData, HopData{
35-
Realm: 0x00,
24+
for i := 0; i < NumMaxHops; i++ {
25+
privKey, err := btcec.NewPrivateKey(btcec.S256())
26+
if err != nil {
27+
b.Fatalf("unable to generate key: %v", privKey)
28+
}
29+
30+
hopData := HopData{
31+
Realm: [1]byte{0x00},
3632
ForwardAmount: uint64(i),
3733
OutgoingCltv: uint32(i),
38-
})
39-
copy(hopsData[i].NextAddress[:], bytes.Repeat([]byte{byte(i)}, 8))
34+
}
35+
copy(hopData.NextAddress[:], bytes.Repeat([]byte{byte(i)}, 8))
36+
37+
route[i] = OnionHop{
38+
NodePub: *privKey.PubKey(),
39+
HopData: hopData,
40+
}
4041
}
4142

4243
d, _ := btcec.PrivKeyFromBytes(btcec.S256(), bytes.Repeat([]byte{'A'}, 32))
44+
4345
b.ReportAllocs()
46+
4447
b.StartTimer()
4548

4649
for i := 0; i < b.N; i++ {
47-
sphinxPacket, err = NewOnionPacket(route, d, hopsData, nil)
50+
sphinxPacket, err = NewOnionPacket(&route, d, nil)
4851
if err != nil {
4952
b.Fatalf("unable to create packet: %v", err)
5053
}
@@ -55,7 +58,7 @@ func BenchmarkPathPacketConstruction(b *testing.B) {
5558

5659
func BenchmarkProcessPacket(b *testing.B) {
5760
b.StopTimer()
58-
path, _, sphinxPacket, err := newTestRoute(1)
61+
path, _, _, sphinxPacket, err := newTestRoute(1)
5962
if err != nil {
6063
b.Fatalf("unable to create test route: %v", err)
6164
}

cmd/main.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"os"
1010
"strings"
1111

12-
sphinx "github.com/lightningnetwork/lightning-onion"
1312
"github.com/btcsuite/btcd/btcec"
1413
"github.com/btcsuite/btcd/chaincfg"
14+
sphinx "github.com/lightningnetwork/lightning-onion"
1515
)
1616

1717
// main implements a simple command line utility that can be used in order to
@@ -25,7 +25,7 @@ func main() {
2525
if len(args) == 1 {
2626
fmt.Printf("Usage: %s (generate|decode) <private-keys>\n", args[0])
2727
} else if args[1] == "generate" {
28-
var route []*btcec.PublicKey
28+
var path sphinx.PaymentPath
2929
for i, hexKey := range args[2:] {
3030
binKey, err := hex.DecodeString(hexKey)
3131
if err != nil || len(binKey) != 33 {
@@ -37,23 +37,22 @@ func main() {
3737
panic(err)
3838
}
3939

40-
route = append(route, pubkey)
40+
path[i] = sphinx.OnionHop{
41+
NodePub: *pubkey,
42+
HopData: sphinx.HopData{
43+
Realm: [1]byte{0x00},
44+
ForwardAmount: uint64(i),
45+
OutgoingCltv: uint32(i),
46+
},
47+
}
48+
copy(path[i].HopData.NextAddress[:], bytes.Repeat([]byte{byte(i)}, 8))
49+
4150
fmt.Fprintf(os.Stderr, "Node %d pubkey %x\n", i, pubkey.SerializeCompressed())
4251
}
4352

4453
sessionKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), bytes.Repeat([]byte{'A'}, 32))
4554

46-
var hopsData []sphinx.HopData
47-
for i := 0; i < len(route); i++ {
48-
hopsData = append(hopsData, sphinx.HopData{
49-
Realm: 0x00,
50-
ForwardAmount: uint64(i),
51-
OutgoingCltv: uint32(i),
52-
})
53-
copy(hopsData[i].NextAddress[:], bytes.Repeat([]byte{byte(i)}, 8))
54-
}
55-
56-
msg, err := sphinx.NewOnionPacket(route, sessionKey, hopsData, assocData)
55+
msg, err := sphinx.NewOnionPacket(&path, sessionKey, assocData)
5756
if err != nil {
5857
log.Fatalf("Error creating message: %v", err)
5958
}

0 commit comments

Comments
 (0)