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

chore(*): remove btcd support #27

Merged
merged 23 commits into from
Aug 29, 2024
Merged
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
113 changes: 41 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ There are four vigilante programs:

## Requirements

- Go 1.23
- [Go 1.23](https://go.dev/dl/go1.23.0.src.tar.gz)
- [Bitcoind](https://bitcoincore.org/bin)
- Package [libzmq](https://github.com/zeromq/libzmq)
- [btcd](https://github.com/btcsuite/btcd/tree/master?tab=readme-ov-file#installation) binaries (only for testing)

## Building

Expand Down Expand Up @@ -66,100 +66,69 @@ This will be later used to retrieve the certificate required for RPC connections
mkdir $TESTNET_PATH/bitcoin
```

For a Docker deployment, we want the vigilante to be able to communicate with
the Babylon and Bitcoin instances running on the local network.
We can accomplish that through the `host.docker.internal` DNS name,
which the Docker network translates to the Docker machine.
To enable Bitcoin RPC requests, we need to add the `host.docker.internal`
DNS host to the `rpc.cert` file that was created by the previous command.
To do that we use the btcd `gencerts` utility,
```bash
# Download Bitcoin Core binary
wget https://bitcoincore.org/bin/bitcoin-core-27.0/bitcoin-27.0-x86_64-linux-gnu.tar.gz # or choose a version depending on your os

```shell
gencerts -d $TESTNET_PATH/bitcoin/ -H host.docker.internal
```

#### Running a Bitcoin simnet with an arbitrary mining address
# Extract the downloaded archive
tar -xvf bitcoin-27.0-x86_64-linux-gnu.tar.gz

Launch a simnet Bitcoin node
which listens for RPC connections at port `18556` and
stores the RPC certificate under the `$TESTNET_PATH/bitcoin` directory.
The mining address is arbitrary.

```shell
btcd --simnet --rpclisten 127.0.0.1:18556 --rpcuser rpcuser --rpcpass rpcpass \
--rpccert $TESTNET_PATH/bitcoin/rpc.cert --rpckey $TESTNET_PATH/bitcoin/rpc.key \
--miningaddr SQqHYFTSPh8WAyJvzbAC8hoLbF12UVsE5s
# Provide execution permissions to binaries
chmod +x bitcoin-27.0/bin/bitcoind
chmod +x bitcoin-27.0/bin/bitcoin-cli
```

#### Running a Bitcoin simnet with a wallet
#### Running a Bitcoin regtest with a wallet

Launch a simnet Bitcoin node
which listens for RPC connections at port `18556` and
stores the RPC certificate under the `$TESTNET_PATH/bitcoin` directory.
Launch a regtest Bitcoind node which listens for RPC connections at port `18443`.

```shell
btcd --simnet --rpclisten 127.0.0.1:18556 --rpcuser rpcuser --rpcpass rpcpass \
--rpccert $TESTNET_PATH/bitcoin/rpc.cert --rpckey $TESTNET_PATH/bitcoin/rpc.key
bitcoind -regtest \
-txindex \
-rpcuser=<rpc_user> \
-rpcpassword=<rpc_password> \
-rpcbind=0.0.0.0:18443 \
-zmqpubsequence=tcp://0.0.0.0:28333 \
-datadir=/data/.bitcoin \

```

Leave this process running.

Then, create a simnet Bitcoin wallet.
Then, create a regtest Bitcoin wallet.
If you want to use the default vigilante file, then give the password `walletpass`.
Otherwise, make sure to edit the `vigilante.yaml` to reflect the correct password.

```shell
btcwallet --simnet -u rpcuser -P rpcpass \
--rpccert $TESTNET_PATH/bitcoin/rpc-wallet.cert --rpckey $TESTNET_PATH/bitcoin/rpc-wallet.key \
--cafile $TESTNET_PATH/bitcoin/rpc.cert \
--create
bitcoin-cli -regtest \
-rpcuser=<rpc_user> \
-rpcpassword=<rpc_password> \
-named createwallet \
wallet_name="<wallet_name>" \
passphrase="<passphrase>" \
load_on_startup=true \
descriptors=true
```
You can generate a btc address through the `getnewaddress` command:

The above instruction is going to prompt you for a password and going to give you the seed.
Store those securely.

Afterwards, start the wallet service listening to port `18554`:

```shell
btcwallet --simnet -u rpcuser -P rpcpass --rpclisten=127.0.0.1:18554 \
--rpccert $TESTNET_PATH/bitcoin/rpc-wallet.cert --rpckey $TESTNET_PATH/bitcoin/rpc-wallet.key \
--cafile $TESTNET_PATH/bitcoin/rpc.cert
```bash
bitcoin-cli -regtest \
-rpcuser=<rpc_user> \
-rpcpassword=<rpc_password> \
getnewaddress
```

Leave this process running. If you get an error that a wallet already exists and you still want
to create one, delete the `wallet.db` file located in the path displayed by the error message.

Create an address that will be later used for mining. The output below is a sample one.

```shell
$ btcctl --simnet --wallet -u rpcuser -P rpcpass \
--rpccert $TESTNET_PATH/bitcoin/rpc-wallet.cert \
--rpcserver 127.0.0.1 getnewaddress

SQqHYFTSPh8WAyJvzbAC8hoLbF12UVsE5s
```

Finally, restart the btcd service with the new address.
First, kill the `btcd` process that you started in the first step, and then:

```shell
btcd --simnet --rpclisten 127.0.0.1:18556 --rpcuser rpcuser --rpcpass rpcpass \
--rpccert $TESTNET_PATH/bitcoin/rpc.cert --rpckey $TESTNET_PATH/bitcoin/rpc.key \
--miningaddr $MINING_ADDRESS
```

where `$MINING_ADDRESS` is the address that you got as an output in the previous command.

#### Generating BTC blocks

While running this setup, one might want to generate BTC blocks.
We accomplish that through the btcd `btcctl` utility and the use
We accomplish that through the `bitcoin-cli` utility and the use
of the parameters we defined above.

```shell
btcctl --simnet --wallet --rpcuser=rpcuser --rpcpass=rpcpass \
--rpccert=$TESTNET_PATH/bitcoin/rpc-wallet.cert \
generate $NUM_BLOCKS
bitcoin-cli -chain=regtest \
-rpcuser=<rpc_user> \
-rpcpassword=<rpc_password> \
-generate $NUM_BLOCKS
```

where `$NUM_BLOCKS` is the number of blocks you want to generate.
Expand Down Expand Up @@ -241,7 +210,7 @@ cp sample-vigilante-docker.yml $TESTNET_PATH/vigilante/vigilante.yml
make reporter-build
```

Afterwards, run the above image and attach the directories
Afterward, run the above image and attach the directories
that contain the configuration for Babylon, Bitcoin, and the vigilante.

```shell
Expand Down
36 changes: 9 additions & 27 deletions btcclient/client_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/babylonlabs-io/vigilante/config"
"github.com/babylonlabs-io/vigilante/netparams"
"github.com/babylonlabs-io/vigilante/types"
)

// NewWallet creates a new BTC wallet
Expand All @@ -30,38 +29,21 @@ func NewWallet(cfg *config.BTCConfig, parentLogger *zap.Logger) (*Client, error)
wallet.params = params
wallet.logger = parentLogger.With(zap.String("module", "btcclient_wallet")).Sugar()

connCfg := &rpcclient.ConnConfig{}
switch cfg.BtcBackend {
case types.Bitcoind:
// TODO Currently we are not using Params field of rpcclient.ConnConfig due to bug in btcd
// when handling signet.
connCfg = &rpcclient.ConnConfig{
// this will work with node loaded with multiple wallets
Host: cfg.Endpoint + "/wallet/" + cfg.WalletName,
HTTPPostMode: true,
User: cfg.Username,
Pass: cfg.Password,
DisableTLS: cfg.DisableClientTLS,
}
case types.Btcd:
// TODO Currently we are not using Params field of rpcclient.ConnConfig due to bug in btcd
// when handling signet.
connCfg = &rpcclient.ConnConfig{
Host: cfg.WalletEndpoint,
Endpoint: "ws", // websocket
User: cfg.Username,
Pass: cfg.Password,
DisableTLS: cfg.DisableClientTLS,
Certificates: cfg.ReadWalletCAFile(),
}
connCfg := &rpcclient.ConnConfig{
// this will work with node loaded with multiple wallets
Host: cfg.Endpoint + "/wallet/" + cfg.WalletName,
HTTPPostMode: true,
User: cfg.Username,
Pass: cfg.Password,
DisableTLS: true,
}

rpcClient, err := rpcclient.New(connCfg, nil)
if err != nil {
return nil, fmt.Errorf("failed to create rpc client to BTC for %s backend: %w", cfg.BtcBackend, err)
return nil, fmt.Errorf("failed to create rpc client to BTC: %w", err)
}

wallet.logger.Infof("Successfully connected to %s backend", cfg.BtcBackend)
wallet.logger.Infof("Successfully connected to bitcoind")

wallet.Client = rpcClient

Expand Down
Loading
Loading