Skip to content

Commit

Permalink
Changes according to comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitronit committed Sep 3, 2023
1 parent 6a613a5 commit 8c2ff7e
Show file tree
Hide file tree
Showing 38 changed files with 441 additions and 436 deletions.
14 changes: 7 additions & 7 deletions cmd/horcrux/cmd/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"strings"

"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"github.com/strangelove-ventures/horcrux/pkg/cosigner"

"github.com/cometbft/cometbft/crypto"
cometprivval "github.com/cometbft/cometbft/privval"
Expand Down Expand Up @@ -35,24 +35,24 @@ func addressCmd() *cobra.Command {
chainID := args[0]

switch config.Config.SignMode {
case pcosigner.SignModeThreshold:
case cosigner.SignModeThreshold:
err := config.Config.ValidateThresholdModeConfig()
if err != nil {
return err
}

keyFile, err := config.KeyFileExistsCosigner(chainID)
keyFile, err := config.KeyFileExistsCosign(chainID)
if err != nil {
return err
}

key, err := pcosigner.LoadCosignerEd25519Key(keyFile)
key, err := cosigner.LoadCosignerEd25519Key(keyFile)
if err != nil {
return fmt.Errorf("error reading cosigner key: %w, check that key is present for chain ID: %s", err, chainID)
}

pubKey = key.PubKey
case pcosigner.SignModeSingle:
case cosigner.SignModeSingle:
err := config.Config.ValidateSingleSignerConfig()
if err != nil {
return err
Expand All @@ -70,7 +70,7 @@ func addressCmd() *cobra.Command {

pubKeyAddress := pubKey.Address()

pubKeyJSON, err := pcosigner.PubKey("", pubKey)
pubKeyJSON, err := cosigner.PubKey("", pubKey)
if err != nil {
return err
}
Expand All @@ -86,7 +86,7 @@ func addressCmd() *cobra.Command {
return err
}
output.ValConsAddress = bech32ValConsAddress
pubKeyBech32, err := pcosigner.PubKey(args[1], pubKey)
pubKeyBech32, err := cosigner.PubKey(args[1], pubKey)
if err != nil {
return err
}
Expand Down
22 changes: 11 additions & 11 deletions cmd/horcrux/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"github.com/strangelove-ventures/horcrux/pkg/cosigner"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -48,7 +48,7 @@ for threshold pkg mode, --cosigner flags and --threshold flag are required.
bare, _ := cmdFlags.GetBool(flagBare)
nodes, _ := cmdFlags.GetStringSlice(flagNode)

cn, err := pcosigner.ChainNodesFromFlag(nodes)
cn, err := cosigner.ChainNodesFromFlag(nodes)
if err != nil {
return err
}
Expand All @@ -60,7 +60,7 @@ for threshold pkg mode, --cosigner flags and --threshold flag are required.
config.ConfigFile)
}

var cfg pcosigner.Config
var cfg cosigner.Config

signMode, _ := cmdFlags.GetString(flagSignMode)
keyDirFlag, _ := cmdFlags.GetString(flagKeyDir)
Expand All @@ -69,21 +69,21 @@ for threshold pkg mode, --cosigner flags and --threshold flag are required.
keyDir = &keyDirFlag
}
debugAddr, _ := cmdFlags.GetString("debug-addr")
if signMode == string(pcosigner.SignModeThreshold) {
if signMode == string(cosigner.SignModeThreshold) {
// Threshold Mode Config
cosignersFlag, _ := cmdFlags.GetStringSlice(flagCosigner)
threshold, _ := cmdFlags.GetInt(flagThreshold)
raftTimeout, _ := cmdFlags.GetString(flagRaftTimeout)
grpcTimeout, _ := cmdFlags.GetString(flagGRPCTimeout)
cosigners, err := pcosigner.CosignersFromFlag(cosignersFlag)
cosigners, err := cosigner.CosignersFromFlag(cosignersFlag)
if err != nil {
return err
}

cfg = pcosigner.Config{
SignMode: pcosigner.SignModeThreshold,
cfg = cosigner.Config{
SignMode: cosigner.SignModeThreshold,
PrivValKeyDir: keyDir,
ThresholdModeConfig: &pcosigner.ThresholdModeConfig{
ThresholdModeConfig: &cosigner.ThresholdModeConfig{
Threshold: threshold,
Cosigners: cosigners,
GRPCTimeout: grpcTimeout,
Expand All @@ -100,8 +100,8 @@ for threshold pkg mode, --cosigner flags and --threshold flag are required.
}
} else {
// Single Signer Config
cfg = pcosigner.Config{
SignMode: pcosigner.SignModeSingle,
cfg = cosigner.Config{
SignMode: cosigner.SignModeSingle,
PrivValKeyDir: keyDir,
ChainNodes: cn,
DebugAddr: debugAddr,
Expand Down Expand Up @@ -132,7 +132,7 @@ for threshold pkg mode, --cosigner flags and --threshold flag are required.
}

f := cmd.Flags()
f.StringP(flagSignMode, "m", string(pcosigner.SignModeThreshold),
f.StringP(flagSignMode, "m", string(cosigner.SignModeThreshold),
`sign mode, "threshold" (recommended) or "single" (unsupported). threshold mode requires --cosigner (multiple) and --threshold`, //nolint
)
f.StringSliceP(flagNode, "n", []string{}, "chain nodes in format tcp://{node-addr}:{privval-port} \n"+
Expand Down
10 changes: 5 additions & 5 deletions cmd/horcrux/cmd/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"time"

"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"github.com/strangelove-ventures/horcrux/pkg/cosigner"

grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -110,21 +110,21 @@ func getLeaderCmd() *cobra.Command {

var id int

keyFileECIES, err := config.KeyFileExistsCosignerECIES()
keyFileECIES, err := config.KeyFileExistsCosignECIES()
if err != nil {
keyFileRSA, err := config.KeyFileExistsCosignerRSA()
keyFileRSA, err := config.KeyFileExistsCosignRSA()
if err != nil {
return fmt.Errorf("cosigner encryption keys not found (%s) - (%s): %w", keyFileECIES, keyFileRSA, err)
}

key, err := pcosigner.LoadCosignerRSAKey(keyFileRSA)
key, err := cosigner.LoadCosignRSAKey(keyFileRSA)
if err != nil {
return fmt.Errorf("error reading cosigner key (%s): %w", keyFileRSA, err)
}

id = key.ID
} else {
key, err := pcosigner.LoadCosignerECIESKey(keyFileECIES)
key, err := cosigner.LoadCosignerECIESKey(keyFileECIES)
if err != nil {
return fmt.Errorf("error reading cosigner key (%s): %w", keyFileECIES, err)
}
Expand Down
24 changes: 12 additions & 12 deletions cmd/horcrux/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"
"path/filepath"

"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"github.com/strangelove-ventures/horcrux/pkg/cosigner"

cometcrypto "github.com/cometbft/cometbft/crypto"
cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519"
Expand Down Expand Up @@ -104,7 +104,7 @@ func (key *v2CosignerKey) UnmarshalJSON(data []byte) error {

// Prior to the tendermint protobuf migration, the public key bytes in key files
// were encoded using the go-amino libraries via
// cdc.MarshalBinaryBare(CosignerEd25519Key.PubKey)
// cdc.MarshalBinaryBare(CosignEd25519Key.PubKey)
//
// To support reading the public key bytes from these key files, we fallback to
// amino unmarshalling if the protobuf unmarshalling fails
Expand Down Expand Up @@ -219,7 +219,7 @@ func migrateCmd() *cobra.Command {
return err
}

newEd25519Key := pcosigner.CosignerEd25519Key{
newEd25519Key := cosigner.CosignEd25519Key{
PubKey: legacyCosignerKey.PubKey,
PrivateShard: legacyCosignerKey.ShareKey,
ID: legacyCosignerKey.ID,
Expand All @@ -235,7 +235,7 @@ func migrateCmd() *cobra.Command {
return fmt.Errorf("failed to write new Ed25519 key to %s: %w", newEd25519Path, err)
}

newRSAKey := pcosigner.CosignerRSAKey{
newRSAKey := cosigner.CosignRSAKey{
RSAKey: legacyCosignerKey.RSAKey,
ID: legacyCosignerKey.ID,
RSAPubs: legacyCosignerKey.RSAPubs,
Expand All @@ -253,42 +253,42 @@ func migrateCmd() *cobra.Command {

// only attempt config migration if legacy config exists
if legacyCfgErr == nil {
var migratedNodes pcosigner.ChainNodes
var migratedNodes cosigner.ChainNodes

for _, n := range legacyCfg.ChainNodes {
migratedNodes = append(migratedNodes, pcosigner.ChainNode{
migratedNodes = append(migratedNodes, cosigner.ChainNode{
PrivValAddr: n.PrivValAddr,
})
}

config.Config.ChainNodes = migratedNodes
config.Config.DebugAddr = legacyCfg.DebugAddr

signMode := pcosigner.SignModeSingle
signMode := cosigner.SignModeSingle

if legacyCfg.Cosigner != nil {
signMode = pcosigner.SignModeThreshold
signMode = cosigner.SignModeThreshold

var migratedCosigners pcosigner.CosignersConfig
var migratedCosigners cosigner.CosignersConfig

if legacyCfg.Cosigner.P2PListen != "" {
migratedCosigners = append(
migratedCosigners,
pcosigner.CosignerConfig{
cosigner.CosignConfig{
ShardID: legacyCosignerKey.ID,
P2PAddr: legacyCfg.Cosigner.P2PListen,
},
)
}

for _, c := range legacyCfg.Cosigner.Peers {
migratedCosigners = append(migratedCosigners, pcosigner.CosignerConfig{
migratedCosigners = append(migratedCosigners, cosigner.CosignConfig{
ShardID: c.ShareID,
P2PAddr: c.P2PAddr,
})
}

config.Config.ThresholdModeConfig = &pcosigner.ThresholdModeConfig{
config.Config.ThresholdModeConfig = &cosigner.ThresholdModeConfig{
Threshold: legacyCfg.Cosigner.Threshold,
Cosigners: migratedCosigners,
GRPCTimeout: legacyCfg.Cosigner.Timeout,
Expand Down
6 changes: 3 additions & 3 deletions cmd/horcrux/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"os"
"path/filepath"

"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"github.com/strangelove-ventures/horcrux/pkg/cosigner"

homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
)

var config pcosigner.RuntimeConfig
var config cosigner.RuntimeConfig

func rootCmd() *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -75,7 +75,7 @@ func initConfig() {
} else {
home = config.HomeDir
}
config = pcosigner.RuntimeConfig{
config = cosigner.RuntimeConfig{
HomeDir: home,
ConfigFile: filepath.Join(home, "config.yaml"),
StateDir: filepath.Join(home, "state"),
Expand Down
14 changes: 7 additions & 7 deletions cmd/horcrux/cmd/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"os"
"path/filepath"

"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"github.com/strangelove-ventures/horcrux/pkg/cosigner"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -113,7 +113,7 @@ func createCosignerEd25519ShardsCmd() *cobra.Command {
return nil
}

csKeys, err := pcosigner.CreateCosignerEd25519ShardsFromFile(keyFile, threshold, shards)
csKeys, err := cosigner.CreateCosignerEd25519ShardsFromFile(keyFile, threshold, shards)
if err != nil {
return err
}
Expand All @@ -134,7 +134,7 @@ func createCosignerEd25519ShardsCmd() *cobra.Command {
return err
}
filename := filepath.Join(dir, fmt.Sprintf("%s_shard.json", chainID))
if err = pcosigner.WriteCosignerEd25519ShardFile(c, filename); err != nil {
if err = cosigner.WriteCosignerEd25519ShardFile(c, filename); err != nil {
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "Created Ed25519 Shard %s\n", filename)
Expand Down Expand Up @@ -171,7 +171,7 @@ func createCosignerECIESShardsCmd() *cobra.Command {
return fmt.Errorf("shards must be greater than zero (%d): %w", shards, err)
}

csKeys, err := pcosigner.CreateCosignerECIESShards(int(shards))
csKeys, err := cosigner.CreateCosignerECIESShards(int(shards))
if err != nil {
return err
}
Expand All @@ -192,7 +192,7 @@ func createCosignerECIESShardsCmd() *cobra.Command {
return err
}
filename := filepath.Join(dir, "ecies_keys.json")
if err = pcosigner.WriteCosignerECIESShardFile(c, filename); err != nil {
if err = cosigner.WriteCosignECIESShardFile(c, filename); err != nil {
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "Created ECIES Shard %s\n", filename)
Expand All @@ -219,7 +219,7 @@ func createCosignerRSAShardsCmd() *cobra.Command {
return fmt.Errorf("shards must be greater than zero (%d): %w", shards, err)
}

csKeys, err := pcosigner.CreateCosignerRSAShards(int(shards))
csKeys, err := cosigner.CreateCosignerRSAShards(int(shards))
if err != nil {
return err
}
Expand All @@ -240,7 +240,7 @@ func createCosignerRSAShardsCmd() *cobra.Command {
return err
}
filename := filepath.Join(dir, "rsa_keys.json")
if err = pcosigner.WriteCosignerRSAShardFile(c, filename); err != nil {
if err = cosigner.WriteCosignerRSAShardFile(c, filename); err != nil {
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "Created RSA Shard %s\n", filename)
Expand Down
6 changes: 3 additions & 3 deletions cmd/horcrux/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"github.com/strangelove-ventures/horcrux/pkg/cosigner"

"github.com/strangelove-ventures/horcrux/pkg/node"

Expand Down Expand Up @@ -50,12 +50,12 @@ func startCmd() *cobra.Command {
var services []service.Service

switch config.Config.SignMode {
case pcosigner.SignModeThreshold:
case cosigner.SignModeThreshold:
services, val, err = NewThresholdValidator(logger)
if err != nil {
return err
}
case pcosigner.SignModeSingle:
case cosigner.SignModeSingle:
val, err = NewSingleSignerValidator(out, acceptRisk)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/horcrux/cmd/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func showStateCmd() *cobra.Command {
return err
}

cs, err := types.LoadSignState(config.CosignerStateFile(chainID))
cs, err := types.LoadSignState(config.CosignStateFile(chainID))
if err != nil {
return err
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func setStateCmd() *cobra.Command {
return err
}

cs, err := types.LoadOrCreateSignState(config.CosignerStateFile(chainID))
cs, err := types.LoadOrCreateSignState(config.CosignStateFile(chainID))
if err != nil {
return err
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func importStateCmd() *cobra.Command {
}

// shareStateFile does not exist during default config init, so create if necessary
cs, err := types.LoadOrCreateSignState(config.CosignerStateFile(chainID))
cs, err := types.LoadOrCreateSignState(config.CosignStateFile(chainID))
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 8c2ff7e

Please sign in to comment.