Browse Source

multi: add signet parameters

With this commit we make lnd compatible with the public signet test
network.
master
Oliver Gugger 3 years ago
parent
commit
4460903399
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
  1. 7
      chainreg/chainparams.go
  2. 21
      chainreg/chainregistry.go
  3. 2
      cmd/lncli/main.go
  4. 45
      config.go
  5. 11
      lncfg/chain.go
  6. 3
      lnd.go
  7. 15
      sample-lnd.conf
  8. 6
      server.go

7
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{

21
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",

2
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)
}

45
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 -- " +

11
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."`

3
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)",

15
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

6
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,

Loading…
Cancel
Save