Skip to content

Commit

Permalink
Merge pull request #4 from babylonlabs-io/release/v0.9.0
Browse files Browse the repository at this point in the history
Release/v0.9.0
  • Loading branch information
KonradStaniec authored Aug 7, 2024
2 parents c6856b6 + a8f1c82 commit 177f364
Show file tree
Hide file tree
Showing 111 changed files with 1,773 additions and 929 deletions.
289 changes: 289 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ RUN apk add --no-cache --update openssh git make build-base linux-headers libc-d
libzmq-static libsodium-static gcc

# Build
WORKDIR /go/src/github.com/babylonchain/vigilante
WORKDIR /go/src/github.com/babylonlabs-io/vigilante
# Cache dependencies
COPY go.mod go.sum /go/src/github.com/babylonchain/vigilante/
COPY go.mod go.sum /go/src/github.com/babylonlabs-io/vigilante/
RUN go mod download
# Copy the rest of the files
COPY ./ /go/src/github.com/babylonchain/vigilante/
COPY ./ /go/src/github.com/babylonlabs-io/vigilante/
# If version is set, then checkout this version
RUN if [ -n "${VERSION}" ]; then \
git checkout -f ${VERSION}; \
fi

# Cosmwasm - Download correct libwasmvm version
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm/v2 | cut -d ' ' -f 2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.a && \
-O /lib/libwasmvm_muslc.$(uname -m).a && \
# verify checksum
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$(uname -m) | cut -d ' ' -f 1)
sha256sum /lib/libwasmvm_muslc.$(uname -m).a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$(uname -m) | cut -d ' ' -f 1)

RUN CGO_LDFLAGS="$CGO_LDFLAGS -lstdc++ -lm -lsodium" \
CGO_ENABLED=1 \
Expand All @@ -46,9 +46,9 @@ RUN addgroup --gid 1138 -S vigilante && adduser --uid 1138 -S vigilante -G vigil
RUN apk add bash curl jq

# Label should match your github repo
LABEL org.opencontainers.image.source="https://github.com/babylonchain/vigilante:${VERSION}"
LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/vigilante:${VERSION}"

COPY --from=build-env /go/src/github.com/babylonchain/vigilante/build/vigilante /bin/vigilante
COPY --from=build-env /go/src/github.com/babylonlabs-io/vigilante/build/vigilante /bin/vigilante

# Set home directory and user
WORKDIR /home/vigilante
Expand Down
20 changes: 16 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ TOOLS_DIR := tools

BTCD_PKG := github.com/btcsuite/btcd
BTCDW_PKG := github.com/btcsuite/btcwallet
BABYLON_PKG := github.com/babylonchain/babylon/cmd/babylond
BABYLON_PKG := github.com/babylonlabs-io/babylon/cmd/babylond

GO_BIN := ${GOPATH}/bin
BTCD_BIN := $(GO_BIN)/btcd
Expand All @@ -30,6 +30,14 @@ endif
BUILD_TARGETS := build install
BUILD_FLAGS := --tags "$(build_tags)" --ldflags '$(ldflags)'

# Update changelog vars
ifneq (,$(SINCE_TAG))
sinceTag := --since-tag $(SINCE_TAG)
endif
ifneq (,$(UPCOMING_TAG))
upcomingTag := --future-release $(UPCOMING_TAG)
endif

all: build install

build: BUILD_ARGS := $(build_args) -o $(BUILDDIR)
Expand All @@ -48,11 +56,11 @@ test-e2e:
go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -count=1 --tags=e2e

build-docker:
$(DOCKER) build --tag babylonchain/vigilante -f Dockerfile \
$(DOCKER) build --tag babylonlabs-io/vigilante -f Dockerfile \
$(shell git rev-parse --show-toplevel)

rm-docker:
$(DOCKER) rmi babylonchain/vigilante 2>/dev/null; true
$(DOCKER) rmi babylonlabs-io/vigilante 2>/dev/null; true

mocks:
mkdir -p $(MOCKS_DIR)
Expand All @@ -65,4 +73,8 @@ mocks:
$(MOCKGEN_CMD) -source=btcstaking-tracker/atomicslasher/expected_babylon_client.go -package atomicslasher -destination btcstaking-tracker/atomicslasher/mock_babylon_client.go
$(MOCKGEN_CMD) -source=btcstaking-tracker/unbondingwatcher/expected_babylon_client.go -package unbondingwatcher -destination btcstaking-tracker/unbondingwatcher/mock_babylon_client.go

.PHONY: build test test-e2e build-docker rm-docker mocks
update-changelog:
@echo ./scripts/update_changelog.sh $(sinceTag) $(upcomingTag)
./scripts/update_changelog.sh $(sinceTag) $(upcomingTag)

.PHONY: build test test-e2e build-docker rm-docker mocks update-changelog
66 changes: 56 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
# vigilante

Vigilante program for Babylon
This repository contains vigilante programs for Babylon. They are daemon programs that relay information between Babylon and Bitcoin for facilitating the Bitcoin timestamping protocol and the Bitcoin staking protocol.

There are four vigilante programs:

- [Submitter](./submitter/README.md): submitting Babylon checkpoints to Bitcoin.
- [Reporter](./reporter/README.md): reporting Bitcoin headers and Babylon checkpoints to Babylon.
- [BTC timestamping monitor](./monitor/README.md): monitoring censorship of Babylon checkpoints in Babylon.
- [BTC staking tracker](./btcstaking-tracker/README.md): monitoring early unbonding of BTC delegations and slashing adversarial finality providers.

## Requirements

- Go 1.19
- Go 1.21
- 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

In order to build the vigilante,

```shell
make build
```

## Running the vigilante

For the following:

```shell
BABYLON_PATH="path_where_babylon_is_built" # example: $HOME/Projects/Babylon/babylon
VIGILANTE_PATH="root_vigilante_dir" # example: $HOME/Projects/Babylon/vigilante
Expand All @@ -38,6 +49,7 @@ $BABYLON_PATH/build/babylond testnet \
```

Using this configuration, start the testnet for the single node.

```shell
$BABYLON_PATH/build/babylond start --home $TESTNET_PATH/node0/babylond
```
Expand Down Expand Up @@ -95,6 +107,7 @@ Leave this process running.
Then, create a simnet 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 \
Expand All @@ -106,43 +119,49 @@ The above instruction is going to prompt you for a password and going to give yo
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
```

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:
```sh

```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.

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
of the parameters we defined above.

```shell
btcctl --simnet --wallet --rpcuser=rpcuser --rpcpass=rpcpass \
--rpccert=$TESTNET_PATH/bitcoin/rpc-wallet.cert \
generate $NUM_BLOCKS
```

where `$NUM_BLOCKS` is the number of blocks you want to generate.

Not that in order to spend the mining rewards, at least 100 blocks should be
Expand All @@ -169,15 +188,16 @@ mkdir $TESTNET_PATH/vigilante
#### Running the vigilante reporter

Initially, copy the sample configuration

```shell
cp sample-vigilante.yml $TESTNET_PATH/vigilante/vigilante.yml
nano $TESTNET_PATH/vigilante/vigilante.yml # edit the config file to replace $TESTNET instances
nano $TESTNET_PATH/vigilante/vigilante.yml # edit the config file to replace $TESTNET instances
```

```shell
go run $VIGILANTE_PATH/cmd/main.go reporter \
--config $TESTNET_PATH/vigilante/vigilante.yml \
--babylon-key $BABYLON_PATH/.testnet/node0/babylond
--babylon-key-dir $BABYLON_PATH/.testnet/node0/babylond
```

#### Running the vigilante submitter
Expand All @@ -199,11 +219,23 @@ go run $VIGILANTE_PATH/cmd/main.go monitor \
--config $TESTNET_PATH/vigilante/vigilante.yml
```

#### Running the BTC staking tracker

We first need to ensure that a BTC full node and the Babylon node that we want to monitor are started running.

Then we start the BTC staking tracker:

```shell
go run $VIGILANTE_PATH/cmd/main.go bstracker \
--config $TESTNET_PATH/vigilante/vigilante.yml
```

### Running the vigilante using Docker

#### Running the vigilante reporter
#### Running the vigilante reporter in Docker container

Initially, build a Docker image named `babylonchain/vigilante-reporter`

```shell
cp sample-vigilante-docker.yml $TESTNET_PATH/vigilante/vigilante.yml
make reporter-build
Expand All @@ -220,9 +252,10 @@ docker run --rm \
babylonchain/vigilante-reporter
```

#### Running the vigilante submitter
#### Running the vigilante submitter in Docker container

Follow the same steps as above, but with the `babylonchain/vigilante-submitter` Docker image.

```shell
docker run --rm \
-v $TESTNET_PATH/bitcoin:/bitcoin \
Expand All @@ -231,9 +264,10 @@ docker run --rm \
babylonchain/vigilante-submitter
```

#### Running the vigilante monitor
#### Running the vigilante monitor in Docker container

Follow the same steps as above, but with the `babylonchain/vigilante-monitor` Docker image.

```shell
docker run --rm \
-v $TESTNET_PATH/bitcoin:/bitcoin \
Expand All @@ -242,6 +276,18 @@ docker run --rm \
babylonchain/vigilante-monitor
```

#### Running the BTC staking tracker in Docker container

Follow the same steps as above, but with the `babylonchain/btc-staking-tracker` Docker image.

```shell
docker run --rm \
-v $TESTNET_PATH/bitcoin:/bitcoin \
-v $TESTNET_PATH/node0/babylond:/babylon \
-v $TESTNET_PATH/vigilante:/vigilante \
babylonchain/btc-staking-tracker
```

#### buildx

The above `Dockerfile`s are also compatible with Docker's [buildx feature](https://docs.docker.com/desktop/multi-arch/)
Expand Down
6 changes: 3 additions & 3 deletions btcclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/btcsuite/btcd/rpcclient"
"go.uber.org/zap"

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

var _ BTCClient = &Client{}
Expand Down
14 changes: 7 additions & 7 deletions btcclient/client_block_subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"fmt"
"time"

"github.com/babylonchain/babylon/types/retry"
"github.com/babylonlabs-io/babylon/types/retry"
"github.com/btcsuite/btcd/btcutil"
"go.uber.org/zap"

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

"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/wire"
Expand Down Expand Up @@ -56,7 +56,7 @@ func NewWithBlockSubscriber(cfg *config.BTCConfig, retrySleepTime, maxRetrySleep
if err != nil {
return nil, fmt.Errorf("failed to get BTC backend: %v", err)
}
if backend != rpcclient.BitcoindPost19 {
if backend != rpcclient.BitcoindPost25 {
return nil, fmt.Errorf("zmq is only supported by bitcoind, but got %v", backend)
}

Expand Down Expand Up @@ -100,7 +100,7 @@ func NewWithBlockSubscriber(cfg *config.BTCConfig, retrySleepTime, maxRetrySleep
if err != nil {
return nil, fmt.Errorf("failed to get BTC backend: %v", err)
}
if backend != rpcclient.Btcd {
if backend != rpcclient.BtcdPost2401 {
return nil, fmt.Errorf("websocket is only supported by btcd, but got %v", backend)
}

Expand Down
6 changes: 3 additions & 3 deletions btcclient/client_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/btcsuite/btcd/wire"
"go.uber.org/zap"

"github.com/babylonchain/vigilante/config"
"github.com/babylonchain/vigilante/netparams"
"github.com/babylonchain/vigilante/types"
"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 Down
4 changes: 2 additions & 2 deletions btcclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"

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

type BTCClient interface {
Expand Down
4 changes: 2 additions & 2 deletions btcclient/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os"
"time"

"github.com/babylonchain/vigilante/config"
"github.com/babylonchain/vigilante/types"
"github.com/babylonlabs-io/vigilante/config"
"github.com/babylonlabs-io/vigilante/types"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcwallet/chain"
Expand Down
4 changes: 2 additions & 2 deletions btcclient/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package btcclient
import (
"fmt"

"github.com/babylonchain/babylon/types/retry"
"github.com/babylonlabs-io/babylon/types/retry"
"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"go.uber.org/zap"

"github.com/babylonchain/vigilante/types"
"github.com/babylonlabs-io/vigilante/types"
)

// GetBestBlock provides similar functionality with the btcd.rpcclient.GetBestBlock function
Expand Down
6 changes: 3 additions & 3 deletions btcclient/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package btcclient
import (
"time"

"github.com/babylonchain/vigilante/config"
"github.com/babylonchain/vigilante/netparams"
"github.com/babylonchain/vigilante/types"
"github.com/babylonlabs-io/vigilante/config"
"github.com/babylonlabs-io/vigilante/netparams"
"github.com/babylonlabs-io/vigilante/types"
"github.com/btcsuite/btcd/rpcclient"
)

Expand Down
Loading

0 comments on commit 177f364

Please sign in to comment.