Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor factorising #188

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e630293
factor test
nitronit Aug 7, 2023
8d01ee6
Merge remote-tracking branch 'upstream/main' into factor
nitronit Aug 7, 2023
9301526
Make fix
nitronit Aug 7, 2023
619b230
//nolint fix
nitronit Aug 8, 2023
49515f0
Added comments and two structs renamings.
nitronit Aug 11, 2023
1bf4d43
cleaning up RaftStore
nitronit Aug 14, 2023
d4dd42d
fix RAFT test
nitronit Aug 14, 2023
496c2da
revert to CosignerGRPCSignBlockRequest
nitronit Aug 14, 2023
40177bd
fix multiresolver test
nitronit Aug 14, 2023
6f66659
comments
nitronit Aug 14, 2023
124bd9f
refactor - breaks
nitronit Aug 15, 2023
34b9ec9
still problem with map key json
nitronit Aug 16, 2023
767bfa5
still breaking
nitronit Aug 16, 2023
39a6303
Cond is now again private, instead "aliasing" cond
nitronit Aug 17, 2023
4606262
linted
nitronit Aug 17, 2023
0cd0cd4
added some tests & signstate.mu now private
nitronit Aug 17, 2023
70f49a4
Comments
nitronit Aug 22, 2023
43c286f
almost done. I have a few more things to do to it.
nitronit Aug 22, 2023
9e25881
should pass now.
nitronit Aug 22, 2023
03f8dab
interfaces defined where it is used.
nitronit Aug 28, 2023
f08f062
linted
nitronit Aug 28, 2023
6a613a5
lint fix
nitronit Aug 28, 2023
8c2ff7e
Changes according to comments.
nitronit Sep 3, 2023
2ad8797
cosign renaming.
nitronit Sep 3, 2023
31e6920
renaming of cosigners.
nitronit Sep 5, 2023
f155fdc
Merge pull request #52 from strangelove-ventures/main
nitronit Sep 5, 2023
5cf7b40
proto files re-compiled.
nitronit Sep 7, 2023
41d514d
proto fix
nitronit Sep 7, 2023
e2cca71
proto fixes
nitronit Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
uses: actions/checkout@v3

# make sure proto files are up to date
- name: generate fresh signer proto .go files
run: make signer-proto
- name: generate fresh pkg proto .go files
run: make pkg-proto

# run tests
- name: run horcrux tests
Expand Down Expand Up @@ -60,8 +60,8 @@ jobs:
uses: actions/checkout@v3

# make sure proto files are up to date
- name: generate fresh signer proto .go files
run: make signer-proto
- name: generate fresh pkg proto .go files
run: make pkg-proto

# run test matrix
- name: run test
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ build-horcrux-docker:
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))

signer-proto:
pkg-proto:
docker run \
--rm \
-u $(shell id -u ${USER}):$(shell id -g ${USER}) \
--mount type=bind,source=$(mkfile_dir)/signer/proto,target=/horcrux/signer/proto \
--mount type=bind,source=$(mkfile_dir)/pkg/proto,target=/horcrux/pkg/proto \
--entrypoint protoc \
namely/protoc-all \
--go_out=/horcrux \
Expand Down
15 changes: 8 additions & 7 deletions cmd/horcrux/cmd/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"fmt"
"strings"

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

"github.com/cometbft/cometbft/crypto"
cometprivval "github.com/cometbft/cometbft/privval"
"github.com/cosmos/cosmos-sdk/types/bech32"
"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/signer"
)

type AddressCmdOutput struct {
Expand All @@ -34,24 +35,24 @@ func addressCmd() *cobra.Command {
chainID := args[0]

switch config.Config.SignMode {
case signer.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 := signer.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 signer.SignModeSingle:
case cosigner.SignModeSingle:
err := config.Config.ValidateSingleSignerConfig()
if err != nil {
return err
Expand All @@ -69,7 +70,7 @@ func addressCmd() *cobra.Command {

pubKeyAddress := pubKey.Address()

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

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

"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/signer"
)

const (
Expand All @@ -23,7 +24,7 @@ const (
func configCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "Commands to configure the horcrux signer",
Short: "Commands to configure the horcrux pkg",
}

cmd.AddCommand(initCmd())
Expand All @@ -38,7 +39,7 @@ func initCmd() *cobra.Command {
Aliases: []string{"i"},
Short: "initialize configuration file and home directory if one doesn't already exist",
Long: `initialize configuration file.
for threshold signer mode, --cosigner flags and --threshold flag are required.
for threshold pkg mode, --cosigner flags and --threshold flag are required.
`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -47,7 +48,7 @@ for threshold signer mode, --cosigner flags and --threshold flag are required.
bare, _ := cmdFlags.GetBool(flagBare)
nodes, _ := cmdFlags.GetStringSlice(flagNode)

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

var cfg signer.Config
var cfg cosigner.Config

signMode, _ := cmdFlags.GetString(flagSignMode)
keyDirFlag, _ := cmdFlags.GetString(flagKeyDir)
Expand All @@ -68,21 +69,21 @@ for threshold signer mode, --cosigner flags and --threshold flag are required.
keyDir = &keyDirFlag
}
debugAddr, _ := cmdFlags.GetString("debug-addr")
if signMode == string(signer.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 := signer.CosignersFromFlag(cosignersFlag)
cosigners, err := cosigner.CosignersFromFlag(cosignersFlag)
if err != nil {
return err
}

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

f := cmd.Flags()
f.StringP(flagSignMode, "m", string(signer.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
19 changes: 10 additions & 9 deletions cmd/horcrux/cmd/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"fmt"
"time"

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

grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/client"
"github.com/strangelove-ventures/horcrux/signer"
"github.com/strangelove-ventures/horcrux/signer/multiresolver"
"github.com/strangelove-ventures/horcrux/signer/proto"
"github.com/strangelove-ventures/horcrux/pkg/multiresolver"
"github.com/strangelove-ventures/horcrux/pkg/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand Down Expand Up @@ -69,7 +70,7 @@ horcrux elect 2 # elect specific leader`,
ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second)
defer cancelFunc()

grpcClient := proto.NewCosignerGRPCClient(conn)
grpcClient := proto.NewICosignerGRPCClient(conn)
_, err = grpcClient.TransferLeadership(
ctx,
&proto.CosignerGRPCTransferLeadershipRequest{LeaderID: leaderID},
Expand Down Expand Up @@ -109,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 := signer.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 := signer.LoadCosignerECIESKey(keyFileECIES)
key, err := cosigner.LoadCosignerECIESKey(keyFileECIES)
if err != nil {
return fmt.Errorf("error reading cosigner key (%s): %w", keyFileECIES, err)
}
Expand Down Expand Up @@ -166,7 +167,7 @@ func getLeaderCmd() *cobra.Command {
ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second)
defer cancelFunc()

grpcClient := proto.NewCosignerGRPCClient(conn)
grpcClient := proto.NewICosignerGRPCClient(conn)

res, err := grpcClient.GetLeader(ctx, &proto.CosignerGRPCGetLeaderRequest{})
if err != nil {
Expand Down
25 changes: 13 additions & 12 deletions cmd/horcrux/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"os"
"path/filepath"

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

cometcrypto "github.com/cometbft/cometbft/crypto"
cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519"
cometcryptoencoding "github.com/cometbft/cometbft/crypto/encoding"
cometprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/signer"
amino "github.com/tendermint/go-amino"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -103,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 @@ -218,7 +219,7 @@ func migrateCmd() *cobra.Command {
return err
}

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

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

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

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

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

signMode := signer.SignModeSingle
signMode := cosigner.SignModeSingle

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

var migratedCosigners signer.CosignersConfig
var migratedCosigners cosigner.CosignersConfig

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

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

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

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

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

var config signer.RuntimeConfig
var config cosigner.RuntimeConfig

func rootCmd() *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -74,7 +75,7 @@ func initConfig() {
} else {
home = config.HomeDir
}
config = signer.RuntimeConfig{
config = cosigner.RuntimeConfig{
HomeDir: home,
ConfigFile: filepath.Join(home, "config.yaml"),
StateDir: filepath.Join(home, "state"),
Expand Down
Loading
Loading