Skip to content

Commit

Permalink
Bump babylon v17 (#99)
Browse files Browse the repository at this point in the history
* bump babylon version

* Remove restaking test
  • Loading branch information
KonradStaniec authored Nov 22, 2024
1 parent 10a89d0 commit ee7aca8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 75 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Improvements

* [#99](https://github.com/babylonlabs-io/btc-staker/pull/99) Bump babylon version
and adapt staker to the changes

## v0.11.0

### Improvements
Expand Down
11 changes: 1 addition & 10 deletions babylonclient/babyloncontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,6 @@ func (bc *BabylonController) Params() (*StakingParams, error) {
return nil, err
}

minUnbondingTimeU64 := sdkmath.Max[uint32](
bccParams.CheckpointFinalizationTimeout,
uint32(stakingTrackerParams.MinUnbondingTime),
)

if minUnbondingTimeU64 > math.MaxUint16 {
return nil, fmt.Errorf("minimum unbonding time should fit in a uint16")
}

return &StakingParams{
ConfirmationTimeBlocks: bccParams.BtcConfirmationDepth,
FinalizationTimeoutBlocks: bccParams.CheckpointFinalizationTimeout,
Expand All @@ -188,7 +179,7 @@ func (bc *BabylonController) Params() (*StakingParams, error) {
MinSlashingTxFeeSat: stakingTrackerParams.MinSlashingFee,
SlashingRate: stakingTrackerParams.SlashingRate,
CovenantQuruomThreshold: stakingTrackerParams.CovenantQuruomThreshold,
MinUnbondingTime: uint16(minUnbondingTimeU64),
MinUnbondingTime: stakingTrackerParams.MinUnbondingTime,
UnbondingFee: stakingTrackerParams.UnbondingFee,
MinStakingTime: stakingTrackerParams.MinStakingTime,
MaxStakingTime: stakingTrackerParams.MaxStakingTime,
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.23.1

require (
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.3.0
cosmossdk.io/math v1.4.0
github.com/avast/retry-go/v4 v4.5.1
github.com/babylonlabs-io/babylon v0.16.0
github.com/babylonlabs-io/babylon v0.17.1
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,7 +18,7 @@ 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.14
github.com/cometbft/cometbft v0.38.15
github.com/cosmos/cosmos-sdk v0.50.9
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/relayer/v2 v2.5.2
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,8 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ=
cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk=
cosmossdk.io/store v1.1.0 h1:LnKwgYMc9BInn9PhpTFEQVbL9UK475G2H911CGGnWHk=
cosmossdk.io/store v1.1.0/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng=
cosmossdk.io/x/circuit v0.1.1 h1:KPJCnLChWrxD4jLwUiuQaf5mFD/1m7Omyo7oooefBVQ=
Expand Down Expand Up @@ -1432,8 +1432,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX
github.com/aws/aws-sdk-go v1.44.312 h1:llrElfzeqG/YOLFFKjg1xNpZCFJ2xraIi3PqSuP+95k=
github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonlabs-io/babylon v0.16.0 h1:SwCBwQLC3jRrvBR+jGzfUNstaCvzH1Mu6PTqQ6at+E0=
github.com/babylonlabs-io/babylon v0.16.0/go.mod h1:wEbfZ6NS/mDRP1ina17WB/4oNtpkFL9Z97bp8Ar6okQ=
github.com/babylonlabs-io/babylon v0.17.1 h1:lyWGdR7B49qDw5pllLyTW/HAM5uQWXXPZefjFzy/Xy0=
github.com/babylonlabs-io/babylon v0.17.1/go.mod h1:sT+KG2U+M0tDMNZZ2L5CwlXX0OpagGEs56BiWXqaZFw=
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 @@ -1569,8 +1569,8 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/cometbft/cometbft v0.38.14 h1:ketYsx8uNLSm32GAMbm98SCSNTQ7Ek7VoZonSto+F/A=
github.com/cometbft/cometbft v0.38.14/go.mod h1:xdfvFic9BHPd/MXJZVRH79XK0iLLOkiMw3ynYNhuulk=
github.com/cometbft/cometbft v0.38.15 h1:5veFd8k1uXM27PBg9sMO3hAfRJ3vbh4OmmLf6cVrqXg=
github.com/cometbft/cometbft v0.38.15/go.mod h1:+wh6ap6xctVG+JOHwbl8pPKZ0GeqdPYqISu7F4b43cQ=
github.com/cometbft/cometbft-db v0.15.0 h1:VLtsRt8udD4jHCyjvrsTBpgz83qne5hnL245AcPJVRk=
github.com/cometbft/cometbft-db v0.15.0/go.mod h1:EBrFs1GDRiTqrWXYi4v90Awf/gcdD5ExzdPbg4X8+mk=
github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ=
Expand Down Expand Up @@ -1814,8 +1814,9 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGw
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ=
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/glog v1.2.2 h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY=
github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down
9 changes: 5 additions & 4 deletions itest/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"bytes"
"context"
"fmt"
bbn "github.com/babylonlabs-io/babylon/types"
"github.com/babylonlabs-io/btc-staker/itest/testutil"
"github.com/btcsuite/btcd/btcec/v2"
"regexp"
"strconv"
"strings"
"testing"
"time"

bbn "github.com/babylonlabs-io/babylon/types"
"github.com/babylonlabs-io/btc-staker/itest/testutil"
"github.com/btcsuite/btcd/btcec/v2"

"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -197,7 +198,7 @@ func (m *Manager) RunBabylondResource(
"sh", "-c", fmt.Sprintf(
"babylond testnet --v=1 --output-dir=/home --starting-ip-address=192.168.10.2 "+
"--keyring-backend=test --chain-id=chain-test --btc-finalization-timeout=4 "+
"--btc-confirmation-depth=2 --additional-sender-account --btc-network=regtest "+
"--btc-confirmation-depth=2 --min-unbonding-time=5 --additional-sender-account --btc-network=regtest "+
"--min-staking-time-blocks=200 --min-staking-amount-sat=10000 "+
"--slashing-pk-script=%s --btc-base-header=%s --covenant-quorum=%d "+
"--covenant-pks=%s && chmod -R 777 /home && "+
Expand Down
52 changes: 5 additions & 47 deletions itest/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ func (tm *TestManager) sendWatchedStakingTx(
testStakingData *testStakingData,
params *babylonclient.StakingParams,
) *chainhash.Hash {
unbondingTme := uint16(params.FinalizationTimeoutBlocks) + 1
unbondingTme := params.MinUnbondingTime

stakingInfo, err := staking.BuildStakingInfo(
testStakingData.StakerKey,
Expand Down Expand Up @@ -1355,8 +1355,8 @@ func TestSendingStakingTransactionWithPreApproval(t *testing.T) {
require.NoError(t, err)
require.Len(t, withdrawableTransactionsResp.Transactions, 1)

// We can spend unbonding tx immediately as in e2e test, finalization time is 4 blocks and we locked it
// finalization time + 1 i.e 5 blocks, but to consider unboning tx as confirmed we need to wait for 6 blocks
// We can spend unbonding tx immediately as in e2e test, min unbonding time is 5 blocks and we locked it
// for 5 blocks, but to consider unbonding tx as confirmed we need to wait for 6 blocks
// so at this point time lock should already have passed
tm.spendStakingTxWithHash(t, txHash)
go tm.mineNEmptyBlocks(t, staker.SpendStakeTxConfirmations, false)
Expand Down Expand Up @@ -1648,8 +1648,8 @@ func TestStakingUnbonding(t *testing.T) {
require.NoError(t, err)
require.Len(t, withdrawableTransactionsResp.Transactions, 1)

// We can spend unbonding tx immediately as in e2e test, finalization time is 4 blocks and we locked it
// finalization time + 1 i.e 5 blocks, but to consider unboning tx as confirmed we need to wait for 6 blocks
// We can spend unbonding tx immediately as in e2e test, min unbonding time is 5 blocks and we locked it
// for 5 blocks, but to consider unbonding tx as confirmed we need to wait for 6 blocks
// so at this point time lock should already have passed
tm.spendStakingTxWithHash(t, txHash)
go tm.mineNEmptyBlocks(t, staker.SpendStakeTxConfirmations, false)
Expand Down Expand Up @@ -1839,48 +1839,6 @@ func TestBitcoindWalletBip322Signing(t *testing.T) {
require.NoError(t, err)
}

func TestSendingStakingTransaction_Restaking(t *testing.T) {
t.Parallel()
// need to have at least 300 block on testnet as only then segwit is activated.
// Mature output is out which has 100 confirmations, which means 200mature outputs
// will generate 300 blocks
numMatureOutputs := uint32(200)
ctx, cancel := context.WithCancel(context.Background())
tm := StartManager(t, ctx, numMatureOutputs)
defer tm.Stop(t, cancel)
tm.insertAllMinedBlocksToBabylon(t)

cl := tm.Sa.BabylonController()
params, err := cl.Params()
require.NoError(t, err)

// restaked to 5 finality providers
testStakingData := tm.getTestStakingData(t, tm.WalletPubKey, params.MinStakingTime, 10000, 5)

hashed, err := chainhash.NewHash(datagen.GenRandomByteArray(r, 32))
require.NoError(t, err)
scr, err := txscript.PayToTaprootScript(tm.CovenantPrivKeys[0].PubKey())
require.NoError(t, err)
_, st, erro := tm.Sa.Wallet().TxDetails(hashed, scr)
// query for exsisting tx is not an error, proper state should be returned
require.NoError(t, erro)
require.Equal(t, st, walletcontroller.TxNotFound)

tm.createAndRegisterFinalityProviders(t, testStakingData)

txHash := tm.sendStakingTxBTC(t, testStakingData, false)

go tm.mineNEmptyBlocks(t, params.ConfirmationTimeBlocks, true)
tm.waitForStakingTxState(t, txHash, proto.TransactionState_SENT_TO_BABYLON)

pend, err := tm.BabylonClient.QueryPendingBTCDelegations()
require.NoError(t, err)
require.Len(t, pend, 1)
// need to activate delegation to unbond
tm.insertCovenantSigForDelegation(t, pend[0])
tm.waitForStakingTxState(t, txHash, proto.TransactionState_DELEGATION_ACTIVE)
}

func TestRecoverAfterRestartDuringWithdrawal(t *testing.T) {
t.Parallel()
// need to have at least 300 block on testnet as only then segwit is activated.
Expand Down
2 changes: 1 addition & 1 deletion staker/babylontypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (app *App) buildOwnedDelegation(
externalData.babylonParams.SlashingPkScript,
externalData.babylonParams.UnbondingFee,
// TODO: Possiblity to customize finalization time
externalData.babylonParams.MinUnbondingTime+1,
externalData.babylonParams.MinUnbondingTime,
app.getSlashingFee(externalData.babylonParams.MinSlashingTxFeeSat),
externalData.babylonParams.SlashingRate,
app.network,
Expand Down
6 changes: 3 additions & 3 deletions staker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func slashingTxForStakingTx(
net *chaincfg.Params,
) (*wire.MsgTx, *staking.SpendInfo, error) {
stakerPubKey := delegationData.stakerPublicKey
lockSlashTxLockTime := delegationData.babylonParams.MinUnbondingTime + 1
lockSlashTxLockTime := delegationData.babylonParams.MinUnbondingTime

slashingTx, err := staking.BuildSlashingTxFromStakingTxStrict(
storedTx.StakingTx,
Expand Down Expand Up @@ -509,8 +509,8 @@ func parseWatchStakingRequest(
return nil, fmt.Errorf("failed to watch staking tx due to tx not matching current data: %w", err)
}

if unbondingTime <= currentParams.MinUnbondingTime {
return nil, fmt.Errorf("failed to watch staking tx. Unbonding time must be greater than min unbonding time. Unbonding time: %d, min unbonding time: %d", unbondingTime, currentParams.MinUnbondingTime)
if unbondingTime < currentParams.MinUnbondingTime {
return nil, fmt.Errorf("failed to watch staking tx. Unbonding time must be greater or equal min unbonding time. Unbonding time: %d, min unbonding time: %d", unbondingTime, currentParams.MinUnbondingTime)
}

// 2. Check whether slashing tx match staking tx
Expand Down

0 comments on commit ee7aca8

Please sign in to comment.