Merge pull request #6853 from yyforyongyu/fix-make-fmt
github: fix `make fmt` and add `make fmt-check`
This commit is contained in:
57 files changed
+217
-133
No files matched your search
@@ -32,6 +32,24 @@ env:
|
|||||||
GO_VERSION: 1.18.2
|
GO_VERSION: 1.18.2
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
########################
|
||||||
|
# format code
|
||||||
|
########################
|
||||||
|
fmt-check:
|
||||||
|
name: check code format
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: git checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: setup go ${{ env.GO_VERSION }}
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '${{ env.GO_VERSION }}'
|
||||||
|
|
||||||
|
- name: fmt
|
||||||
|
run: make fmt-check
|
||||||
|
|
||||||
########################
|
########################
|
||||||
# RPC and mobile compilation check
|
# RPC and mobile compilation check
|
||||||
########################
|
########################
|
||||||
|
|||||||
@@ -258,6 +258,10 @@ fmt: $(GOIMPORTS_BIN)
|
|||||||
@$(call print, "Formatting source.")
|
@$(call print, "Formatting source.")
|
||||||
gofmt -l -w -s $(GOFILES_NOVENDOR)
|
gofmt -l -w -s $(GOFILES_NOVENDOR)
|
||||||
|
|
||||||
|
fmt-check: fmt
|
||||||
|
@$(call print, "Checking fmt results.")
|
||||||
|
if test -n "$$(git status --porcelain)"; then echo "code not formatted correctly, please run `make fmt` again!"; git status; git diff; exit 1; fi
|
||||||
|
|
||||||
lint: docker-tools
|
lint: docker-tools
|
||||||
@$(call print, "Linting source.")
|
@$(call print, "Linting source.")
|
||||||
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
|
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
|
||||||
|
|||||||
@@ -165,10 +165,12 @@ func ReconstructChildren(descs ...ChildDesc) []*Child {
|
|||||||
|
|
||||||
// split splits a share into two random values, that when XOR'd reproduce the
|
// split splits a share into two random values, that when XOR'd reproduce the
|
||||||
// original share. Given a share s, the two shares are derived as:
|
// original share. Given a share s, the two shares are derived as:
|
||||||
|
//
|
||||||
// left <-$- random
|
// left <-$- random
|
||||||
// right = parent ^ left.
|
// right = parent ^ left.
|
||||||
//
|
//
|
||||||
// When reconstructed, we have that:
|
// When reconstructed, we have that:
|
||||||
|
//
|
||||||
// left ^ right = left ^ parent ^ left
|
// left ^ right = left ^ parent ^ left
|
||||||
// = parent.
|
// = parent.
|
||||||
func split(parent *Share) (Share, Share, error) {
|
func split(parent *Share) (Share, Share, error) {
|
||||||
|
|||||||
@@ -346,6 +346,7 @@ func EphemeralGenerator(gen func() (*btcec.PrivateKey, error)) func(*Machine) {
|
|||||||
// itself.
|
// itself.
|
||||||
//
|
//
|
||||||
// The acts proceeds the following order (initiator on the left):
|
// The acts proceeds the following order (initiator on the left):
|
||||||
|
//
|
||||||
// GenActOne() ->
|
// GenActOne() ->
|
||||||
// RecvActOne()
|
// RecvActOne()
|
||||||
// <- GenActTwo()
|
// <- GenActTwo()
|
||||||
@@ -354,6 +355,7 @@ func EphemeralGenerator(gen func() (*btcec.PrivateKey, error)) func(*Machine) {
|
|||||||
// RecvActThree()
|
// RecvActThree()
|
||||||
//
|
//
|
||||||
// This exchange corresponds to the following Noise handshake:
|
// This exchange corresponds to the following Noise handshake:
|
||||||
|
//
|
||||||
// <- s
|
// <- s
|
||||||
// ...
|
// ...
|
||||||
// -> e, es
|
// -> e, es
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const (
|
|||||||
// running full node.
|
// running full node.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): heavily consolidate with NeutrinoNotifier code
|
// TODO(roasbeef): heavily consolidate with NeutrinoNotifier code
|
||||||
// * maybe combine into single package?
|
// - maybe combine into single package?
|
||||||
type NeutrinoNotifier struct {
|
type NeutrinoNotifier struct {
|
||||||
epochClientCounter uint64 // To be used atomically.
|
epochClientCounter uint64 // To be used atomically.
|
||||||
|
|
||||||
|
|||||||
@@ -110,10 +110,10 @@ func checkPkgFilterRand(t *testing.T, b, p uint16) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// checkPkgFilterEncodeDecode tests the serialization of a pkg filter by:
|
// checkPkgFilterEncodeDecode tests the serialization of a pkg filter by:
|
||||||
// 1) writing it to a buffer
|
// 1. writing it to a buffer
|
||||||
// 2) verifying the number of bytes written matches the filter's Size()
|
// 2. verifying the number of bytes written matches the filter's Size()
|
||||||
// 3) reconstructing the filter decoding the bytes
|
// 3. reconstructing the filter decoding the bytes
|
||||||
// 4) checking that the two filters are the same according to Equal
|
// 4. checking that the two filters are the same according to Equal
|
||||||
func checkPkgFilterEncodeDecode(t *testing.T, i uint16, f *channeldb.PkgFilter) {
|
func checkPkgFilterEncodeDecode(t *testing.T, i uint16, f *channeldb.PkgFilter) {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
if err := f.Encode(&b); err != nil {
|
if err := f.Encode(&b); err != nil {
|
||||||
|
|||||||
@@ -140,7 +140,6 @@ func (a *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
|
|||||||
|
|
||||||
// Encode serializes the target NodeAnnouncement into the passed io.Writer
|
// Encode serializes the target NodeAnnouncement into the passed io.Writer
|
||||||
// observing the protocol version specified.
|
// observing the protocol version specified.
|
||||||
//
|
|
||||||
func (a *NodeAnnouncement) Encode(w io.Writer, pver uint32) error {
|
func (a *NodeAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||||
return WriteElements(w,
|
return WriteElements(w,
|
||||||
a.Signature,
|
a.Signature,
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
|
||||||
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
|
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
|
||||||
mig24 "github.com/lightningnetwork/lnd/channeldb/migration24"
|
mig24 "github.com/lightningnetwork/lnd/channeldb/migration24"
|
||||||
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
||||||
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
|
||||||
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
||||||
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
||||||
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,13 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/channeldb/migtest"
|
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
|
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
|
||||||
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
||||||
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
||||||
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/migtest"
|
||||||
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ package migration30
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
||||||
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
||||||
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
mig24 "github.com/lightningnetwork/lnd/channeldb/migration24"
|
mig24 "github.com/lightningnetwork/lnd/channeldb/migration24"
|
||||||
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
||||||
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
||||||
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
|
|||||||
@@ -8,14 +8,13 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
|
||||||
"github.com/lightningnetwork/lnd/shachain"
|
|
||||||
|
|
||||||
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
|
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
|
||||||
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
|
||||||
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
|
||||||
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
||||||
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
|
"github.com/lightningnetwork/lnd/shachain"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ var (
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): also add current OnionKey plus rotation schedule?
|
// TODO(roasbeef): also add current OnionKey plus rotation schedule?
|
||||||
// TODO(roasbeef): add bitfield for supported services
|
// TODO(roasbeef): add bitfield for supported services
|
||||||
// * possibly add a wire.NetAddress type, type
|
// - possibly add a wire.NetAddress type, type
|
||||||
type LinkNode struct {
|
type LinkNode struct {
|
||||||
// Network indicates the Bitcoin network that the LinkNode advertises
|
// Network indicates the Bitcoin network that the LinkNode advertises
|
||||||
// for incoming channel creation.
|
// for incoming channel creation.
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ var (
|
|||||||
// use this cache to detect duplicate witnesses.
|
// use this cache to detect duplicate witnesses.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): need expiry policy?
|
// TODO(roasbeef): need expiry policy?
|
||||||
// * encrypt?
|
// - encrypt?
|
||||||
type WitnessCache struct {
|
type WitnessCache struct {
|
||||||
db *DB
|
db *DB
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,6 +388,7 @@ func openChannel(ctx *cli.Context) error {
|
|||||||
// protocol involves several steps between the RPC server and the CLI client:
|
// protocol involves several steps between the RPC server and the CLI client:
|
||||||
//
|
//
|
||||||
// RPC server CLI client
|
// RPC server CLI client
|
||||||
|
//
|
||||||
// | |
|
// | |
|
||||||
// | |<------open channel (stream)-----|
|
// | |<------open channel (stream)-----|
|
||||||
// | |-------ready for funding----->| |
|
// | |-------ready for funding----->| |
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/neutrinorpc"
|
"github.com/lightningnetwork/lnd/lnrpc/neutrinorpc"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getNeutrinoKitClient(ctx *cli.Context) (neutrinorpc.NeutrinoKitClient, func()) {
|
func getNeutrinoKitClient(ctx *cli.Context) (neutrinorpc.NeutrinoKitClient, func()) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !neutrinorpc
|
||||||
// +build !neutrinorpc
|
// +build !neutrinorpc
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -642,10 +642,10 @@ func DefaultConfig() Config {
|
|||||||
// line options.
|
// line options.
|
||||||
//
|
//
|
||||||
// The configuration proceeds as follows:
|
// The configuration proceeds as follows:
|
||||||
// 1) Start with a default config with sane settings
|
// 1. Start with a default config with sane settings
|
||||||
// 2) Pre-parse the command line to check for an alternative config file
|
// 2. Pre-parse the command line to check for an alternative config file
|
||||||
// 3) Load configuration file overwriting defaults with any specified options
|
// 3. Load configuration file overwriting defaults with any specified options
|
||||||
// 4) Parse CLI options and overwrite/add any specified options
|
// 4. Parse CLI options and overwrite/add any specified options
|
||||||
func LoadConfig(interceptor signal.Interceptor) (*Config, error) {
|
func LoadConfig(interceptor signal.Interceptor) (*Config, error) {
|
||||||
// Pre-parse the command line options to pick up an alternative config
|
// Pre-parse the command line options to pick up an alternative config
|
||||||
// file.
|
// file.
|
||||||
|
|||||||
@@ -1191,7 +1191,7 @@ func (u *UtxoNursery) closeAndRemoveIfMature(chanPoint *wire.OutPoint) error {
|
|||||||
// be used to spend the CSV output contained in the timeout txn.
|
// be used to spend the CSV output contained in the timeout txn.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): re-rename to timeout tx
|
// TODO(roasbeef): re-rename to timeout tx
|
||||||
// * create CltvCsvSpendableOutput
|
// - create CltvCsvSpendableOutput
|
||||||
type babyOutput struct {
|
type babyOutput struct {
|
||||||
// expiry is the absolute block height at which the secondLevelTx
|
// expiry is the absolute block height at which the secondLevelTx
|
||||||
// should be broadcast to the network.
|
// should be broadcast to the network.
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ func (c *ChannelGraphBootstrapper) Name() string {
|
|||||||
// interface which implements peer bootstrapping via a special DNS seed as
|
// interface which implements peer bootstrapping via a special DNS seed as
|
||||||
// defined in BOLT-0010. For further details concerning Lightning's current DNS
|
// defined in BOLT-0010. For further details concerning Lightning's current DNS
|
||||||
// boot strapping protocol, see this link:
|
// boot strapping protocol, see this link:
|
||||||
// * https://github.com/lightningnetwork/lightning-rfc/blob/master/10-dns-bootstrap.md
|
// - https://github.com/lightningnetwork/lightning-rfc/blob/master/10-dns-bootstrap.md
|
||||||
type DNSSeedBootstrapper struct {
|
type DNSSeedBootstrapper struct {
|
||||||
// dnsSeeds is an array of two tuples we'll use for bootstrapping. The
|
// dnsSeeds is an array of two tuples we'll use for bootstrapping. The
|
||||||
// first item in the tuple is the primary host we'll use to attempt the
|
// first item in the tuple is the primary host we'll use to attempt the
|
||||||
|
|||||||
@@ -1608,12 +1608,14 @@ func TestGossipSyncerDelayDOS(t *testing.T) {
|
|||||||
// rate-limiting. The provided chanSeries should belong to syncer2.
|
// rate-limiting. The provided chanSeries should belong to syncer2.
|
||||||
//
|
//
|
||||||
// The state transition performed is the following:
|
// The state transition performed is the following:
|
||||||
|
//
|
||||||
// syncer1 -- QueryShortChanIDs --> syncer2
|
// syncer1 -- QueryShortChanIDs --> syncer2
|
||||||
// chanSeries.FetchChanAnns()
|
// chanSeries.FetchChanAnns()
|
||||||
// syncer1 <-- ReplyShortChanIDsEnd -- syncer2
|
// syncer1 <-- ReplyShortChanIDsEnd -- syncer2
|
||||||
//
|
//
|
||||||
// If expDelayResponse is true, this method will assert that the call the
|
// If expDelayResponse is true, this method will assert that the call the
|
||||||
// FetchChanAnns happens between:
|
// FetchChanAnns happens between:
|
||||||
|
//
|
||||||
// [delayedQueryInterval-delayTolerance, delayedQueryInterval+delayTolerance].
|
// [delayedQueryInterval-delayTolerance, delayedQueryInterval+delayTolerance].
|
||||||
func queryBatch(t *testing.T,
|
func queryBatch(t *testing.T,
|
||||||
msgChan1, msgChan2 chan []lnwire.Message,
|
msgChan1, msgChan2 chan []lnwire.Message,
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ transaction](https://github.com/lightningnetwork/lnd/pull/6730).
|
|||||||
* [The `golangci-lint` tool was updated to
|
* [The `golangci-lint` tool was updated to
|
||||||
`v1.46.2`](https://github.com/lightningnetwork/lnd/pull/6731)
|
`v1.46.2`](https://github.com/lightningnetwork/lnd/pull/6731)
|
||||||
|
|
||||||
|
* Updated the github actions to use `make fmt-check` in its [build
|
||||||
|
process](https://github.com/lightningnetwork/lnd/pull/6853).
|
||||||
|
|
||||||
# Contributors (Alphabetical Order)
|
# Contributors (Alphabetical Order)
|
||||||
|
|
||||||
* Carla Kirk-Cohen
|
* Carla Kirk-Cohen
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ type SphinxErrorEncrypter struct {
|
|||||||
// should be used to deserialize an encoded SphinxErrorEncrypter. Since the
|
// should be used to deserialize an encoded SphinxErrorEncrypter. Since the
|
||||||
// actual encrypter is not stored in plaintext while at rest, reconstructing the
|
// actual encrypter is not stored in plaintext while at rest, reconstructing the
|
||||||
// error encrypter requires:
|
// error encrypter requires:
|
||||||
// 1) Decode: to deserialize the ephemeral public key.
|
// 1. Decode: to deserialize the ephemeral public key.
|
||||||
// 2) Reextract: to "unlock" the actual error encrypter using an active
|
// 2. Reextract: to "unlock" the actual error encrypter using an active
|
||||||
// OnionProcessor.
|
// OnionProcessor.
|
||||||
func NewSphinxErrorEncrypter() *SphinxErrorEncrypter {
|
func NewSphinxErrorEncrypter() *SphinxErrorEncrypter {
|
||||||
return &SphinxErrorEncrypter{
|
return &SphinxErrorEncrypter{
|
||||||
|
|||||||
@@ -155,7 +155,6 @@ type ChannelUpdateHandler interface {
|
|||||||
// | (Peer) (Peer) (Peer)
|
// | (Peer) (Peer) (Peer)
|
||||||
// | Alice <----- tcp conn --> Bob <---- tcp conn -----> Carol
|
// | Alice <----- tcp conn --> Bob <---- tcp conn -----> Carol
|
||||||
// |
|
// |
|
||||||
//
|
|
||||||
type ChannelLink interface {
|
type ChannelLink interface {
|
||||||
// TODO(roasbeef): modify interface to embed mail boxes?
|
// TODO(roasbeef): modify interface to embed mail boxes?
|
||||||
|
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ func createInterceptorFunc(prefix, receiver string, messages []expectedMessage,
|
|||||||
// Specifically, this tests the following scenario:
|
// Specifically, this tests the following scenario:
|
||||||
//
|
//
|
||||||
// A B
|
// A B
|
||||||
|
//
|
||||||
// <----add-----
|
// <----add-----
|
||||||
// -----add---->
|
// -----add---->
|
||||||
// <----sig-----
|
// <----sig-----
|
||||||
@@ -301,6 +302,7 @@ func TestChannelLinkRevThenSig(t *testing.T) {
|
|||||||
// Specifically, this tests the following scenario:
|
// Specifically, this tests the following scenario:
|
||||||
//
|
//
|
||||||
// A B
|
// A B
|
||||||
|
//
|
||||||
// <----add-----
|
// <----add-----
|
||||||
// -----add---->
|
// -----add---->
|
||||||
// -----sig----x
|
// -----sig----x
|
||||||
|
|||||||
@@ -1012,10 +1012,10 @@ func (s *Switch) extractResult(deobfuscator ErrorDecrypter, n *networkResult,
|
|||||||
|
|
||||||
// parseFailedPayment determines the appropriate failure message to return to
|
// parseFailedPayment determines the appropriate failure message to return to
|
||||||
// a user initiated payment. The three cases handled are:
|
// a user initiated payment. The three cases handled are:
|
||||||
// 1) An unencrypted failure, which should already plaintext.
|
// 1. An unencrypted failure, which should already plaintext.
|
||||||
// 2) A resolution from the chain arbitrator, which possibly has no failure
|
// 2. A resolution from the chain arbitrator, which possibly has no failure
|
||||||
// reason attached.
|
// reason attached.
|
||||||
// 3) A failure from the remote party, which will need to be decrypted using
|
// 3. A failure from the remote party, which will need to be decrypted using
|
||||||
// the payment deobfuscator.
|
// the payment deobfuscator.
|
||||||
func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
|
func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
|
||||||
attemptID uint64, paymentHash lntypes.Hash, unencrypted,
|
attemptID uint64, paymentHash lntypes.Hash, unencrypted,
|
||||||
|
|||||||
@@ -943,11 +943,15 @@ func createClusterChannels(aliceToBob, bobToCarol btcutil.Amount) (
|
|||||||
//
|
//
|
||||||
// alice bob carol
|
// alice bob carol
|
||||||
// server - <-connection-> - server - - <-connection-> - - - server
|
// server - <-connection-> - server - - <-connection-> - - - server
|
||||||
|
//
|
||||||
// | | |
|
// | | |
|
||||||
|
//
|
||||||
// alice htlc bob htlc carol htlc
|
// alice htlc bob htlc carol htlc
|
||||||
// switch switch \ switch
|
// switch switch \ switch
|
||||||
|
//
|
||||||
// | | \ |
|
// | | \ |
|
||||||
// | | \ |
|
// | | \ |
|
||||||
|
//
|
||||||
// alice first bob second bob carol
|
// alice first bob second bob carol
|
||||||
// channel link channel link channel link channel link
|
// channel link channel link channel link channel link
|
||||||
//
|
//
|
||||||
@@ -1212,14 +1216,17 @@ type twoHopNetwork struct {
|
|||||||
//
|
//
|
||||||
// alice bob
|
// alice bob
|
||||||
// server - <-connection-> - server
|
// server - <-connection-> - server
|
||||||
|
//
|
||||||
// | |
|
// | |
|
||||||
|
//
|
||||||
// alice htlc bob htlc
|
// alice htlc bob htlc
|
||||||
// switch switch
|
// switch switch
|
||||||
// | |
|
|
||||||
// | |
|
|
||||||
// alice bob
|
|
||||||
// channel link channel link
|
|
||||||
//
|
//
|
||||||
|
// | |
|
||||||
|
// | |
|
||||||
|
//
|
||||||
|
// alice bob
|
||||||
|
// channel link channel link.
|
||||||
func newTwoHopNetwork(t testing.TB,
|
func newTwoHopNetwork(t testing.TB,
|
||||||
aliceChannel, bobChannel *lnwallet.LightningChannel,
|
aliceChannel, bobChannel *lnwallet.LightningChannel,
|
||||||
startingHeight uint32) *twoHopNetwork {
|
startingHeight uint32) *twoHopNetwork {
|
||||||
|
|||||||
+48
-24
@@ -203,22 +203,25 @@ func Ripemd160H(d []byte) []byte {
|
|||||||
// output payment for the sender's version of the commitment transaction. The
|
// output payment for the sender's version of the commitment transaction. The
|
||||||
// possible script paths from this output include:
|
// possible script paths from this output include:
|
||||||
//
|
//
|
||||||
// * The sender timing out the HTLC using the second level HTLC timeout
|
// - The sender timing out the HTLC using the second level HTLC timeout
|
||||||
// transaction.
|
// transaction.
|
||||||
// * The receiver of the HTLC claiming the output on-chain with the payment
|
// - The receiver of the HTLC claiming the output on-chain with the payment
|
||||||
// preimage.
|
// preimage.
|
||||||
// * The receiver of the HTLC sweeping all the funds in the case that a
|
// - The receiver of the HTLC sweeping all the funds in the case that a
|
||||||
// revoked commitment transaction bearing this HTLC was broadcast.
|
// revoked commitment transaction bearing this HTLC was broadcast.
|
||||||
//
|
//
|
||||||
// If confirmedSpend=true, a 1 OP_CSV check will be added to the non-revocation
|
// If confirmedSpend=true, a 1 OP_CSV check will be added to the non-revocation
|
||||||
// cases, to allow sweeping only after confirmation.
|
// cases, to allow sweeping only after confirmation.
|
||||||
//
|
//
|
||||||
// Possible Input Scripts:
|
// Possible Input Scripts:
|
||||||
|
//
|
||||||
// SENDR: <0> <sendr sig> <recvr sig> <0> (spend using HTLC timeout transaction)
|
// SENDR: <0> <sendr sig> <recvr sig> <0> (spend using HTLC timeout transaction)
|
||||||
// RECVR: <recvr sig> <preimage>
|
// RECVR: <recvr sig> <preimage>
|
||||||
// REVOK: <revoke sig> <revoke key>
|
// REVOK: <revoke sig> <revoke key>
|
||||||
// * receiver revoke
|
// * receiver revoke
|
||||||
//
|
//
|
||||||
|
// Offered HTLC Output Script:
|
||||||
|
//
|
||||||
// OP_DUP OP_HASH160 <revocation key hash160> OP_EQUAL
|
// OP_DUP OP_HASH160 <revocation key hash160> OP_EQUAL
|
||||||
// OP_IF
|
// OP_IF
|
||||||
// OP_CHECKSIG
|
// OP_CHECKSIG
|
||||||
@@ -231,7 +234,8 @@ func Ripemd160H(d []byte) []byte {
|
|||||||
// OP_HASH160 <ripemd160(payment hash)> OP_EQUALVERIFY
|
// OP_HASH160 <ripemd160(payment hash)> OP_EQUALVERIFY
|
||||||
// OP_CHECKSIG
|
// OP_CHECKSIG
|
||||||
// OP_ENDIF
|
// OP_ENDIF
|
||||||
// [1 OP_CHECKSEQUENCEVERIFY OP_DROP] <- if allowing confirmed spend only.
|
// [1 OP_CHECKSEQUENCEVERIFY OP_DROP] <- if allowing confirmed
|
||||||
|
// spend only.
|
||||||
// OP_ENDIF
|
// OP_ENDIF
|
||||||
func SenderHTLCScript(senderHtlcKey, receiverHtlcKey,
|
func SenderHTLCScript(senderHtlcKey, receiverHtlcKey,
|
||||||
revocationKey *btcec.PublicKey, paymentHash []byte,
|
revocationKey *btcec.PublicKey, paymentHash []byte,
|
||||||
@@ -442,21 +446,23 @@ func SenderHtlcSpendTimeout(receiverSig Signature,
|
|||||||
// ReceiverHTLCScript constructs the public key script for an incoming HTLC
|
// ReceiverHTLCScript constructs the public key script for an incoming HTLC
|
||||||
// output payment for the receiver's version of the commitment transaction. The
|
// output payment for the receiver's version of the commitment transaction. The
|
||||||
// possible execution paths from this script include:
|
// possible execution paths from this script include:
|
||||||
// * The receiver of the HTLC uses its second level HTLC transaction to
|
// - The receiver of the HTLC uses its second level HTLC transaction to
|
||||||
// advance the state of the HTLC into the delay+claim state.
|
// advance the state of the HTLC into the delay+claim state.
|
||||||
// * The sender of the HTLC sweeps all the funds of the HTLC as a breached
|
// - The sender of the HTLC sweeps all the funds of the HTLC as a breached
|
||||||
// commitment was broadcast.
|
// commitment was broadcast.
|
||||||
// * The sender of the HTLC sweeps the HTLC on-chain after the timeout period
|
// - The sender of the HTLC sweeps the HTLC on-chain after the timeout period
|
||||||
// of the HTLC has passed.
|
// of the HTLC has passed.
|
||||||
//
|
//
|
||||||
// If confirmedSpend=true, a 1 OP_CSV check will be added to the non-revocation
|
// If confirmedSpend=true, a 1 OP_CSV check will be added to the non-revocation
|
||||||
// cases, to allow sweeping only after confirmation.
|
// cases, to allow sweeping only after confirmation.
|
||||||
//
|
//
|
||||||
// Possible Input Scripts:
|
// Possible Input Scripts:
|
||||||
|
//
|
||||||
// RECVR: <0> <sender sig> <recvr sig> <preimage> (spend using HTLC success transaction)
|
// RECVR: <0> <sender sig> <recvr sig> <preimage> (spend using HTLC success transaction)
|
||||||
// REVOK: <sig> <key>
|
// REVOK: <sig> <key>
|
||||||
// SENDR: <sig> 0
|
// SENDR: <sig> 0
|
||||||
//
|
//
|
||||||
|
// Received HTLC Output Script:
|
||||||
//
|
//
|
||||||
// OP_DUP OP_HASH160 <revocation key hash160> OP_EQUAL
|
// OP_DUP OP_HASH160 <revocation key hash160> OP_EQUAL
|
||||||
// OP_IF
|
// OP_IF
|
||||||
@@ -471,7 +477,8 @@ func SenderHtlcSpendTimeout(receiverSig Signature,
|
|||||||
// OP_DROP <cltv expiry> OP_CHECKLOCKTIMEVERIFY OP_DROP
|
// OP_DROP <cltv expiry> OP_CHECKLOCKTIMEVERIFY OP_DROP
|
||||||
// OP_CHECKSIG
|
// OP_CHECKSIG
|
||||||
// OP_ENDIF
|
// OP_ENDIF
|
||||||
// [1 OP_CHECKSEQUENCEVERIFY OP_DROP] <- if allowing confirmed spend only.
|
// [1 OP_CHECKSEQUENCEVERIFY OP_DROP] <- if allowing confirmed
|
||||||
|
// spend only.
|
||||||
// OP_ENDIF
|
// OP_ENDIF
|
||||||
func ReceiverHTLCScript(cltvExpiry uint32, senderHtlcKey,
|
func ReceiverHTLCScript(cltvExpiry uint32, senderHtlcKey,
|
||||||
receiverHtlcKey, revocationKey *btcec.PublicKey,
|
receiverHtlcKey, revocationKey *btcec.PublicKey,
|
||||||
@@ -714,12 +721,15 @@ func ReceiverHtlcSpendTimeout(signer Signer, signDesc *SignDescriptor,
|
|||||||
// spent in a particular way, and to a particular output.
|
// spent in a particular way, and to a particular output.
|
||||||
//
|
//
|
||||||
// Possible Input Scripts:
|
// Possible Input Scripts:
|
||||||
// * To revoke an HTLC output that has been transitioned to the claim+delay
|
|
||||||
// state:
|
|
||||||
// * <revoke sig> 1
|
|
||||||
//
|
//
|
||||||
// * To claim and HTLC output, either with a pre-image or due to a timeout:
|
// - To revoke an HTLC output that has been transitioned to the claim+delay
|
||||||
// * <delay sig> 0
|
// state:
|
||||||
|
// <revoke sig> 1
|
||||||
|
//
|
||||||
|
// - To claim and HTLC output, either with a pre-image or due to a timeout:
|
||||||
|
// <delay sig> 0
|
||||||
|
//
|
||||||
|
// Output Script:
|
||||||
//
|
//
|
||||||
// OP_IF
|
// OP_IF
|
||||||
// <revoke key>
|
// <revoke key>
|
||||||
@@ -732,8 +742,8 @@ func ReceiverHtlcSpendTimeout(signer Signer, signDesc *SignDescriptor,
|
|||||||
// OP_CHECKSIG
|
// OP_CHECKSIG
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): possible renames for second-level
|
// TODO(roasbeef): possible renames for second-level
|
||||||
// * transition?
|
// - transition?
|
||||||
// * covenant output
|
// - covenant output
|
||||||
func SecondLevelHtlcScript(revocationKey, delayKey *btcec.PublicKey,
|
func SecondLevelHtlcScript(revocationKey, delayKey *btcec.PublicKey,
|
||||||
csvDelay uint32) ([]byte, error) {
|
csvDelay uint32) ([]byte, error) {
|
||||||
|
|
||||||
@@ -780,12 +790,15 @@ func SecondLevelHtlcScript(revocationKey, delayKey *btcec.PublicKey,
|
|||||||
// spent in a particular way, and to a particular output.
|
// spent in a particular way, and to a particular output.
|
||||||
//
|
//
|
||||||
// Possible Input Scripts:
|
// Possible Input Scripts:
|
||||||
// * To revoke an HTLC output that has been transitioned to the claim+delay
|
|
||||||
// state:
|
|
||||||
// * <revoke sig> 1
|
|
||||||
//
|
//
|
||||||
// * To claim an HTLC output, either with a pre-image or due to a timeout:
|
// - To revoke an HTLC output that has been transitioned to the claim+delay
|
||||||
// * <delay sig> 0
|
// state:
|
||||||
|
// <revoke sig> 1
|
||||||
|
//
|
||||||
|
// - To claim an HTLC output, either with a pre-image or due to a timeout:
|
||||||
|
// <delay sig> 0
|
||||||
|
//
|
||||||
|
// Output Script:
|
||||||
//
|
//
|
||||||
// OP_IF
|
// OP_IF
|
||||||
// <revoke key>
|
// <revoke key>
|
||||||
@@ -944,7 +957,7 @@ func HtlcSecondLevelSpend(signer Signer, signDesc *SignDescriptor,
|
|||||||
// LockTimeToSequence converts the passed relative locktime to a sequence
|
// LockTimeToSequence converts the passed relative locktime to a sequence
|
||||||
// number in accordance to BIP-68.
|
// number in accordance to BIP-68.
|
||||||
// See: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
|
// See: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
|
||||||
// * (Compatibility)
|
// - (Compatibility)
|
||||||
func LockTimeToSequence(isSeconds bool, locktime uint32) uint32 {
|
func LockTimeToSequence(isSeconds bool, locktime uint32) uint32 {
|
||||||
if !isSeconds {
|
if !isSeconds {
|
||||||
// The locktime is to be expressed in confirmations.
|
// The locktime is to be expressed in confirmations.
|
||||||
@@ -964,10 +977,12 @@ func LockTimeToSequence(isSeconds bool, locktime uint32) uint32 {
|
|||||||
// can claim all the settled funds in the channel, plus the unsettled funds.
|
// can claim all the settled funds in the channel, plus the unsettled funds.
|
||||||
//
|
//
|
||||||
// Possible Input Scripts:
|
// Possible Input Scripts:
|
||||||
|
//
|
||||||
// REVOKE: <sig> 1
|
// REVOKE: <sig> 1
|
||||||
// SENDRSWEEP: <sig> <emptyvector>
|
// SENDRSWEEP: <sig> <emptyvector>
|
||||||
//
|
//
|
||||||
// Output Script:
|
// Output Script:
|
||||||
|
//
|
||||||
// OP_IF
|
// OP_IF
|
||||||
// <revokeKey>
|
// <revokeKey>
|
||||||
// OP_ELSE
|
// OP_ELSE
|
||||||
@@ -1015,10 +1030,12 @@ func CommitScriptToSelf(csvTimeout uint32, selfKey, revokeKey *btcec.PublicKey)
|
|||||||
// can claim all the settled funds in the channel, plus the unsettled funds.
|
// can claim all the settled funds in the channel, plus the unsettled funds.
|
||||||
//
|
//
|
||||||
// Possible Input Scripts:
|
// Possible Input Scripts:
|
||||||
|
//
|
||||||
// REVOKE: <sig> 1
|
// REVOKE: <sig> 1
|
||||||
// SENDRSWEEP: <sig> <emptyvector>
|
// SENDRSWEEP: <sig> <emptyvector>
|
||||||
//
|
//
|
||||||
// Output Script:
|
// Output Script:
|
||||||
|
//
|
||||||
// OP_IF
|
// OP_IF
|
||||||
// <revokeKey>
|
// <revokeKey>
|
||||||
// OP_ELSE
|
// OP_ELSE
|
||||||
@@ -1194,9 +1211,11 @@ func CommitScriptUnencumbered(key *btcec.PublicKey) ([]byte, error) {
|
|||||||
// transaction. The money can only be spend after one confirmation.
|
// transaction. The money can only be spend after one confirmation.
|
||||||
//
|
//
|
||||||
// Possible Input Scripts:
|
// Possible Input Scripts:
|
||||||
|
//
|
||||||
// SWEEP: <sig>
|
// SWEEP: <sig>
|
||||||
//
|
//
|
||||||
// Output Script:
|
// Output Script:
|
||||||
|
//
|
||||||
// <key> OP_CHECKSIGVERIFY
|
// <key> OP_CHECKSIGVERIFY
|
||||||
// 1 OP_CHECKSEQUENCEVERIFY
|
// 1 OP_CHECKSEQUENCEVERIFY
|
||||||
func CommitScriptToRemoteConfirmed(key *btcec.PublicKey) ([]byte, error) {
|
func CommitScriptToRemoteConfirmed(key *btcec.PublicKey) ([]byte, error) {
|
||||||
@@ -1218,9 +1237,11 @@ func CommitScriptToRemoteConfirmed(key *btcec.PublicKey) ([]byte, error) {
|
|||||||
// transaction. The money can only be spend after one confirmation.
|
// transaction. The money can only be spend after one confirmation.
|
||||||
//
|
//
|
||||||
// Possible Input Scripts:
|
// Possible Input Scripts:
|
||||||
|
//
|
||||||
// SWEEP: <sig>
|
// SWEEP: <sig>
|
||||||
//
|
//
|
||||||
// Output Script:
|
// Output Script:
|
||||||
|
//
|
||||||
// <key> OP_CHECKSIGVERIFY
|
// <key> OP_CHECKSIGVERIFY
|
||||||
// <lease maturity in blocks> OP_CHECKLOCKTIMEVERIFY OP_DROP
|
// <lease maturity in blocks> OP_CHECKLOCKTIMEVERIFY OP_DROP
|
||||||
// 1 OP_CHECKSEQUENCEVERIFY
|
// 1 OP_CHECKSEQUENCEVERIFY
|
||||||
@@ -1278,10 +1299,12 @@ func CommitSpendToRemoteConfirmed(signer Signer, signDesc *SignDescriptor,
|
|||||||
// the given key immediately, or by anyone after 16 confirmations.
|
// the given key immediately, or by anyone after 16 confirmations.
|
||||||
//
|
//
|
||||||
// Possible Input Scripts:
|
// Possible Input Scripts:
|
||||||
|
//
|
||||||
// By owner: <sig>
|
// By owner: <sig>
|
||||||
// By anyone (after 16 conf): <emptyvector>
|
// By anyone (after 16 conf): <emptyvector>
|
||||||
//
|
//
|
||||||
// Output Script:
|
// Output Script:
|
||||||
|
//
|
||||||
// <funding_pubkey> OP_CHECKSIG OP_IFDUP
|
// <funding_pubkey> OP_CHECKSIG OP_IFDUP
|
||||||
// OP_NOTIF
|
// OP_NOTIF
|
||||||
// OP_16 OP_CSV
|
// OP_16 OP_CSV
|
||||||
@@ -1348,7 +1371,7 @@ func CommitSpendAnchorAnyone(script []byte) (wire.TxWitness, error) {
|
|||||||
// the pay/delay base point. The end end results is that the basePoint is
|
// the pay/delay base point. The end end results is that the basePoint is
|
||||||
// tweaked as follows:
|
// tweaked as follows:
|
||||||
//
|
//
|
||||||
// * key = basePoint + sha256(commitPoint || basePoint)*G
|
// - key = basePoint + sha256(commitPoint || basePoint)*G
|
||||||
func SingleTweakBytes(commitPoint, basePoint *btcec.PublicKey) []byte {
|
func SingleTweakBytes(commitPoint, basePoint *btcec.PublicKey) []byte {
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write(commitPoint.SerializeCompressed())
|
h.Write(commitPoint.SerializeCompressed())
|
||||||
@@ -1415,7 +1438,7 @@ func TweakPubKeyWithTweak(pubKey *btcec.PublicKey,
|
|||||||
// revoked state. Precisely, the following operation is used to derive a
|
// revoked state. Precisely, the following operation is used to derive a
|
||||||
// tweaked private key:
|
// tweaked private key:
|
||||||
//
|
//
|
||||||
// * tweakPriv := basePriv + sha256(commitment || basePub) mod N
|
// - tweakPriv := basePriv + sha256(commitment || basePub) mod N
|
||||||
//
|
//
|
||||||
// Where N is the order of the sub-group.
|
// Where N is the order of the sub-group.
|
||||||
func TweakPrivKey(basePriv *btcec.PrivateKey,
|
func TweakPrivKey(basePriv *btcec.PrivateKey,
|
||||||
@@ -1436,7 +1459,7 @@ func TweakPrivKey(basePriv *btcec.PrivateKey,
|
|||||||
// revoked commitment transaction, then if the other party knows the revocation
|
// revoked commitment transaction, then if the other party knows the revocation
|
||||||
// preimage, then they'll be able to derive the corresponding private key to
|
// preimage, then they'll be able to derive the corresponding private key to
|
||||||
// this private key by exploiting the homomorphism in the elliptic curve group:
|
// this private key by exploiting the homomorphism in the elliptic curve group:
|
||||||
// * https://en.wikipedia.org/wiki/Group_homomorphism#Homomorphisms_of_abelian_groups
|
// - https://en.wikipedia.org/wiki/Group_homomorphism#Homomorphisms_of_abelian_groups
|
||||||
//
|
//
|
||||||
// The derivation is performed as follows:
|
// The derivation is performed as follows:
|
||||||
//
|
//
|
||||||
@@ -1505,6 +1528,7 @@ func DeriveRevocationPubkey(revokeBase,
|
|||||||
// a previously revoked commitment transaction.
|
// a previously revoked commitment transaction.
|
||||||
//
|
//
|
||||||
// The private key is derived as follows:
|
// The private key is derived as follows:
|
||||||
|
//
|
||||||
// revokePriv := (revokeBasePriv * sha256(revocationBase || commitPoint)) +
|
// revokePriv := (revokeBasePriv * sha256(revocationBase || commitPoint)) +
|
||||||
// (commitSecret * sha256(commitPoint || revocationBase)) mod N
|
// (commitSecret * sha256(commitPoint || revocationBase)) mod N
|
||||||
//
|
//
|
||||||
|
|||||||
+16
-16
@@ -159,14 +159,14 @@ func makeWitnessTestCase(t *testing.T,
|
|||||||
//
|
//
|
||||||
// The following cases are exercised by this test:
|
// The following cases are exercised by this test:
|
||||||
// sender script:
|
// sender script:
|
||||||
// * receiver spends
|
// - receiver spends
|
||||||
// * revoke w/ sig
|
// - revoke w/ sig
|
||||||
// * HTLC with invalid preimage size
|
// - HTLC with invalid preimage size
|
||||||
// * HTLC with valid preimage size + sig
|
// - HTLC with valid preimage size + sig
|
||||||
// * sender spends
|
// - sender spends
|
||||||
// * invalid lock-time for CLTV
|
// - invalid lock-time for CLTV
|
||||||
// * invalid sequence for CSV
|
// - invalid sequence for CSV
|
||||||
// * valid lock-time+sequence, valid sig
|
// - valid lock-time+sequence, valid sig
|
||||||
func TestHTLCSenderSpendValidation(t *testing.T) {
|
func TestHTLCSenderSpendValidation(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -559,14 +559,14 @@ func TestHTLCSenderSpendValidation(t *testing.T) {
|
|||||||
// incoming HTLC.
|
// incoming HTLC.
|
||||||
//
|
//
|
||||||
// The following cases are exercised by this test:
|
// The following cases are exercised by this test:
|
||||||
// * receiver spends
|
// - receiver spends
|
||||||
// * HTLC redemption w/ invalid preimage size
|
// 1. HTLC redemption w/ invalid preimage size
|
||||||
// * HTLC redemption w/ invalid sequence
|
// 2. HTLC redemption w/ invalid sequence
|
||||||
// * HTLC redemption w/ valid preimage size
|
// 3. HTLC redemption w/ valid preimage size
|
||||||
// * sender spends
|
// - sender spends
|
||||||
// * revoke w/ sig
|
// 1. revoke w/ sig
|
||||||
// * refund w/ invalid lock time
|
// 2. refund w/ invalid lock time
|
||||||
// * refund w/ valid lock time
|
// 3. refund w/ valid lock time
|
||||||
func TestHTLCReceiverSpendValidation(t *testing.T) {
|
func TestHTLCReceiverSpendValidation(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ var (
|
|||||||
// The key derivation in this file follows the following hierarchy based on
|
// The key derivation in this file follows the following hierarchy based on
|
||||||
// BIP43:
|
// BIP43:
|
||||||
//
|
//
|
||||||
// * m/1017'/coinType'/keyFamily'/0/index
|
// - m/1017'/coinType'/keyFamily'/0/index
|
||||||
type KeyFamily uint32
|
type KeyFamily uint32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -143,7 +143,7 @@ var VersionZeroKeyFamilies = []KeyFamily{
|
|||||||
// Version 0 of our key derivation schema uses the following BIP43-like
|
// Version 0 of our key derivation schema uses the following BIP43-like
|
||||||
// derivation:
|
// derivation:
|
||||||
//
|
//
|
||||||
// * m/1017'/coinType'/keyFamily'/0/index
|
// - m/1017'/coinType'/keyFamily'/0/index
|
||||||
//
|
//
|
||||||
// Our purpose is 1017 (chosen arbitrary for now), and the coin type will vary
|
// Our purpose is 1017 (chosen arbitrary for now), and the coin type will vary
|
||||||
// based on which coin/chain the channels are being created on. The key family
|
// based on which coin/chain the channels are being created on. The key family
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ func IsUnix(addr net.Addr) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsPrivate returns true if the address is private. The definitions are,
|
// IsPrivate returns true if the address is private. The definitions are,
|
||||||
|
//
|
||||||
// https://en.wikipedia.org/wiki/Link-local_address
|
// https://en.wikipedia.org/wiki/Link-local_address
|
||||||
// https://en.wikipedia.org/wiki/Multicast_address
|
// https://en.wikipedia.org/wiki/Multicast_address
|
||||||
// Local IPv4 addresses, https://tools.ietf.org/html/rfc1918
|
// Local IPv4 addresses, https://tools.ietf.org/html/rfc1918
|
||||||
|
|||||||
@@ -8,16 +8,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"gopkg.in/macaroon-bakery.v2/bakery"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/blockchain"
|
"github.com/btcsuite/btcd/blockchain"
|
||||||
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"gopkg.in/macaroon-bakery.v2/bakery"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -288,6 +288,7 @@ func (cfg *BaseNodeConfig) GenArgs() []string {
|
|||||||
|
|
||||||
// policyUpdateMap defines a type to store channel policy updates. It has the
|
// policyUpdateMap defines a type to store channel policy updates. It has the
|
||||||
// format,
|
// format,
|
||||||
|
//
|
||||||
// {
|
// {
|
||||||
// "chanPoint1": {
|
// "chanPoint1": {
|
||||||
// "advertisingNode1": [
|
// "advertisingNode1": [
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ import (
|
|||||||
// testCommitmentTransactionDeadline tests that the anchor sweep transaction is
|
// testCommitmentTransactionDeadline tests that the anchor sweep transaction is
|
||||||
// taking account of the deadline of the commitment transaction. It tests two
|
// taking account of the deadline of the commitment transaction. It tests two
|
||||||
// scenarios:
|
// scenarios:
|
||||||
// 1) when the CPFP is skipped, checks that the deadline is not used.
|
// 1. when the CPFP is skipped, checks that the deadline is not used.
|
||||||
// 2) when the CPFP is used, checks that the deadline is applied.
|
// 2. when the CPFP is used, checks that the deadline is applied.
|
||||||
|
//
|
||||||
// Note that whether the deadline is used or not is implicitly checked by its
|
// Note that whether the deadline is used or not is implicitly checked by its
|
||||||
// corresponding fee rates.
|
// corresponding fee rates.
|
||||||
func testCommitmentTransactionDeadline(net *lntest.NetworkHarness,
|
func testCommitmentTransactionDeadline(net *lntest.NetworkHarness,
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ var singleHopSendToRouteCases = []singleHopSendToRouteCase{
|
|||||||
// testSingleHopSendToRoute tests that payments are properly processed through a
|
// testSingleHopSendToRoute tests that payments are properly processed through a
|
||||||
// provided route with a single hop. We'll create the following network
|
// provided route with a single hop. We'll create the following network
|
||||||
// topology:
|
// topology:
|
||||||
|
//
|
||||||
// Carol --100k--> Dave
|
// Carol --100k--> Dave
|
||||||
|
//
|
||||||
// We'll query the daemon for routes from Carol to Dave and then send payments
|
// We'll query the daemon for routes from Carol to Dave and then send payments
|
||||||
// by feeding the route back into the various SendToRoute RPC methods. Here we
|
// by feeding the route back into the various SendToRoute RPC methods. Here we
|
||||||
// test all three SendToRoute endpoints, forcing each to perform both a regular
|
// test all three SendToRoute endpoints, forcing each to perform both a regular
|
||||||
@@ -428,7 +430,9 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
|
|
||||||
// testMultiHopSendToRoute tests that payments are properly processed
|
// testMultiHopSendToRoute tests that payments are properly processed
|
||||||
// through a provided route. We'll create the following network topology:
|
// through a provided route. We'll create the following network topology:
|
||||||
|
//
|
||||||
// Alice --100k--> Bob --100k--> Carol
|
// Alice --100k--> Bob --100k--> Carol
|
||||||
|
//
|
||||||
// We'll query the daemon for routes from Alice to Carol and then
|
// We'll query the daemon for routes from Alice to Carol and then
|
||||||
// send payments through the routes.
|
// send payments through the routes.
|
||||||
func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
|
func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
@@ -446,7 +450,9 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// runMultiHopSendToRoute tests that payments are properly processed
|
// runMultiHopSendToRoute tests that payments are properly processed
|
||||||
// through a provided route. We'll create the following network topology:
|
// through a provided route. We'll create the following network topology:
|
||||||
|
//
|
||||||
// Alice --100k--> Bob --100k--> Carol
|
// Alice --100k--> Bob --100k--> Carol
|
||||||
|
//
|
||||||
// We'll query the daemon for routes from Alice to Carol and then
|
// We'll query the daemon for routes from Alice to Carol and then
|
||||||
// send payments through the routes.
|
// send payments through the routes.
|
||||||
func runMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest,
|
func runMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
@@ -1429,7 +1435,9 @@ func computeFee(baseFee, feeRate, amt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
|||||||
|
|
||||||
// testQueryRoutes checks the response of queryroutes.
|
// testQueryRoutes checks the response of queryroutes.
|
||||||
// We'll create the following network topology:
|
// We'll create the following network topology:
|
||||||
|
//
|
||||||
// Alice --> Bob --> Carol --> Dave
|
// Alice --> Bob --> Carol --> Dave
|
||||||
|
//
|
||||||
// and query the daemon for routes from Alice to Dave.
|
// and query the daemon for routes from Alice to Dave.
|
||||||
func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
|
func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|||||||
+21
-19
@@ -229,7 +229,7 @@ func (u updateType) String() string {
|
|||||||
// the original added HTLC.
|
// the original added HTLC.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): LogEntry interface??
|
// TODO(roasbeef): LogEntry interface??
|
||||||
// * need to separate attrs for cancel/add/settle/feeupdate
|
// - need to separate attrs for cancel/add/settle/feeupdate
|
||||||
type PaymentDescriptor struct {
|
type PaymentDescriptor struct {
|
||||||
// RHash is the payment hash for this HTLC. The HTLC can be settled iff
|
// RHash is the payment hash for this HTLC. The HTLC can be settled iff
|
||||||
// the preimage to this hash is presented.
|
// the preimage to this hash is presented.
|
||||||
@@ -1038,8 +1038,8 @@ func (s *commitmentChain) hasUnackedCommitment() bool {
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): create lightning package, move commitment and update to
|
// TODO(roasbeef): create lightning package, move commitment and update to
|
||||||
// package?
|
// package?
|
||||||
// * also move state machine, separate from lnwallet package
|
// - also move state machine, separate from lnwallet package
|
||||||
// * possible embed updateLog within commitmentChain.
|
// - possible embed updateLog within commitmentChain.
|
||||||
type updateLog struct {
|
type updateLog struct {
|
||||||
// logIndex is a monotonically increasing integer that tracks the total
|
// logIndex is a monotonically increasing integer that tracks the total
|
||||||
// number of update entries ever applied to the log. When sending new
|
// number of update entries ever applied to the log. When sending new
|
||||||
@@ -1235,18 +1235,18 @@ func compactLogs(ourLog, theirLog *updateLog,
|
|||||||
// preimages in order to populate their revocation window for the remote party.
|
// preimages in order to populate their revocation window for the remote party.
|
||||||
//
|
//
|
||||||
// The state machine has for main methods:
|
// The state machine has for main methods:
|
||||||
// * .SignNextCommitment()
|
// - .SignNextCommitment()
|
||||||
// * Called one one wishes to sign the next commitment, either initiating a
|
// - Called one one wishes to sign the next commitment, either initiating a
|
||||||
// new state update, or responding to a received commitment.
|
// new state update, or responding to a received commitment.
|
||||||
// * .ReceiveNewCommitment()
|
// - .ReceiveNewCommitment()
|
||||||
// * Called upon receipt of a new commitment from the remote party. If the
|
// - Called upon receipt of a new commitment from the remote party. If the
|
||||||
// new commitment is valid, then a revocation should immediately be
|
// new commitment is valid, then a revocation should immediately be
|
||||||
// generated and sent.
|
// generated and sent.
|
||||||
// * .RevokeCurrentCommitment()
|
// - .RevokeCurrentCommitment()
|
||||||
// * Revokes the current commitment. Should be called directly after
|
// - Revokes the current commitment. Should be called directly after
|
||||||
// receiving a new commitment.
|
// receiving a new commitment.
|
||||||
// * .ReceiveRevocation()
|
// - .ReceiveRevocation()
|
||||||
// * Processes a revocation from the remote party. If successful creates a
|
// - Processes a revocation from the remote party. If successful creates a
|
||||||
// new defacto broadcastable state.
|
// new defacto broadcastable state.
|
||||||
//
|
//
|
||||||
// See the individual comments within the above methods for further details.
|
// See the individual comments within the above methods for further details.
|
||||||
@@ -3844,9 +3844,9 @@ func (lc *LightningChannel) SignNextCommitment() (lnwire.Sig, []lnwire.Sig,
|
|||||||
//
|
//
|
||||||
// One of two message sets will be returned:
|
// One of two message sets will be returned:
|
||||||
//
|
//
|
||||||
// * CommitSig+Updates: if we have a pending remote commit which they claim to
|
// - CommitSig+Updates: if we have a pending remote commit which they claim to
|
||||||
// have not received
|
// have not received
|
||||||
// * RevokeAndAck: if we sent a revocation message that they claim to have
|
// - RevokeAndAck: if we sent a revocation message that they claim to have
|
||||||
// not received
|
// not received
|
||||||
//
|
//
|
||||||
// If we detect a scenario where we need to send a CommitSig+Updates, this
|
// If we detect a scenario where we need to send a CommitSig+Updates, this
|
||||||
@@ -5377,17 +5377,18 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, err
|
|||||||
// is invalid, an error is returned.
|
// is invalid, an error is returned.
|
||||||
//
|
//
|
||||||
// The additional arguments correspond to:
|
// The additional arguments correspond to:
|
||||||
// * sourceRef: specifies the location of the Add HTLC within a forwarding
|
//
|
||||||
|
// - sourceRef: specifies the location of the Add HTLC within a forwarding
|
||||||
// package that this HTLC is settling. Every Settle fails exactly one Add,
|
// package that this HTLC is settling. Every Settle fails exactly one Add,
|
||||||
// so this should never be empty in practice.
|
// so this should never be empty in practice.
|
||||||
//
|
//
|
||||||
// * destRef: specifies the location of the Settle HTLC within another
|
// - destRef: specifies the location of the Settle HTLC within another
|
||||||
// channel's forwarding package. This value can be nil if the corresponding
|
// channel's forwarding package. This value can be nil if the corresponding
|
||||||
// Add HTLC was never locked into an outgoing commitment txn, or this
|
// Add HTLC was never locked into an outgoing commitment txn, or this
|
||||||
// HTLC does not originate as a response from the peer on the outgoing
|
// HTLC does not originate as a response from the peer on the outgoing
|
||||||
// link, e.g. on-chain resolutions.
|
// link, e.g. on-chain resolutions.
|
||||||
//
|
//
|
||||||
// * closeKey: identifies the circuit that should be deleted after this Settle
|
// - closeKey: identifies the circuit that should be deleted after this Settle
|
||||||
// HTLC is included in a commitment txn. This value should only be nil if
|
// HTLC is included in a commitment txn. This value should only be nil if
|
||||||
// the HTLC was settled locally before committing a circuit to the circuit
|
// the HTLC was settled locally before committing a circuit to the circuit
|
||||||
// map.
|
// map.
|
||||||
@@ -5487,17 +5488,18 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
|
|||||||
// _incoming_ HTLC.
|
// _incoming_ HTLC.
|
||||||
//
|
//
|
||||||
// The additional arguments correspond to:
|
// The additional arguments correspond to:
|
||||||
// * sourceRef: specifies the location of the Add HTLC within a forwarding
|
//
|
||||||
|
// - sourceRef: specifies the location of the Add HTLC within a forwarding
|
||||||
// package that this HTLC is failing. Every Fail fails exactly one Add, so
|
// package that this HTLC is failing. Every Fail fails exactly one Add, so
|
||||||
// this should never be empty in practice.
|
// this should never be empty in practice.
|
||||||
//
|
//
|
||||||
// * destRef: specifies the location of the Fail HTLC within another channel's
|
// - destRef: specifies the location of the Fail HTLC within another channel's
|
||||||
// forwarding package. This value can be nil if the corresponding Add HTLC
|
// forwarding package. This value can be nil if the corresponding Add HTLC
|
||||||
// was never locked into an outgoing commitment txn, or this HTLC does not
|
// was never locked into an outgoing commitment txn, or this HTLC does not
|
||||||
// originate as a response from the peer on the outgoing link, e.g.
|
// originate as a response from the peer on the outgoing link, e.g.
|
||||||
// on-chain resolutions.
|
// on-chain resolutions.
|
||||||
//
|
//
|
||||||
// * closeKey: identifies the circuit that should be deleted after this Fail
|
// - closeKey: identifies the circuit that should be deleted after this Fail
|
||||||
// HTLC is included in a commitment txn. This value should only be nil if
|
// HTLC is included in a commitment txn. This value should only be nil if
|
||||||
// the HTLC was failed locally before committing a circuit to the circuit
|
// the HTLC was failed locally before committing a circuit to the circuit
|
||||||
// map.
|
// map.
|
||||||
|
|||||||
@@ -316,8 +316,8 @@ func testAddSettleWorkflow(t *testing.T, tweakless bool) {
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): write higher level framework to exercise various states of
|
// TODO(roasbeef): write higher level framework to exercise various states of
|
||||||
// the state machine
|
// the state machine
|
||||||
// * DSL language perhaps?
|
// - DSL language perhaps?
|
||||||
// * constructed via input/output files
|
// - constructed via input/output files
|
||||||
func TestSimpleAddSettleWorkflow(t *testing.T) {
|
func TestSimpleAddSettleWorkflow(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -335,6 +335,7 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
|
|||||||
// The full state transition of this test is:
|
// The full state transition of this test is:
|
||||||
//
|
//
|
||||||
// Alice Bob
|
// Alice Bob
|
||||||
|
//
|
||||||
// -----add------>
|
// -----add------>
|
||||||
// -----sig------>
|
// -----sig------>
|
||||||
// <----rev-------
|
// <----rev-------
|
||||||
@@ -5804,7 +5805,9 @@ func TestMaxAcceptedHTLCs(t *testing.T) {
|
|||||||
// fail) an HTLC from Alice when exchanging asynchronous payments. We want to
|
// fail) an HTLC from Alice when exchanging asynchronous payments. We want to
|
||||||
// mimic the following case where Bob's commitment transaction is full before
|
// mimic the following case where Bob's commitment transaction is full before
|
||||||
// starting:
|
// starting:
|
||||||
|
//
|
||||||
// Alice Bob
|
// Alice Bob
|
||||||
|
//
|
||||||
// 1. <---settle/fail---
|
// 1. <---settle/fail---
|
||||||
// 2. <-------sig-------
|
// 2. <-------sig-------
|
||||||
// 3. --------sig------> (covers an add sent before step 1)
|
// 3. --------sig------> (covers an add sent before step 1)
|
||||||
@@ -8799,6 +8802,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
// The full state transition of this test is:
|
// The full state transition of this test is:
|
||||||
//
|
//
|
||||||
// Alice Bob
|
// Alice Bob
|
||||||
|
//
|
||||||
// -----add----->
|
// -----add----->
|
||||||
// -----sig----->
|
// -----sig----->
|
||||||
// <----rev------
|
// <----rev------
|
||||||
@@ -8915,6 +8919,7 @@ func TestChannelUnsignedAckedFailure(t *testing.T) {
|
|||||||
// The full state transition is:
|
// The full state transition is:
|
||||||
//
|
//
|
||||||
// Alice Bob
|
// Alice Bob
|
||||||
|
//
|
||||||
// <----add-----
|
// <----add-----
|
||||||
// <----sig-----
|
// <----sig-----
|
||||||
// -----rev---->
|
// -----rev---->
|
||||||
@@ -9000,6 +9005,7 @@ func TestChannelLocalUnsignedUpdatesFailure(t *testing.T) {
|
|||||||
// The full state transition of this test is:
|
// The full state transition of this test is:
|
||||||
//
|
//
|
||||||
// Alice Bob
|
// Alice Bob
|
||||||
|
//
|
||||||
// <----add-------
|
// <----add-------
|
||||||
// <----sig-------
|
// <----sig-------
|
||||||
// -----rev------>
|
// -----rev------>
|
||||||
@@ -9015,7 +9021,6 @@ func TestChannelLocalUnsignedUpdatesFailure(t *testing.T) {
|
|||||||
// *restarts*
|
// *restarts*
|
||||||
// -----rev------>
|
// -----rev------>
|
||||||
// <----sig-------
|
// <----sig-------
|
||||||
//
|
|
||||||
func TestChannelSignedAckRegression(t *testing.T) {
|
func TestChannelSignedAckRegression(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ var (
|
|||||||
//
|
//
|
||||||
// In order to spend the HTLC output, the witness for the passed transaction
|
// In order to spend the HTLC output, the witness for the passed transaction
|
||||||
// should be:
|
// should be:
|
||||||
// * <0> <sender sig> <recvr sig> <preimage>
|
// - <0> <sender sig> <recvr sig> <preimage>
|
||||||
func CreateHtlcSuccessTx(chanType channeldb.ChannelType, initiator bool,
|
func CreateHtlcSuccessTx(chanType channeldb.ChannelType, initiator bool,
|
||||||
htlcOutput wire.OutPoint, htlcAmt btcutil.Amount, csvDelay,
|
htlcOutput wire.OutPoint, htlcAmt btcutil.Amount, csvDelay,
|
||||||
leaseExpiry uint32, revocationKey, delayKey *btcec.PublicKey) (
|
leaseExpiry uint32, revocationKey, delayKey *btcec.PublicKey) (
|
||||||
|
|||||||
@@ -711,10 +711,10 @@ func testSpendValidation(t *testing.T, tweakless bool) {
|
|||||||
// the commitment transaction.
|
// the commitment transaction.
|
||||||
//
|
//
|
||||||
// The following spending cases are covered by this test:
|
// The following spending cases are covered by this test:
|
||||||
// * Alice's spend from the delayed output on her commitment transaction.
|
// - Alice's spend from the delayed output on her commitment transaction.
|
||||||
// * Bob's spend from Alice's delayed output when she broadcasts a revoked
|
// - Bob's spend from Alice's delayed output when she broadcasts a revoked
|
||||||
// commitment transaction.
|
// commitment transaction.
|
||||||
// * Bob's spend from his unencumbered output within Alice's commitment
|
// - Bob's spend from his unencumbered output within Alice's commitment
|
||||||
// transaction.
|
// transaction.
|
||||||
func TestCommitmentSpendValidation(t *testing.T) {
|
func TestCommitmentSpendValidation(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|||||||
@@ -160,7 +160,6 @@ var _ Message = (*OpenChannel)(nil)
|
|||||||
// Encode serializes the target OpenChannel into the passed io.Writer
|
// Encode serializes the target OpenChannel into the passed io.Writer
|
||||||
// implementation. Serialization will observe the rules defined by the passed
|
// implementation. Serialization will observe the rules defined by the passed
|
||||||
// protocol version.
|
// protocol version.
|
||||||
//
|
|
||||||
func (o *OpenChannel) Encode(w *bytes.Buffer, pver uint32) error {
|
func (o *OpenChannel) Encode(w *bytes.Buffer, pver uint32) error {
|
||||||
recordProducers := []tlv.RecordProducer{&o.UpfrontShutdownScript}
|
recordProducers := []tlv.RecordProducer{&o.UpfrontShutdownScript}
|
||||||
if o.ChannelType != nil {
|
if o.ChannelType != nil {
|
||||||
|
|||||||
@@ -252,6 +252,7 @@ func (svc *Service) CreateUnlock(password *[]byte) error {
|
|||||||
// NewMacaroon wraps around the function Oven.NewMacaroon with the defaults,
|
// NewMacaroon wraps around the function Oven.NewMacaroon with the defaults,
|
||||||
// - version is always bakery.LatestVersion;
|
// - version is always bakery.LatestVersion;
|
||||||
// - caveats is always nil.
|
// - caveats is always nil.
|
||||||
|
//
|
||||||
// In addition, it takes a rootKeyID parameter, and puts it into the context.
|
// In addition, it takes a rootKeyID parameter, and puts it into the context.
|
||||||
// The context is passed through Oven.NewMacaroon(), in which calls the function
|
// The context is passed through Oven.NewMacaroon(), in which calls the function
|
||||||
// RootKey(), that reads the context for rootKeyID.
|
// RootKey(), that reads the context for rootKeyID.
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ var lndStarted int32
|
|||||||
//
|
//
|
||||||
// extraArgs can be used to pass command line arguments to lnd that will
|
// extraArgs can be used to pass command line arguments to lnd that will
|
||||||
// override what is found in the config file. Example:
|
// override what is found in the config file. Example:
|
||||||
|
//
|
||||||
// extraArgs = "--bitcoin.testnet --lnddir=\"/tmp/folder name/\" --profile=5050"
|
// extraArgs = "--bitcoin.testnet --lnddir=\"/tmp/folder name/\" --profile=5050"
|
||||||
//
|
//
|
||||||
// The rpcReady is called lnd is ready to accept RPC calls.
|
// The rpcReady is called lnd is ready to accept RPC calls.
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ type ChanStatusManager struct {
|
|||||||
// NewChanStatusManager initializes a new ChanStatusManager using the given
|
// NewChanStatusManager initializes a new ChanStatusManager using the given
|
||||||
// configuration. An error is returned if the timeouts and sample interval fail
|
// configuration. An error is returned if the timeouts and sample interval fail
|
||||||
// to meet do not satisfy the equation:
|
// to meet do not satisfy the equation:
|
||||||
|
//
|
||||||
// ChanEnableTimeout + ChanStatusSampleInterval > ChanDisableTimeout.
|
// ChanEnableTimeout + ChanStatusSampleInterval > ChanDisableTimeout.
|
||||||
func NewChanStatusManager(cfg *ChanStatusConfig) (*ChanStatusManager, error) {
|
func NewChanStatusManager(cfg *ChanStatusConfig) (*ChanStatusManager, error) {
|
||||||
// Assert that the config timeouts are properly formed. We require the
|
// Assert that the config timeouts are properly formed. We require the
|
||||||
@@ -268,6 +269,7 @@ func (m *ChanStatusManager) RequestEnable(outpoint wire.OutPoint,
|
|||||||
// ManuallyDisabled | true | ManuallyDisabled
|
// ManuallyDisabled | true | ManuallyDisabled
|
||||||
//
|
//
|
||||||
// (*) If a channel was manually disabled, subsequent automatic / background
|
// (*) If a channel was manually disabled, subsequent automatic / background
|
||||||
|
//
|
||||||
// requests to disable the channel do not change the fact that the channel
|
// requests to disable the channel do not change the fact that the channel
|
||||||
// was manually disabled.
|
// was manually disabled.
|
||||||
func (m *ChanStatusManager) RequestDisable(outpoint wire.OutPoint,
|
func (m *ChanStatusManager) RequestDisable(outpoint wire.OutPoint,
|
||||||
@@ -367,12 +369,12 @@ func (m *ChanStatusManager) statusManager() {
|
|||||||
|
|
||||||
// processEnableRequest attempts to enable the given outpoint.
|
// processEnableRequest attempts to enable the given outpoint.
|
||||||
//
|
//
|
||||||
// * If the channel is not active at the time of the request,
|
// - If the channel is not active at the time of the request,
|
||||||
// ErrEnableInactiveChan will be returned.
|
// ErrEnableInactiveChan will be returned.
|
||||||
// * If the channel was in the ManuallyDisabled state and manual = false,
|
// - If the channel was in the ManuallyDisabled state and manual = false,
|
||||||
// the request will be ignored and ErrEnableManuallyDisabledChan will be
|
// the request will be ignored and ErrEnableManuallyDisabledChan will be
|
||||||
// returned.
|
// returned.
|
||||||
// * Otherwise, the status of the channel in chanStates will be
|
// - Otherwise, the status of the channel in chanStates will be
|
||||||
// ChanStatusEnabled and the method will return nil.
|
// ChanStatusEnabled and the method will return nil.
|
||||||
//
|
//
|
||||||
// An update will be broadcast only if the channel is currently disabled,
|
// An update will be broadcast only if the channel is currently disabled,
|
||||||
|
|||||||
+1
-1
@@ -5936,7 +5936,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
|||||||
// within the HTLC.
|
// within the HTLC.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): should return a slice of routes in reality
|
// TODO(roasbeef): should return a slice of routes in reality
|
||||||
// * create separate PR to send based on well formatted route
|
// - create separate PR to send based on well formatted route
|
||||||
func (r *rpcServer) QueryRoutes(ctx context.Context,
|
func (r *rpcServer) QueryRoutes(ctx context.Context,
|
||||||
in *lnrpc.QueryRoutesRequest) (*lnrpc.QueryRoutesResponse, error) {
|
in *lnrpc.QueryRoutesRequest) (*lnrpc.QueryRoutesResponse, error) {
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ func newIndex(v uint64) index {
|
|||||||
// | | | | | | | | |
|
// | | | | | | | | |
|
||||||
// +---|---|---|---|---|---|---|---|---> index
|
// +---|---|---|---|---|---|---|---|---> index
|
||||||
// 0 1 2 3 4 5 6 7
|
// 0 1 2 3 4 5 6 7
|
||||||
//
|
|
||||||
func (from index) deriveBitTransformations(to index) ([]uint8, error) {
|
func (from index) deriveBitTransformations(to index) ([]uint8, error) {
|
||||||
var positions []uint8
|
var positions []uint8
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
// bitsToIndex is a helper function which takes 'n' last bits as input and
|
// bitsToIndex is a helper function which takes 'n' last bits as input and
|
||||||
// create shachain index.
|
// create shachain index.
|
||||||
// Example:
|
// Example:
|
||||||
|
//
|
||||||
// Input: 0,1,1,0,0
|
// Input: 0,1,1,0,0
|
||||||
// Output: 0b000000000000000000000000000000000000000[01100] == 12
|
// Output: 0b000000000000000000000000000000000000000[01100] == 12
|
||||||
func bitsToIndex(bs ...uint64) (index, error) {
|
func bitsToIndex(bs ...uint64) (index, error) {
|
||||||
|
|||||||
+2
-2
@@ -1517,10 +1517,10 @@ func (s *UtxoSweeper) UpdateParams(input wire.OutPoint,
|
|||||||
// fee preference to ensure it will properly create a replacement transaction.
|
// fee preference to ensure it will properly create a replacement transaction.
|
||||||
//
|
//
|
||||||
// TODO(wilmer):
|
// TODO(wilmer):
|
||||||
// * Validate fee preference to ensure we'll create a valid replacement
|
// - Validate fee preference to ensure we'll create a valid replacement
|
||||||
// transaction to allow the new fee rate to propagate throughout the
|
// transaction to allow the new fee rate to propagate throughout the
|
||||||
// network.
|
// network.
|
||||||
// * Ensure we don't combine this input with any other unconfirmed inputs that
|
// - Ensure we don't combine this input with any other unconfirmed inputs that
|
||||||
// did not exist in the original sweep transaction, resulting in an invalid
|
// did not exist in the original sweep transaction, resulting in an invalid
|
||||||
// replacement transaction.
|
// replacement transaction.
|
||||||
func (s *UtxoSweeper) handleUpdateReq(req *updateReq, bestHeight int32) (
|
func (s *UtxoSweeper) handleUpdateReq(req *updateReq, bestHeight int32) (
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ func MustNewStream(records ...Record) *Stream {
|
|||||||
//
|
//
|
||||||
// The stream is constructed by concatenating the individual, serialized Records
|
// The stream is constructed by concatenating the individual, serialized Records
|
||||||
// where each record has the following format:
|
// where each record has the following format:
|
||||||
|
//
|
||||||
// [varint: type]
|
// [varint: type]
|
||||||
// [varint: length]
|
// [varint: length]
|
||||||
// [length: value]
|
// [length: value]
|
||||||
@@ -117,6 +118,7 @@ func (s *Stream) Encode(w io.Writer) error {
|
|||||||
// record.
|
// record.
|
||||||
//
|
//
|
||||||
// Each record has the following format:
|
// Each record has the following format:
|
||||||
|
//
|
||||||
// [varint: type]
|
// [varint: type]
|
||||||
// [varint: length]
|
// [varint: length]
|
||||||
// [length: value]
|
// [length: value]
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ func (c *Controller) prepareAddOnion(cfg AddOnionConfig) (string, error) {
|
|||||||
// - the onion service is removed via `DEL_ONION`.
|
// - the onion service is removed via `DEL_ONION`.
|
||||||
// - the Tor daemon terminates.
|
// - the Tor daemon terminates.
|
||||||
// - the controller connection that originated the `ADD_ONION` is closed.
|
// - the controller connection that originated the `ADD_ONION` is closed.
|
||||||
|
//
|
||||||
// Each connection can only see its own ephemeral services. If a service needs
|
// Each connection can only see its own ephemeral services. If a service needs
|
||||||
// to survive beyond current controller connection, use the "Detach" flag when
|
// to survive beyond current controller connection, use the "Detach" flag when
|
||||||
// creating new service via `ADD_ONION`.
|
// creating new service via `ADD_ONION`.
|
||||||
|
|||||||
+5
-3
@@ -99,9 +99,9 @@ var (
|
|||||||
// proceeding to send commands. Otherwise, the connection will be closed.
|
// proceeding to send commands. Otherwise, the connection will be closed.
|
||||||
//
|
//
|
||||||
// TODO:
|
// TODO:
|
||||||
// * if adding support for more commands, extend this with a command queue?
|
// - if adding support for more commands, extend this with a command queue?
|
||||||
// * place under sub-package?
|
// - place under sub-package?
|
||||||
// * support async replies from the server
|
// - support async replies from the server
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
// started is used atomically in order to prevent multiple calls to
|
// started is used atomically in order to prevent multiple calls to
|
||||||
// Start.
|
// Start.
|
||||||
@@ -283,6 +283,7 @@ func (c *Controller) sendCommand(command string) (int, string, error) {
|
|||||||
// Unless specified otherwise, multiple lines in a single reply from Tor daemon
|
// Unless specified otherwise, multiple lines in a single reply from Tor daemon
|
||||||
// to the controller are guaranteed to share the same status code. Read more on
|
// to the controller are guaranteed to share the same status code. Read more on
|
||||||
// this topic:
|
// this topic:
|
||||||
|
//
|
||||||
// https://gitweb.torproject.org/torspec.git/tree/control-spec.txt#n158
|
// https://gitweb.torproject.org/torspec.git/tree/control-spec.txt#n158
|
||||||
//
|
//
|
||||||
// NOTE: this code is influenced by https://github.com/Yawning/bulb.
|
// NOTE: this code is influenced by https://github.com/Yawning/bulb.
|
||||||
@@ -618,6 +619,7 @@ func computeHMAC256(key, message []byte) []byte {
|
|||||||
// supportsV3 is a helper function that parses the current version of the Tor
|
// supportsV3 is a helper function that parses the current version of the Tor
|
||||||
// server and determines whether it supports creating v3 onion services through
|
// server and determines whether it supports creating v3 onion services through
|
||||||
// Tor's control port. The version string should be of the format:
|
// Tor's control port. The version string should be of the format:
|
||||||
|
//
|
||||||
// major.minor.revision.build
|
// major.minor.revision.build
|
||||||
func supportsV3(version string) error {
|
func supportsV3(version string) error {
|
||||||
// We'll split the minimum Tor version that's supported and the given
|
// We'll split the minimum Tor version that's supported and the given
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ func (k BreachKey) String() string {
|
|||||||
|
|
||||||
// NewBreachHintAndKeyFromHash derives a BreachHint and BreachKey from a given
|
// NewBreachHintAndKeyFromHash derives a BreachHint and BreachKey from a given
|
||||||
// txid in a single pass. The hint and key are computed as:
|
// txid in a single pass. The hint and key are computed as:
|
||||||
|
//
|
||||||
// hint = SHA256(txid)
|
// hint = SHA256(txid)
|
||||||
// key = SHA256(txid || txid)
|
// key = SHA256(txid || txid)
|
||||||
func NewBreachHintAndKeyFromHash(hash *chainhash.Hash) (BreachHint, BreachKey) {
|
func NewBreachHintAndKeyFromHash(hash *chainhash.Hash) (BreachHint, BreachKey) {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Size returns the size of the encoded-and-encrypted blob in bytes.
|
// Size returns the size of the encoded-and-encrypted blob in bytes.
|
||||||
|
//
|
||||||
// nonce: 24 bytes
|
// nonce: 24 bytes
|
||||||
// enciphered plaintext: n bytes
|
// enciphered plaintext: n bytes
|
||||||
// MAC: 16 bytes
|
// MAC: 16 bytes
|
||||||
@@ -173,6 +174,7 @@ func (b *JusticeKit) CommitToLocalWitnessScript() ([]byte, error) {
|
|||||||
|
|
||||||
// CommitToLocalRevokeWitnessStack constructs a witness stack spending the
|
// CommitToLocalRevokeWitnessStack constructs a witness stack spending the
|
||||||
// revocation clause of the commitment to-local output.
|
// revocation clause of the commitment to-local output.
|
||||||
|
//
|
||||||
// <revocation-sig> 1
|
// <revocation-sig> 1
|
||||||
func (b *JusticeKit) CommitToLocalRevokeWitnessStack() ([][]byte, error) {
|
func (b *JusticeKit) CommitToLocalRevokeWitnessStack() ([][]byte, error) {
|
||||||
toLocalSig, err := b.CommitToLocalSig.ToSignature()
|
toLocalSig, err := b.CommitToLocalSig.ToSignature()
|
||||||
@@ -220,6 +222,7 @@ func (b *JusticeKit) CommitToRemoteWitnessScript() ([]byte, error) {
|
|||||||
// CommitToRemoteWitnessStack returns a witness stack spending the commitment
|
// CommitToRemoteWitnessStack returns a witness stack spending the commitment
|
||||||
// to-remote output, which consists of a single signature satisfying either the
|
// to-remote output, which consists of a single signature satisfying either the
|
||||||
// legacy or anchor witness scripts.
|
// legacy or anchor witness scripts.
|
||||||
|
//
|
||||||
// <to-remote-sig>
|
// <to-remote-sig>
|
||||||
func (b *JusticeKit) CommitToRemoteWitnessStack() ([][]byte, error) {
|
func (b *JusticeKit) CommitToRemoteWitnessStack() ([][]byte, error) {
|
||||||
toRemoteSig, err := b.CommitToRemoteSig.ToSignature()
|
toRemoteSig, err := b.CommitToRemoteSig.ToSignature()
|
||||||
@@ -345,6 +348,7 @@ func (b *JusticeKit) decode(r io.Reader, blobType Type) error {
|
|||||||
// constant-size plaintext size of 274 bytes.
|
// constant-size plaintext size of 274 bytes.
|
||||||
//
|
//
|
||||||
// blob version 0 plaintext encoding:
|
// blob version 0 plaintext encoding:
|
||||||
|
//
|
||||||
// sweep address length: 1 byte
|
// sweep address length: 1 byte
|
||||||
// padded sweep address: 42 bytes
|
// padded sweep address: 42 bytes
|
||||||
// revocation pubkey: 33 bytes
|
// revocation pubkey: 33 bytes
|
||||||
@@ -416,6 +420,7 @@ func (b *JusticeKit) encodeV0(w io.Writer) error {
|
|||||||
// to-remote output.
|
// to-remote output.
|
||||||
//
|
//
|
||||||
// blob version 0 plaintext encoding:
|
// blob version 0 plaintext encoding:
|
||||||
|
//
|
||||||
// sweep address length: 1 byte
|
// sweep address length: 1 byte
|
||||||
// padded sweep address: 42 bytes
|
// padded sweep address: 42 bytes
|
||||||
// revocation pubkey: 33 bytes
|
// revocation pubkey: 33 bytes
|
||||||
|
|||||||
@@ -203,8 +203,8 @@ func (s *Server) peerHandler() {
|
|||||||
|
|
||||||
// handleClient processes a series watchtower messages sent by a client. The
|
// handleClient processes a series watchtower messages sent by a client. The
|
||||||
// client may either send:
|
// client may either send:
|
||||||
// * a single CreateSession message.
|
// - a single CreateSession message.
|
||||||
// * a series of StateUpdate messages.
|
// - a series of StateUpdate messages.
|
||||||
//
|
//
|
||||||
// This method uses the server's peer map to ensure at most one peer using the
|
// This method uses the server's peer map to ensure at most one peer using the
|
||||||
// same session id can enter the main event loop. The connection will be
|
// same session id can enter the main event loop. The connection will be
|
||||||
|
|||||||
Reference in new issue
Block a user