Skip to content

Commit

Permalink
bump babylon and remove unbonding sending (#79)
Browse files Browse the repository at this point in the history
* bump babylon and remove unbonding sending
  • Loading branch information
KonradStaniec authored Oct 23, 2024
1 parent 7162d31 commit 65a3178
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 219 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
`withdrawable-transactions` query bug, introduced when adding pre-approval
transactions handling

### Improvements

* [#79](https://github.com/babylonlabs-io/btc-staker/pull/79) Remove `BTCUndelegate`
message sending

## v0.8.0

### Improvements
Expand Down
15 changes: 0 additions & 15 deletions babylonclient/babyloncontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,21 +435,6 @@ func (bc *BabylonController) Delegate(dg *DelegationData) (*pv.RelayerTxResponse
return bc.reliablySendMsgs([]sdk.Msg{delegateMsg})
}

func (bc *BabylonController) Undelegate(
req *UndelegationRequest,
) (*pv.RelayerTxResponse, error) {

ubSig := bbntypes.NewBIP340SignatureFromBTCSig(req.StakerUnbondingSig)

msg := &btcstypes.MsgBTCUndelegate{
Signer: bc.getTxSigner(),
StakingTxHash: req.StakingTxHash.String(),
UnbondingTxSig: ubSig,
}

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

func getQueryContext(timeout time.Duration) (context.Context, context.CancelFunc) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
return ctx, cancel
Expand Down
1 change: 0 additions & 1 deletion babylonclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ type BabylonClient interface {
SingleKeyKeyring
Params() (*StakingParams, error)
Delegate(dg *DelegationData) (*pv.RelayerTxResponse, error)
Undelegate(req *UndelegationRequest) (*pv.RelayerTxResponse, error)
QueryFinalityProviders(limit uint64, offset uint64) (*FinalityProvidersClientResponse, error)
QueryFinalityProvider(btcPubKey *btcec.PublicKey) (*FinalityProviderClientResponse, error)
QueryHeaderDepth(headerHash *chainhash.Hash) (uint32, error)
Expand Down
105 changes: 9 additions & 96 deletions babylonclient/msgsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ func newSendDelegationRequest(
}
}

type sendUndelegationRequest struct {
utils.Request[*pv.RelayerTxResponse]
stakingTxHash *chainhash.Hash
ur *UndelegationRequest
}

func newSendUndelegationRequest(
ur *UndelegationRequest,
) sendUndelegationRequest {
return sendUndelegationRequest{
Request: utils.NewRequest[*pv.RelayerTxResponse](),
ur: ur,
stakingTxHash: &ur.StakingTxHash,
}
}

// BabylonMsgSender is responsible for sending delegation and undelegation requests to babylon
// It makes sure:
// - that babylon is ready for either delgetion or undelegation
Expand All @@ -61,11 +45,10 @@ type BabylonMsgSender struct {
wg sync.WaitGroup
quit chan struct{}

cl BabylonClient
logger *logrus.Logger
sendDelegationRequestChan chan *sendDelegationRequest
sendUndelegationRequestChan chan *sendUndelegationRequest
s *semaphore.Weighted
cl BabylonClient
logger *logrus.Logger
sendDelegationRequestChan chan *sendDelegationRequest
s *semaphore.Weighted
}

func NewBabylonMsgSender(
Expand All @@ -75,12 +58,11 @@ func NewBabylonMsgSender(
) *BabylonMsgSender {
s := semaphore.NewWeighted(int64(maxConcurrentTransactions))
return &BabylonMsgSender{
quit: make(chan struct{}),
cl: cl,
logger: logger,
sendDelegationRequestChan: make(chan *sendDelegationRequest),
sendUndelegationRequestChan: make(chan *sendUndelegationRequest),
s: s,
quit: make(chan struct{}),
cl: cl,
logger: logger,
sendDelegationRequestChan: make(chan *sendDelegationRequest),
s: s,
}
}

Expand Down Expand Up @@ -160,41 +142,6 @@ func (m *BabylonMsgSender) sendDelegationAsync(stakingTxHash *chainhash.Hash, re
}()
}

func (m *BabylonMsgSender) sendUndelegationAsync(stakingTxHash *chainhash.Hash, req *sendUndelegationRequest) {
// do not check the error, as only way for it to return err is if provided context would be cancelled
// which can't happen here
_ = m.s.Acquire(context.Background(), 1)
m.wg.Add(1)
go func() {
defer m.s.Release(1)
defer m.wg.Done()
// TODO pass context to undelegate
txResp, err := m.cl.Undelegate(req.ur)

if err != nil {
if errors.Is(err, ErrInvalidBabylonExecution) {
// Additional logging if for some reason we send unbonding request which was
// accepted by babylon, but failed execution
m.logger.WithFields(logrus.Fields{
"btcTxHash": req.stakingTxHash.String(),
"babylonTxHash": txResp.TxHash,
"babylonBlockHeight": txResp.Height,
"babylonErrorCode": txResp.Code,
}).Error("Invalid delegation data sent to babylon")
}

m.logger.WithFields(logrus.Fields{
"btcTxHash": req.stakingTxHash,
"err": err,
}).Error("Error while sending undelegation data to babylon")

req.ErrorChan() <- fmt.Errorf("failed to send unbonding for delegation with staking hash:%s:%w", req.stakingTxHash.String(), err)
}

req.ResultChan() <- txResp
}()
}

func (m *BabylonMsgSender) handleSentToBabylon() {
defer m.wg.Done()
for {
Expand All @@ -219,26 +166,6 @@ func (m *BabylonMsgSender) handleSentToBabylon() {

m.sendDelegationAsync(&stakingTxHash, req)

case req := <-m.sendUndelegationRequestChan:
di, err := m.cl.QueryDelegationInfo(req.stakingTxHash)

if err != nil {
req.ErrorChan() <- fmt.Errorf("failed to retrieve delegation info for staking tx with hash: %s: %w", req.stakingTxHash.String(), err)
continue
}

if !di.Active {
req.ErrorChan() <- fmt.Errorf("cannot sent unbonding request for staking tx with hash: %s, as delegation is not active", req.stakingTxHash.String())
continue
}

if di.UndelegationInfo != nil {
req.ErrorChan() <- fmt.Errorf("cannot sent unbonding request for staking tx with hash: %s, as unbonding request was already sent", req.stakingTxHash.String())
continue
}

m.sendUndelegationAsync(req.stakingTxHash, req)

case <-m.quit:
return
}
Expand All @@ -258,17 +185,3 @@ func (m *BabylonMsgSender) SendDelegation(
)

}

// TODO: Curenttly not used.
// We may introduce the option for staker to self report unbonding tx to babylon.
func (m *BabylonMsgSender) SendUndelegation(
ur *UndelegationRequest,
) (*pv.RelayerTxResponse, error) {
req := newSendUndelegationRequest(ur)

return utils.SendRequestAndWaitForResponseOrQuit[*pv.RelayerTxResponse, *sendUndelegationRequest](
&req,
m.sendUndelegationRequestChan,
m.quit,
)
}
71 changes: 37 additions & 34 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.3.0
github.com/avast/retry-go/v4 v4.5.1
github.com/babylonlabs-io/babylon v0.13.0
github.com/babylonlabs-io/babylon v0.14.0
github.com/babylonlabs-io/networks/parameters v0.2.2
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.2
Expand All @@ -18,16 +18,16 @@ require (
github.com/btcsuite/btcwallet/wallet/txrules v1.2.0
github.com/btcsuite/btcwallet/wallet/txsizes v1.2.3
github.com/btcsuite/btcwallet/walletdb v1.4.0
github.com/cometbft/cometbft v0.38.7
github.com/cosmos/cosmos-sdk v0.50.6
github.com/cometbft/cometbft v0.38.9
github.com/cosmos/cosmos-sdk v0.50.7
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/relayer/v2 v2.5.2
github.com/jessevdk/go-flags v1.5.0
github.com/jsternberg/zap-logfmt v1.3.0
github.com/lightningnetwork/lnd v0.16.4-beta.rc1
github.com/lightningnetwork/lnd/kvdb v1.4.1
github.com/ory/dockertest/v3 v3.10.0
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/client_golang v1.19.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/urfave/cli v1.22.14
Expand All @@ -38,31 +38,31 @@ require (
)

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.36.0 // indirect
cosmossdk.io/api v0.7.4 // indirect
cloud.google.com/go/storage v1.38.0 // indirect
cosmossdk.io/api v0.7.5 // indirect
cosmossdk.io/client/v2 v2.0.0-beta.1 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/core v0.11.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/store v1.1.0 // indirect
cosmossdk.io/x/circuit v0.1.0 // indirect
cosmossdk.io/x/evidence v0.1.0 // indirect
cosmossdk.io/x/feegrant v0.1.0 // indirect
cosmossdk.io/x/nft v0.1.0 // indirect
cosmossdk.io/x/circuit v0.1.1 // indirect
cosmossdk.io/x/evidence v0.1.1 // indirect
cosmossdk.io/x/feegrant v0.1.1 // indirect
cosmossdk.io/x/nft v0.1.1 // indirect
cosmossdk.io/x/tx v0.13.3 // indirect
cosmossdk.io/x/upgrade v0.1.1 // indirect
cosmossdk.io/x/upgrade v0.1.3 // indirect
dario.cat/mergo v1.0.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/CosmWasm/wasmd v0.51.0 // indirect
github.com/CosmWasm/wasmvm/v2 v2.0.1 // indirect
github.com/CosmWasm/wasmd v0.52.0 // indirect
github.com/CosmWasm/wasmvm/v2 v2.1.3 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand Down Expand Up @@ -101,11 +101,12 @@ require (
github.com/cosmos/cosmos-db v1.0.2 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.12 // indirect
github.com/cosmos/iavl v1.1.2 // indirect
github.com/cosmos/gogoproto v1.5.0 // indirect
github.com/cosmos/iavl v1.2.0 // indirect
github.com/cosmos/ibc-go/modules/apps/callbacks v0.2.1-0.20231113120333-342c00b0f8bd // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.0 // indirect
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240429153234-e1e6da7e4ead // indirect
github.com/cosmos/ibc-go/v8 v8.3.0 // indirect
github.com/cosmos/ibc-go/v8 v8.3.2 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
Expand Down Expand Up @@ -158,7 +159,7 @@ 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.3 // 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
Expand All @@ -168,14 +169,15 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.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
github.com/hashicorp/go-getter v1.7.5 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.3 // indirect
github.com/hashicorp/go-plugin v1.5.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
Expand Down Expand Up @@ -245,7 +247,7 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect
github.com/pierrec/lz4/v4 v4.1.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -258,18 +260,19 @@ require (
github.com/rogpeppe/fastuuid v1.2.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shamaton/msgpack/v2 v2.2.0 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/strangelove-ventures/cometbft-client v0.1.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
Expand All @@ -288,22 +291,22 @@ require (
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.etcd.io/etcd/api/v3 v3.5.10 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.10 // indirect
go.etcd.io/etcd/client/v2 v2.305.10 // indirect
go.etcd.io/etcd/client/v3 v3.5.10 // indirect
go.etcd.io/etcd/api/v3 v3.5.12 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.12 // indirect
go.etcd.io/etcd/client/v2 v2.305.12 // indirect
go.etcd.io/etcd/client/v3 v3.5.12 // indirect
go.etcd.io/etcd/pkg/v3 v3.5.7 // indirect
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
Expand All @@ -315,10 +318,10 @@ require (
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/api v0.171.0 // indirect
google.golang.org/appengine v1.6.8 // 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/api v0.0.0-20240311132316-a219d84964c2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
gopkg.in/errgo.v1 v1.0.1 // indirect
Expand Down
Loading

0 comments on commit 65a3178

Please sign in to comment.