Skip to content

Commit

Permalink
backport: fpd panics on jailed finality provider (#78) (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry authored Oct 1, 2024
1 parent 8bb68ff commit 5b02689
Show file tree
Hide file tree
Showing 19 changed files with 675 additions and 243 deletions.
21 changes: 21 additions & 0 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,27 @@ func (bc *BabylonController) SubmitBatchFinalitySigs(
return &types.TxResponse{TxHash: res.TxHash, Events: res.Events}, nil
}

// UnjailFinalityProvider sends an unjail transaction to the consumer chain
func (bc *BabylonController) UnjailFinalityProvider(fpPk *btcec.PublicKey) (*types.TxResponse, error) {
msg := &finalitytypes.MsgUnjailFinalityProvider{
Signer: bc.mustGetTxSigner(),
FpBtcPk: bbntypes.NewBIP340PubKeyFromBTCPK(fpPk),
}

unrecoverableErrs := []*sdkErr.Error{
btcstakingtypes.ErrFpNotFound,
btcstakingtypes.ErrFpNotJailed,
btcstakingtypes.ErrFpAlreadySlashed,
}

res, err := bc.reliablySendMsg(msg, emptyErrs, unrecoverableErrs)
if err != nil {
return nil, err
}

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

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())
Expand Down
3 changes: 2 additions & 1 deletion clientcontroller/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ type ClientController interface {
// SubmitBatchFinalitySigs submits a batch of finality signatures to the consumer chain
SubmitBatchFinalitySigs(fpPk *btcec.PublicKey, blocks []*types.BlockInfo, pubRandList []*btcec.FieldVal, proofList [][]byte, sigs []*btcec.ModNScalar) (*types.TxResponse, error)

// Note: the following queries are only for PoC
// UnjailFinalityProvider sends an unjail transaction to the consumer chain
UnjailFinalityProvider(fpPk *btcec.PublicKey) (*types.TxResponse, error)

// QueryFinalityProviderVotingPower queries the voting power of the finality provider at a given height
QueryFinalityProviderVotingPower(fpPk *btcec.PublicKey, blockHeight uint64) (uint64, error)
Expand Down
38 changes: 38 additions & 0 deletions finality-provider/cmd/fpd/daemon/daemon_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,44 @@ func runCommandCreateFP(ctx client.Context, cmd *cobra.Command, _ []string) erro
return nil
}

// CommandUnjailFP returns the unjail-finality-provider command by connecting to the fpd daemon.
func CommandUnjailFP() *cobra.Command {
var cmd = &cobra.Command{
Use: "unjail-finality-provider",
Aliases: []string{"ufp"},
Short: "Unjail the given finality provider.",
Example: fmt.Sprintf(`fpd unjail-finality-provider [eots-pk] --daemon-address %s ...`, defaultFpdDaemonAddress),
Args: cobra.ExactArgs(1),
RunE: fpcmd.RunEWithClientCtx(runCommandUnjailFP),
}

f := cmd.Flags()
f.String(fpdDaemonAddressFlag, defaultFpdDaemonAddress, "The RPC server address of fpd")

return cmd
}

func runCommandUnjailFP(_ client.Context, cmd *cobra.Command, args []string) error {
flags := cmd.Flags()
daemonAddress, err := flags.GetString(fpdDaemonAddressFlag)
if err != nil {
return fmt.Errorf("failed to read flag %s: %w", fpdDaemonAddressFlag, err)
}

client, cleanUp, err := dc.NewFinalityProviderServiceGRpcClient(daemonAddress)
if err != nil {
return err
}
defer cleanUp()

_, err = client.UnjailFinalityProvider(context.Background(), args[0])
if err != nil {
return err
}

return nil
}

func getDescriptionFromFlags(f *pflag.FlagSet) (desc stakingtypes.Description, err error) {
// get information for description
monikerStr, err := f.GetString(monikerFlag)
Expand Down
16 changes: 15 additions & 1 deletion finality-provider/cmd/fpd/daemon/start.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package daemon

import (
"errors"
"fmt"
"net"
"path/filepath"
Expand Down Expand Up @@ -133,9 +134,22 @@ func startApp(
}

if err := fpApp.StartHandlingFinalityProvider(fpPk, passphrase); err != nil {
if errors.Is(err, service.ErrFinalityProviderJailed) {
fpApp.Logger().Error("failed to start finality provider", zap.Error(err))
// do not return error as we still want the service to start
return nil
}
return fmt.Errorf("failed to start the finality-provider instance %s: %w", fpPkStr, err)
}
}

return fpApp.StartHandlingAll()
if err := fpApp.StartHandlingAll(); err != nil {
if errors.Is(err, service.ErrFinalityProviderJailed) {
fpApp.Logger().Error("failed to start finality provider", zap.Error(err))
// do not return error as we still want the service to start
return nil
}
}

return nil
}
2 changes: 0 additions & 2 deletions finality-provider/cmd/fpd/daemon/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

btcstakingcli "github.com/babylonlabs-io/babylon/x/btcstaking/client/cli"
btcstakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
finalitycli "github.com/babylonlabs-io/babylon/x/finality/client/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
Expand All @@ -28,7 +27,6 @@ func CommandTxs() *cobra.Command {
cmd.AddCommand(
authcli.GetSignCommand(),
btcstakingcli.NewCreateFinalityProviderCmd(),
finalitycli.NewUnjailFinalityProviderCmd(),
NewValidateSignedFinalityProviderCmd(),
)

Expand Down
2 changes: 1 addition & 1 deletion finality-provider/cmd/fpd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
daemon.CommandInit(), daemon.CommandStart(), daemon.CommandKeys(),
daemon.CommandGetDaemonInfo(), daemon.CommandCreateFP(), daemon.CommandLsFP(),
daemon.CommandInfoFP(), daemon.CommandRegisterFP(), daemon.CommandAddFinalitySig(),
daemon.CommandExportFP(), daemon.CommandTxs(),
daemon.CommandExportFP(), daemon.CommandTxs(), daemon.CommandUnjailFP(),
)

if err := cmd.Execute(); err != nil {
Expand Down
Loading

0 comments on commit 5b02689

Please sign in to comment.