Skip to content

Commit 67d2eac

Browse files
authored
Merge pull request #9620 from guggero/testnet4
chain: add testnet4 support
2 parents f7b3177 + d757bb5 commit 67d2eac

File tree

16 files changed

+83
-30
lines changed

16 files changed

+83
-30
lines changed

chainreg/chainparams.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ var BitcoinTestNetParams = BitcoinNetParams{
2222
CoinType: keychain.CoinTypeTestnet,
2323
}
2424

25+
// BitcoinTestNet4Params contains parameters specific to the 4th version of the
26+
// test network.
27+
var BitcoinTestNet4Params = BitcoinNetParams{
28+
Params: &bitcoinCfg.TestNet4Params,
29+
RPCPort: "48334",
30+
CoinType: keychain.CoinTypeTestnet,
31+
}
32+
2533
// BitcoinMainNetParams contains parameters specific to the current Bitcoin
2634
// mainnet.
2735
var BitcoinMainNetParams = BitcoinNetParams{
@@ -53,8 +61,9 @@ var BitcoinRegTestNetParams = BitcoinNetParams{
5361
CoinType: keychain.CoinTypeTestnet,
5462
}
5563

56-
// IsTestnet tests if the givern params correspond to a testnet
57-
// parameter configuration.
64+
// IsTestnet tests if the given params correspond to a testnet parameter
65+
// configuration.
5866
func IsTestnet(params *BitcoinNetParams) bool {
59-
return params.Params.Net == bitcoinWire.TestNet3
67+
return params.Params.Net == bitcoinWire.TestNet3 ||
68+
params.Params.Net == bitcoinWire.TestNet4
6069
}

chainreg/chainregistry.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,15 @@ var (
838838
0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00,
839839
})
840840

841+
// BitcoinTestnet4Genesis is the genesis hash of Bitcoin's testnet4
842+
// chain.
843+
BitcoinTestnet4Genesis = chainhash.Hash([chainhash.HashSize]byte{
844+
0x43, 0xf0, 0x8b, 0xda, 0xb0, 0x50, 0xe3, 0x5b,
845+
0x56, 0x7c, 0x86, 0x4b, 0x91, 0xf4, 0x7f, 0x50,
846+
0xae, 0x72, 0x5a, 0xe2, 0xde, 0x53, 0xbc, 0xfb,
847+
0xba, 0xf2, 0x84, 0xda, 0x00, 0x00, 0x00, 0x00,
848+
})
849+
841850
// BitcoinSignetGenesis is the genesis hash of Bitcoin's signet chain.
842851
BitcoinSignetGenesis = chainhash.Hash([chainhash.HashSize]byte{
843852
0xf6, 0x1e, 0xee, 0x3b, 0x63, 0xa3, 0x80, 0xa4,

cmd/commands/main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func contextWithMetadata(ctx context.Context,
286286
func extractPathArgs(ctx *cli.Context) (string, string, error) {
287287
network := strings.ToLower(ctx.GlobalString("network"))
288288
switch network {
289-
case "mainnet", "testnet", "regtest", "simnet", "signet":
289+
case "mainnet", "testnet", "testnet4", "regtest", "simnet", "signet":
290290
default:
291291
return "", "", fmt.Errorf("unknown network: %v", network)
292292
}
@@ -386,8 +386,9 @@ func Main() {
386386
},
387387
cli.StringFlag{
388388
Name: "network, n",
389-
Usage: "The network lnd is running on, e.g. mainnet, " +
390-
"testnet, etc.",
389+
Usage: "The network lnd is running on; valid values " +
390+
"are: mainnet, testnet, testnet4, regtest, " +
391+
"signet and simnet.",
391392
Value: "mainnet",
392393
EnvVar: envVarNetwork,
393394
},
@@ -555,9 +556,12 @@ func networkParams(ctx *cli.Context) (*chaincfg.Params, error) {
555556
case "mainnet":
556557
return &chaincfg.MainNetParams, nil
557558

558-
case "testnet":
559+
case "testnet", "testnet3":
559560
return &chaincfg.TestNet3Params, nil
560561

562+
case "testnet4":
563+
return &chaincfg.TestNet4Params, nil
564+
561565
case "regtest":
562566
return &chaincfg.RegressionNetParams, nil
563567

config.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,10 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
12081208
numNets++
12091209
cfg.ActiveNetParams = chainreg.BitcoinTestNetParams
12101210
}
1211+
if cfg.Bitcoin.TestNet4 {
1212+
numNets++
1213+
cfg.ActiveNetParams = chainreg.BitcoinTestNet4Params
1214+
}
12111215
if cfg.Bitcoin.RegTest {
12121216
numNets++
12131217
cfg.ActiveNetParams = chainreg.BitcoinRegTestNetParams
@@ -1265,8 +1269,8 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
12651269
cfg.ActiveNetParams.Params = &chainParams
12661270
}
12671271
if numNets > 1 {
1268-
str := "The mainnet, testnet, regtest, simnet and signet " +
1269-
"params can't be used together -- choose one " +
1272+
str := "The mainnet, testnet, testnet4, regtest, simnet and " +
1273+
"signet params can't be used together -- choose one " +
12701274
"of the five"
12711275

12721276
return nil, mkErr(str)
@@ -1275,9 +1279,10 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
12751279
// The target network must be provided, otherwise, we won't
12761280
// know how to initialize the daemon.
12771281
if numNets == 0 {
1278-
str := "either --bitcoin.mainnet, or bitcoin.testnet, " +
1279-
"bitcoin.simnet, bitcoin.regtest or bitcoin.signet " +
1280-
"must be specified"
1282+
str := "either --bitcoin.mainnet, or --bitcoin.testnet, " +
1283+
"--bitcoin.testnet4, --bitcoin.simnet, " +
1284+
"--bitcoin.regtest or --bitcoin.signet must be " +
1285+
"specified"
12811286

12821287
return nil, mkErr(str)
12831288
}
@@ -2202,7 +2207,7 @@ func extractBitcoindRPCParams(networkName, bitcoindDataDir, bitcoindConfigPath,
22022207
switch networkName {
22032208
case "mainnet":
22042209
chainDir = ""
2205-
case "regtest", "testnet3", "signet":
2210+
case "regtest", "testnet3", "testnet4", "signet":
22062211
chainDir = networkName
22072212
default:
22082213
return "", "", "", "", fmt.Errorf("unexpected networkname %v", networkName)

docs/release-notes/release-notes-0.19.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ close transaction.
234234
* [The server](https://github.com/lightningnetwork/lnd/pull/9458) now allocates
235235
restricted slots for certain peers. This is configured by --num-restricted-slots.
236236

237+
* [The bitcoin `testnet4` test network is now also
238+
supported](https://github.com/lightningnetwork/lnd/pull/9620).
239+
237240
## RPC Updates
238241

239242
* Some RPCs that previously just returned an empty response message now at least

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ require (
44
github.com/NebulousLabs/go-upnp v0.0.0-20180202185039-29b680b06c82
55
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344
66
github.com/andybalholm/brotli v1.0.4
7-
github.com/btcsuite/btcd v0.24.3-0.20241210095828-e646d437e95b
7+
github.com/btcsuite/btcd v0.24.3-0.20250318170759-4f4ea81776d6
88
github.com/btcsuite/btcd/btcec/v2 v2.3.4
99
github.com/btcsuite/btcd/btcutil v1.1.5
1010
github.com/btcsuite/btcd/btcutil/psbt v1.1.8
1111
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
1212
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c
1313
github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318
14-
github.com/btcsuite/btcwallet v0.16.11
14+
github.com/btcsuite/btcwallet v0.16.12
1515
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5
1616
github.com/btcsuite/btcwallet/wallet/txrules v1.2.2
1717
github.com/btcsuite/btcwallet/walletdb v1.4.4
@@ -31,7 +31,7 @@ require (
3131
github.com/jessevdk/go-flags v1.4.0
3232
github.com/jrick/logrotate v1.1.2
3333
github.com/kkdai/bstream v1.0.0
34-
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd
34+
github.com/lightninglabs/neutrino v0.16.1
3535
github.com/lightninglabs/neutrino/cache v1.1.2
3636
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb
3737
github.com/lightningnetwork/lnd/cert v1.2.2
@@ -64,7 +64,7 @@ require (
6464
google.golang.org/protobuf v1.33.0
6565
gopkg.in/macaroon-bakery.v2 v2.0.1
6666
gopkg.in/macaroon.v2 v2.0.0
67-
pgregory.net/rapid v1.1.0
67+
pgregory.net/rapid v1.2.0
6868
)
6969

7070
require (

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
7373
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
7474
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
7575
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
76-
github.com/btcsuite/btcd v0.24.3-0.20241210095828-e646d437e95b h1:VQoobSrWdxICuqFU3tKVu/Lzk7BTk9SsCgRr5dUvC70=
77-
github.com/btcsuite/btcd v0.24.3-0.20241210095828-e646d437e95b/go.mod h1:zHK7t7sw8XbsCkD64WePHE3r3k9/XoGAcf6mXV14c64=
76+
github.com/btcsuite/btcd v0.24.3-0.20250318170759-4f4ea81776d6 h1:8n9k3I7e8DkpdQ5YAP4j8ly/LSsbe6qX9vmVbrUGvVw=
77+
github.com/btcsuite/btcd v0.24.3-0.20250318170759-4f4ea81776d6/go.mod h1:OmM4kFtB0klaG/ZqT86rQiyw/1iyXlJgc3UHClPhhbs=
7878
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
7979
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
8080
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
@@ -95,8 +95,8 @@ github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c/go.mod h1:w7xnGOhw
9595
github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318 h1:oCjIcinPt7XQ644MP/22JcjYEC84qRc3bRBH0d7Hhd4=
9696
github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318/go.mod h1:XItGUfVOxotJL8kkuk2Hj3EVow5KCugXl3wWfQ6K0AE=
9797
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
98-
github.com/btcsuite/btcwallet v0.16.11 h1:c8RgW/HO79if8P+KFQLQE00ITmFnLPKAzIy9FwxE37A=
99-
github.com/btcsuite/btcwallet v0.16.11/go.mod h1:1HJXYbjJzgumlnxOC2+ViR1U+gnHWoOn7WeK5OfY1eU=
98+
github.com/btcsuite/btcwallet v0.16.12 h1:9SREKY892i1xTGlGLcu6x7O+WSQFn6+uQrSuskAOqh0=
99+
github.com/btcsuite/btcwallet v0.16.12/go.mod h1:jBn+ThFrx/QqW0nXiGvXtJytju4aVoW7C0hY4s/+9vo=
100100
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5 h1:Rr0njWI3r341nhSPesKQ2JF+ugDSzdPoeckS75SeDZk=
101101
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5/go.mod h1:+tXJ3Ym0nlQc/iHSwW1qzjmPs3ev+UVWMbGgfV1OZqU=
102102
github.com/btcsuite/btcwallet/wallet/txrules v1.2.2 h1:YEO+Lx1ZJJAtdRrjuhXjWrYsmAk26wLTlNzxt2q0lhk=
@@ -444,8 +444,8 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
444444
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
445445
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf h1:HZKvJUHlcXI/f/O0Avg7t8sqkPo78HFzjmeYFl6DPnc=
446446
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQPeIQxPf6Jf9rM8R+B4rKBqLA2AjttNxkFBL2Plk=
447-
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd h1:D8aRocHpoCv43hL8egXEMYyPmyOiefFHZ66338KQB2s=
448-
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd/go.mod h1:x3OmY2wsA18+Kc3TSV2QpSUewOCiscw2mKpXgZv2kZk=
447+
github.com/lightninglabs/neutrino v0.16.1 h1:5Kz4ToxncEVkpKC6fwUjXKtFKJhuxlG3sBB3MdJTJjs=
448+
github.com/lightninglabs/neutrino v0.16.1/go.mod h1:L+5UAccpUdyM7yDgmQySgixf7xmwBgJtOfs/IP26jCs=
449449
github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3shmlu5hIQ798g=
450450
github.com/lightninglabs/neutrino/cache v1.1.2/go.mod h1:XJNcgdOw1LQnanGjw8Vj44CvguYA25IMKjWFZczwZuo=
451451
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display h1:pRdza2wleRN1L2fJXd6ZoQ9ZegVFTAb2bOQfruJPKcY=
@@ -1076,8 +1076,8 @@ modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
10761076
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
10771077
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
10781078
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
1079-
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
1080-
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
1079+
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
1080+
pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
10811081
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
10821082
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
10831083
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

lncfg/chain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Chain struct {
1717

1818
MainNet bool `long:"mainnet" description:"Use the main network"`
1919
TestNet3 bool `long:"testnet" description:"Use the test network"`
20+
TestNet4 bool `long:"testnet4" description:"Use the testnet4 test network"`
2021
SimNet bool `long:"simnet" description:"Use the simulation test network"`
2122
RegTest bool `long:"regtest" description:"Use the regression test network"`
2223
SigNet bool `long:"signet" description:"Use the signet test network"`

lncfg/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ func CleanAndExpandPath(path string) string {
108108
// NormalizeNetwork returns the common name of a network type used to create
109109
// file paths. This allows differently versioned networks to use the same path.
110110
func NormalizeNetwork(network string) string {
111+
// The 4th testnet isn't the "default" yet, so we'll want to explicitly
112+
// point that to a "testnet4" directory.
113+
if network == "testnet4" {
114+
return network
115+
}
116+
117+
// We want to collapse "testnet3" and "testnet" to the same "testnet"
118+
// directory.
111119
if strings.HasPrefix(network, "testnet") {
112120
return "testnet"
113121
}

lnd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg,
194194
case cfg.Bitcoin.TestNet3:
195195
network = "testnet"
196196

197+
case cfg.Bitcoin.TestNet4:
198+
network = "testnet4"
199+
197200
case cfg.Bitcoin.MainNet:
198201
network = "mainnet"
199202

lnrpc/lightning.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lnrpc/lightning.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,8 +2008,8 @@ message GetInfoResponse {
20082008
bool synced_to_graph = 18;
20092009

20102010
/*
2011-
Whether the current node is connected to testnet. This field is
2012-
deprecated and the network field should be used instead
2011+
Whether the current node is connected to testnet or testnet4. This field is
2012+
deprecated and the network field should be used instead.
20132013
*/
20142014
bool testnet = 10 [deprecated = true];
20152015

lnrpc/lightning.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5196,7 +5196,7 @@
51965196
},
51975197
"testnet": {
51985198
"type": "boolean",
5199-
"title": "Whether the current node is connected to testnet. This field is\ndeprecated and the network field should be used instead"
5199+
"description": "Whether the current node is connected to testnet or testnet4. This field is\ndeprecated and the network field should be used instead."
52005200
},
52015201
"chains": {
52025202
"type": "array",

lntest/node/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ func (cfg *BaseNodeConfig) GenArgs() []string {
222222
switch cfg.NetParams {
223223
case &chaincfg.TestNet3Params:
224224
args = append(args, "--bitcoin.testnet")
225+
case &chaincfg.TestNet4Params:
226+
args = append(args, "--bitcoin.testnet4")
225227
case &chaincfg.SimNetParams:
226228
args = append(args, "--bitcoin.simnet")
227229
case &chaincfg.RegressionNetParams:

sample-lnd.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,9 @@
621621
; Use Bitcoin's test network.
622622
; bitcoin.testnet=false
623623
;
624+
; Use Bitcoin's 4th version test network.
625+
; bitcoin.testnet4=false
626+
;
624627
; Use Bitcoin's simulation test network
625628
; bitcoin.simnet=false
626629

server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,6 +2594,12 @@ func (s *server) Start() error {
25942594
chainreg.BitcoinTestnetGenesis,
25952595
)
25962596
}
2597+
if s.cfg.Bitcoin.TestNet4 {
2598+
setSeedList(
2599+
s.cfg.Bitcoin.DNSSeeds,
2600+
chainreg.BitcoinTestnet4Genesis,
2601+
)
2602+
}
25972603
if s.cfg.Bitcoin.SigNet {
25982604
setSeedList(
25992605
s.cfg.Bitcoin.DNSSeeds,

0 commit comments

Comments
 (0)