diff --git a/CHANGELOG.md b/CHANGELOG.md index 42fe4d0..e257601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * [#207](https://github.com/babylonlabs-io/finality-provider/pull/207) create finality provider from JSON file * [#208](https://github.com/babylonlabs-io/finality-provider/pull/208) Remove sync fp status loop +* [#211](https://github.com/babylonlabs-io/finality-provider/pull/211) Clean up unused cmd ## v0.13.1 diff --git a/eotsmanager/proto/signstore.pb.go b/eotsmanager/proto/signstore.pb.go index 142d3d7..af35582 100644 --- a/eotsmanager/proto/signstore.pb.go +++ b/eotsmanager/proto/signstore.pb.go @@ -21,7 +21,7 @@ const ( ) // SigningRecord represents a record of a signing operation. -// it is keyed by (public_key || chain_id || height) +// it is keyed by (chain_id || public_key || height) type SigningRecord struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/finality-provider/cmd/fpd/daemon/daemon_commands.go b/finality-provider/cmd/fpd/daemon/daemon_commands.go index 6ed9050..a919c56 100644 --- a/finality-provider/cmd/fpd/daemon/daemon_commands.go +++ b/finality-provider/cmd/fpd/daemon/daemon_commands.go @@ -110,7 +110,7 @@ Where finality-provider.json contains: f.String(sdkflags.FlagHome, fpcfg.DefaultFpdDir, "The application home directory") f.String(chainIDFlag, "", "The identifier of the consumer chain") f.String(passphraseFlag, "", "The pass phrase used to encrypt the keys") - f.String(commissionRateFlag, "0.05", "The commission rate for the finality provider, e.g., 0.05") + f.String(commissionRateFlag, "", "The commission rate for the finality provider, e.g., 0.05") f.String(monikerFlag, "", "A human-readable name for the finality provider") f.String(identityFlag, "", "An optional identity signature (ex. UPort or Keybase)") f.String(websiteFlag, "", "An optional website link") diff --git a/finality-provider/cmd/fpd/daemon/export.go b/finality-provider/cmd/fpd/daemon/export.go deleted file mode 100644 index 1989072..0000000 --- a/finality-provider/cmd/fpd/daemon/export.go +++ /dev/null @@ -1,151 +0,0 @@ -package daemon - -import ( - "context" - "encoding/hex" - "fmt" - - "cosmossdk.io/math" - 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" - - 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 -// signature signed by the finality provider's Babylon key in hex -type FinalityProviderSigned struct { - btcstktypes.FinalityProvider - // FpSigHex is the finality provider cosmos sdk chain key - // can be verified with the pub key in btcstktypes.FinalityProvider.BabylonPk - FpSigHex string `json:"fp_sig_hex"` -} - -// CommandExportFP returns the export-finality-provider command by loading the fp and export the data. -func CommandExportFP() *cobra.Command { - var cmd = &cobra.Command{ - Use: "export-finality-provider [fp-eots-pk-hex]", - Aliases: []string{"exfp"}, - Short: "It exports the finality provider by the given EOTS public key.", - Example: fmt.Sprintf(`fpd export-finality-provider --daemon-address %s`, defaultFpdDaemonAddress), - Args: cobra.NoArgs, - RunE: fpcmd.RunEWithClientCtx(runCommandExportFP), - } - - f := cmd.Flags() - f.String(fpdDaemonAddressFlag, defaultFpdDaemonAddress, "The RPC server address of fpd") - f.Bool(signedFlag, false, - `Specify if the exported finality provider information should be signed, - if true, it will sign using the flag key-name, if not set it will load from the - babylon key on config.`, - ) - f.String(keyNameFlag, "", "The unique name of the finality provider key") - f.String(sdkflags.FlagHome, fpcfg.DefaultFpdDir, "The application home directory") - f.String(passphraseFlag, "", "The pass phrase used to encrypt the keys") - f.String(hdPathFlag, "", "The hd path used to derive the private key") - - return cmd -} - -func runCommandExportFP(ctx 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 fmt.Errorf("failled to connect to daemon addr %s: %w", daemonAddress, err) - } - defer func() { - if err := cleanUp(); err != nil { - fmt.Printf("Failed to clean up grpc client: %v\n", err) - } - }() - - fpBtcPkHex := args[0] - fpPk, err := bbn.NewBIP340PubKeyFromHex(fpBtcPkHex) - if err != nil { - return fmt.Errorf("invalid fp btc pk hex %s: %w", fpBtcPkHex, err) - } - - fpInfoResp, err := client.QueryFinalityProviderInfo(context.Background(), fpPk) - if err != nil { - return fmt.Errorf("failed to query fp info from %s: %w", fpBtcPkHex, err) - } - - fpInfo := fpInfoResp.FinalityProvider - comm, err := math.LegacyNewDecFromStr(fpInfo.Commission) - if err != nil { - return fmt.Errorf("failed to parse fp commission %s: %w", fpInfo.Commission, err) - } - - desc := fpInfo.Description - fp := btcstktypes.FinalityProvider{ - Addr: fpInfo.FpAddr, - Description: &types.Description{ - Moniker: desc.Moniker, - Identity: desc.Identity, - Website: desc.Website, - SecurityContact: desc.SecurityContact, - Details: desc.Details, - }, - Commission: &comm, - BtcPk: fpPk, - Pop: nil, // TODO: fill PoP? - } - - signed, err := flags.GetBool(signedFlag) - if err != nil { - return fmt.Errorf("failed to read flag %s: %w", signedFlag, err) - } - if !signed { - printRespJSON(fp) - return nil - } - - keyName, err := loadKeyName(ctx.HomeDir, cmd) - if err != nil { - return fmt.Errorf("not able to load key name: %w", err) - } - - // sign the finality provider data. - fpbz, err := fp.Marshal() - if err != nil { - return fmt.Errorf("failed to marshal finality provider %+v: %w", fp, err) - } - - passphrase, err := flags.GetString(passphraseFlag) - if err != nil { - return fmt.Errorf("failed to read flag %s: %w", passphraseFlag, err) - } - - hdPath, err := flags.GetString(hdPathFlag) - if err != nil { - return fmt.Errorf("failed to read flag %s: %w", hdPathFlag, err) - } - - resp, err := client.SignMessageFromChainKey( - context.Background(), - keyName, - passphrase, - hdPath, - fpbz, - ) - if err != nil { - return fmt.Errorf("failed to sign finality provider: %w", err) - } - - printRespJSON(FinalityProviderSigned{ - FinalityProvider: fp, - FpSigHex: hex.EncodeToString(resp.Signature), - }) - return nil -} diff --git a/finality-provider/cmd/fpd/daemon/tx.go b/finality-provider/cmd/fpd/daemon/tx.go deleted file mode 100644 index 6d21ca9..0000000 --- a/finality-provider/cmd/fpd/daemon/tx.go +++ /dev/null @@ -1,121 +0,0 @@ -package daemon - -import ( - "fmt" - "strings" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/spf13/cobra" - - btcstakingcli "github.com/babylonlabs-io/babylon/x/btcstaking/client/cli" - incentivecli "github.com/babylonlabs-io/babylon/x/incentive/client/cli" - - btcstakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" - 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" -) - -// CommandTxs returns the transaction commands for finality provider related msgs. -func CommandTxs() *cobra.Command { - cmd := &cobra.Command{ - Use: "tx", - Short: "transactions subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - authcli.GetSignCommand(), - btcstakingcli.NewCreateFinalityProviderCmd(), - NewValidateSignedFinalityProviderCmd(), - incentivecli.NewWithdrawRewardCmd(), - incentivecli.NewSetWithdrawAddressCmd(), - ) - - return cmd -} - -// NewValidateSignedFinalityProviderCmd returns the command line for -// tx validate-signed-finality-provider -func NewValidateSignedFinalityProviderCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "validate-signed-finality-provider [file_path_signed_msg]", - Args: cobra.ExactArgs(1), - Short: "Validates the signed MsgCreateFinalityProvider", - Long: strings.TrimSpace(` - Loads the signed MsgCreateFinalityProvider and checks if the basic - information is satisfied and the Proof of Possession is valid against the - signer of the msg and the finality provider's BTC public key - `), - Example: strings.TrimSpace( - `fdp tx validate-signed-finality-provider ./path/to/signed-msg.json`, - ), - RunE: func(cmd *cobra.Command, args []string) error { - ctx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - stdTx, err := authclient.ReadTxFromFile(ctx, args[0]) - if err != nil { - return err - } - - msgsV2, err := stdTx.GetMsgsV2() - if err != nil { - return err - } - - msgs := stdTx.GetMsgs() - if len(msgs) == 0 { - return fmt.Errorf("invalid msg, there is no msg inside %s file", args[0]) - } - - for i, sdkMsg := range msgs { - msgV2 := msgsV2[i] - msg, ok := sdkMsg.(*btcstakingtypes.MsgCreateFinalityProvider) - if !ok { - return fmt.Errorf("unable to parse %+v to MsgCreateFinalityProvider", msg) - } - - if err := msg.ValidateBasic(); err != nil { - return fmt.Errorf("error validating basic msg: %w", err) - } - - signers, err := ctx.Codec.GetMsgV2Signers(msgV2) - if err != nil { - return fmt.Errorf("failed to get signers from msg %+v: %w", msg, err) - } - - if len(signers) == 0 { - return fmt.Errorf("no signer at msg %+v", msgV2) - } - - signerAddrStr, err := ctx.Codec.InterfaceRegistry().SigningContext().AddressCodec().BytesToString(signers[0]) - if err != nil { - return err - } - - signerBbnAddr, err := sdk.AccAddressFromBech32(signerAddrStr) - if err != nil { - return fmt.Errorf("invalid signer address %s, please sign with a valid bbn address, err: %w", signerAddrStr, err) - } - - if !strings.EqualFold(msg.Addr, signerAddrStr) { - return fmt.Errorf("signer address: %s is different from finality provider address: %s", signerAddrStr, msg.Addr) - } - - if err := msg.Pop.VerifyBIP340(signerBbnAddr, msg.BtcPk); err != nil { - return fmt.Errorf("invalid Proof of Possession with signer %s: %w", signerBbnAddr.String(), err) - } - } - - _, err = cmd.OutOrStdout().Write([]byte("The signed MsgCreateFinalityProvider is valid")) - return err - }, - } - - return cmd -} diff --git a/finality-provider/cmd/fpd/daemon/tx_test.go b/finality-provider/cmd/fpd/daemon/tx_test.go deleted file mode 100644 index b2f7530..0000000 --- a/finality-provider/cmd/fpd/daemon/tx_test.go +++ /dev/null @@ -1,174 +0,0 @@ -package daemon_test - -import ( - "bytes" - "encoding/json" - "fmt" - "math/rand" - "os" - "path/filepath" - "testing" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/keys" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/spf13/cobra" - - "github.com/stretchr/testify/require" - - "github.com/babylonlabs-io/babylon/app" - "github.com/babylonlabs-io/babylon/testutil/datagen" - bbn "github.com/babylonlabs-io/babylon/types" - - btcstakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" - - fpcmd "github.com/babylonlabs-io/finality-provider/finality-provider/cmd" - "github.com/babylonlabs-io/finality-provider/finality-provider/cmd/fpd/daemon" - fpcfg "github.com/babylonlabs-io/finality-provider/finality-provider/config" - "github.com/babylonlabs-io/finality-provider/testutil" -) - -func FuzzNewValidateSignedFinalityProviderCmd(f *testing.F) { - testutil.AddRandomSeedsToFuzzer(f, 10) - tempApp := app.NewTmpBabylonApp() - - f.Fuzz(func(t *testing.T, seed int64) { - r := rand.New(rand.NewSource(seed)) - - rootCmdBuff := new(bytes.Buffer) - root := rootCmd(rootCmdBuff) - - tDir := t.TempDir() - tempHome := filepath.Join(tDir, "homefpnew") - homeFlag := fmt.Sprintf("--home=%s", tempHome) - - exec(t, root, rootCmdBuff, "init", homeFlag) - - keyName := datagen.GenRandomHexStr(r, 5) - kbt := "--keyring-backend=test" - - keyOut := execUnmarshal[keys.KeyOutput](t, root, rootCmdBuff, "keys", "add", keyName, homeFlag, kbt) - require.Equal(t, keyName, keyOut.Name) - - fpAddr, err := sdk.AccAddressFromBech32(keyOut.Address) - require.NoError(t, err) - - btcSK, btcPK, err := datagen.GenRandomBTCKeyPair(r) - require.NoError(t, err) - - pop, err := btcstakingtypes.NewPoPBTC(fpAddr, btcSK) - require.NoError(t, err) - - popHex, err := pop.ToHexStr() - require.NoError(t, err) - - bip340PK := bbn.NewBIP340PubKeyFromBTCPK(btcPK) - - _, unsignedMsgStr := exec( - t, root, rootCmdBuff, "tx", "create-finality-provider", bip340PK.MarshalHex(), popHex, homeFlag, kbt, - fmt.Sprintf("--from=%s", keyName), "--generate-only", "--gas-prices=10ubbn", - "--commission-rate=0.05", "--moniker='niceFP'", "--identity=x", "--website=test.com", - "--security-contact=niceEmail", "--details='no Details'", - ) - - tx, err := tempApp.TxConfig().TxJSONDecoder()([]byte(unsignedMsgStr)) - require.NoError(t, err) - - txMsgs := tx.GetMsgs() - require.Len(t, txMsgs, 1) - sdkMsg := txMsgs[0] - - msg, ok := sdkMsg.(*btcstakingtypes.MsgCreateFinalityProvider) - require.True(t, ok) - require.Equal(t, msg.Addr, fpAddr.String()) - - // sends the unsigned msg to a file to be signed. - unsignedMsgFilePath := writeToTempFile(t, r, unsignedMsgStr) - - _, signedMsgStr := exec(t, root, rootCmdBuff, "tx", "sign", unsignedMsgFilePath, homeFlag, kbt, - fmt.Sprintf("--from=%s", keyName), "--offline", "--account-number=0", "--sequence=0", - ) - // sends the signed msg to a file. - signedMsgFilePath := writeToTempFile(t, r, signedMsgStr) - - tx, err = tempApp.TxConfig().TxJSONDecoder()([]byte(signedMsgStr)) - require.NoError(t, err) - - msgSigned, ok := tx.GetMsgs()[0].(*btcstakingtypes.MsgCreateFinalityProvider) - require.True(t, ok) - require.Equal(t, msgSigned.Addr, fpAddr.String()) - - // executes the verification. - _, outputValidate := exec(t, root, rootCmdBuff, "tx", "validate-signed-finality-provider", signedMsgFilePath, homeFlag) - require.Equal(t, "The signed MsgCreateFinalityProvider is valid", outputValidate) - }) -} - -func rootCmd(outputBuff *bytes.Buffer) *cobra.Command { - cmd := &cobra.Command{ - Use: "fpd", - PersistentPreRunE: fpcmd.PersistClientCtx(client.Context{}.WithOutput(outputBuff)), - } - cmd.PersistentFlags().String(flags.FlagHome, fpcfg.DefaultFpdDir, "The application home directory") - - cmd.AddCommand( - daemon.CommandInit(), daemon.CommandStart(), daemon.CommandKeys(), - daemon.CommandGetDaemonInfo(), daemon.CommandCreateFP(), daemon.CommandLsFP(), - daemon.CommandInfoFP(), daemon.CommandAddFinalitySig(), - daemon.CommandExportFP(), daemon.CommandTxs(), - ) - - return cmd -} - -// exec executes a command based on the cmd passed, the args should only search for subcommands, not parent commands -// it also receives rootCmdBuf as a parameter, which is the buff set in the cmd context standard output for the commands -// that do print to the context stdout instead of the root stdout. -func exec(t *testing.T, root *cobra.Command, rootCmdBuf *bytes.Buffer, args ...string) (c *cobra.Command, output string) { - buf := new(bytes.Buffer) - root.SetOut(buf) - root.SetErr(buf) - root.SetArgs(args) - - c, err := root.ExecuteC() - require.NoError(t, err) - - outStr := buf.String() - if len(outStr) > 0 { - return c, outStr - } - - _, err = buf.Write(rootCmdBuf.Bytes()) - require.NoError(t, err) - - return c, buf.String() -} - -func execUnmarshal[structure any](t *testing.T, root *cobra.Command, rootCmdBuf *bytes.Buffer, args ...string) (output structure) { - var typed structure - _, outStr := exec(t, root, rootCmdBuf, args...) - - // helpful for debug - // fmt.Printf("\nargs %s", strings.Join(args, " ")) - // fmt.Printf("\nout %s", outStr) - - err := json.Unmarshal([]byte(outStr), &typed) - require.NoError(t, err) - - return typed -} - -func writeToTempFile(t *testing.T, r *rand.Rand, str string) (outputFilePath string) { - outputFilePath = filepath.Join(t.TempDir(), datagen.GenRandomHexStr(r, 5)) - - outPutFile, err := os.Create(outputFilePath) - require.NoError(t, err) - defer outPutFile.Close() - - _, err = outPutFile.WriteString(str) - require.NoError(t, err) - - return outputFilePath -} diff --git a/finality-provider/cmd/fpd/main.go b/finality-provider/cmd/fpd/main.go index 46efc58..8c03b56 100644 --- a/finality-provider/cmd/fpd/main.go +++ b/finality-provider/cmd/fpd/main.go @@ -4,8 +4,7 @@ import ( "fmt" "os" - "github.com/babylonlabs-io/finality-provider/version" - + incentivecli "github.com/babylonlabs-io/babylon/x/incentive/client/cli" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/spf13/cobra" @@ -13,6 +12,7 @@ import ( fpcmd "github.com/babylonlabs-io/finality-provider/finality-provider/cmd" "github.com/babylonlabs-io/finality-provider/finality-provider/cmd/fpd/daemon" fpcfg "github.com/babylonlabs-io/finality-provider/finality-provider/config" + "github.com/babylonlabs-io/finality-provider/version" ) // NewRootCmd creates a new root command for fpd. It is called once in the main function. @@ -34,10 +34,10 @@ func main() { cmd.AddCommand( daemon.CommandInit(), daemon.CommandStart(), daemon.CommandKeys(), daemon.CommandGetDaemonInfo(), daemon.CommandCreateFP(), daemon.CommandLsFP(), - daemon.CommandInfoFP(), daemon.CommandAddFinalitySig(), - daemon.CommandExportFP(), daemon.CommandTxs(), daemon.CommandUnjailFP(), - daemon.CommandEditFinalityDescription(), version.CommandVersion("fpd"), - daemon.CommandCommitPubRand(), + daemon.CommandInfoFP(), daemon.CommandAddFinalitySig(), daemon.CommandUnjailFP(), + daemon.CommandEditFinalityDescription(), daemon.CommandCommitPubRand(), + incentivecli.NewWithdrawRewardCmd(), incentivecli.NewSetWithdrawAddressCmd(), + version.CommandVersion("fpd"), ) if err := cmd.Execute(); err != nil { diff --git a/finality-provider/proto/finality_providers.pb.go b/finality-provider/proto/finality_providers.pb.go index 2a1bb8e..69255d4 100644 --- a/finality-provider/proto/finality_providers.pb.go +++ b/finality-provider/proto/finality_providers.pb.go @@ -1555,7 +1555,7 @@ var file_finality_providers_proto_rawDesc = []byte{ 0x0a, 0x07, 0x53, 0x4c, 0x41, 0x53, 0x48, 0x45, 0x44, 0x10, 0x03, 0x1a, 0x0b, 0x8a, 0x9d, 0x20, 0x07, 0x53, 0x4c, 0x41, 0x53, 0x48, 0x45, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x4a, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x10, 0x04, 0x1a, 0x0a, 0x8a, 0x9d, 0x20, 0x06, 0x4a, 0x41, 0x49, 0x4c, 0x45, 0x44, - 0x1a, 0x04, 0x88, 0xa3, 0x1e, 0x00, 0x32, 0x8c, 0x06, 0x0a, 0x11, 0x46, 0x69, 0x6e, 0x61, 0x6c, + 0x1a, 0x04, 0x88, 0xa3, 0x1e, 0x00, 0x32, 0xa2, 0x05, 0x0a, 0x11, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x73, 0x12, 0x38, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, @@ -1592,24 +1592,17 @@ var file_finality_providers_proto_rawDesc = []byte{ 0x69, 0x64, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x4c, 0x69, 0x73, - 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, 0x0a, 0x17, 0x53, 0x69, 0x67, - 0x6e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x46, 0x72, 0x6f, 0x6d, 0x43, 0x68, 0x61, 0x69, - 0x6e, 0x4b, 0x65, 0x79, 0x12, 0x25, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, 0x67, - 0x6e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x46, 0x72, 0x6f, 0x6d, 0x43, 0x68, 0x61, 0x69, - 0x6e, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x46, - 0x72, 0x6f, 0x6d, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, 0x14, 0x45, 0x64, 0x69, 0x74, 0x46, 0x69, 0x6e, 0x61, 0x6c, - 0x69, 0x74, 0x79, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x22, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x64, 0x69, 0x74, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x74, 0x79, - 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x45, 0x5a, 0x43, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x61, 0x62, 0x79, 0x6c, 0x6f, 0x6e, 0x6c, 0x61, 0x62, 0x73, 0x2d, - 0x69, 0x6f, 0x2f, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x2d, 0x70, 0x72, 0x6f, 0x76, - 0x69, 0x64, 0x65, 0x72, 0x2f, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x2d, 0x70, 0x72, - 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, 0x14, 0x45, 0x64, 0x69, + 0x74, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, + 0x72, 0x12, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x64, 0x69, 0x74, 0x46, 0x69, + 0x6e, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x6d, + 0x70, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x45, 0x5a, 0x43, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x61, 0x62, 0x79, 0x6c, 0x6f, + 0x6e, 0x6c, 0x61, 0x62, 0x73, 0x2d, 0x69, 0x6f, 0x2f, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x74, + 0x79, 0x2d, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2f, 0x66, 0x69, 0x6e, 0x61, 0x6c, + 0x69, 0x74, 0x79, 0x2d, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1663,18 +1656,16 @@ var file_finality_providers_proto_depIdxs = []int32{ 7, // 9: proto.FinalityProviders.UnjailFinalityProvider:input_type -> proto.UnjailFinalityProviderRequest 9, // 10: proto.FinalityProviders.QueryFinalityProvider:input_type -> proto.QueryFinalityProviderRequest 11, // 11: proto.FinalityProviders.QueryFinalityProviderList:input_type -> proto.QueryFinalityProviderListRequest - 18, // 12: proto.FinalityProviders.SignMessageFromChainKey:input_type -> proto.SignMessageFromChainKeyRequest - 20, // 13: proto.FinalityProviders.EditFinalityProvider:input_type -> proto.EditFinalityProviderRequest - 2, // 14: proto.FinalityProviders.GetInfo:output_type -> proto.GetInfoResponse - 4, // 15: proto.FinalityProviders.CreateFinalityProvider:output_type -> proto.CreateFinalityProviderResponse - 6, // 16: proto.FinalityProviders.AddFinalitySignature:output_type -> proto.AddFinalitySignatureResponse - 8, // 17: proto.FinalityProviders.UnjailFinalityProvider:output_type -> proto.UnjailFinalityProviderResponse - 10, // 18: proto.FinalityProviders.QueryFinalityProvider:output_type -> proto.QueryFinalityProviderResponse - 12, // 19: proto.FinalityProviders.QueryFinalityProviderList:output_type -> proto.QueryFinalityProviderListResponse - 19, // 20: proto.FinalityProviders.SignMessageFromChainKey:output_type -> proto.SignMessageFromChainKeyResponse - 21, // 21: proto.FinalityProviders.EditFinalityProvider:output_type -> proto.EmptyResponse - 14, // [14:22] is the sub-list for method output_type - 6, // [6:14] is the sub-list for method input_type + 20, // 12: proto.FinalityProviders.EditFinalityProvider:input_type -> proto.EditFinalityProviderRequest + 2, // 13: proto.FinalityProviders.GetInfo:output_type -> proto.GetInfoResponse + 4, // 14: proto.FinalityProviders.CreateFinalityProvider:output_type -> proto.CreateFinalityProviderResponse + 6, // 15: proto.FinalityProviders.AddFinalitySignature:output_type -> proto.AddFinalitySignatureResponse + 8, // 16: proto.FinalityProviders.UnjailFinalityProvider:output_type -> proto.UnjailFinalityProviderResponse + 10, // 17: proto.FinalityProviders.QueryFinalityProvider:output_type -> proto.QueryFinalityProviderResponse + 12, // 18: proto.FinalityProviders.QueryFinalityProviderList:output_type -> proto.QueryFinalityProviderListResponse + 21, // 19: proto.FinalityProviders.EditFinalityProvider:output_type -> proto.EmptyResponse + 13, // [13:20] is the sub-list for method output_type + 6, // [6:13] is the sub-list for method input_type 6, // [6:6] is the sub-list for extension type_name 6, // [6:6] is the sub-list for extension extendee 0, // [0:6] is the sub-list for field type_name diff --git a/finality-provider/proto/finality_providers.proto b/finality-provider/proto/finality_providers.proto index 10c617a..38a32a3 100644 --- a/finality-provider/proto/finality_providers.proto +++ b/finality-provider/proto/finality_providers.proto @@ -33,10 +33,6 @@ service FinalityProviders { rpc QueryFinalityProviderList (QueryFinalityProviderListRequest) returns (QueryFinalityProviderListResponse); - // SignMessageFromChainKey signs a message from the chain keyring. - rpc SignMessageFromChainKey (SignMessageFromChainKeyRequest) - returns (SignMessageFromChainKeyResponse); - // EditFinalityProvider edits finality provider rpc EditFinalityProvider (EditFinalityProviderRequest) returns (EmptyResponse); } diff --git a/finality-provider/proto/finality_providers_grpc.pb.go b/finality-provider/proto/finality_providers_grpc.pb.go index 79dd0bf..ca523db 100644 --- a/finality-provider/proto/finality_providers_grpc.pb.go +++ b/finality-provider/proto/finality_providers_grpc.pb.go @@ -25,7 +25,6 @@ const ( FinalityProviders_UnjailFinalityProvider_FullMethodName = "/proto.FinalityProviders/UnjailFinalityProvider" FinalityProviders_QueryFinalityProvider_FullMethodName = "/proto.FinalityProviders/QueryFinalityProvider" FinalityProviders_QueryFinalityProviderList_FullMethodName = "/proto.FinalityProviders/QueryFinalityProviderList" - FinalityProviders_SignMessageFromChainKey_FullMethodName = "/proto.FinalityProviders/SignMessageFromChainKey" FinalityProviders_EditFinalityProvider_FullMethodName = "/proto.FinalityProviders/EditFinalityProvider" ) @@ -47,8 +46,6 @@ type FinalityProvidersClient interface { QueryFinalityProvider(ctx context.Context, in *QueryFinalityProviderRequest, opts ...grpc.CallOption) (*QueryFinalityProviderResponse, error) // QueryFinalityProviderList queries a list of finality providers QueryFinalityProviderList(ctx context.Context, in *QueryFinalityProviderListRequest, opts ...grpc.CallOption) (*QueryFinalityProviderListResponse, error) - // SignMessageFromChainKey signs a message from the chain keyring. - SignMessageFromChainKey(ctx context.Context, in *SignMessageFromChainKeyRequest, opts ...grpc.CallOption) (*SignMessageFromChainKeyResponse, error) // EditFinalityProvider edits finality provider EditFinalityProvider(ctx context.Context, in *EditFinalityProviderRequest, opts ...grpc.CallOption) (*EmptyResponse, error) } @@ -115,15 +112,6 @@ func (c *finalityProvidersClient) QueryFinalityProviderList(ctx context.Context, return out, nil } -func (c *finalityProvidersClient) SignMessageFromChainKey(ctx context.Context, in *SignMessageFromChainKeyRequest, opts ...grpc.CallOption) (*SignMessageFromChainKeyResponse, error) { - out := new(SignMessageFromChainKeyResponse) - err := c.cc.Invoke(ctx, FinalityProviders_SignMessageFromChainKey_FullMethodName, in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *finalityProvidersClient) EditFinalityProvider(ctx context.Context, in *EditFinalityProviderRequest, opts ...grpc.CallOption) (*EmptyResponse, error) { out := new(EmptyResponse) err := c.cc.Invoke(ctx, FinalityProviders_EditFinalityProvider_FullMethodName, in, out, opts...) @@ -151,8 +139,6 @@ type FinalityProvidersServer interface { QueryFinalityProvider(context.Context, *QueryFinalityProviderRequest) (*QueryFinalityProviderResponse, error) // QueryFinalityProviderList queries a list of finality providers QueryFinalityProviderList(context.Context, *QueryFinalityProviderListRequest) (*QueryFinalityProviderListResponse, error) - // SignMessageFromChainKey signs a message from the chain keyring. - SignMessageFromChainKey(context.Context, *SignMessageFromChainKeyRequest) (*SignMessageFromChainKeyResponse, error) // EditFinalityProvider edits finality provider EditFinalityProvider(context.Context, *EditFinalityProviderRequest) (*EmptyResponse, error) mustEmbedUnimplementedFinalityProvidersServer() @@ -180,9 +166,6 @@ func (UnimplementedFinalityProvidersServer) QueryFinalityProvider(context.Contex func (UnimplementedFinalityProvidersServer) QueryFinalityProviderList(context.Context, *QueryFinalityProviderListRequest) (*QueryFinalityProviderListResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method QueryFinalityProviderList not implemented") } -func (UnimplementedFinalityProvidersServer) SignMessageFromChainKey(context.Context, *SignMessageFromChainKeyRequest) (*SignMessageFromChainKeyResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method SignMessageFromChainKey not implemented") -} func (UnimplementedFinalityProvidersServer) EditFinalityProvider(context.Context, *EditFinalityProviderRequest) (*EmptyResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method EditFinalityProvider not implemented") } @@ -307,24 +290,6 @@ func _FinalityProviders_QueryFinalityProviderList_Handler(srv interface{}, ctx c return interceptor(ctx, in, info, handler) } -func _FinalityProviders_SignMessageFromChainKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SignMessageFromChainKeyRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(FinalityProvidersServer).SignMessageFromChainKey(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: FinalityProviders_SignMessageFromChainKey_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(FinalityProvidersServer).SignMessageFromChainKey(ctx, req.(*SignMessageFromChainKeyRequest)) - } - return interceptor(ctx, in, info, handler) -} - func _FinalityProviders_EditFinalityProvider_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(EditFinalityProviderRequest) if err := dec(in); err != nil { @@ -374,10 +339,6 @@ var FinalityProviders_ServiceDesc = grpc.ServiceDesc{ MethodName: "QueryFinalityProviderList", Handler: _FinalityProviders_QueryFinalityProviderList_Handler, }, - { - MethodName: "SignMessageFromChainKey", - Handler: _FinalityProviders_SignMessageFromChainKey_Handler, - }, { MethodName: "EditFinalityProvider", Handler: _FinalityProviders_EditFinalityProvider_Handler, diff --git a/finality-provider/service/app.go b/finality-provider/service/app.go index 6074ada..c9dd81c 100644 --- a/finality-provider/service/app.go +++ b/finality-provider/service/app.go @@ -12,7 +12,6 @@ import ( "github.com/btcsuite/btcd/btcec/v2" "github.com/cometbft/cometbft/crypto/tmhash" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/lightningnetwork/lnd/kvdb" @@ -459,40 +458,6 @@ func (app *FinalityProviderApp) CreatePop(fpAddress sdk.AccAddress, fpPk *bbntyp return pop, nil } -// SignRawMsg loads the keyring private key and signs a message. -func (app *FinalityProviderApp) SignRawMsg( - keyName, passPhrase, hdPath string, - rawMsgToSign []byte, -) ([]byte, error) { - _, chainSk, err := app.loadChainKeyring(keyName, passPhrase, hdPath) - if err != nil { - return nil, err - } - - return chainSk.Sign(rawMsgToSign) -} - -// loadChainKeyring checks the keyring by loading or creating a chain key. -func (app *FinalityProviderApp) loadChainKeyring( - keyName, passPhrase, hdPath string, -) (*fpkr.ChainKeyringController, *secp256k1.PrivKey, error) { - kr, err := fpkr.NewChainKeyringControllerWithKeyring(app.kr, keyName, app.input) - if err != nil { - return nil, nil, err - } - chainSk, err := kr.GetChainPrivKey(passPhrase) - if err != nil { - // the chain key does not exist, should create the chain key first - keyInfo, err := kr.CreateChainKey(passPhrase, hdPath, "") - if err != nil { - return nil, nil, fmt.Errorf("failed to create chain key %s: %w", keyName, err) - } - chainSk = &secp256k1.PrivKey{Key: keyInfo.PrivateKey.Serialize()} - } - - return kr, chainSk, nil -} - func (app *FinalityProviderApp) startFinalityProviderInstance( pk *bbntypes.BIP340PubKey, passphrase string, diff --git a/finality-provider/service/client/rpcclient.go b/finality-provider/service/client/rpcclient.go index b40bc3f..fc3ea57 100644 --- a/finality-provider/service/client/rpcclient.go +++ b/finality-provider/service/client/rpcclient.go @@ -141,17 +141,3 @@ func (c *FinalityProviderServiceGRpcClient) EditFinalityProvider( return nil } - -func (c *FinalityProviderServiceGRpcClient) SignMessageFromChainKey( - ctx context.Context, - keyName, passphrase, hdPath string, - rawMsgToSign []byte, -) (*proto.SignMessageFromChainKeyResponse, error) { - req := &proto.SignMessageFromChainKeyRequest{ - MsgToSign: rawMsgToSign, - KeyName: keyName, - Passphrase: passphrase, - HdPath: hdPath, - } - return c.client.SignMessageFromChainKey(ctx, req) -} diff --git a/finality-provider/service/rpcserver.go b/finality-provider/service/rpcserver.go index e86544a..ad506e8 100644 --- a/finality-provider/service/rpcserver.go +++ b/finality-provider/service/rpcserver.go @@ -269,17 +269,6 @@ func (r *rpcServer) QueryFinalityProviderList(_ context.Context, _ *proto.QueryF return &proto.QueryFinalityProviderListResponse{FinalityProviders: fps}, nil } -// SignMessageFromChainKey signs a message from the chain keyring. -func (r *rpcServer) SignMessageFromChainKey(_ context.Context, req *proto.SignMessageFromChainKeyRequest) ( - *proto.SignMessageFromChainKeyResponse, error) { - signature, err := r.app.SignRawMsg(req.KeyName, req.Passphrase, req.HdPath, req.MsgToSign) - if err != nil { - return nil, err - } - - return &proto.SignMessageFromChainKeyResponse{Signature: signature}, nil -} - func parseEotsPk(eotsPkHex string) (*bbntypes.BIP340PubKey, error) { if eotsPkHex == "" { return nil, fmt.Errorf("eots-pk cannot be empty") diff --git a/itest/e2e_test.go b/itest/e2e_test.go index 5591a0f..93b0b4e 100644 --- a/itest/e2e_test.go +++ b/itest/e2e_test.go @@ -1,15 +1,19 @@ +//go:build e2e +// +build e2e + package e2etest import ( "encoding/json" "fmt" - bbntypes "github.com/babylonlabs-io/babylon/types" "log" "math/rand" "os" "testing" "time" + bbntypes "github.com/babylonlabs-io/babylon/types" + sdkmath "cosmossdk.io/math" "github.com/babylonlabs-io/babylon/testutil/datagen" "github.com/btcsuite/btcd/btcec/v2"