Skip to content
Merged
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
7 changes: 7 additions & 0 deletions chainreg/chainparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ var BitcoinSimNetParams = BitcoinNetParams{
CoinType: keychain.CoinTypeTestnet,
}

// BitcoinSigNetParams contains parameters specific to the signet test network.
var BitcoinSigNetParams = BitcoinNetParams{
Comment thread
guggero marked this conversation as resolved.
Outdated
Params: &bitcoinCfg.SigNetParams,
RPCPort: "38332",
CoinType: keychain.CoinTypeTestnet,
}

// LitecoinSimNetParams contains parameters specific to the simulation test
// network.
var LitecoinSimNetParams = LitecoinNetParams{
Expand Down
21 changes: 19 additions & 2 deletions chainreg/chainregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,13 @@ func NewChainControl(cfg *Config, blockCache *blockcache.BlockCache) (
(cfg.Litecoin.Active && cfg.Litecoin.RegTest) {
conn, err := net.Dial("tcp", bitcoindHost)
if err != nil || conn == nil {
if cfg.Bitcoin.Active && cfg.Bitcoin.RegTest {
switch {
case cfg.Bitcoin.Active && cfg.Bitcoin.RegTest:
rpcPort = 18443
} else if cfg.Litecoin.Active && cfg.Litecoin.RegTest {
case cfg.Litecoin.Active && cfg.Litecoin.RegTest:
rpcPort = 19443
case cfg.Bitcoin.Active && cfg.Bitcoin.SigNet:
rpcPort = 38332
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vwoo perhaps something is being morphed before the call is made? We enforce the default port here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change the signet port from 38332 to 38334 in chainreg/chainparams.go then the default port works.

Just following the pattern in the rest of chainparams.go where the port is always +2.

bitcoind --help | grep rpcport
mainnet: 8332
testnet: 18332
signet: 38332

chainreg/chainparams.go
mainnet: 8334
testnet: 18334
signet: 38332

Seems like the pattern break is intentional but maybe there was a mixup between chainregistry.go and chainparams.go?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vwoo see #5351.

}
bitcoindHost = fmt.Sprintf("%v:%d",
bitcoindMode.RPCHost,
Expand Down Expand Up @@ -743,6 +746,14 @@ var (
0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00,
})

// BitcoinSignetGenesis is the genesis hash of Bitcoin's signet chain.
BitcoinSignetGenesis = chainhash.Hash([chainhash.HashSize]byte{
0xf6, 0x1e, 0xee, 0x3b, 0x63, 0xa3, 0x80, 0xa4,
0x77, 0xa0, 0x63, 0xaf, 0x32, 0xb2, 0xbb, 0xc9,
0x7c, 0x9f, 0xf9, 0xf0, 0x1f, 0x2c, 0x42, 0x25,
0xe9, 0x73, 0x98, 0x81, 0x08, 0x00, 0x00, 0x00,
})

// BitcoinMainnetGenesis is the genesis hash of Bitcoin's main chain.
BitcoinMainnetGenesis = chainhash.Hash([chainhash.HashSize]byte{
0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72,
Expand Down Expand Up @@ -808,6 +819,12 @@ var (
},
},

BitcoinSignetGenesis: {
{
"ln.signet.secp.tech",
},
},

LitecoinMainnetGenesis: {
{
"ltc.nodes.lightning.directory",
Expand Down
2 changes: 1 addition & 1 deletion cmd/lncli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func extractPathArgs(ctx *cli.Context) (string, string, error) {

network := strings.ToLower(ctx.GlobalString("network"))
switch network {
case "mainnet", "testnet", "regtest", "simnet":
case "mainnet", "testnet", "regtest", "simnet", "signet":
default:
return "", "", fmt.Errorf("unknown network: %v", network)
}
Expand Down
45 changes: 45 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package lnd

import (
"encoding/hex"
"errors"
"fmt"
"io/ioutil"
Expand All @@ -17,6 +18,7 @@ import (
"strings"
"time"

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
flags "github.com/jessevdk/go-flags"
"github.com/lightninglabs/neutrino"
Expand Down Expand Up @@ -952,6 +954,10 @@ func ValidateConfig(cfg Config, usageMessage string,
numNets++
ltcParams = chainreg.LitecoinSimNetParams
}
if cfg.Litecoin.SigNet {
return nil, fmt.Errorf("%s: litecoin.signet is not "+
"supported", funcName)
}

if numNets > 1 {
str := "%s: The mainnet, testnet, and simnet params " +
Expand Down Expand Up @@ -1033,6 +1039,45 @@ func ValidateConfig(cfg Config, usageMessage string,
numNets++
cfg.ActiveNetParams = chainreg.BitcoinSimNetParams
}
if cfg.Bitcoin.SigNet {
Comment thread
wpaulino marked this conversation as resolved.
Outdated
numNets++
cfg.ActiveNetParams = chainreg.BitcoinSigNetParams

// Let the user overwrite the default signet parameters.
// The challenge defines the actual signet network to
// join and the seed nodes are needed for network
// discovery.
sigNetChallenge := chaincfg.DefaultSignetChallenge
sigNetSeeds := chaincfg.DefaultSignetDNSSeeds
if cfg.Bitcoin.SigNetChallenge != "" {
challenge, err := hex.DecodeString(
cfg.Bitcoin.SigNetChallenge,
)
if err != nil {
return nil, fmt.Errorf("%s: Invalid "+
"signet challenge, hex decode "+
"failed: %v", funcName, err)
}
sigNetChallenge = challenge
}

if len(cfg.Bitcoin.SigNetSeedNode) > 0 {
sigNetSeeds = make([]chaincfg.DNSSeed, len(
cfg.Bitcoin.SigNetSeedNode,
))
for idx, seed := range cfg.Bitcoin.SigNetSeedNode {
sigNetSeeds[idx] = chaincfg.DNSSeed{
Host: seed,
HasFiltering: false,
}
}
}

chainParams := chaincfg.CustomSignetParams(
sigNetChallenge, sigNetSeeds,
)
cfg.ActiveNetParams.Params = &chainParams
}
if numNets > 1 {
str := "%s: The mainnet, testnet, regtest, and " +
"simnet params can't be used together -- " +
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e // indirect
github.com/NebulousLabs/go-upnp v0.0.0-20180202185039-29b680b06c82
github.com/Yawning/aez v0.0.0-20180114000226-4dad034d9db2
github.com/btcsuite/btcd v0.21.0-beta.0.20210429225535-ce697fe7e82b
github.com/btcsuite/btcd v0.21.0-beta.0.20210513141527-ee5896bad5be
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/btcsuite/btcutil/psbt v1.0.3-0.20201208143702-a53e38424cce
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcug
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.21.0-beta.0.20201208033208-6bd4c64a54fa/go.mod h1:Sv4JPQ3/M+teHz9Bo5jBpkNcP0x6r7rdihlNL/7tTAs=
github.com/btcsuite/btcd v0.21.0-beta.0.20210426180113-7eba688b65e5/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
github.com/btcsuite/btcd v0.21.0-beta.0.20210429225535-ce697fe7e82b h1:+BMyRYlNCozjv6zGhnyHExB6JquAIYZRwsc5bxPEXrI=
github.com/btcsuite/btcd v0.21.0-beta.0.20210429225535-ce697fe7e82b/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
github.com/btcsuite/btcd v0.21.0-beta.0.20210513141527-ee5896bad5be h1:vDD/JWWS2v4GJUG/RZE/50wT6Saerbujijd7mFqgsKI=
github.com/btcsuite/btcd v0.21.0-beta.0.20210513141527-ee5896bad5be/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
Expand Down
11 changes: 7 additions & 4 deletions lncfg/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ type Chain struct {

Node string `long:"node" description:"The blockchain interface to use." choice:"btcd" choice:"bitcoind" choice:"neutrino" choice:"ltcd" choice:"litecoind"`

MainNet bool `long:"mainnet" description:"Use the main network"`
TestNet3 bool `long:"testnet" description:"Use the test network"`
SimNet bool `long:"simnet" description:"Use the simulation test network"`
RegTest bool `long:"regtest" description:"Use the regression test network"`
MainNet bool `long:"mainnet" description:"Use the main network"`
TestNet3 bool `long:"testnet" description:"Use the test network"`
SimNet bool `long:"simnet" description:"Use the simulation test network"`
RegTest bool `long:"regtest" description:"Use the regression test network"`
SigNet bool `long:"signet" description:"Use the signet test network"`
SigNetChallenge string `long:"signetchallenge" description:"Connect to a custom signet network defined by this challenge instead of using the global default signet test network -- Can be specified multiple times"`
SigNetSeedNode []string `long:"signetseednode" description:"Specify a seed node for the signet network instead of using the global default signet network seed nodes"`

DefaultNumChanConfs int `long:"defaultchanconfs" description:"The default number of confirmations a channel must have before it's considered open. If this is not set, we will scale the value according to the channel size."`
DefaultRemoteDelay int `long:"defaultremotedelay" description:"The default number of blocks we will require our channel counterparty to wait before accessing its funds in case of unilateral close. If this is not set, we will scale the value according to the channel size."`
Expand Down
3 changes: 3 additions & 0 deletions lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error

case cfg.Bitcoin.RegTest || cfg.Litecoin.RegTest:
network = "regtest"

case cfg.Bitcoin.SigNet:
network = "signet"
}

ltndLog.Infof("Active chain: %v (network=%v)",
Expand Down
15 changes: 15 additions & 0 deletions sample-lnd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,17 @@ bitcoin.simnet=true
; Use Bitcoin's regression test network
; bitcoin.regtest=false

; Use Bitcoin's signet test network
; bitcoin.signet=false

; Connect to a custom signet network defined by this challenge instead of using
; the global default signet test network -- Can be specified multiple times
; bitcoin.signetchallenge=

; Specify a seed node for the signet network instead of using the global default
; signet network seed nodes
; bitcoin.signetseednode=123.45.67.89

; Use the btcd back-end
bitcoin.node=btcd

Expand Down Expand Up @@ -647,6 +658,10 @@ bitcoin.node=btcd
; Use Litecoin's regression test network
; litecoin.regtest=false

; Litecoin does not support the signet test network. The options
; litecoin.signet, litecoin.signetchallenge and litecoin.signetseednode are
; only defined because the data structure is shared with bitcoind.

; Use the ltcd back-end.
litecoin.node=ltcd

Expand Down
6 changes: 6 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,12 @@ func (s *server) Start() error {
chainreg.BitcoinTestnetGenesis,
)
}
if s.cfg.Bitcoin.Active && s.cfg.Bitcoin.SigNet {
setSeedList(
s.cfg.Bitcoin.DNSSeeds,
chainreg.BitcoinSignetGenesis,
)
}
if s.cfg.Litecoin.Active && s.cfg.Litecoin.MainNet {
setSeedList(
s.cfg.Litecoin.DNSSeeds,
Expand Down
17 changes: 13 additions & 4 deletions zpay32/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,25 @@ func Decode(invoice string, net *chaincfg.Params) (*Invoice, error) {
}

// The next characters should be a valid prefix for a segwit BIP173
// address that match the active network.
if !strings.HasPrefix(hrp[2:], net.Bech32HRPSegwit) {
// address that match the active network except for signet where we add
// an additional "s" to differentiate it from the older testnet3 (Core
// devs decided to use the same hrp for signet as for testnet3 which is
// not optimal for LN). See
// https://github.com/lightningnetwork/lightning-rfc/pull/844 for more
// information.
expectedPrefix := net.Bech32HRPSegwit
if net.Name == chaincfg.SigNetParams.Name {
expectedPrefix = "tbs"
}
if !strings.HasPrefix(hrp[2:], expectedPrefix) {
return nil, fmt.Errorf(
"invoice not for current active network '%s'", net.Name)
}
decodedInvoice.Net = net

// Optionally, if there's anything left of the HRP after ln + the segwit
// prefix, we try to decode this as the payment amount.
var netPrefixLength = len(net.Bech32HRPSegwit) + 2
var netPrefixLength = len(expectedPrefix) + 2
if len(hrp) > netPrefixLength {
amount, err := decodeAmount(hrp[netPrefixLength:])
if err != nil {
Expand Down Expand Up @@ -378,7 +387,7 @@ func parseMinFinalCLTVExpiry(data []byte) (*uint64, error) {

// parseFallbackAddr converts the data (encoded in base32) into a fallback
// on-chain address.
func parseFallbackAddr(data []byte, net *chaincfg.Params) (btcutil.Address, error) {
func parseFallbackAddr(data []byte, net *chaincfg.Params) (btcutil.Address, error) { // nolint:dupl
// Checks if the data is empty or contains a version without an address.
if len(data) < 2 {
return nil, fmt.Errorf("empty fallback address field")
Expand Down
11 changes: 10 additions & 1 deletion zpay32/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/binary"
"fmt"

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/bech32"
Expand Down Expand Up @@ -51,8 +52,16 @@ func (invoice *Invoice) Encode(signer MessageSigner) (string, error) {
return "", err
}

// The human-readable part (hrp) is "ln" + net hrp + optional amount.
// The human-readable part (hrp) is "ln" + net hrp + optional amount,
// except for signet where we add an additional "s" to differentiate it
// from the older testnet3 (Core devs decided to use the same hrp for
// signet as for testnet3 which is not optimal for LN). See
// https://github.com/lightningnetwork/lightning-rfc/pull/844 for more
// information.
hrp := "ln" + invoice.Net.Bech32HRPSegwit
if invoice.Net.Name == chaincfg.SigNetParams.Name {
hrp = "lntbs"
}
if invoice.MilliSat != nil {
// Encode the amount using the fewest possible characters.
am, err := encodeAmount(*invoice.MilliSat)
Expand Down