Skip to content

Instantly share code, notes, and snippets.

@mably
Created June 1, 2017 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mably/b8dba5803b24bbc4a2a5797bbef1c919 to your computer and use it in GitHub Desktop.
Save mably/b8dba5803b24bbc4a2a5797bbef1c919 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/hex"
"flag"
"fmt"
"log"
"time"
"golang.org/x/net/context"
"github.com/roasbeef/btcutil"
"github.com/lightningnetwork/lnd/lnrpc"
"google.golang.org/grpc"
)
var (
dest = flag.String("dest", "", "target to send htlc's to")
amt = flag.Int("amt", 100, "amt of each htlc to send")
numHtlcs = flag.Int("num_htlcs", 2000, "number of htlcs to send")
)
func getClient() lnrpc.LightningClient {
opts := []grpc.DialOption{grpc.WithInsecure()}
conn, err := grpc.Dial("localhost:10009", opts...)
if err != nil {
panic(err)
}
return lnrpc.NewLightningClient(conn)
}
func main() {
flag.Parse()
if *dest == "" {
panic(fmt.Errorf("dest flag must be set"))
}
// Establish an HTTP/2 connection to lnd's gRPC server.
lndConn := getClient()
lnAddr, err := hex.DecodeString(*dest)
if err != nil {
panic(err)
}
sendReq := &lnrpc.SendRequest{
Dest: lnAddr,
Amt: int64(*amt),
}
satoshisSent := btcutil.Amount(0)
paymentStream, err := lndConn.SendPayment(context.Background())
if err != nil {
panic(err)
}
i := 0
numSatoshis := *numHtlcs
log.Println("sending payments...")
now := time.Now()
for satoshisSent < btcutil.Amount(numSatoshis) {
if err := paymentStream.Send(sendReq); err != nil {
panic(err)
}
satoshisSent++
i++
}
log.Println("payments sent...")
log.Println("waiting...")
for i := 0; i < numSatoshis; i++ {
if _, err := paymentStream.Recv(); err != nil {
panic(err)
}
}
timeTaken := time.Since(now)
fmt.Println("Elapsed time: ", timeTaken)
fmt.Println("tps: ", float64(numSatoshis)/float64(timeTaken.Seconds()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment