multi: add testnet4 support

This commit is contained in:
Oliver Gugger 2025-03-20 11:47:18 -05:00
parent e5b9d9684a
commit 0aea482b51
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
13 changed files with 68 additions and 18 deletions

View File

@ -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
}

View File

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

View File

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

View File

@ -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)

View File

@ -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"`

View File

@ -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"
}

3
lnd.go
View File

@ -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"

View File

@ -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"`

View File

@ -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];

View File

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

View File

@ -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:

View File

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

View File

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