From 446090339941a1ead6f0db5ca3233e941e76439b Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 24 Dec 2020 16:46:13 +0100 Subject: [PATCH] multi: add signet parameters With this commit we make lnd compatible with the public signet test network. --- chainreg/chainparams.go | 7 ++++++ chainreg/chainregistry.go | 21 ++++++++++++++++-- cmd/lncli/main.go | 2 +- config.go | 45 +++++++++++++++++++++++++++++++++++++++ lncfg/chain.go | 11 ++++++---- lnd.go | 3 +++ sample-lnd.conf | 15 +++++++++++++ server.go | 6 ++++++ 8 files changed, 103 insertions(+), 7 deletions(-) diff --git a/chainreg/chainparams.go b/chainreg/chainparams.go index 0ed2fae6..6d15c930 100644 --- a/chainreg/chainparams.go +++ b/chainreg/chainparams.go @@ -50,6 +50,13 @@ var BitcoinSimNetParams = BitcoinNetParams{ CoinType: keychain.CoinTypeTestnet, } +// BitcoinSigNetParams contains parameters specific to the signet test network. +var BitcoinSigNetParams = BitcoinNetParams{ + Params: &bitcoinCfg.SigNetParams, + RPCPort: "38332", + CoinType: keychain.CoinTypeTestnet, +} + // LitecoinSimNetParams contains parameters specific to the simulation test // network. var LitecoinSimNetParams = LitecoinNetParams{ diff --git a/chainreg/chainregistry.go b/chainreg/chainregistry.go index 13d3db18..3366d129 100644 --- a/chainreg/chainregistry.go +++ b/chainreg/chainregistry.go @@ -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 } bitcoindHost = fmt.Sprintf("%v:%d", bitcoindMode.RPCHost, @@ -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, @@ -808,6 +819,12 @@ var ( }, }, + BitcoinSignetGenesis: { + { + "ln.signet.secp.tech", + }, + }, + LitecoinMainnetGenesis: { { "ltc.nodes.lightning.directory", diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 0abe2510..e121c2fb 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -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) } diff --git a/config.go b/config.go index 232c90be..8630f8b9 100644 --- a/config.go +++ b/config.go @@ -5,6 +5,7 @@ package lnd import ( + "encoding/hex" "errors" "fmt" "io/ioutil" @@ -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" @@ -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 " + @@ -1033,6 +1039,45 @@ func ValidateConfig(cfg Config, usageMessage string, numNets++ cfg.ActiveNetParams = chainreg.BitcoinSimNetParams } + if cfg.Bitcoin.SigNet { + 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 -- " + diff --git a/lncfg/chain.go b/lncfg/chain.go index 4feeab29..014cd19c 100644 --- a/lncfg/chain.go +++ b/lncfg/chain.go @@ -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."` diff --git a/lnd.go b/lnd.go index 81831ffd..b78244e2 100644 --- a/lnd.go +++ b/lnd.go @@ -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)", diff --git a/sample-lnd.conf b/sample-lnd.conf index 2cfe9716..f87e8631 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -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 @@ -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 diff --git a/server.go b/server.go index cfab0db3..7242a493 100644 --- a/server.go +++ b/server.go @@ -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,