diff --git a/chainreg/chainparams.go b/chainreg/chainparams.go index 33006d5a2..166a1fec5 100644 --- a/chainreg/chainparams.go +++ b/chainreg/chainparams.go @@ -22,6 +22,14 @@ var BitcoinTestNetParams = BitcoinNetParams{ CoinType: keychain.CoinTypeTestnet, } +// BitcoinTestNet4Params contains parameters specific to the 4th version of the +// test network. +var BitcoinTestNet4Params = BitcoinNetParams{ + Params: &bitcoinCfg.TestNet4Params, + RPCPort: "48334", + CoinType: keychain.CoinTypeTestnet, +} + // BitcoinMainNetParams contains parameters specific to the current Bitcoin // mainnet. var BitcoinMainNetParams = BitcoinNetParams{ @@ -53,8 +61,9 @@ var BitcoinRegTestNetParams = BitcoinNetParams{ CoinType: keychain.CoinTypeTestnet, } -// IsTestnet tests if the givern params correspond to a testnet -// parameter configuration. +// IsTestnet tests if the given params correspond to a testnet parameter +// configuration. func IsTestnet(params *BitcoinNetParams) bool { - return params.Params.Net == bitcoinWire.TestNet3 + return params.Params.Net == bitcoinWire.TestNet3 || + params.Params.Net == bitcoinWire.TestNet4 } diff --git a/chainreg/chainregistry.go b/chainreg/chainregistry.go index a9a9ede70..3f9f738b2 100644 --- a/chainreg/chainregistry.go +++ b/chainreg/chainregistry.go @@ -838,6 +838,15 @@ var ( 0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00, }) + // BitcoinTestnet4Genesis is the genesis hash of Bitcoin's testnet4 + // chain. + BitcoinTestnet4Genesis = chainhash.Hash([chainhash.HashSize]byte{ + 0x43, 0xf0, 0x8b, 0xda, 0xb0, 0x50, 0xe3, 0x5b, + 0x56, 0x7c, 0x86, 0x4b, 0x91, 0xf4, 0x7f, 0x50, + 0xae, 0x72, 0x5a, 0xe2, 0xde, 0x53, 0xbc, 0xfb, + 0xba, 0xf2, 0x84, 0xda, 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, diff --git a/cmd/commands/main.go b/cmd/commands/main.go index 71a8531d9..ec593f1ad 100644 --- a/cmd/commands/main.go +++ b/cmd/commands/main.go @@ -286,7 +286,7 @@ func contextWithMetadata(ctx context.Context, func extractPathArgs(ctx *cli.Context) (string, string, error) { network := strings.ToLower(ctx.GlobalString("network")) switch network { - case "mainnet", "testnet", "regtest", "simnet", "signet": + case "mainnet", "testnet", "testnet4", "regtest", "simnet", "signet": default: return "", "", fmt.Errorf("unknown network: %v", network) } @@ -386,8 +386,9 @@ func Main() { }, cli.StringFlag{ Name: "network, n", - Usage: "The network lnd is running on, e.g. mainnet, " + - "testnet, etc.", + Usage: "The network lnd is running on; valid values " + + "are: mainnet, testnet, testnet4, regtest, " + + "signet and simnet.", Value: "mainnet", EnvVar: envVarNetwork, }, @@ -555,9 +556,12 @@ func networkParams(ctx *cli.Context) (*chaincfg.Params, error) { case "mainnet": return &chaincfg.MainNetParams, nil - case "testnet": + case "testnet", "testnet3": return &chaincfg.TestNet3Params, nil + case "testnet4": + return &chaincfg.TestNet4Params, nil + case "regtest": return &chaincfg.RegressionNetParams, nil diff --git a/config.go b/config.go index be0838be2..2390a3ee2 100644 --- a/config.go +++ b/config.go @@ -1208,6 +1208,10 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, numNets++ cfg.ActiveNetParams = chainreg.BitcoinTestNetParams } + if cfg.Bitcoin.TestNet4 { + numNets++ + cfg.ActiveNetParams = chainreg.BitcoinTestNet4Params + } if cfg.Bitcoin.RegTest { numNets++ cfg.ActiveNetParams = chainreg.BitcoinRegTestNetParams @@ -1265,8 +1269,8 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, cfg.ActiveNetParams.Params = &chainParams } if numNets > 1 { - str := "The mainnet, testnet, regtest, simnet and signet " + - "params can't be used together -- choose one " + + str := "The mainnet, testnet, testnet4, regtest, simnet and " + + "signet params can't be used together -- choose one " + "of the five" return nil, mkErr(str) @@ -1275,9 +1279,10 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, // The target network must be provided, otherwise, we won't // know how to initialize the daemon. if numNets == 0 { - str := "either --bitcoin.mainnet, or bitcoin.testnet, " + - "bitcoin.simnet, bitcoin.regtest or bitcoin.signet " + - "must be specified" + str := "either --bitcoin.mainnet, or --bitcoin.testnet, " + + "--bitcoin.testnet4, --bitcoin.simnet, " + + "--bitcoin.regtest or --bitcoin.signet must be " + + "specified" return nil, mkErr(str) } @@ -2202,7 +2207,7 @@ func extractBitcoindRPCParams(networkName, bitcoindDataDir, bitcoindConfigPath, switch networkName { case "mainnet": chainDir = "" - case "regtest", "testnet3", "signet": + case "regtest", "testnet3", "testnet4", "signet": chainDir = networkName default: return "", "", "", "", fmt.Errorf("unexpected networkname %v", networkName) diff --git a/lncfg/chain.go b/lncfg/chain.go index 36586ff3a..cbcb9d0ee 100644 --- a/lncfg/chain.go +++ b/lncfg/chain.go @@ -17,6 +17,7 @@ type Chain struct { MainNet bool `long:"mainnet" description:"Use the main network"` TestNet3 bool `long:"testnet" description:"Use the test network"` + TestNet4 bool `long:"testnet4" description:"Use the testnet4 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"` diff --git a/lncfg/config.go b/lncfg/config.go index 94ca02f46..178ef203b 100644 --- a/lncfg/config.go +++ b/lncfg/config.go @@ -108,6 +108,14 @@ func CleanAndExpandPath(path string) string { // NormalizeNetwork returns the common name of a network type used to create // file paths. This allows differently versioned networks to use the same path. func NormalizeNetwork(network string) string { + // The 4th testnet isn't the "default" yet, so we'll want to explicitly + // point that to a "testnet4" directory. + if network == "testnet4" { + return network + } + + // We want to collapse "testnet3" and "testnet" to the same "testnet" + // directory. if strings.HasPrefix(network, "testnet") { return "testnet" } diff --git a/lnd.go b/lnd.go index 2b46e83c9..e63ddc196 100644 --- a/lnd.go +++ b/lnd.go @@ -194,6 +194,9 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg, case cfg.Bitcoin.TestNet3: network = "testnet" + case cfg.Bitcoin.TestNet4: + network = "testnet4" + case cfg.Bitcoin.MainNet: network = "mainnet" diff --git a/lnrpc/lightning.pb.go b/lnrpc/lightning.pb.go index 42ce54284..c2ff05f3e 100644 --- a/lnrpc/lightning.pb.go +++ b/lnrpc/lightning.pb.go @@ -6265,8 +6265,8 @@ type GetInfoResponse struct { SyncedToChain bool `protobuf:"varint,9,opt,name=synced_to_chain,json=syncedToChain,proto3" json:"synced_to_chain,omitempty"` // Whether we consider ourselves synced with the public channel graph. SyncedToGraph bool `protobuf:"varint,18,opt,name=synced_to_graph,json=syncedToGraph,proto3" json:"synced_to_graph,omitempty"` - // Whether the current node is connected to testnet. This field is - // deprecated and the network field should be used instead + // Whether the current node is connected to testnet or testnet4. This field is + // deprecated and the network field should be used instead. // // Deprecated: Marked as deprecated in lightning.proto. Testnet bool `protobuf:"varint,10,opt,name=testnet,proto3" json:"testnet,omitempty"` diff --git a/lnrpc/lightning.proto b/lnrpc/lightning.proto index 2de09da1f..ca40e4b4c 100644 --- a/lnrpc/lightning.proto +++ b/lnrpc/lightning.proto @@ -2008,8 +2008,8 @@ message GetInfoResponse { bool synced_to_graph = 18; /* - Whether the current node is connected to testnet. This field is - deprecated and the network field should be used instead + Whether the current node is connected to testnet or testnet4. This field is + deprecated and the network field should be used instead. */ bool testnet = 10 [deprecated = true]; diff --git a/lnrpc/lightning.swagger.json b/lnrpc/lightning.swagger.json index c1a5ab4b4..69478fc94 100644 --- a/lnrpc/lightning.swagger.json +++ b/lnrpc/lightning.swagger.json @@ -5196,7 +5196,7 @@ }, "testnet": { "type": "boolean", - "title": "Whether the current node is connected to testnet. This field is\ndeprecated and the network field should be used instead" + "description": "Whether the current node is connected to testnet or testnet4. This field is\ndeprecated and the network field should be used instead." }, "chains": { "type": "array", diff --git a/lntest/node/config.go b/lntest/node/config.go index 6cba60941..d71723aac 100644 --- a/lntest/node/config.go +++ b/lntest/node/config.go @@ -222,6 +222,8 @@ func (cfg *BaseNodeConfig) GenArgs() []string { switch cfg.NetParams { case &chaincfg.TestNet3Params: args = append(args, "--bitcoin.testnet") + case &chaincfg.TestNet4Params: + args = append(args, "--bitcoin.testnet4") case &chaincfg.SimNetParams: args = append(args, "--bitcoin.simnet") case &chaincfg.RegressionNetParams: diff --git a/sample-lnd.conf b/sample-lnd.conf index 4b9c68afa..53be66404 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -621,6 +621,9 @@ ; Use Bitcoin's test network. ; bitcoin.testnet=false ; +; Use Bitcoin's 4th version test network. +; bitcoin.testnet4=false +; ; Use Bitcoin's simulation test network ; bitcoin.simnet=false diff --git a/server.go b/server.go index ad521cd67..19d836a4e 100644 --- a/server.go +++ b/server.go @@ -2594,6 +2594,12 @@ func (s *server) Start() error { chainreg.BitcoinTestnetGenesis, ) } + if s.cfg.Bitcoin.TestNet4 { + setSeedList( + s.cfg.Bitcoin.DNSSeeds, + chainreg.BitcoinTestnet4Genesis, + ) + } if s.cfg.Bitcoin.SigNet { setSeedList( s.cfg.Bitcoin.DNSSeeds,