Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/json"
"fmt"
"net"
"net/http"
Expand All @@ -11,6 +12,8 @@ import (
"syscall"
"time"

"golang.org/x/exp/slices"

"github.com/btcsuite/btcd/rpcclient"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
Expand Down Expand Up @@ -222,6 +225,38 @@ func startServer(opts *common.Options) error {
// The default is zebrad
common.NodeName = "zcashd"
}

// Detect backend from subversion and, for zcashd, ensure the
// required experimental features are enabled.
subver := getLightdInfo.ZcashdSubversion

switch {
case strings.Contains(subver, "/Zebra:"):
common.Log.Info("Detected zebrad backend; skipping experimental feature check")

case strings.Contains(subver, "/MagicBean:"):
result, rpcErr := common.RawRequest("getexperimentalfeatures", []json.RawMessage{})
if rpcErr != nil {
common.Log.Fatalf("zcashd backend detected but getexperimentalfeatures RPC failed: %s", rpcErr.Error())
}

var feats []string
if err := json.Unmarshal(result, &feats); err != nil {
common.Log.Info("failed to decode getexperimentalfeatures reply: %w", err)
}

switch {
case slices.Contains(feats, "lightwalletd"):
case slices.Contains(feats, "insightexplorer"):
default:
common.Log.Fatal(
"zcashd is running without the required experimental feature enabled; " +
"enable 'lightwalletd' or 'insightexplorer'")
}

default:
common.Log.Fatalf("unsupported backend subversion %q (expected zcashd or zebrad)", subver)
}
}

dbPath := filepath.Join(opts.DataDir, "db")
Expand Down
Loading