Skip to content

Commit

Permalink
feat: Add cli flags for description (ethereum-optimism#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry authored Sep 18, 2023
1 parent eb211b5 commit 5e3a758
Show file tree
Hide file tree
Showing 24 changed files with 393 additions and 222 deletions.
6 changes: 2 additions & 4 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,16 @@ func (bc *BabylonController) RegisterValidator(
btcPubKey *bbntypes.BIP340PubKey,
pop *btcstakingtypes.ProofOfPossession,
commission sdkTypes.Dec,
description *sttypes.Description,
) (*provider.RelayerTxResponse, error) {

// TODO: This should be user configurable
emptyDesc := sttypes.Description{}

msg := &btcstakingtypes.MsgCreateBTCValidator{
Signer: bc.MustGetTxSigner(),
BabylonPk: bbnPubKey,
BtcPk: btcPubKey,
Pop: pop,
Commission: &commission,
Description: &emptyDesc,
Description: description,
}

res, err := bc.reliablySendMsg(msg)
Expand Down
5 changes: 4 additions & 1 deletion clientcontroller/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
ctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/relayer/v2/relayer/provider"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -49,7 +50,9 @@ type ClientController interface {
bbnPubKey *secp256k1.PubKey,
btcPubKey *bbntypes.BIP340PubKey,
pop *btcstakingtypes.ProofOfPossession,
commission sdkTypes.Dec) (*provider.RelayerTxResponse, error)
commission sdkTypes.Dec,
description *stakingtypes.Description,
) (*provider.RelayerTxResponse, error)
// CommitPubRandList commits a list of Schnorr public randomness via a MsgCommitPubRand to Babylon
// it returns tx hash and error
CommitPubRandList(btcPubKey *bbntypes.BIP340PubKey, startHeight uint64, pubRandList []bbntypes.SchnorrPubRand, sig *bbntypes.BIP340Signature) (*provider.RelayerTxResponse, error)
Expand Down
53 changes: 52 additions & 1 deletion cmd/valcli/daemoncmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"

"github.com/babylonchain/babylon/x/checkpointing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/urfave/cli"

"github.com/babylonchain/btc-validator/proto"
Expand Down Expand Up @@ -37,6 +38,13 @@ const (
valBabylonPkFlag = "babylon-pk"
blockHeightFlag = "height"
lastCommitHashFlag = "last-commit-hash"

// flags for description
monikerFlag = "moniker"
identityFlag = "identity"
websiteFlag = "website"
securityContractFlag = "security-contract"
detailsFlag = "details"
)

var (
Expand Down Expand Up @@ -92,20 +100,50 @@ var createValDaemonCmd = cli.Command{
Usage: "The unique name of the validator key",
Required: true,
},
cli.StringFlag{
Name: monikerFlag,
Usage: "A human-readable name for the validator",
Value: "",
},
cli.StringFlag{
Name: identityFlag,
Usage: "An optional identity signature (ex. UPort or Keybase)",
Value: "",
},
cli.StringFlag{
Name: websiteFlag,
Usage: "An optional website link",
Value: "",
},
cli.StringFlag{
Name: securityContractFlag,
Usage: "An optional email for security contact",
Value: "",
},
cli.StringFlag{
Name: detailsFlag,
Usage: "Other optional details",
Value: "",
},
},
Action: createValDaemon,
}

func createValDaemon(ctx *cli.Context) error {
daemonAddress := ctx.String(valdDaemonAddressFlag)
keyName := ctx.String(keyNameFlag)
description, err := getDesciptionFromContext(ctx)
if err != nil {
return err
}

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

info, err := client.CreateValidator(context.Background(), keyName)
info, err := client.CreateValidator(context.Background(), keyName, &description)

if err != nil {
return err
Expand All @@ -116,6 +154,19 @@ func createValDaemon(ctx *cli.Context) error {
return nil
}

func getDesciptionFromContext(ctx *cli.Context) (stakingtypes.Description, error) {

// get information for description
monikerStr := ctx.String(monikerFlag)
identityStr := ctx.String(identityFlag)
websiteStr := ctx.String(websiteFlag)
securityContractStr := ctx.String(securityContractFlag)
detailsStr := ctx.String(detailsFlag)

description := stakingtypes.NewDescription(monikerStr, identityStr, websiteStr, securityContractStr, detailsStr)
return description.EnsureLength()
}

var lsValDaemonCmd = cli.Command{
Name: "list-validators",
ShortName: "ls",
Expand Down
32 changes: 31 additions & 1 deletion cmd/valcli/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ var createValCmd = cli.Command{
Name: keyringDirFlag,
Usage: "The directory where the keyring is stored",
},
cli.StringFlag{
Name: monikerFlag,
Usage: "A human-readable name for the validator",
Value: "",
},
cli.StringFlag{
Name: identityFlag,
Usage: "An optional identity signature (ex. UPort or Keybase)",
Value: "",
},
cli.StringFlag{
Name: websiteFlag,
Usage: "An optional website link",
Value: "",
},
cli.StringFlag{
Name: securityContractFlag,
Usage: "An optional email for security contact",
Value: "",
},
cli.StringFlag{
Name: detailsFlag,
Usage: "Other optional details",
Value: "",
},
},
Action: createVal,
}
Expand All @@ -82,7 +107,12 @@ func createVal(ctx *cli.Context) error {
return fmt.Errorf("the key name %s is taken", krController.GetKeyName())
}

validator, err := krController.CreateBTCValidator()
description, err := getDesciptionFromContext(ctx)
if err != nil {
return err
}

validator, err := krController.CreateBTCValidator(&description)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/cometbft/cometbft v0.37.2
github.com/cosmos/cosmos-sdk v0.47.3
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/relayer/v2 v2.4.1
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.6.0
Expand Down Expand Up @@ -84,7 +85,6 @@ require (
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.10 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
github.com/cosmos/ibc-go/v7 v7.2.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion itest/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/babylonchain/btc-validator/clientcontroller"
"github.com/babylonchain/btc-validator/service"
"github.com/babylonchain/btc-validator/testutil"
"github.com/babylonchain/btc-validator/types"
"github.com/babylonchain/btc-validator/valcfg"
)
Expand Down Expand Up @@ -113,7 +114,7 @@ func StartManagerWithValidator(t *testing.T, n int, isJury bool) *TestManager {
var newValName = "test-val-"
for i := 0; i < n; i++ {
newValName += strconv.Itoa(i)
_, err := app.CreateValidator(newValName)
_, err := app.CreateValidator(newValName, testutil.EmptyDescription())
require.NoError(t, err)
_, bbnPk, err := app.RegisterValidator(newValName)
require.NoError(t, err)
Expand Down
18 changes: 14 additions & 4 deletions proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
version: v1
deps:
- remote: buf.build
owner: gogo
repository: protobuf
commit: 4df00b267f944190a229ce3695781e99
digest: shake256:de60e0534d11dfd7a1817909618e847e15d4ab6f5cc6d71154a9735af651c7bda2232b33f3fb6a4daf23f64a3fe80270e99d42d77c551bb9a69ab5dc48ec2e04
owner: cosmos
repository: cosmos-proto
commit: 1935555c206d4afb9e94615dfd0fad31
digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: 954f7b05f38440fc8250134b15adec47
digest: shake256:2ab4404fd04a7d1d52df0e2d0f2d477a3d83ffd88d876957bf3fedfd702c8e52833d65b3ce1d89a3c5adf2aab512616b0e4f51d8463f07eda9a8a3317ee3ac54
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 34d970b699f84aa382f3c29773a60836
digest: shake256:3d3bee5229ba579e7d19ffe6e140986a228b48a8c7fe74348f308537ab95e9135210e81812489d42cd8941d33ff71f11583174ccc5972e86e6112924b6ce9f04
- remote: buf.build
owner: googleapis
repository: googleapis
Expand Down
4 changes: 3 additions & 1 deletion proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: v1
name: buf.build/babylonchain/btc-validator
deps:
- buf.build/cosmos/cosmos-sdk:v0.47.0
- buf.build/cosmos/cosmos-proto:1935555c206d4afb9e94615dfd0fad31
- buf.build/googleapis/googleapis:8d7204855ec14631a499bd7393ce1970
- buf.build/gogo/protobuf:b03c65ea87cdc3521ede29f62fe3ce239267c1bc
- buf.build/cosmos/gogo-proto:a14993478f40695898ed8a86931094b6656e8a5d
breaking:
use:
- FILE
Expand Down
2 changes: 2 additions & 0 deletions proto/scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ cd proto
buf mod update
buf generate .
cd ..

go mod tidy -compat=1.20
1 change: 1 addition & 0 deletions proto/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func NewValidatorInfo(v *StoreValidator) *ValidatorInfo {
return &ValidatorInfo{
BabylonPkHex: v.GetBabylonPkHexString(),
BtcPkHex: v.MustGetBIP340BTCPK().MarshalHex(),
Description: v.Description,
LastVotedHeight: v.LastVotedHeight,
LastCommittedHeight: v.LastCommittedHeight,
Status: v.Status,
Expand Down
Loading

0 comments on commit 5e3a758

Please sign in to comment.