Skip to content

Commit

Permalink
Merge branch 'main' into try-rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Sep 24, 2024
2 parents bace5ce + 8bb68ff commit d884717
Show file tree
Hide file tree
Showing 49 changed files with 1,086 additions and 460 deletions.
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- 'main'
- 'dev'
tags:
- '*'

Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Contributing

Finality-provider repository follows the same contributing rules as
[Babylon node](https://github.com/babylonlabs-io/babylon/blob/main/CONTRIBUTING.md)
repository.
5 changes: 5 additions & 0 deletions RELEASE_PROCESS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release Process

Finality-provider repository follows the same release process rules as
[Babylon node](https://github.com/babylonlabs-io/babylon/blob/main/RELEASE_PROCESS.md)
repository.
4 changes: 2 additions & 2 deletions clientcontroller/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ type ClientController interface {

// Note: the following queries are only for PoC

// QueryFinalityProviderSlashed queries if the finality provider is slashed
// QueryFinalityProviderSlashedOrJailed queries if the finality provider is slashed or slashed
// Note: if the FP wants to get the information from the consumer chain directly, they should add this interface
// function in ConsumerController. (https://github.com/babylonchain/finality-provider/pull/335#discussion_r1606175344)
QueryFinalityProviderSlashed(fpPk *btcec.PublicKey) (bool, error)
QueryFinalityProviderSlashedOrJailed(fpPk *btcec.PublicKey) (slashed bool, jailed bool, err error)

Close() error
}
Expand Down
42 changes: 25 additions & 17 deletions clientcontroller/babylon/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ func NewBabylonController(

bbnConfig := fpcfg.BBNConfigToBabylonConfig(cfg)

if err := bbnConfig.Validate(); err != nil {
return nil, fmt.Errorf("invalid config for Babylon client: %w", err)
}

bc, err := bbnclient.New(
&bbnConfig,
logger,
Expand All @@ -59,6 +55,12 @@ func NewBabylonController(
return nil, fmt.Errorf("failed to create Babylon client: %w", err)
}

// makes sure that the key in config really exists and it is a valid bech 32 addr
// to allow using mustGetTxSigner
if _, err := bc.GetAddr(); err != nil {
return nil, err
}

return &BabylonController{
bc,
cfg,
Expand Down Expand Up @@ -142,16 +144,14 @@ func (bc *BabylonController) RegisterFinalityProvider(
return &types.TxResponse{TxHash: res.TxHash}, nil
}

func (bc *BabylonController) QueryFinalityProviderSlashed(fpPk *btcec.PublicKey) (bool, error) {
func (bc *BabylonController) QueryFinalityProviderSlashedOrJailed(fpPk *btcec.PublicKey) (slashed bool, jailed bool, err error) {
fpPubKey := bbntypes.NewBIP340PubKeyFromBTCPK(fpPk)
res, err := bc.bbnClient.QueryClient.FinalityProvider(fpPubKey.MarshalHex())
if err != nil {
return false, fmt.Errorf("failed to query the finality provider %s: %v", fpPubKey.MarshalHex(), err)
return false, false, fmt.Errorf("failed to query the finality provider %s: %v", fpPubKey.MarshalHex(), err)
}

slashed := res.FinalityProvider.SlashedBtcHeight > 0

return slashed, nil
return res.FinalityProvider.SlashedBtcHeight > 0, res.FinalityProvider.Jailed, nil
}

// QueryFinalityProviderHasPower queries whether the finality provider has voting power at a given height
Expand All @@ -161,7 +161,7 @@ func (bc *BabylonController) QueryFinalityProviderHasPower(fpPk *btcec.PublicKey
blockHeight,
)
if err != nil {
return false, fmt.Errorf("failed to query BTC delegations: %w", err)
return false, fmt.Errorf("failed to query Finality Voting Power at Height %d: %w", blockHeight, err)
}

return res.VotingPower > 0, nil
Expand Down Expand Up @@ -332,7 +332,15 @@ func (bc *BabylonController) QueryBtcLightClientTip() (*btclctypes.BTCHeaderInfo
return res.Header, nil
}

// TODO: this method only used in test. this should be refactored out to test files
func (bc *BabylonController) QueryCurrentEpoch() (uint64, error) {
res, err := bc.bbnClient.QueryClient.CurrentEpoch()
if err != nil {
return 0, fmt.Errorf("failed to query BTC tip: %v", err)
}

return res.CurrentEpoch, nil
}

func (bc *BabylonController) QueryVotesAtHeight(height uint64) ([]bbntypes.BIP340PubKey, error) {
res, err := bc.bbnClient.QueryClient.VotesAtHeight(height)
if err != nil {
Expand Down Expand Up @@ -387,20 +395,16 @@ func (bc *BabylonController) QueryStakingParams() (*types.StakingParams, error)
}
covenantPks = append(covenantPks, covPk)
}
slashingAddress, err := btcutil.DecodeAddress(stakingParamRes.Params.SlashingAddress, bc.btcParams)
if err != nil {
return nil, err
}

return &types.StakingParams{
ComfirmationTimeBlocks: ckptParamRes.Params.BtcConfirmationDepth,
FinalizationTimeoutBlocks: ckptParamRes.Params.CheckpointFinalizationTimeout,
MinSlashingTxFeeSat: btcutil.Amount(stakingParamRes.Params.MinSlashingTxFeeSat),
CovenantPks: covenantPks,
SlashingAddress: slashingAddress,
SlashingPkScript: stakingParamRes.Params.SlashingPkScript,
CovenantQuorum: stakingParamRes.Params.CovenantQuorum,
SlashingRate: stakingParamRes.Params.SlashingRate,
MinUnbondingTime: stakingParamRes.Params.MinUnbondingTime,
MinUnbondingTime: stakingParamRes.Params.MinUnbondingTimeBlocks,
}, nil
}

Expand Down Expand Up @@ -460,3 +464,7 @@ func (bc *BabylonController) RegisterConsumerChain(id, name, description string)

return &types.TxResponse{TxHash: res.TxHash}, nil
}

func (bc *BabylonController) GetBBNClient() *bbnclient.Client {
return bc.bbnClient
}
1 change: 1 addition & 0 deletions clientcontroller/retry_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var unrecoverableErrors = []*sdkErr.Error{
finalitytypes.ErrPubRandNotFound,
finalitytypes.ErrTooFewPubRand,
btcstakingtypes.ErrFpAlreadySlashed,
btcstakingtypes.ErrFpAlreadyJailed,
}

// IsUnrecoverable returns true when the error is in the unrecoverableErrors list
Expand Down
2 changes: 1 addition & 1 deletion eotsmanager/proto/eotsmanager.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 25 additions & 12 deletions eotsmanager/proto/eotsmanager_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions finality-provider/cmd/fpd/daemon/daemon_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"

"cosmossdk.io/math"
"github.com/babylonlabs-io/babylon/types"
bbntypes "github.com/babylonlabs-io/babylon/types"
"github.com/cosmos/cosmos-sdk/client"
sdkflags "github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -66,6 +67,12 @@ func CommandCreateFP() *cobra.Command {
Use: "create-finality-provider",
Aliases: []string{"cfp"},
Short: "Create a finality provider object and save it in database.",
Long: fmt.Sprintf(`
Create a new finality provider object and store it in the finality provider database.
It needs to have an operating EOTS manager available and running.
If the flag %s is set, it will ask for the key record from the EOTS manager for the
corresponding EOTS public key. If it is not set, it will create a new EOTS key`, fpEotsPkFlag),
Example: fmt.Sprintf(`fpd create-finality-provider --daemon-address %s ...`, defaultFpdDaemonAddress),
Args: cobra.NoArgs,
RunE: fpcmd.RunEWithClientCtx(runCommandCreateFP),
Expand All @@ -84,6 +91,7 @@ func CommandCreateFP() *cobra.Command {
f.String(websiteFlag, "", "An optional website link")
f.String(securityContactFlag, "", "An email for security contact")
f.String(detailsFlag, "", "Other optional details")
f.String(fpEotsPkFlag, "", "Optional hex EOTS public key, if not provided a new one will be created")

return cmd
}
Expand Down Expand Up @@ -135,10 +143,24 @@ func runCommandCreateFP(ctx client.Context, cmd *cobra.Command, _ []string) erro
return fmt.Errorf("failed to read flag %s: %w", hdPathFlag, err)
}

eotsPkHex, err := flags.GetString(fpEotsPkFlag)
if err != nil {
return fmt.Errorf("failed to read flag %s: %w", fpEotsPkFlag, err)
}

if len(eotsPkHex) > 0 {
// if is set, validate before the creation request
_, err := types.NewBIP340PubKeyFromHex(eotsPkHex)
if err != nil {
return fmt.Errorf("invalid eots public key %s: %w", eotsPkHex, err)
}
}

info, err := client.CreateFinalityProvider(
context.Background(),
keyName,
chainId,
eotsPkHex,
passphrase,
hdPath,
description,
Expand Down
10 changes: 5 additions & 5 deletions finality-provider/cmd/fpd/daemon/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"fmt"

"cosmossdk.io/math"
fpcmd "github.com/babylonlabs-io/finality-provider/finality-provider/cmd"
fpcfg "github.com/babylonlabs-io/finality-provider/finality-provider/config"
dc "github.com/babylonlabs-io/finality-provider/finality-provider/service/client"
bbn "github.com/babylonlabs-io/babylon/types"
btcstktypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
"github.com/cosmos/cosmos-sdk/client"
sdkflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/spf13/cobra"

bbn "github.com/babylonlabs-io/babylon/types"
btcstktypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
fpcmd "github.com/babylonlabs-io/finality-provider/finality-provider/cmd"
fpcfg "github.com/babylonlabs-io/finality-provider/finality-provider/config"
dc "github.com/babylonlabs-io/finality-provider/finality-provider/service/client"
)

// FinalityProviderSigned wraps the finality provider by adding the
Expand Down
2 changes: 1 addition & 1 deletion finality-provider/cmd/fpd/daemon/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func runInitCmd(ctx client.Context, cmd *cobra.Command, args []string) error {
homePath = util.CleanAndExpandPath(homePath)
force, err := cmd.Flags().GetBool(forceFlag)
if err != nil {
return fmt.Errorf("failed to read flag %s: %w", fpEotsPkFlag, err)
return fmt.Errorf("failed to read flag %s: %w", forceFlag, err)
}

if util.FileExists(homePath) && !force {
Expand Down
5 changes: 3 additions & 2 deletions finality-provider/cmd/fpd/daemon/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package daemon
import (
"strings"

helper "github.com/babylonlabs-io/finality-provider/finality-provider/cmd"
fpcfg "github.com/babylonlabs-io/finality-provider/finality-provider/config"
"github.com/cosmos/cosmos-sdk/client"
sdkflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
goflags "github.com/jessevdk/go-flags"
"github.com/spf13/cobra"

helper "github.com/babylonlabs-io/finality-provider/finality-provider/cmd"
fpcfg "github.com/babylonlabs-io/finality-provider/finality-provider/config"
)

// CommandKeys returns the keys group command and updates the add command to do a
Expand Down
5 changes: 0 additions & 5 deletions finality-provider/cmd/fpd/daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ func loadApp(
return nil, fmt.Errorf("failed to create finality-provider app: %v", err)
}

// sync finality-provider status
if err := fpApp.SyncFinalityProviderStatus(); err != nil {
return nil, fmt.Errorf("failed to sync finality-provider status: %w", err)
}

return fpApp, nil
}

Expand Down
Loading

0 comments on commit d884717

Please sign in to comment.