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

[DO NOT MERGE] Diff between dev and base branch #169

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
command: "go env"
- go/load-cache:
key: go-mod-v6-{{ checksum "go.sum" }}
- add_ssh_keys
- go/mod-download
- go/save-cache:
key: go-mod-v6-{{ checksum "go.sum" }}
Expand Down Expand Up @@ -46,13 +47,15 @@ jobs:
resource_class: large
steps:
- checkout
- add_ssh_keys
- aws-ecr/build-image:
push-image: false
dockerfile: Dockerfile
path: ./
build-path: ./
tag: "$CIRCLE_SHA1,$CIRCLE_TAG"
repo: "$CIRCLE_PROJECT_REPONAME"
extra-build-args: "--secret id=sshKey,src=/home/circleci/.ssh/$DEPLOY_KEY_NAME"
- run:
name: Save Docker image to export it to workspace
command: |
Expand Down Expand Up @@ -101,3 +104,4 @@ workflows:
only:
- main
- dev
- base/consumer-chain-support
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
# Changelog

## [Unreleased](https://github.com/babylonchain/btc-staker/tree/HEAD)
## [euphrates-0.1.0-rc.0](https://github.com/babylonchain/btc-staker/tree/euphrates-0.1.0-rc.0) (2024-03-26)

[Full Changelog](https://github.com/babylonchain/btc-staker/compare/v0.1.0...HEAD)
[Full Changelog](https://github.com/babylonchain/btc-staker/compare/v0.1.0...euphrates-0.1.0-rc.0)

**Closed issues:**

- restaking: support restaking to consumer chain FPs [\#126](https://github.com/babylonchain/btc-staker/issues/126)
- testing restaking support [\#124](https://github.com/babylonchain/btc-staker/issues/124)
- Faucet scarcity [\#118](https://github.com/babylonchain/btc-staker/issues/118)
- Stakerd init fails if directory doesn't exist [\#108](https://github.com/babylonchain/btc-staker/issues/108)

**Merged pull requests:**

- e2e test for restaking [\#125](https://github.com/babylonchain/btc-staker/pull/125) ([SebastianElvis](https://github.com/SebastianElvis))
- Add cli command to verify whether tx is valid phase1 staking tx [\#123](https://github.com/babylonchain/btc-staker/pull/123) ([KonradStaniec](https://github.com/KonradStaniec))
- Bump babylon version [\#121](https://github.com/babylonchain/btc-staker/pull/121) ([KonradStaniec](https://github.com/KonradStaniec))
- Add possiblity to send concurrent transactions [\#117](https://github.com/babylonchain/btc-staker/pull/117) ([KonradStaniec](https://github.com/KonradStaniec))
- Add metrics [\#115](https://github.com/babylonchain/btc-staker/pull/115) ([KonradStaniec](https://github.com/KonradStaniec))
- Switch e2e test to use bitcoind instead of btcd/btcd wallet combo [\#114](https://github.com/babylonchain/btc-staker/pull/114) ([KonradStaniec](https://github.com/KonradStaniec))
- chore: Increase staking time in docs [\#113](https://github.com/babylonchain/btc-staker/pull/113) ([vitsalis](https://github.com/vitsalis))
- Add CHANGELOG [\#112](https://github.com/babylonchain/btc-staker/pull/112) ([maurolacy](https://github.com/maurolacy))
- Bitcoind tests [\#110](https://github.com/babylonchain/btc-staker/pull/110) ([KonradStaniec](https://github.com/KonradStaniec))
- docs: Incorporate validator feedback [\#109](https://github.com/babylonchain/btc-staker/pull/109) ([gusin13](https://github.com/gusin13))
- Bump staker to stable babylon version [\#106](https://github.com/babylonchain/btc-staker/pull/106) ([KonradStaniec](https://github.com/KonradStaniec))
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ ARG COSMOS_BUILD_OPTIONS=""
# Install cli tools for building and final image
RUN apt-get update && apt-get install -y make git bash gcc curl jq

RUN mkdir -p /root/.ssh && ssh-keyscan github.com >> /root/.ssh/known_hosts
RUN git config --global url."[email protected]:".insteadOf "https://github.com/"
ENV GOPRIVATE=github.com/babylonchain/*

# Build
WORKDIR /go/src/github.com/babylonchain/btc-staker
# Cache dependencies
COPY go.mod go.sum /go/src/github.com/babylonchain/btc-staker/
RUN go mod download

RUN --mount=type=secret,id=sshKey,target=/root/.ssh/id_rsa go mod download
# Copy the rest of the files
COPY ./ /go/src/github.com/babylonchain/btc-staker/

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

build-docker:
$(DOCKER) build --tag babylonchain/btc-staker -f Dockerfile \
$(DOCKER) build --secret id=sshKey,src=${BBN_PRIV_DEPLOY_KEY} --tag babylonchain/btc-staker -f Dockerfile \
$(shell git rev-parse --show-toplevel)

.PHONY: build build-docker
Expand Down
73 changes: 62 additions & 11 deletions babylonclient/babyloncontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
bcctypes "github.com/babylonchain/babylon/x/btccheckpoint/types"
btclctypes "github.com/babylonchain/babylon/x/btclightclient/types"
btcstypes "github.com/babylonchain/babylon/x/btcstaking/types"
bsctypes "github.com/babylonchain/babylon/x/btcstkconsumer/types"
"github.com/babylonchain/btc-staker/stakercfg"
"github.com/babylonchain/btc-staker/stakerdb"
"github.com/babylonchain/btc-staker/utils"
Expand Down Expand Up @@ -565,28 +566,63 @@ func (bc *BabylonController) QueryFinalityProvider(btcPubKey *btcec.PublicKey) (
defer cancel()

clientCtx := client.Context{Client: bc.bbnClient.RPCClient}

queryClient := btcstypes.NewQueryClient(clientCtx)
bscQueryClient := bsctypes.NewQueryClient(clientCtx)

hexPubKey := hex.EncodeToString(schnorr.SerializePubKey(btcPubKey))

var response *btcstypes.QueryFinalityProviderResponse
var (
slashedHeight uint64
pk *bbntypes.BIP340PubKey
babylonPK *secp256k1.PubKey
)
if err := retry.Do(func() error {
// check if the finality provider is a Babylon one
resp, err := queryClient.FinalityProvider(
ctx,
&btcstypes.QueryFinalityProviderRequest{
FpBtcPkHex: hexPubKey,
},
)
if err != nil {
if strings.Contains(err.Error(), btcstypes.ErrFpNotFound.Error()) {
// if there is no finality provider with such key, we return unrecoverable error, as we not need to retry any more
return retry.Unrecoverable(fmt.Errorf("failed to get finality provider with key: %s: %w", hexPubKey, ErrFinalityProviderDoesNotExist))
if err == nil {
slashedHeight = resp.FinalityProvider.SlashedBabylonHeight
pk = resp.FinalityProvider.BtcPk
babylonPK = resp.FinalityProvider.BabylonPk
return nil
}

// check if the finality provider is a consumer chain one
bscResp, bscErr := bscQueryClient.FinalityProviderConsumer(
ctx,
&bsctypes.QueryFinalityProviderConsumerRequest{
FpBtcPkHex: hexPubKey,
},
)
if bscErr == nil {
consumerFPResp, consumerFPErr := bscQueryClient.FinalityProvider(
ctx,
&bsctypes.QueryFinalityProviderRequest{
ConsumerId: bscResp.ConsumerId,
FpBtcPkHex: hexPubKey,
},
)
if consumerFPErr != nil {
return consumerFPErr
}
slashedHeight = consumerFPResp.FinalityProvider.SlashedBabylonHeight
pk = consumerFPResp.FinalityProvider.BtcPk
babylonPK = consumerFPResp.FinalityProvider.BabylonPk
return nil
}

return err
// the finality provider cannot be found
if strings.Contains(err.Error(), btcstypes.ErrFpNotFound.Error()) &&
strings.Contains(bscErr.Error(), btcstypes.ErrFpNotFound.Error()) {
// if there is no finality provider with such key, we return unrecoverable error, as we not need to retry any more
return retry.Unrecoverable(fmt.Errorf("failed to get finality provider with key: %s: %w", hexPubKey, ErrFinalityProviderDoesNotExist))
}
response = resp
return nil
return err
}, RtyAtt, RtyDel, RtyErr, retry.OnRetry(func(n uint, err error) {
bc.logger.WithFields(logrus.Fields{
"attempt": n + 1,
Expand All @@ -598,19 +634,19 @@ func (bc *BabylonController) QueryFinalityProvider(btcPubKey *btcec.PublicKey) (
return nil, err
}

if response.FinalityProvider.SlashedBabylonHeight > 0 {
if slashedHeight > 0 {
return nil, fmt.Errorf("failed to get finality provider with key: %s: %w", hexPubKey, ErrFinalityProviderIsSlashed)
}

btcPk, err := response.FinalityProvider.BtcPk.ToBTCPK()
btcPk, err := pk.ToBTCPK()

if err != nil {
return nil, fmt.Errorf("received malformed btc pk in babylon response: %w", err)
}

return &FinalityProviderClientResponse{
FinalityProvider: FinalityProviderInfo{
BabylonPk: *response.FinalityProvider.BabylonPk,
BabylonPk: *babylonPK,
BtcPk: *btcPk,
},
}, nil
Expand Down Expand Up @@ -670,6 +706,7 @@ func chainToChainBytes(chain []*wire.BlockHeader) []bbntypes.BTCHeaderBytes {
return chainBytes
}

// Test methods for e2e testing
// RegisterFinalityProvider registers a BTC finality provider via a MsgCreateFinalityProvider to Babylon
// it returns tx hash and error
func (bc *BabylonController) RegisterFinalityProvider(
Expand All @@ -678,6 +715,7 @@ func (bc *BabylonController) RegisterFinalityProvider(
commission *sdkmath.LegacyDec,
description *sttypes.Description,
pop *btcstypes.ProofOfPossession,
consumerID string,
) (*pv.RelayerTxResponse, error) {
registerMsg := &btcstypes.MsgCreateFinalityProvider{
Signer: bc.getTxSigner(),
Expand All @@ -686,6 +724,7 @@ func (bc *BabylonController) RegisterFinalityProvider(
BtcPk: btcPubKey,
Description: description,
Pop: pop,
ConsumerId: consumerID,
}

return bc.reliablySendMsgs([]sdk.Msg{registerMsg})
Expand Down Expand Up @@ -811,6 +850,18 @@ func (bc *BabylonController) SubmitCovenantSig(
return bc.reliablySendMsgs([]sdk.Msg{msg})
}

// Test methods for e2e testing
func (bc *BabylonController) RegisterConsumerChain(id, name, description string) (*pv.RelayerTxResponse, error) {
msg := &bsctypes.MsgRegisterConsumer{
Signer: bc.getTxSigner(),
ConsumerId: id,
ConsumerName: name,
ConsumerDescription: description,
}

return bc.reliablySendMsgs([]sdk.Msg{msg})
}

func (bc *BabylonController) QueryPendingBTCDelegations() ([]*btcstypes.BTCDelegationResponse, error) {
ctx, cancel := getQueryContext(bc.cfg.Timeout)
defer cancel()
Expand Down
41 changes: 21 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ require (
github.com/urfave/cli v1.22.14
go.uber.org/zap v1.26.0
golang.org/x/sync v0.7.0
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.34.1
)

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.36.0 // indirect
cloud.google.com/go/storage v1.38.0 // indirect
cosmossdk.io/api v0.7.4 // indirect
cosmossdk.io/client/v2 v2.0.0-beta.1 // indirect
cosmossdk.io/collections v0.4.0 // indirect
Expand Down Expand Up @@ -157,14 +156,14 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.3 // indirect
Expand Down Expand Up @@ -296,32 +295,31 @@ require (
go.etcd.io/etcd/raft/v3 v3.5.7 // indirect
go.etcd.io/etcd/server/v3 v3.5.7 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.0.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.0.1 // indirect
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v0.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/api v0.162.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/api v0.169.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/grpc v1.64.0 // indirect
gopkg.in/errgo.v1 v1.0.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/macaroon-bakery.v2 v2.0.1 // indirect
Expand All @@ -346,4 +344,7 @@ require (
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
replace (
github.com/babylonchain/babylon => github.com/babylonchain/babylon-private v0.8.6-0.20240613120442-4654b8129974
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
)
Loading