Skip to content

Commit

Permalink
Merge branch 'main' of github.com:babylonlabs-io/vigilante into depen…
Browse files Browse the repository at this point in the history
…dabot/go_modules/github.com/opencontainers/runc-1.1.12
  • Loading branch information
Lazar955 committed Sep 11, 2024
2 parents 55988e5 + 0058b5c commit 910da7b
Show file tree
Hide file tree
Showing 77 changed files with 1,685 additions and 1,767 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
lint_test:
uses: babylonlabs-io/.github/.github/workflows/[email protected]
with:
go-version: '1.23'
go-lint-version: 'v1.60.2'
run-unit-tests: true
run-integration-tests: true
run-lint: true
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ on:
push:
branches:
- 'main'
- 'dev'
tags:
- '*'

jobs:
lint_test:
uses: babylonlabs-io/.github/.github/workflows/[email protected]
with:
go-version: '1.23'
go-lint-version: 'v1.60.2'
run-unit-tests: true
run-integration-tests: true
run-lint: true
Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Contributing

Vigilante repository follows the same contributing rules as
[Babylon node](https://github.com/babylonlabs-io/babylon/blob/main/CONTRIBUTING.md)
repository.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Image for building
FROM golang:1.21-alpine AS build-env
FROM golang:1.23-alpine AS build-env


# TARGETPLATFORM should be one of linux/amd64 or linux/arm64.
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ $(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

test:
go test ./...
go test -race ./...

test-e2e:
cd $(TOOLS_DIR); go install -trimpath $(BABYLON_PKG);
go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -count=1 --tags=e2e
go test -race -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -count=1 --tags=e2e

build-docker:
$(DOCKER) build --tag babylonlabs-io/vigilante -f Dockerfile \
Expand Down
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.21
- [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
5 changes: 5 additions & 0 deletions RELEASE_PROCESS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release Process

Vigilate repository follows the same release process rules as
[Babylon node](https://github.com/babylonlabs-io/babylon/blob/main/RELEASE_PROCESS.md)
repository.
23 changes: 3 additions & 20 deletions btcclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"go.uber.org/zap"

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

var _ BTCClient = &Client{}
Expand All @@ -25,18 +23,15 @@ var _ BTCClient = &Client{}
// for information regarding the current best block chain.
type Client struct {
*rpcclient.Client
zmqClient *zmq.Client

Params *chaincfg.Params
Cfg *config.BTCConfig
params *chaincfg.Params
cfg *config.BTCConfig
logger *zap.SugaredLogger

// retry attributes
retrySleepTime time.Duration
maxRetrySleepTime time.Duration

// channel for notifying new BTC blocks to reporter
blockEventChan chan *types.BlockEvent
maxRetryTimes uint
}

func (c *Client) GetTipBlockVerbose() (*btcjson.GetBlockVerboseResult, error) {
Expand All @@ -54,16 +49,4 @@ func (c *Client) GetTipBlockVerbose() (*btcjson.GetBlockVerboseResult, error) {

func (c *Client) Stop() {
c.Shutdown()
// NewWallet will create a client with nil blockEventChan,
// while NewWithBlockSubscriber will have a non-nil one, so
// we need to check here
if c.blockEventChan != nil {
close(c.blockEventChan)
}

if c.zmqClient != nil {
if err := c.zmqClient.Close(); err != nil {
c.logger.Debug(err)
}
}
}
Loading

0 comments on commit 910da7b

Please sign in to comment.