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

fix: merge base to main #114

Merged
merged 19 commits into from
Feb 6, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Improvements

- [#114](https://github.com/babylonlabs-io/btc-staker/pull/114) **Multi-staking support**.
This PR contains a series of PRs on multi-staking support and BTC staking integration.
* [#127](https://github.com/babylonlabs-io/btc-staker/pull/127) Add support for
taproot addresses bip322 signing

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN apt-get update && apt-get install -y bash curl jq wget
COPY --from=builder /go/src/github.com/babylonlabs-io/btc-staker/go.mod /tmp
RUN WASMVM_VERSION=$(grep github.com/CosmWasm/wasmvm /tmp/go.mod | cut -d' ' -f2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.$(uname -m).so \
-O /lib/libwasmvm.$(uname -m).so && \
-O /lib/libwasmvm.$(uname -m).so && \
# verify checksum
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm.$(uname -m).so | grep $(cat /tmp/checksums.txt | grep libwasmvm.$(uname -m) | cut -d ' ' -f 1)
Expand All @@ -40,4 +40,4 @@ USER btcstaker

ENTRYPOINT ["/bin/stakerd"]
CMD []
STOPSIGNAL SIGTERM
STOPSIGNAL SIGTERM
83 changes: 62 additions & 21 deletions babylonclient/babyloncontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
bbntypes "github.com/babylonlabs-io/babylon/types"
btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
btcstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
bsctypes "github.com/babylonlabs-io/babylon/x/btcstkconsumer/types"
"github.com/babylonlabs-io/btc-staker/stakercfg"
"github.com/babylonlabs-io/btc-staker/stakerdb"
"github.com/babylonlabs-io/btc-staker/utils"
Expand Down Expand Up @@ -703,28 +704,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
addr string
)
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
addr = resp.FinalityProvider.Addr
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
addr = resp.FinalityProvider.Addr
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 @@ -736,24 +772,14 @@ 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()
if err != nil {
return nil, fmt.Errorf("received malformed btc pk in babylon response: %w", err)
}

fpAddr, err := sdk.AccAddressFromBech32(response.FinalityProvider.Addr)
if err != nil {
return nil, fmt.Errorf("received malformed fp addr in babylon response: %s - %w", response.FinalityProvider.Addr, err)
}

return &FinalityProviderClientResponse{
FinalityProvider: FinalityProviderInfo{
BabylonAddr: fpAddr,
BtcPk: *btcPk,
BabylonAddr: sdk.MustAccAddressFromBech32(addr),
BtcPk: *pk.MustToBTCPK(),
},
}, nil
}
Expand Down Expand Up @@ -810,6 +836,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 @@ -819,13 +846,15 @@ func (bc *BabylonController) RegisterFinalityProvider(
commission *sdkmath.LegacyDec,
description *sttypes.Description,
pop *btcstypes.ProofOfPossessionBTC,
consumerID string,
) error {
registerMsg := &btcstypes.MsgCreateFinalityProvider{
Addr: fpAddr.String(),
Commission: commission,
BtcPk: btcPubKey,
Description: description,
Pop: pop,
ConsumerId: consumerID,
}

relayerMsgs := bbnclient.ToProviderMsgs([]sdk.Msg{registerMsg})
Expand Down Expand Up @@ -966,6 +995,18 @@ func (bc *BabylonController) SubmitMultipleCovenantMessages(
return bc.reliablySendMsgs(msgs)
}

// Test methods for e2e testing
func (bc *BabylonController) RegisterConsumerChain(id, name, description string) (*bct.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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.4.0
github.com/avast/retry-go/v4 v4.5.1
github.com/babylonlabs-io/babylon v1.0.0-rc.4
github.com/babylonlabs-io/babylon v1.99.0-snapshot.250131
github.com/babylonlabs-io/networks/parameters v0.2.2
github.com/btcsuite/btcd v0.24.3-0.20240921052913-67b8efd3ba53
github.com/btcsuite/btcd/btcec/v2 v2.3.4
Expand Down Expand Up @@ -79,7 +79,7 @@ require (
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
github.com/btcsuite/winsvc v1.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
Expand Down Expand Up @@ -130,7 +130,7 @@ require (
github.com/go-kit/kit v0.13.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobwas/ws v1.2.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX
github.com/aws/aws-sdk-go v1.49.6 h1:yNldzF5kzLBRvKlKz1S0bkvc2+04R1kt13KfBWQBfFA=
github.com/aws/aws-sdk-go v1.49.6/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonlabs-io/babylon v1.0.0-rc.4 h1:fZNqUxyfGNwk7bJddglbDkEYsbNAB8jaaxaxRepb2Ow=
github.com/babylonlabs-io/babylon v1.0.0-rc.4/go.mod h1:4nCZ40ZbUFMG7OkbYV91rhwSZUmjBBNc4c3RGLrtrUY=
github.com/babylonlabs-io/babylon v1.99.0-snapshot.250131 h1:sw6c4Rkd2SwtZnLSFyVPMuf8yor/lNTQt17XP2P3AgY=
github.com/babylonlabs-io/babylon v1.99.0-snapshot.250131/go.mod h1:NxghSOJHuPCwdIKUsSrmmbVJweTRCLW2tLJ4UjlSwUc=
github.com/babylonlabs-io/networks/parameters v0.2.2 h1:TCu39fZvjX5f6ZZrjhYe54M6wWxglNewuKu56yE+zrc=
github.com/babylonlabs-io/networks/parameters v0.2.2/go.mod h1:iEJVOzaLsE33vpP7J4u+CRGfkSIfErUAwRmgCFCBpyI=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down Expand Up @@ -334,8 +334,8 @@ github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4=
github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -543,8 +543,8 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
Expand Down Expand Up @@ -769,8 +769,8 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
Expand Down Expand Up @@ -1059,8 +1059,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/onsi/gomega v1.26.0 h1:03cDLK28U6hWvCAns6NeydX3zIm4SF3ci69ulidS32Q=
github.com/onsi/gomega v1.26.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
Expand Down
3 changes: 2 additions & 1 deletion itest/containers/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package containers

import (
"testing"

"github.com/babylonlabs-io/btc-staker/itest/testutil"
"github.com/stretchr/testify/require"
"testing"
)

// ImageConfig contains all images and their respective tags
Expand Down
Loading
Loading