Skip to content

Commit

Permalink
fix: checkpointing: Do not make the home flag a required one and un…
Browse files Browse the repository at this point in the history
…marshall PubKey (#271)
  • Loading branch information
vitsalis authored Jan 12, 2023
1 parent 01d77ec commit 82d5277
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ type BabylonApp struct {
}

func init() {
// Note: If this changes, the home directory under x/checkpointing/client/cli/tx.go needs to change as well
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
Expand Down
14 changes: 12 additions & 2 deletions x/checkpointing/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cli

import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -105,9 +107,17 @@ before running the command (e.g., via babylond create-bls-key).`))

return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
}
// HACK: test cases need to setup the path where the priv validator BLS key is going to be set
// so we redefine the FlagHome here. Since we can't import `app` due to a cyclic dependency,
// we have to duplicate the definition here.
// If this changes, the `DefaultHomeDir` flag at `app/app.go` needs to change as well.
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}

cmd.Flags().String(flags.FlagHome, "", "The node home directory")
_ = cmd.MarkFlagRequired(flags.FlagHome)
defaultNodeHome := filepath.Join(userHomeDir, ".babylond")
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The node home directory")

return cmd
}
11 changes: 5 additions & 6 deletions x/checkpointing/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"

"github.com/babylonchain/babylon/app"
"github.com/babylonchain/babylon/app/params"
"github.com/babylonchain/babylon/privval"
testutilcli "github.com/babylonchain/babylon/testutil/cli"
checkpointcli "github.com/babylonchain/babylon/x/checkpointing/client/cli"
abci "github.com/tendermint/tendermint/abci/types"
tmconfig "github.com/tendermint/tendermint/config"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
Expand All @@ -30,12 +35,6 @@ import (
rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/babylonchain/babylon/app"
"github.com/babylonchain/babylon/app/params"
"github.com/babylonchain/babylon/privval"
testutilcli "github.com/babylonchain/babylon/testutil/cli"
checkpointcli "github.com/babylonchain/babylon/x/checkpointing/client/cli"
)

type mockTendermintRPC struct {
Expand Down
7 changes: 6 additions & 1 deletion x/checkpointing/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ func (m *MsgWrappedCreateValidator) ValidateBasic() error {
if err != nil {
return err
}
ok := m.VerifyPoP(m.MsgCreateValidator.Pubkey.GetCachedValue().(*ed255192.PubKey))
var pubKey ed255192.PubKey
err = pubKey.Unmarshal(m.MsgCreateValidator.Pubkey.GetValue())
if err != nil {
return err
}
ok := m.VerifyPoP(&pubKey)
if !ok {
return errors.New("the proof-of-possession is not valid")
}
Expand Down

0 comments on commit 82d5277

Please sign in to comment.