Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for signet #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions cmd/nigiri/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ var datadirFlag = cli.StringFlag{
}

//go:embed resources/docker-compose.yml
//go:embed resources/docker-compose.signet.yml
//go:embed resources/bitcoin.conf
//go:embed resources/bitcoin.signet.conf
//go:embed resources/elements.conf
var f embed.FS

Expand Down Expand Up @@ -106,6 +108,9 @@ func provisionResourcesToDatadir(datadir string) error {
if err := makeDirectoryIfNotExists(filepath.Join(datadir, "volumes", "elements")); err != nil {
return err
}
if err := makeDirectoryIfNotExists(filepath.Join(datadir, "volumes", "bitcoin-signet")); err != nil {
return err
}

// copy resources into the Nigiri data directory
if err := copyFromResourcesToDatadir(
Expand All @@ -115,6 +120,13 @@ func provisionResourcesToDatadir(datadir string) error {
return err
}

if err := copyFromResourcesToDatadir(
filepath.Join("resources", config.SignetCompose),
filepath.Join(datadir, config.SignetCompose),
); err != nil {
return err
}

if err := copyFromResourcesToDatadir(
filepath.Join("resources", "bitcoin.conf"),
filepath.Join(datadir, "volumes", "bitcoin", "bitcoin.conf"),
Expand All @@ -129,6 +141,13 @@ func provisionResourcesToDatadir(datadir string) error {
return err
}

if err := copyFromResourcesToDatadir(
filepath.Join("resources", "bitcoin.signet.conf"),
filepath.Join(datadir, "volumes", "bitcoin-signet", "bitcoin.conf"),
); err != nil {
return err
}

if err := nigiriState.Set(map[string]string{"ready": strconv.FormatBool(true)}); err != nil {
return err
}
Expand Down
20 changes: 20 additions & 0 deletions cmd/nigiri/resources/bitcoin.signet.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
signet=1

[signet]
port=38333
rpcport=38332

server=1
txindex=1

rpcuser=admin1
rpcpassword=123
rpcallowip=0.0.0.0/0
rpcbind=0.0.0.0
fallbackfee=0.00001

zmqpubrawblock=tcp://0.0.0.0:48332
zmqpubrawtx=tcp://0.0.0.0:48333

blockfilterindex=1
peerblockfilters=1
66 changes: 66 additions & 0 deletions cmd/nigiri/resources/docker-compose.signet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: '3.7'
services:

# Signet
bitcoin:
image: ghcr.io/vulpemventures/bitcoin:latest
user: 1000:1000
container_name: bitcoin
command:
- -datadir=config
ports:
- 38333:38333
- 38332:38332
# ZMQ
- 48332:48332
- 48333:48333
volumes:
- ./volumes/bitcoin-signet/:/config
restart: unless-stopped

electrs:
image: ghcr.io/vulpemventures/electrs:latest
container_name: electrs
entrypoint:
- /build/electrs
command:
- -vvvv
- --network
- signet
- --daemon-dir
- /config
- --daemon-rpc-addr
- bitcoin:38332
- --cookie
- admin1:123
- --http-addr
- 0.0.0.0:30000
- --electrum-rpc-addr
- 0.0.0.0:50000
- --cors
- "*"
- --jsonrpc-import
depends_on:
- bitcoin
ports:
- 50000:50000
- 30000:30000
volumes:
- ./volumes/bitcoin-signet/:/config
restart: unless-stopped

# Block explorer frontend
esplora:
image: ghcr.io/vulpemventures/esplora:latest
container_name: esplora
depends_on:
- electrs
environment:
API_URL: http://localhost:30000
ports:
- 5000:5000
restart: unless-stopped

networks:
default:
name: nigiri
23 changes: 21 additions & 2 deletions cmd/nigiri/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var start = cli.Command{
Action: startAction,
Flags: []cli.Flag{
&liquidFlag,
&cli.BoolFlag{
Name: "signet",
Usage: "start Bitcoin node in signet",
},
&cli.BoolFlag{
Name: "ci",
Usage: "runs in headless mode without esplora for continuous integration environments",
Expand All @@ -35,8 +39,16 @@ func startAction(ctx *cli.Context) error {
}

isLiquid := ctx.Bool("liquid")
isSignet := ctx.Bool("signet")
runWithoutFrontend := ctx.Bool("ci")
datadir := ctx.String("datadir")
composePath := filepath.Join(datadir, config.DefaultCompose)
regtestComposePath := filepath.Join(datadir, config.DefaultCompose)
signetComposePath := filepath.Join(datadir, config.SignetCompose)

composePath := regtestComposePath
if isSignet {
composePath = signetComposePath
}

// spin up all the services in the compose file
bashCmd := exec.Command("docker-compose", "-f", composePath, "up", "-d", "esplora")
Expand All @@ -45,7 +57,7 @@ func startAction(ctx *cli.Context) error {
bashCmd = exec.Command("docker-compose", "-f", composePath, "up", "-d", "esplora", "esplora-liquid")
}

if ctx.Bool("ci") {
if runWithoutFrontend {
//this will only run chopsticks and servives it depends on
bashCmd = exec.Command("docker-compose", "-f", composePath, "up", "-d", "chopsticks")
if isLiquid {
Expand All @@ -54,6 +66,13 @@ func startAction(ctx *cli.Context) error {
}
}

if isSignet {
if isLiquid || runWithoutFrontend {
return errors.New("signet can only be used with bitcoin")
}
bashCmd = exec.Command("docker-compose", "-f", composePath, "up", "-d", "esplora")
}

bashCmd.Stdout = os.Stdout
bashCmd.Stderr = os.Stderr

Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
var (
DefaultName = "nigiri.config.json"
DefaultCompose = "docker-compose.yml"
SignetCompose = "docker-compose.signet.yml"

DefaultDatadir = btcutil.AppDataDir("nigiri", false)
DefaultPath = filepath.Join(DefaultDatadir, DefaultName)
Expand Down