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

fix: fpd panics on jailed finality provider #78

Merged
merged 5 commits into from
Oct 1, 2024
Merged
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
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),
}
Comment on lines +262 to +265
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think if it's beneficial to check whether the jail_until is passed before submitting this tx? If the operator submits unjail tx when the FP hasn't passed the jailing period, the tx will still consume gas but the FP won't get unjailed, which is not expected

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I thought gas would not be confused as it will be rejected in the mempool level? Created an issue #79 to track this as this needs introduction of signing info queries and will be handled in a separate pr


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(),
RafilxTenfen marked this conversation as resolved.
Show resolved Hide resolved
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
Loading