Skip to content

Commit

Permalink
Release v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vitsalis authored Feb 8, 2024
2 parents 495b7c9 + 2e453af commit 78bff6d
Show file tree
Hide file tree
Showing 11 changed files with 545 additions and 509 deletions.
34 changes: 14 additions & 20 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
btclctypes "github.com/babylonchain/babylon/x/btclightclient/types"
btcstakingtypes "github.com/babylonchain/babylon/x/btcstaking/types"
bbnclient "github.com/babylonchain/rpc-client/client"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
sdkclient "github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -147,25 +146,20 @@ func (bc *BabylonController) reliablySendMsgs(msgs []sdk.Msg) (*provider.Relayer

// SubmitCovenantSigs submits the Covenant signature via a MsgAddCovenantSig to Babylon if the daemon runs in Covenant mode
// it returns tx hash and error
func (bc *BabylonController) SubmitCovenantSigs(
covPk *btcec.PublicKey,
stakingTxHash string,
slashingSigs [][]byte,
unbondingSig *schnorr.Signature,
unbondingSlashingSigs [][]byte,
) (*types.TxResponse, error) {
bip340UnbondingSig := bbntypes.NewBIP340SignatureFromBTCSig(unbondingSig)

msg := &btcstakingtypes.MsgAddCovenantSigs{
Signer: bc.mustGetTxSigner(),
Pk: bbntypes.NewBIP340PubKeyFromBTCPK(covPk),
StakingTxHash: stakingTxHash,
SlashingTxSigs: slashingSigs,
UnbondingTxSig: bip340UnbondingSig,
SlashingUnbondingTxSigs: unbondingSlashingSigs,
}

res, err := bc.reliablySendMsg(msg)
func (bc *BabylonController) SubmitCovenantSigs(covSigs []*types.CovenantSigs) (*types.TxResponse, error) {
msgs := make([]sdk.Msg, 0, len(covSigs))
for _, covSig := range covSigs {
bip340UnbondingSig := bbntypes.NewBIP340SignatureFromBTCSig(covSig.UnbondingSig)
msgs = append(msgs, &btcstakingtypes.MsgAddCovenantSigs{
Signer: bc.mustGetTxSigner(),
Pk: bbntypes.NewBIP340PubKeyFromBTCPK(covSig.PublicKey),
StakingTxHash: covSig.StakingTxHash.String(),
SlashingTxSigs: covSig.SlashingSigs,
UnbondingTxSig: bip340UnbondingSig,
SlashingUnbondingTxSigs: covSig.SlashingUnbondingSigs,
})
}
res, err := bc.reliablySendMsgs(msgs)
if err != nil {
return nil, err
}
Expand Down
7 changes: 1 addition & 6 deletions clientcontroller/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package clientcontroller

import (
"fmt"

"github.com/btcsuite/btcd/chaincfg"
"go.uber.org/zap"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"

"github.com/babylonchain/covenant-emulator/config"
"github.com/babylonchain/covenant-emulator/types"
)
Expand All @@ -21,8 +17,7 @@ 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(covPk *btcec.PublicKey, stakingTxHash string,
sigs [][]byte, unbondingSig *schnorr.Signature, unbondingSlashingSigs [][]byte) (*types.TxResponse, error)
SubmitCovenantSigs(covSigMsgs []*types.CovenantSigs) (*types.TxResponse, error)

// QueryPendingDelegations queries BTC delegations that are in status of pending
QueryPendingDelegations(limit uint64) ([]*types.Delegation, error)
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
defaultCovenantKeyName = "covenant-key"
defaultQueryInterval = 15 * time.Second
defaultDelegationLimit = uint64(100)
defaultSigsBatchSize = uint64(20)
defaultBitcoinNetwork = "simnet"
defaultLogDirname = "logs"
)
Expand All @@ -37,6 +38,7 @@ type Config struct {
LogLevel string `long:"loglevel" description:"Logging level for all subsystems" choice:"trace" choice:"debug" choice:"info" choice:"warn" choice:"error" choice:"fatal"`
QueryInterval time.Duration `long:"queryinterval" description:"The interval between each query for pending BTC delegations"`
DelegationLimit uint64 `long:"delegationlimit" description:"The maximum number of delegations that the Covenant processes each time"`
SigsBatchSize uint64 `long:"sigsbatchsize" description:"The maximum number of signatures to send in a single transaction"`
BitcoinNetwork string `long:"bitcoinnetwork" description:"Bitcoin network to run on" choice:"mainnet" choice:"regtest" choice:"testnet" choice:"simnet" choice:"signet"`

BTCNetParams chaincfg.Params
Expand Down Expand Up @@ -119,6 +121,7 @@ func DefaultConfigWithHomePath(homePath string) Config {
LogLevel: defaultLogLevel,
QueryInterval: defaultQueryInterval,
DelegationLimit: defaultDelegationLimit,
SigsBatchSize: defaultSigsBatchSize,
BitcoinNetwork: defaultBitcoinNetwork,
BTCNetParams: defaultBTCNetParams,
BabylonConfig: &bbnCfg,
Expand Down
Loading

0 comments on commit 78bff6d

Please sign in to comment.