Skip to content

Commit

Permalink
chore(*): bump babylon to v0.13.0 (#80)
Browse files Browse the repository at this point in the history
Update babylon to v0.13.0

---------

Co-authored-by: Lazar <[email protected]>
  • Loading branch information
RafilxTenfen and Lazar955 authored Oct 16, 2024
1 parent 8284925 commit 02afa9d
Show file tree
Hide file tree
Showing 33 changed files with 170 additions and 114 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Improvements

* [#80](https://github.com/babylonlabs-io/vigilante/pull/80) bump babylon to use
uint32 in BTC block heights and BLS valset response
* [#79](https://github.com/babylonlabs-io/vigilante/pull/79) handle no change output when building tx

* [#77](https://github.com/babylonlabs-io/vigilante/pull/77) add arm64 static build

* [#76](https://github.com/babylonlabs-io/vigilante/pull/76) add goreleaser
* [#76](https://github.com/babylonlabs-io/vigilante/pull/76) add goreleaser
setup and move out changelog reminder
6 changes: 3 additions & 3 deletions btcclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
type BTCClient interface {
Stop()
WaitForShutdown()
GetBestBlock() (uint64, error)
GetBestBlock() (uint32, error)
GetBlockByHash(blockHash *chainhash.Hash) (*types.IndexedBlock, *wire.MsgBlock, error)
FindTailBlocksByHeight(height uint64) ([]*types.IndexedBlock, error)
GetBlockByHeight(height uint64) (*types.IndexedBlock, *wire.MsgBlock, error)
FindTailBlocksByHeight(height uint32) ([]*types.IndexedBlock, error)
GetBlockByHeight(height uint32) (*types.IndexedBlock, *wire.MsgBlock, error)
GetTxOut(txHash *chainhash.Hash, index uint32, mempool bool) (*btcjson.GetTxOutResult, error)
SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (*chainhash.Hash, error)
GetTransaction(txHash *chainhash.Hash) (*btcjson.GetTransactionResult, error)
Expand Down
18 changes: 9 additions & 9 deletions btcclient/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
)

// GetBestBlock returns the height of the best block
func (c *Client) GetBestBlock() (uint64, error) {
func (c *Client) GetBestBlock() (uint32, error) {
height, err := c.getBlockCountWithRetry()
if err != nil {
return 0, err
}

return uint64(height), nil
return uint32(height), nil
}

func (c *Client) GetBlockByHash(blockHash *chainhash.Hash) (*types.IndexedBlock, *wire.MsgBlock, error) {
Expand All @@ -38,7 +38,7 @@ func (c *Client) GetBlockByHash(blockHash *chainhash.Hash) (*types.IndexedBlock,
}

// GetBlockByHeight returns a block with the given height
func (c *Client) GetBlockByHeight(height uint64) (*types.IndexedBlock, *wire.MsgBlock, error) {
func (c *Client) GetBlockByHeight(height uint32) (*types.IndexedBlock, *wire.MsgBlock, error) {
blockHash, err := c.getBlockHashWithRetry(height)
if err != nil {
return nil, nil, fmt.Errorf("failed to get block by height %d: %w", height, err)
Expand Down Expand Up @@ -78,7 +78,7 @@ func (c *Client) getBestBlockHashWithRetry() (*chainhash.Hash, error) {
return blockHash, nil
}

func (c *Client) getBlockHashWithRetry(height uint64) (*chainhash.Hash, error) {
func (c *Client) getBlockHashWithRetry(height uint32) (*chainhash.Hash, error) {
var (
blockHash *chainhash.Hash
err error
Expand All @@ -96,7 +96,7 @@ func (c *Client) getBlockHashWithRetry(height uint64) (*chainhash.Hash, error) {
retry.Attempts(c.maxRetryTimes),
); err != nil {
c.logger.Debug(
"failed to query the block hash", zap.Uint64("height", height), zap.Error(err))
"failed to query the block hash", zap.Uint32("height", height), zap.Error(err))
}

return blockHash, nil
Expand Down Expand Up @@ -152,8 +152,8 @@ func (c *Client) getBlockVerboseWithRetry(hash *chainhash.Hash) (*btcjson.GetBlo

// getChainBlocks returns a chain of indexed blocks from the block at baseHeight to the tipBlock
// note: the caller needs to ensure that tipBlock is on the blockchain
func (c *Client) getChainBlocks(baseHeight uint64, tipBlock *types.IndexedBlock) ([]*types.IndexedBlock, error) {
tipHeight := uint64(tipBlock.Height)
func (c *Client) getChainBlocks(baseHeight uint32, tipBlock *types.IndexedBlock) ([]*types.IndexedBlock, error) {
tipHeight := uint32(tipBlock.Height)
if tipHeight < baseHeight {
return nil, fmt.Errorf("the tip block height %v is less than the base height %v", tipHeight, baseHeight)
}
Expand Down Expand Up @@ -195,13 +195,13 @@ func (c *Client) getBestIndexedBlock() (*types.IndexedBlock, error) {
}

// FindTailBlocksByHeight returns the chain of blocks from the block at baseHeight to the tip
func (c *Client) FindTailBlocksByHeight(baseHeight uint64) ([]*types.IndexedBlock, error) {
func (c *Client) FindTailBlocksByHeight(baseHeight uint32) ([]*types.IndexedBlock, error) {
tipIb, err := c.getBestIndexedBlock()
if err != nil {
return nil, err
}

if baseHeight > uint64(tipIb.Height) {
if baseHeight > uint32(tipIb.Height) {
return nil, fmt.Errorf("invalid base height %d, should not be higher than tip block %d", baseHeight, tipIb.Height)
}

Expand Down
2 changes: 2 additions & 0 deletions btcstaking-tracker/btcslasher/bootstrapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func FuzzSlasher_Bootstrapping(f *testing.F) {
covPks,
bsParams.Params.CovenantQuorum,
slashingPkScript,
1000,
100,
1100,
delAmount,
Expand Down Expand Up @@ -150,6 +151,7 @@ func FuzzSlasher_Bootstrapping(f *testing.F) {
covPks,
bsParams.Params.CovenantQuorum,
slashingPkScript,
1000,
100,
1100,
delAmount,
Expand Down
7 changes: 4 additions & 3 deletions btcstaking-tracker/btcslasher/slasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package btcslasher
import (
"context"
"fmt"
"sync"
"time"

"github.com/babylonlabs-io/vigilante/types"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"golang.org/x/sync/semaphore"
"sync"
"time"

bbn "github.com/babylonlabs-io/babylon/types"
bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
Expand Down Expand Up @@ -35,7 +36,7 @@ type BTCSlasher struct {

// parameters
netParams *chaincfg.Params
btcFinalizationTimeout uint64
btcFinalizationTimeout uint32
retrySleepTime time.Duration
maxRetrySleepTime time.Duration
maxRetryTimes uint
Expand Down
3 changes: 3 additions & 0 deletions btcstaking-tracker/btcslasher/slasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func FuzzSlasher(f *testing.F) {
covenantBtcPks,
bsParams.Params.CovenantQuorum,
slashingPkScript,
999,
100,
1099,
delAmount,
Expand Down Expand Up @@ -142,6 +143,7 @@ func FuzzSlasher(f *testing.F) {
covenantBtcPks,
bsParams.Params.CovenantQuorum,
slashingPkScript,
1000,
100,
1100,
delAmount,
Expand Down Expand Up @@ -169,6 +171,7 @@ func FuzzSlasher(f *testing.F) {
covenantBtcPks,
bsParams.Params.CovenantQuorum,
slashingPkScript,
1000,
100,
1100,
delAmount,
Expand Down
2 changes: 2 additions & 0 deletions btcstaking-tracker/btcslasher/slasher_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func BuildUnbondingSlashingTxWithWitness(
0,
delSlashingSig,
covAdaptorSigs,
bsParams.CovenantQuorum,
slashingSpendInfo,
)
if err != nil {
Expand Down Expand Up @@ -364,6 +365,7 @@ func BuildSlashingTxWithWitness(
d.StakingOutputIdx,
delSigSlash,
covAdaptorSigs,
bsParams.CovenantQuorum,
slashingSpendInfo,
)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package stakingeventwatcher
import (
"context"
"fmt"

btcctypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types"

"cosmossdk.io/errors"
Expand All @@ -18,7 +19,7 @@ import (
type Delegation struct {
StakingTx *wire.MsgTx
StakingOutputIdx uint32
DelegationStartHeight uint64
DelegationStartHeight uint32
UnbondingOutput *wire.TxOut
HasProof bool
}
Expand Down
9 changes: 5 additions & 4 deletions btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"context"
"errors"
"fmt"
"sync"
"sync/atomic"
"time"

btcctypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types"
btcstakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
"github.com/babylonlabs-io/vigilante/btcclient"
"github.com/babylonlabs-io/vigilante/types"
"sync"
"sync/atomic"
"time"

"github.com/avast/retry-go/v4"
"github.com/babylonlabs-io/vigilante/config"
Expand Down Expand Up @@ -50,7 +51,7 @@ type newDelegation struct {
stakingTxHash chainhash.Hash
stakingTx *wire.MsgTx
stakingOutputIdx uint32
delegationStartHeight uint64
delegationStartHeight uint32
unbondingOutput *wire.TxOut
}

Expand Down
4 changes: 2 additions & 2 deletions btcstaking-tracker/stakingeventwatcher/tracked_delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type TrackedDelegation struct {
StakingTx *wire.MsgTx
StakingOutputIdx uint32
UnbondingOutput *wire.TxOut
DelegationStartHeight uint64
DelegationStartHeight uint32
}

type TrackedDelegations struct {
Expand Down Expand Up @@ -61,7 +61,7 @@ func (td *TrackedDelegations) AddDelegation(
StakingTx *wire.MsgTx,
StakingOutputIdx uint32,
UnbondingOutput *wire.TxOut,
delegationStartHeight uint64,
delegationStartHeight uint32,
shouldUpdate bool,
) (*TrackedDelegation, error) {
delegation := &TrackedDelegation{
Expand Down
7 changes: 4 additions & 3 deletions e2etest/reporter_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
package e2etest

import (
"github.com/babylonlabs-io/vigilante/btcclient"
"github.com/babylonlabs-io/vigilante/netparams"
"sync"
"testing"
"time"

"github.com/babylonlabs-io/vigilante/btcclient"
"github.com/babylonlabs-io/vigilante/netparams"

"github.com/babylonlabs-io/vigilante/metrics"
"github.com/babylonlabs-io/vigilante/reporter"
"github.com/stretchr/testify/require"
Expand All @@ -27,7 +28,7 @@ func (tm *TestManager) BabylonBTCChainMatchesBtc(t *testing.T) bool {
bbnBtcLcTip, err := tm.BabylonClient.BTCHeaderChainTip()
require.NoError(t, err)

return uint64(tipHeight) == bbnBtcLcTip.Header.Height && tipHash.String() == bbnBtcLcTip.Header.HashHex
return uint32(tipHeight) == bbnBtcLcTip.Header.Height && tipHash.String() == bbnBtcLcTip.Header.HashHex
}

func (tm *TestManager) GenerateAndSubmitBlockNBlockStartingFromDepth(t *testing.T, N int, depth uint32) {
Expand Down
11 changes: 6 additions & 5 deletions e2etest/test_manager_btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package e2etest
import (
"bytes"
"context"
sdkmath "cosmossdk.io/math"
"encoding/hex"
"fmt"
"math/rand"
"testing"
"time"

sdkmath "cosmossdk.io/math"
"github.com/avast/retry-go/v4"
"github.com/babylonlabs-io/babylon/btcstaking"
txformat "github.com/babylonlabs-io/babylon/btctxformatter"
Expand All @@ -29,9 +33,6 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/relayer/v2/relayer/provider"
"github.com/stretchr/testify/require"
"math/rand"
"testing"
"time"
)

var (
Expand All @@ -43,7 +44,7 @@ var (
)
)

func (tm *TestManager) getBTCUnbondingTime(t *testing.T) uint64 {
func (tm *TestManager) getBTCUnbondingTime(t *testing.T) uint32 {
bsParams, err := tm.BabylonClient.BTCStakingParams()
require.NoError(t, err)
btccParams, err := tm.BabylonClient.BTCCheckpointParams()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
cosmossdk.io/log v1.4.1
cosmossdk.io/math v1.3.0
github.com/avast/retry-go/v4 v4.6.0
github.com/babylonlabs-io/babylon v0.12.0
github.com/babylonlabs-io/babylon v0.13.0
github.com/boljen/go-bitmap v0.0.0-20151001105940-23cd2fb0ce7d
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,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.12.0 h1:s2OTcxpk0RzrkVBnVTfnPdJVYDSqnm/33YKPQqEzNCE=
github.com/babylonlabs-io/babylon v0.12.0/go.mod h1:ZOrTde9vs2xoqGTFw4xhupu2CMulnpywiuk0eh4kPOw=
github.com/babylonlabs-io/babylon v0.13.0 h1:h7cazmFmItePvZHEbLhDbsq2l7xN4e2AjDHRM7zDLkg=
github.com/babylonlabs-io/babylon v0.13.0/go.mod h1:cxRwVqVLoJ39FpyovTEHJLu1lwwrM1tE8davu7nRHwY=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down
3 changes: 2 additions & 1 deletion monitor/btcscanner/block_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package btcscanner
import (
"errors"
"fmt"

"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs"
)
Expand Down Expand Up @@ -91,7 +92,7 @@ func (bs *BtcScanner) handleNewBlock(height int32, header *wire.BlockHeader) err
bs.unconfirmedBlockCache.Add(ib)

// still unconfirmed
if bs.unconfirmedBlockCache.Size() <= bs.k {
if uint32(bs.unconfirmedBlockCache.Size()) <= bs.k {
return nil
}

Expand Down
Loading

0 comments on commit 02afa9d

Please sign in to comment.