From dab668712682094ed4dfa687e0730bbf153a173d Mon Sep 17 00:00:00 2001 From: 0xHansLee <hansol.lee@storyprotocol.xyz> Date: Tue, 19 Nov 2024 16:21:31 +0900 Subject: [PATCH 1/2] feat(cli): separate unjail and unjail on behalf cmd --- client/cmd/flags.go | 8 +++++++ client/cmd/validator.go | 53 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/client/cmd/flags.go b/client/cmd/flags.go index 100889f3..9d1bda74 100644 --- a/client/cmd/flags.go +++ b/client/cmd/flags.go @@ -147,6 +147,10 @@ func bindRollbackFlags(cmd *cobra.Command, cfg *config.Config) { func bindValidatorUnjailFlags(cmd *cobra.Command, cfg *unjailConfig) { bindValidatorBaseFlags(cmd, &cfg.baseConfig) +} + +func bindValidatorUnjailOnBehalfFlags(cmd *cobra.Command, cfg *unjailConfig) { + bindValidatorBaseFlags(cmd, &cfg.baseConfig) cmd.Flags().StringVar(&cfg.ValidatorPubKey, "validator-pubkey", "", "Validator's hex-encoded compressed 33-byte secp256k1 public key") } @@ -229,6 +233,10 @@ func validateKeyConvertFlags(cmd *cobra.Command) error { } func validateValidatorUnjailFlags(cmd *cobra.Command) error { + return validateFlags(cmd, []string{}) +} + +func validateValidatorUnjailOnBehalfFlags(cmd *cobra.Command) error { return validateFlags(cmd, []string{"validator-pubkey"}) } diff --git a/client/cmd/validator.go b/client/cmd/validator.go index e2bf375a..5b0650da 100644 --- a/client/cmd/validator.go +++ b/client/cmd/validator.go @@ -147,6 +147,7 @@ func newValidatorCmds() *cobra.Command { newValidatorRemoveOperatorCmd(), newValidatorSetWithdrawalAddressCmd(), newValidatorUnjailCmd(), + newValidatorUnjailOnBehalfCmd(), ) return cmd @@ -376,6 +377,27 @@ func newValidatorUnjailCmd() *cobra.Command { return cmd } +func newValidatorUnjailOnBehalfCmd() *cobra.Command { + var cfg unjailConfig + + cmd := &cobra.Command{ + Use: "unjail-on-behalf", + Short: "Unjail the validator on behalf of a validator", + Args: cobra.NoArgs, + PreRunE: func(_ *cobra.Command, _ []string) error { + return initializeBaseConfig(&cfg.baseConfig) + }, + RunE: runValidatorCommand( + validateValidatorUnjailOnBehalfFlags, + func(ctx context.Context) error { return unjailOnBehalf(ctx, cfg) }, + ), + } + + bindValidatorUnjailOnBehalfFlags(cmd, &cfg) + + return cmd +} + func runValidatorCommand( validate func(cmd *cobra.Command) error, execute func(ctx context.Context) error, @@ -715,6 +737,35 @@ func unstakeOnBehalf(ctx context.Context, cfg unstakeConfig) error { } func unjail(ctx context.Context, cfg unjailConfig) error { + uncompressedValidatorPubKeyBytes, err := uncompressPrivateKey(cfg.PrivateKey) + if err != nil { + return errors.Wrap(err, "failed to get uncompressed pub key from private key") + } + + result, err := prepareAndReadContract(ctx, &cfg.baseConfig, "fee") + if err != nil { + return err + } + + var unjailFee *big.Int + err = cfg.ABI.UnpackIntoInterface(&unjailFee, "fee", result) + if err != nil { + return errors.Wrap(err, "failed to unpack unjailFee") + } + + fmt.Printf("Unjail fee: %s\n", unjailFee.String()) + + _, err = prepareAndExecuteTransaction(ctx, &cfg.baseConfig, "unjailOnBehalf", unjailFee, uncompressedValidatorPubKeyBytes, []byte{}) + if err != nil { + return err + } + + fmt.Println("Validator successfully unjailed on behalf of validator!") + + return nil +} + +func unjailOnBehalf(ctx context.Context, cfg unjailConfig) error { validatorPubKeyBytes, err := hex.DecodeString(cfg.ValidatorPubKey) if err != nil { return errors.Wrap(err, "failed to decode hex-encoded validator public key") @@ -743,7 +794,7 @@ func unjail(ctx context.Context, cfg unjailConfig) error { return err } - fmt.Println("Validator successfully unjailed!") + fmt.Println("Validator successfully unjailed on behalf of validator!") return nil } From 8a21eda2ef45c3bb7a670203ab14a3693d84f97b Mon Sep 17 00:00:00 2001 From: 0xHansLee <hansol.lee@storyprotocol.xyz> Date: Mon, 25 Nov 2024 12:29:04 +0900 Subject: [PATCH 2/2] chore(evmengine): review applied --- client/cmd/validator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cmd/validator.go b/client/cmd/validator.go index 5b0650da..a96fb3a8 100644 --- a/client/cmd/validator.go +++ b/client/cmd/validator.go @@ -755,12 +755,12 @@ func unjail(ctx context.Context, cfg unjailConfig) error { fmt.Printf("Unjail fee: %s\n", unjailFee.String()) - _, err = prepareAndExecuteTransaction(ctx, &cfg.baseConfig, "unjailOnBehalf", unjailFee, uncompressedValidatorPubKeyBytes, []byte{}) + _, err = prepareAndExecuteTransaction(ctx, &cfg.baseConfig, "unjail", unjailFee, uncompressedValidatorPubKeyBytes, []byte{}) if err != nil { return err } - fmt.Println("Validator successfully unjailed on behalf of validator!") + fmt.Println("Validator successfully unjailed!") return nil }