lnd: properly switch RPC port with target net change
With this commit, support for changing the target network (testnet, simnet, etc) has been finalized. Previously a command line option was present to swap networks, but the RPC port wouldn’t automatically be updated to reflect the network.
This commit is contained in:
parent
98fae7f329
commit
a56ab46e97
13
config.go
13
config.go
@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
|
||||
flags "github.com/btcsuite/go-flags"
|
||||
"github.com/roasbeef/btcd/chaincfg"
|
||||
"github.com/roasbeef/btcutil"
|
||||
)
|
||||
|
||||
@ -34,10 +33,6 @@ var (
|
||||
defaultDataDir = filepath.Join(lndHomeDir, defaultDataDirname)
|
||||
defaultLogDir = filepath.Join(lndHomeDir, defaultLogDirname)
|
||||
|
||||
// activeNetParams is a pointer to the parameters specific to the
|
||||
// currently active bitcoin network.
|
||||
activeNetParams = &chaincfg.SegNet4Params
|
||||
|
||||
btcdHomeDir = btcutil.AppDataDir("btcd", false)
|
||||
defaultRPCKeyFile = filepath.Join(btcdHomeDir, "rpc.key")
|
||||
defaultRPCCertFile = filepath.Join(btcdHomeDir, "rpc.cert")
|
||||
@ -154,15 +149,11 @@ func loadConfig() (*config, error) {
|
||||
numNets := 0
|
||||
if cfg.TestNet3 {
|
||||
numNets++
|
||||
activeNetParams = &chaincfg.TestNet3Params
|
||||
}
|
||||
if cfg.SegNet {
|
||||
numNets++
|
||||
activeNetParams = &chaincfg.SegNet4Params
|
||||
activeNetParams = testNetParams
|
||||
}
|
||||
if cfg.SimNet {
|
||||
numNets++
|
||||
activeNetParams = &chaincfg.SimNetParams
|
||||
activeNetParams = simNetParams
|
||||
}
|
||||
if numNets > 1 {
|
||||
str := "%s: The testnet, segnet, and simnet params can't be " +
|
||||
|
@ -331,7 +331,7 @@ func (f *fundingManager) handleFundingRequest(fmsg *fundingRequestMsg) {
|
||||
|
||||
// With our portion of the reservation initialied, process the
|
||||
// initiators contribution to the channel.
|
||||
_, addrs, _, err := txscript.ExtractPkScriptAddrs(msg.DeliveryPkScript, activeNetParams)
|
||||
_, addrs, _, err := txscript.ExtractPkScriptAddrs(msg.DeliveryPkScript, activeNetParams.Params)
|
||||
if err != nil {
|
||||
fndgLog.Errorf("Unable to extract addresses from script: %v", err)
|
||||
return
|
||||
@ -390,7 +390,7 @@ func (f *fundingManager) handleFundingResponse(fmsg *fundingResponseMsg) {
|
||||
// contribution. At this point, we can process their contribution which
|
||||
// allows us to construct and sign both the commitment transaction, and
|
||||
// the funding transaction.
|
||||
_, addrs, _, err := txscript.ExtractPkScriptAddrs(msg.DeliveryPkScript, activeNetParams)
|
||||
_, addrs, _, err := txscript.ExtractPkScriptAddrs(msg.DeliveryPkScript, activeNetParams.Params)
|
||||
if err != nil {
|
||||
fndgLog.Errorf("Unable to extract addresses from script: %v", err)
|
||||
return
|
||||
|
9
lnd.go
9
lnd.go
@ -40,7 +40,7 @@ func lndMain() error {
|
||||
ltndLog.Infof("Version %s", version())
|
||||
|
||||
if loadedConfig.SPVMode == true {
|
||||
shell(loadedConfig.SPVHostAdr, activeNetParams)
|
||||
shell(loadedConfig.SPVHostAdr, activeNetParams.Params)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ func lndMain() error {
|
||||
|
||||
// Open the channeldb, which is dedicated to storing channel, and
|
||||
// network related meta-data.
|
||||
chanDB, err := channeldb.Open(loadedConfig.DataDir, activeNetParams)
|
||||
chanDB, err := channeldb.Open(loadedConfig.DataDir, activeNetParams.Params)
|
||||
if err != nil {
|
||||
fmt.Println("unable to open channeldb: ", err)
|
||||
return err
|
||||
@ -82,11 +82,11 @@ func lndMain() error {
|
||||
config := &lnwallet.Config{
|
||||
PrivatePass: []byte("hello"),
|
||||
DataDir: filepath.Join(loadedConfig.DataDir, "lnwallet"),
|
||||
RpcHost: loadedConfig.RPCHost,
|
||||
RpcHost: fmt.Sprintf("%v:%v", loadedConfig.RPCHost, activeNetParams.rpcPort),
|
||||
RpcUser: loadedConfig.RPCUser,
|
||||
RpcPass: loadedConfig.RPCPass,
|
||||
CACert: cert,
|
||||
NetParams: activeNetParams,
|
||||
NetParams: activeNetParams.Params,
|
||||
}
|
||||
wallet, err := lnwallet.NewLightningWallet(config, chanDB)
|
||||
if err != nil {
|
||||
@ -151,6 +151,7 @@ func main() {
|
||||
// Call the "real" main in a nested manner so the defers will properly
|
||||
// be executed in the case of a graceful shutdown.
|
||||
if err := lndMain(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
33
params.go
Normal file
33
params.go
Normal file
@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import "github.com/roasbeef/btcd/chaincfg"
|
||||
|
||||
// activeNetParams is a pointer to the parameters specific to the currently
|
||||
// active bitcoin network.
|
||||
var activeNetParams = segNetParams
|
||||
|
||||
// netParams couples the p2p parameters of a network with the corresponding RPC
|
||||
// port of a daemon running on the particular network.
|
||||
type netParams struct {
|
||||
*chaincfg.Params
|
||||
rpcPort string
|
||||
}
|
||||
|
||||
// testNetParams contains parameters specific to the 3rd version of the test network.
|
||||
var testNetParams = netParams{
|
||||
Params: &chaincfg.TestNet3Params,
|
||||
rpcPort: "18334",
|
||||
}
|
||||
|
||||
// segNetParams contains parameters specific to the segregated witness test
|
||||
// network.
|
||||
var segNetParams = netParams{
|
||||
Params: &chaincfg.SegNet4Params,
|
||||
rpcPort: "28902",
|
||||
}
|
||||
|
||||
// simNetParams contains parameters specific to the simulation test network.
|
||||
var simNetParams = netParams{
|
||||
Params: &chaincfg.SimNetParams,
|
||||
rpcPort: "18556",
|
||||
}
|
@ -71,7 +71,7 @@ func (r *rpcServer) Stop() error {
|
||||
func addrPairsToOutputs(addrPairs map[string]int64) ([]*wire.TxOut, error) {
|
||||
outputs := make([]*wire.TxOut, 0, len(addrPairs))
|
||||
for addr, amt := range addrPairs {
|
||||
addr, err := btcutil.DecodeAddress(addr, activeNetParams)
|
||||
addr, err := btcutil.DecodeAddress(addr, activeNetParams.Params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -286,7 +286,7 @@ func (r *rpcServer) GetInfo(ctx context.Context,
|
||||
pendingChannels := r.server.fundingMgr.NumPendingChannels()
|
||||
|
||||
idPub := r.server.identityPriv.PubKey().SerializeCompressed()
|
||||
idAddr, err := btcutil.NewAddressPubKeyHash(btcutil.Hash160(idPub), activeNetParams)
|
||||
idAddr, err := btcutil.NewAddressPubKeyHash(btcutil.Hash160(idPub), activeNetParams.Params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user