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

chore: release v0.11.4 #101

Closed
wants to merge 17 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ jobs:
with:
publish: false
dockerfile: ./covenant-signer/Dockerfile
dockerContext: ./covenant-signer
dockerContext: ./
repoName: covenant-signer
docker_scan: true
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
with:
publish: true
dockerfile: ./covenant-signer/Dockerfile
dockerContext: ./covenant-signer
dockerContext: ./
repoName: covenant-signer
docker_scan: true
permissions:
Expand Down
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,49 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

## v0.11.4

* [#83](https://github.com/babylonlabs-io/covenant-emulator/pull/83) covenant-signer: remove go.mod
* [#95](https://github.com/babylonlabs-io/covenant-emulator/pull/95) removed local signer option
as the covenant emulator should only connect to a remote signer
* [#96](https://github.com/babylonlabs-io/covenant-emulator/pull/96) add pagination to `queryDelegationsWithStatus`
* [#99](https://github.com/babylonlabs-io/covenant-emulator/pull/99) add more metrics
covenant-signer
* [#100](https://github.com/babylonlabs-io/covenant-emulator/pull/100) bump babylon to v1.0.0-rc.4

## v0.11.3

### Bug fixes

* [#91](https://github.com/babylonlabs-io/covenant-emulator/pull/91) Add verification
if the covenant public key was present in the params of the versioned BTC delegation

## v0.11.2

### Bug fixes

* [#84](https://github.com/babylonlabs-io/covenant-emulator/pull/84) Fix bug with
deduplication of already signed delegations

## v0.11.1

### Bug fixes

* [#71](https://github.com/babylonlabs-io/covenant-emulator/pull/71) Fix delegation
response to delegation conversion

## v0.11.0

### Improvements

* [#83](https://github.com/babylonlabs-io/covenant-emulator/pull/83) covenant-signer: remove go.mod
* [#95](https://github.com/babylonlabs-io/covenant-emulator/pull/95) removed local signer option
as the covenant emulator should only connect to a remote signer
* [#96](https://github.com/babylonlabs-io/covenant-emulator/pull/96) add pagination to `queryDelegationsWithStatus`
* [#99](https://github.com/babylonlabs-io/covenant-emulator/pull/99) add more metrics
covenant-signer
* [#100](https://github.com/babylonlabs-io/covenant-emulator/pull/100) bump babylon to v1.0.0-rc.4

## v0.11.3

### Bug fixes
Expand Down
73 changes: 52 additions & 21 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/babylonlabs-io/babylon/client/babylonclient"
bbnclient "github.com/babylonlabs-io/babylon/client/client"
bbntypes "github.com/babylonlabs-io/babylon/types"
btcctypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types"
Expand All @@ -20,14 +21,16 @@ import (
sdkclient "github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkquery "github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/relayer/v2/relayer/provider"
"go.uber.org/zap"

"github.com/babylonlabs-io/covenant-emulator/config"
"github.com/babylonlabs-io/covenant-emulator/types"
)

var _ ClientController = &BabylonController{}
var (
_ ClientController = &BabylonController{}
MaxPaginationLimit = uint64(1000)
)

type BabylonController struct {
bbnClient *bbnclient.Client
Expand Down Expand Up @@ -143,11 +146,11 @@ func (bc *BabylonController) QueryStakingParamsByVersion(version uint32) (*types
}, nil
}

func (bc *BabylonController) reliablySendMsg(msg sdk.Msg) (*provider.RelayerTxResponse, error) {
func (bc *BabylonController) reliablySendMsg(msg sdk.Msg) (*babylonclient.RelayerTxResponse, error) {
return bc.reliablySendMsgs([]sdk.Msg{msg})
}

func (bc *BabylonController) reliablySendMsgs(msgs []sdk.Msg) (*provider.RelayerTxResponse, error) {
func (bc *BabylonController) reliablySendMsgs(msgs []sdk.Msg) (*babylonclient.RelayerTxResponse, error) {
return bc.bbnClient.ReliablySendMsgs(
context.Background(),
msgs,
Expand Down Expand Up @@ -183,39 +186,67 @@ func (bc *BabylonController) SubmitCovenantSigs(covSigs []*types.CovenantSigs) (
return &types.TxResponse{TxHash: res.TxHash, Events: res.Events}, nil
}

func (bc *BabylonController) QueryPendingDelegations(limit uint64) ([]*types.Delegation, error) {
return bc.queryDelegationsWithStatus(btcstakingtypes.BTCDelegationStatus_PENDING, limit)
func (bc *BabylonController) QueryPendingDelegations(limit uint64, filter FilterFn) ([]*types.Delegation, error) {
return bc.queryDelegationsWithStatus(btcstakingtypes.BTCDelegationStatus_PENDING, limit, filter)
}

func (bc *BabylonController) QueryActiveDelegations(limit uint64) ([]*types.Delegation, error) {
return bc.queryDelegationsWithStatus(btcstakingtypes.BTCDelegationStatus_ACTIVE, limit)
return bc.queryDelegationsWithStatus(btcstakingtypes.BTCDelegationStatus_ACTIVE, limit, nil)
}

func (bc *BabylonController) QueryVerifiedDelegations(limit uint64) ([]*types.Delegation, error) {
return bc.queryDelegationsWithStatus(btcstakingtypes.BTCDelegationStatus_VERIFIED, limit)
return bc.queryDelegationsWithStatus(btcstakingtypes.BTCDelegationStatus_VERIFIED, limit, nil)
}

// queryDelegationsWithStatus queries BTC delegations that need a Covenant signature
// with the given status (either pending or unbonding)
// it is only used when the program is running in Covenant mode
func (bc *BabylonController) queryDelegationsWithStatus(status btcstakingtypes.BTCDelegationStatus, limit uint64) ([]*types.Delegation, error) {
func (bc *BabylonController) queryDelegationsWithStatus(status btcstakingtypes.BTCDelegationStatus, delsLimit uint64, filter FilterFn) ([]*types.Delegation, error) {
pgLimit := min(MaxPaginationLimit, delsLimit)
pagination := &sdkquery.PageRequest{
Limit: limit,
Limit: pgLimit,
}

res, err := bc.bbnClient.QueryClient.BTCDelegations(status, pagination)
if err != nil {
return nil, fmt.Errorf("failed to query BTC delegations: %v", err)
}
dels := make([]*types.Delegation, 0, delsLimit)
indexDels := uint64(0)

dels := make([]*types.Delegation, 0, len(res.BtcDelegations))
for _, delResp := range res.BtcDelegations {
del, err := DelegationRespToDelegation(delResp)
for indexDels < delsLimit {
res, err := bc.bbnClient.QueryClient.BTCDelegations(status, pagination)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to query BTC delegations: %v", err)
}

dels = append(dels, del)
for _, delResp := range res.BtcDelegations {
del, err := DelegationRespToDelegation(delResp)
if err != nil {
return nil, err
}

if filter != nil {
accept, err := filter(del)
if err != nil {
return nil, err
}

if !accept {
continue
}
}

dels = append(dels, del)
indexDels++

if indexDels == delsLimit {
return dels, nil
}
}

// if returned a different number of btc delegations than the pagination limit
// it means that there is no more delegations at the store
if uint64(len(res.BtcDelegations)) != pgLimit {
return dels, nil
}
pagination.Key = res.Pagination.NextKey
}

return dels, nil
Expand Down Expand Up @@ -399,7 +430,7 @@ func (bc *BabylonController) CreateBTCDelegation(
// Currently this is only used for e2e tests, probably does not need to add it into the interface
func (bc *BabylonController) RegisterFinalityProvider(
btcPubKey *bbntypes.BIP340PubKey, commission *sdkmath.LegacyDec,
description *stakingtypes.Description, pop *btcstakingtypes.ProofOfPossessionBTC) (*provider.RelayerTxResponse, error) {
description *stakingtypes.Description, pop *btcstakingtypes.ProofOfPossessionBTC) (*babylonclient.RelayerTxResponse, error) {
registerMsg := &btcstakingtypes.MsgCreateFinalityProvider{
Addr: bc.mustGetTxSigner(),
Commission: commission,
Expand All @@ -413,7 +444,7 @@ func (bc *BabylonController) RegisterFinalityProvider(

// Insert BTC block header using rpc client
// Currently this is only used for e2e tests, probably does not need to add it into the interface
func (bc *BabylonController) InsertBtcBlockHeaders(headers []bbntypes.BTCHeaderBytes) (*provider.RelayerTxResponse, error) {
func (bc *BabylonController) InsertBtcBlockHeaders(headers []bbntypes.BTCHeaderBytes) (*babylonclient.RelayerTxResponse, error) {
msg := &btclctypes.MsgInsertHeaders{
Signer: bc.mustGetTxSigner(),
Headers: headers,
Expand Down
23 changes: 13 additions & 10 deletions clientcontroller/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ const (
babylonConsumerChainName = "babylon"
)

type ClientController interface {
// SubmitCovenantSigs submits Covenant signatures to the consumer chain, each corresponding to
// a finality provider that the delegation is (re-)staked to
// it returns tx hash and error
SubmitCovenantSigs(covSigMsgs []*types.CovenantSigs) (*types.TxResponse, error)
type (
FilterFn func(del *types.Delegation) (accept bool, err error)
ClientController interface {
// SubmitCovenantSigs submits Covenant signatures to the consumer chain, each corresponding to
// a finality provider that the delegation is (re-)staked to
// it returns tx hash and error
SubmitCovenantSigs(covSigMsgs []*types.CovenantSigs) (*types.TxResponse, error)

// QueryPendingDelegations queries BTC delegations that are in status of pending
QueryPendingDelegations(limit uint64) ([]*types.Delegation, error)
// QueryPendingDelegations queries BTC delegations that are in status of pending
QueryPendingDelegations(limit uint64, filter FilterFn) ([]*types.Delegation, error)

QueryStakingParamsByVersion(version uint32) (*types.StakingParams, error)
QueryStakingParamsByVersion(version uint32) (*types.StakingParams, error)

Close() error
}
Close() error
}
)

func NewClientController(chainName string, bbnConfig *config.BBNConfig, netParams *chaincfg.Params, logger *zap.Logger) (ClientController, error) {
var (
Expand Down
33 changes: 3 additions & 30 deletions cmd/covd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"

covcfg "github.com/babylonlabs-io/covenant-emulator/config"
"github.com/babylonlabs-io/covenant-emulator/keyring"
"github.com/babylonlabs-io/covenant-emulator/log"
"github.com/babylonlabs-io/covenant-emulator/remotesigner"
"github.com/babylonlabs-io/covenant-emulator/util"
Expand All @@ -23,11 +22,6 @@ var startCommand = cli.Command{
Usage: "Start the Covenant Emulator Daemon",
Description: "Start the Covenant Emulator Daemon. Note that the Covenant key pair should be created beforehand",
Flags: []cli.Flag{
cli.StringFlag{
Name: passphraseFlag,
Usage: "The pass phrase used to encrypt the keys",
Value: defaultPassphrase,
},
cli.StringFlag{
Name: homeFlag,
Usage: "The path to the covenant home directory",
Expand Down Expand Up @@ -59,20 +53,9 @@ func start(ctx *cli.Context) error {
return fmt.Errorf("failed to create rpc client for the consumer chain: %w", err)
}

pwd := ctx.String(passphraseFlag)

var signer covenant.Signer

if cfg.RemoteSignerEnabled {
signer, err = newRemoteSignerFromConfig(cfg)
if err != nil {
return fmt.Errorf("failed to create remote signer from config: %w", err)
}
} else {
signer, err = newSignerFromConfig(cfg, pwd)
if err != nil {
return fmt.Errorf("failed to create keyring signer from config: %w", err)
}
signer, err := newRemoteSignerFromConfig(cfg)
if err != nil {
return fmt.Errorf("failed to create remote signer from config: %w", err)
}

ce, err := covenant.NewCovenantEmulator(cfg, bbnClient, logger, signer)
Expand All @@ -94,16 +77,6 @@ func start(ctx *cli.Context) error {
return srv.RunUntilShutdown()
}

func newSignerFromConfig(cfg *covcfg.Config, passphrase string) (covenant.Signer, error) {
return keyring.NewKeyringSigner(
cfg.BabylonConfig.ChainID,
cfg.BabylonConfig.Key,
cfg.BabylonConfig.KeyDirectory,
cfg.BabylonConfig.KeyringBackend,
passphrase,
)
}

func newRemoteSignerFromConfig(cfg *covcfg.Config) (covenant.Signer, error) {
return remotesigner.NewRemoteSigner(cfg.RemoteSigner), nil
}
21 changes: 9 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ type Config struct {

BabylonConfig *BBNConfig `group:"babylon" namespace:"babylon"`

RemoteSignerEnabled bool `long:"remote-signer-enabled" description:"if true, covenant will use the remote signer to sign transactions"`

RemoteSigner *RemoteSignerCfg `group:"remotesigner" namespace:"remotesigner"`
}

Expand Down Expand Up @@ -134,16 +132,15 @@ func DefaultConfigWithHomePath(homePath string) Config {
metricsCfg := DefaultMetricsConfig()
remoteSignerCfg := DefaultRemoteSignerConfig()
cfg := Config{
LogLevel: defaultLogLevel,
QueryInterval: defaultQueryInterval,
DelegationLimit: defaultDelegationLimit,
SigsBatchSize: defaultSigsBatchSize,
BitcoinNetwork: defaultBitcoinNetwork,
BTCNetParams: defaultBTCNetParams,
Metrics: &metricsCfg,
BabylonConfig: &bbnCfg,
RemoteSignerEnabled: false,
RemoteSigner: &remoteSignerCfg,
LogLevel: defaultLogLevel,
QueryInterval: defaultQueryInterval,
DelegationLimit: defaultDelegationLimit,
SigsBatchSize: defaultSigsBatchSize,
BitcoinNetwork: defaultBitcoinNetwork,
BTCNetParams: defaultBTCNetParams,
Metrics: &metricsCfg,
BabylonConfig: &bbnCfg,
RemoteSigner: &remoteSignerCfg,
}

if err := cfg.Validate(); err != nil {
Expand Down
16 changes: 12 additions & 4 deletions covenant-signer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ RUN apk add --no-cache --update openssh git make build-base linux-headers libc-d
# Build
WORKDIR /go/src/github.com/babylonlabs-io/covenant-emulator/covenant-signer
# Cache dependencies
COPY go.mod go.sum /go/src/github.com/babylonlabs-io/covenant-emulator/covenant-signer/
COPY ../go.mod ../go.sum /go/src/github.com/babylonlabs-io/covenant-emulator/covenant-signer/
# Copy the rest of the files
COPY ./ /go/src/github.com/babylonlabs-io/covenant-emulator/covenant-signer/

RUN CGO_LDFLAGS="$CGO_LDFLAGS -lstdc++ -lm -lsodium" \
CGO_ENABLED=1 \
BUILD_TAGS=$BUILD_TAGS \
# Cosmwasm - Download correct libwasmvm version
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm/v2 | cut -d ' ' -f 2) && \
wget -q https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc."$(uname -m)".a \
-O /lib/libwasmvm_muslc."$(uname -m)".a && \
# verify checksum
wget -q https://github.com/CosmWasm/wasmvm/releases/download/"$WASMVM_VERSION"/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm_muslc."$(uname -m)".a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc."$(uname -m)" | cut -d ' ' -f 1)


RUN BUILD_TAGS=$BUILD_TAGS \
LINK_STATICALLY=true \
make build

Expand Down
2 changes: 1 addition & 1 deletion covenant-signer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ all: build install

build: BUILD_ARGS := $(build_args) -o $(BUILDDIR)

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
$(BUILD_TARGETS): ../go.sum $(BUILDDIR)/
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...

$(BUILDDIR)/:
Expand Down
Loading
Loading