Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onion messaging + bolt 12 offers #9369

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@ build-itest:
@$(call print, "Building itest binary for ${backend} backend.")
CGO_ENABLED=0 $(GOTEST) -v ./itest -tags="$(DEV_TAGS) $(RPC_TAGS) integration $(backend)" -c -o itest/itest.test$(EXEC_SUFFIX)

#? build-itest-race: Build integration test binaries in race detector mode, place them in itest directory
build-itest-b12:
@$(call print, "Building itest btcd and lnd.")
CGO_ENABLED=0 $(GOBUILD) -tags="integration bolt12" -o itest/btcd-itest$(EXEC_SUFFIX) $(ITEST_LDFLAGS) $(BTCD_PKG)
CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS) bolt12" -o itest/lnd-itest$(EXEC_SUFFIX) $(ITEST_LDFLAGS) $(PKG)/cmd/lnd

@$(call print, "Building itest binary for ${backend} backend.")
CGO_ENABLED=0 $(GOTEST) -v ./itest -tags="$(DEV_TAGS) $(RPC_TAGS) rpctest bolt12 $(backend)" -c -o itest/itest.test$(EXEC_SUFFIX)


build-itest-race:
@$(call print, "Building itest btcd and lnd with race detector.")
CGO_ENABLED=0 $(GOBUILD) -tags="integration" -o itest/btcd-itest$(EXEC_SUFFIX) $(DEV_LDFLAGS) $(BTCD_PKG)
Expand Down Expand Up @@ -214,7 +222,8 @@ itest-only: db-instance
#? itest: Build and run integration tests
itest: build-itest itest-only

#? itest-race: Build and run integration tests in race detector mode
itest-b12: build-itest-b12 itest-only

itest-race: build-itest-race itest-only

#? itest-parallel: Build and run integration tests in parallel mode, running up to ITEST_PARALLELISM test tranches in parallel (default 4)
Expand Down
96 changes: 11 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,24 @@
## Lightning Network Daemon
## Lightning Network Daemon - Bolt 12 Experimental Fork

[![Release build](https://github.com/lightningnetwork/lnd/actions/workflows/release.yaml/badge.svg)](https://github.com/lightningnetwork/lnd/actions/workflows/release.yaml)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/lightningnetwork/lnd/blob/master/LICENSE)
[![Irc](https://img.shields.io/badge/chat-on%20libera-brightgreen.svg)](https://web.libera.chat/#lnd)
[![Godoc](https://godoc.org/github.com/lightningnetwork/lnd?status.svg)](https://godoc.org/github.com/lightningnetwork/lnd)
[![Go Report Card](https://goreportcard.com/badge/github.com/lightningnetwork/lnd)](https://goreportcard.com/report/github.com/lightningnetwork/lnd)

<img src="logo.png">
### About

The Lightning Network Daemon (`lnd`) - is a complete implementation of a
[Lightning Network](https://lightning.network) node. `lnd` has several pluggable back-end
chain services including [`btcd`](https://github.com/btcsuite/btcd) (a
full-node), [`bitcoind`](https://github.com/bitcoin/bitcoin), and
[`neutrino`](https://github.com/lightninglabs/neutrino) (a new experimental light client). The project's codebase uses the
[btcsuite](https://github.com/btcsuite/) set of Bitcoin libraries, and also
exports a large set of isolated re-usable Lightning Network related libraries
within it. In the current state `lnd` is capable of:
* Creating channels.
* Closing channels.
* Completely managing all channel states (including the exceptional ones!).
* Maintaining a fully authenticated+validated channel graph.
* Performing path finding within the network, passively forwarding incoming payments.
* Sending outgoing [onion-encrypted payments](https://github.com/lightningnetwork/lightning-onion)
through the network.
* Updating advertised fee schedules.
* Automatic channel management ([`autopilot`](https://github.com/lightningnetwork/lnd/tree/master/autopilot)).
This is an experimental fork of LND which adds external support for [bolt 12](https://github.com/lightning/bolts/pull/798).

## Lightning Network Specification Compliance
`lnd` _fully_ conforms to the [Lightning Network specification
(BOLTs)](https://github.com/lightningnetwork/lightning-rfc). BOLT stands for:
Basis of Lightning Technology. The specifications are currently being drafted
by several groups of implementers based around the world including the
developers of `lnd`. The set of specification documents as well as our
implementation of the specification are still a work-in-progress. With that
said, the current status of `lnd`'s BOLT compliance is:
_Please do not run this in production, ffs._

- [X] BOLT 1: Base Protocol
- [X] BOLT 2: Peer Protocol for Channel Management
- [X] BOLT 3: Bitcoin Transaction and Script Formats
- [X] BOLT 4: Onion Routing Protocol
- [X] BOLT 5: Recommendations for On-chain Transaction Handling
- [X] BOLT 7: P2P Node and Channel Discovery
- [X] BOLT 8: Encrypted and Authenticated Transport
- [X] BOLT 9: Assigned Feature Flags
- [X] BOLT 10: DNS Bootstrap and Assisted Node Location
- [X] BOLT 11: Invoice Protocol for Lightning Payments
### Installation

## Developer Resources
This code is largely implemented in an external library, to keep a clean
separation of experimental code. However, we put it all together in lnd behind
the `bolt12` build tag so that we can take advantage of lnd's exception build
and test infrastructure.

The daemon has been designed to be as developer friendly as possible in order
to facilitate application development on top of `lnd`. Two primary RPC
interfaces are exported: an HTTP REST API, and a [gRPC](https://grpc.io/)
service. The exported APIs are not yet stable, so be warned: they may change
drastically in the near future.
All functionality can be accessed using the `bolt12` build tag, eg:

An automatically generated set of documentation for the RPC APIs can be found
at [api.lightning.community](https://api.lightning.community). A set of developer
resources including guides, articles, example applications and community resources can be found at:
[docs.lightning.engineering](https://docs.lightning.engineering).

Finally, we also have an active
[Slack](https://lightning.engineering/slack.html) where protocol developers, application developers, testers and users gather to
discuss various aspects of `lnd` and also Lightning in general.

## Installation
In order to build from source, please see [the installation
instructions](docs/INSTALL.md).

## Docker
To run lnd from Docker, please see the main [Docker instructions](docs/DOCKER.md)

## IRC
* irc.libera.chat
* channel #lnd
* [webchat](https://web.libera.chat/#lnd)

## Safety

When operating a mainnet `lnd` node, please refer to our [operational safety
guidelines](docs/safety.md). It is important to note that `lnd` is still
**beta** software and that ignoring these operational guidelines can lead to
loss of funds.

## Security

The developers of `lnd` take security _very_ seriously. The disclosure of
security vulnerabilities helps us secure the health of `lnd`, privacy of our
users, and also the health of the Lightning Network as a whole. If you find
any issues regarding security or privacy, please disclose the information
responsibly by sending an email to security at lightning dot engineering,
preferably encrypted using our designated PGP key
(`91FE464CD75101DA6B6BAB60555C6465E5BCB3AF`) which can be found
[here](https://gist.githubusercontent.com/Roasbeef/6fb5b52886183239e4aa558f83d085d3/raw/5fa96010af201628bcfa61e9309d9b13d23d220f/[email protected]).

## Further reading
* [Step-by-step send payment guide with docker](https://github.com/lightningnetwork/lnd/tree/master/docker)
* [Contribution guide](https://github.com/lightningnetwork/lnd/blob/master/docs/code_contribution_guidelines.md)
`make install tags=bolt12`
1 change: 1 addition & 0 deletions cmd/commands/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ func Main() {
app.Commands = append(app.Commands, devCommands()...)
app.Commands = append(app.Commands, peersCommands()...)
app.Commands = append(app.Commands, chainCommands()...)
app.Commands = append(app.Commands, onionMessageCommands()...)

if err := app.Run(os.Args); err != nil {
fatal(err)
Expand Down
71 changes: 71 additions & 0 deletions cmd/commands/onionmessage_active.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//go:build bolt12

package commands

import (
"encoding/hex"
"errors"
"fmt"

"github.com/gijswijs/boltnd/offersrpc"
"github.com/urfave/cli"
)

var sendOnionMessageCommand = cli.Command{
Name: "sendonion",
Flags: []cli.Flag{
cli.StringFlag{
Name: "pubkey",
},
},
Action: actionDecorator(sendOnion),
}

func sendOnion(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getOffersClient(ctx)
defer cleanUp()

pubkeyFlag := ctx.String("pubkey")
if pubkeyFlag == "" {
return errors.New("public key required for onion message")
}

pubkeyBytes, err := hex.DecodeString(pubkeyFlag)
if err != nil {
return fmt.Errorf("pubkey: %w", err)
}

req := &offersrpc.SendOnionMessageRequest{
Pubkey: pubkeyBytes,
}

_, err = client.SendOnionMessage(ctxc, req)
return err
}

func getOffersClient(ctx *cli.Context) (offersrpc.OffersClient, func()) {
conn := getClientConn(ctx, true)

cleanUp := func() {
conn.Close()
}

return offersrpc.NewOffersClient(conn), cleanUp
}

// autopilotCommands will return the set of commands to enable for autopilotrpc
// builds.
func onionMessageCommands() []cli.Command {
return []cli.Command{
{
Name: "onionmessage",
Category: "Onion Message",
Usage: "Send and receive onion messages.",
Description: "",
Subcommands: []cli.Command{
sendOnionMessageCommand,
},
},
}
}
12 changes: 12 additions & 0 deletions cmd/commands/onionmessage_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !bolt12

package commands

import (
"github.com/urfave/cli"
)

// autopilotCommands will return nil for non-bolt12 builds.
func onionMessageCommands() []cli.Command {
return nil
}
2 changes: 2 additions & 0 deletions cmd/lnd/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !bolt12

package main

import (
Expand Down
99 changes: 99 additions & 0 deletions cmd/lnd/main_boltnd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//go:build bolt12

package main

import (
"fmt"
"os"

"github.com/gijswijs/boltnd"
"github.com/jessevdk/go-flags"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/signal"
)

func main() {
// Hook interceptor for os signals.
shutdownInterceptor, err := signal.Intercept()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

// Load the configuration, and parse any command line options. This
// function will also set up logging properly.
loadedConfig, err := lnd.LoadConfig(shutdownInterceptor)
if err != nil {
if e, ok := err.(*flags.Error); !ok || e.Type != flags.ErrHelp {
// Print error if not due to help request.
err = fmt.Errorf("failed to load config: %w", err)
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

// Help was requested, exit normally.
os.Exit(0)
}

// Create a new, external bolt implementation using our config and
// logger.
boltImpl, err := boltnd.NewBoltnd(
boltnd.OptionLNDConfig(loadedConfig),
boltnd.OptionLNDLogger(
loadedConfig.SubLogMgr, shutdownInterceptor,
),
boltnd.OptionRequestShutdown(
shutdownInterceptor.RequestShutdown,
),
)
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

// TODO(carla): figure out defaults/ whether we need this?
implCfg := loadedConfig.ImplementationConfig(shutdownInterceptor)

// Add our external macaroon validator and grpc registrar.
implCfg.GrpcRegistrar = boltImpl
implCfg.ExternalValidator = boltImpl

// We want lnd to start up before we start our boltnd implementation,
// because it needs to connect to the API. We start lnd in a goroutine
// using the done channel to indicate when lnd has exited.
done := make(chan struct{})
go func() {
defer close(done)

// Call the "real" main in a nested manner so the defers will
// properly be executed in the case of a graceful shutdown.
if err = lnd.Main(
loadedConfig, lnd.ListenerCfg{}, implCfg,
shutdownInterceptor,
); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}()

// Start our external bolt impl. If our start fails, we do not exit but
// rather request shutdown from lnd and allow it the time to cleanly
// exit.
if err := boltImpl.Start(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, "boltnd start", err)
shutdownInterceptor.RequestShutdown()
}

// Once the done channel is closed, we know that lnd has exited, either
// from an internal error or on request from boltnd (because it
// encountered a critical error.
<-done

// Finally, shut down our external implementation.
if err := boltImpl.Stop(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, "boltnd stop",
err)
os.Exit(1)
}

}
17 changes: 13 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f
github.com/davecgh/go-spew v1.1.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/gijswijs/boltnd v0.0.0-20241209200049-1310602927e8
github.com/go-errors/errors v1.0.1
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
Expand Down Expand Up @@ -63,10 +64,18 @@ require (
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.33.0
gopkg.in/macaroon-bakery.v2 v2.0.1
gopkg.in/macaroon.v2 v2.0.0
gopkg.in/macaroon.v2 v2.1.0
pgregory.net/rapid v1.1.0
)

require (
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/lightninglabs/lndclient v1.0.1-0.20241031082205-9c87f640ce2c // indirect
github.com/lightningnetwork/lnd/fn v1.2.5 // indirect
go.opentelemetry.io/otel/metric v1.20.0 // indirect
)

require (
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand Down Expand Up @@ -165,12 +174,12 @@ require (
go.etcd.io/etcd/pkg/v3 v3.5.7 // indirect
go.etcd.io/etcd/raft/v3 v3.5.7 // indirect
go.etcd.io/etcd/server/v3 v3.5.7 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.25.0 // indirect
go.opentelemetry.io/otel v1.0.1 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0 // indirect
go.opentelemetry.io/otel v1.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.0.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.0.1 // indirect
go.opentelemetry.io/otel/sdk v1.0.1 // indirect
go.opentelemetry.io/otel/trace v1.0.1 // indirect
go.opentelemetry.io/otel/trace v1.20.0 // indirect
go.opentelemetry.io/proto/otlp v0.9.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
Expand Down
Loading
Loading