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

Refactor v3.2.2 #55

Open
wants to merge 38 commits into
base: test_rabbit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
26c340c
Fix stuck leader when cosigner goes down (#232)
agouin Dec 11, 2023
7ded03c
Reverse where we start checking for a non-expired nonce, oldest -> ne…
misko9 Dec 12, 2023
60760f2
add unit tests for prune (#235)
agouin Dec 12, 2023
8e01923
mitigate unexpected state (#233)
agouin Dec 12, 2023
dfeab36
Refactor code and update comments
nitronit Dec 18, 2023
3ee2bd1
Update function names and add missing imports + metrics factorization
nitronit Dec 18, 2023
e7db1ea
Merge branch 'main' of https://github.com/strangelove-ventures/horcru…
nitronit Dec 18, 2023
88f0a31
go fmt:ed
nitronit Dec 18, 2023
d0ff41f
Refactor code to use new package structure
nitronit Dec 19, 2023
44881fd
Refactor cosigner security initialization
nitronit Dec 19, 2023
9439ccf
Update Go packages and fix test cases
nitronit Dec 19, 2023
95a1cba
Refactor cosigner health test and raft store test
nitronit Dec 19, 2023
731103a
Refactor mock leader in nonce cache tests
nitronit Dec 19, 2023
5489c5e
Refactor sign mode flag and fix formatting in cosigner_security_ecies.go
nitronit Dec 19, 2023
761c7ff
Just testing it works exluding some tests.
nitronit Dec 19, 2023
ae0123a
lint
nitronit Dec 19, 2023
ff8502d
Refactor RemoteCosigner initialization and update test case
nitronit Dec 19, 2023
727846c
Update package imports and variable names
nitronit Dec 21, 2023
6dac3f3
Update import statements for tss package. Changed name from temp to tss
nitronit Dec 21, 2023
d222ee6
Add ICosignerSecurity interface for cosigner security layer
nitronit Dec 21, 2023
35e5f1f
Update cosigner to mycosigner in raft_events.go and raft_store.go
nitronit Dec 21, 2023
adce5e8
Refactor MockLeader struct and update type of leader variable
nitronit Dec 21, 2023
5f854ad
Update interface names in signer package
nitronit Dec 21, 2023
e5409d9
Fix variable assignment and method name in local_cosigner.go and bloc…
nitronit Dec 21, 2023
22c6dbd
Add Ed25519Key struct and update references
nitronit Dec 23, 2023
6011f98
Remove privval.FilePVKey from VaultPrivateKey interface
nitronit Dec 23, 2023
7f94824
Fix issues with cosigner and tss packages
nitronit Dec 23, 2023
abeebc6
Refactor cosigner package and add ted25519SignerSoft type
nitronit Dec 23, 2023
31f7684
Add new files and update existing code
nitronit Dec 26, 2023
c804cd8
Add threshold dealer interface and implementation
nitronit Dec 27, 2023
a9cc824
Refactor cosigner package and interfaces
nitronit Dec 28, 2023
7d4c8b6
Add new files and interfaces for cosigner and threshold signer
nitronit Jan 6, 2024
9d5bf25
Update import paths in test files
nitronit Jan 6, 2024
493d6af
Reorg files and update imports, and fix some tests
nitronit Jan 16, 2024
d485298
Fix sign mode comment formatting
nitronit Jan 16, 2024
063e0d2
refactor and name change
nitronit Jan 28, 2024
2e39f23
node changes
nitronit Jan 28, 2024
e16edda
Fix import paths and update dependencies
nitronit Feb 16, 2024
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
6 changes: 4 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,18 @@ linters-settings:
alias: gmprometheus
- pkg: github.com/mitchellh/go-homedir
alias: homedir
- pkg: gitlab.com/unit410/threshold-ed25519/pkg
- pkg: gitlab.com/unit410/threshold-ed25519/src
alias: tsed25519
- pkg: github.com/Jille/raft-grpc-transport
alias: raftgrpctransport
- pkg: github.com/hashicorp/raft-boltdb/v2
alias: boltdb
- pkg: math/rand
alias: mrand
- pkg: github.com/strangelove-ventures/horcrux/pkg/types
- pkg: github.com/strangelove-ventures/horcrux/src/types
alias: htypes
- pkg: github.com/strangelove-ventures/horcrux/src/config
alias: cconfig
maligned:
suggest-new: true
govet:
Expand Down
4 changes: 4 additions & 0 deletions client/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"strings"
)

type clientAdresses struct {
id []string
}

func SanitizeAddress(address string) (string, error) {
u, err := url.Parse(address)
if err != nil {
Expand Down
21 changes: 11 additions & 10 deletions cmd/horcrux/cmd/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
cometprivval "github.com/cometbft/cometbft/privval"
"github.com/cosmos/cosmos-sdk/types/bech32"
"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/signer"
cconfig "github.com/strangelove-ventures/horcrux/src/config"
"github.com/strangelove-ventures/horcrux/src/tss"
)

type AddressCmdOutput struct {
Expand All @@ -29,12 +30,12 @@ func addressCmd() *cobra.Command {
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {

var pubKey crypto.PubKey
var pubKey tss.PubKey

chainID := args[0]

switch config.Config.SignMode {
case signer.SignModeThreshold:
case cconfig.SignModeThreshold:
err := config.Config.ValidateThresholdModeConfig()
if err != nil {
return err
Expand All @@ -45,13 +46,13 @@ func addressCmd() *cobra.Command {
return err
}

key, err := signer.LoadThresholdSignerEd25519Key(keyFile)
key, err := tss.LoadVaultKeyFromFile(keyFile)
if err != nil {
return fmt.Errorf("error reading threshold key: %w, check that key is present for chain id: %s", err, chainID)
}

pubKey = key.PubKey
case signer.SignModeSingle:
pubKey = key.PubKey.(crypto.PubKey)
case cconfig.SignModeSingle:
err := config.Config.ValidateSingleSignerConfig()
if err != nil {
return err
Expand All @@ -67,10 +68,10 @@ func addressCmd() *cobra.Command {
default:
panic(fmt.Errorf("unexpected sign mode: %s", config.Config.SignMode))
}
pubKeyComet := pubKey.(crypto.PubKey)
pubKeyAddress := pubKeyComet.Address()

pubKeyAddress := pubKey.Address()

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

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

const (
Expand Down Expand Up @@ -48,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 := cconfig.ChainNodesFromFlag(nodes)
if err != nil {
return err
}
Expand All @@ -60,7 +60,7 @@ for threshold signer mode, --cosigner flags and --threshold flag are required.
config.ConfigFile)
}

var cfg signer.Config
var cfg cconfig.Config

signMode, _ := cmdFlags.GetString(flagSignMode)
keyDirFlag, _ := cmdFlags.GetString(flagKeyDir)
Expand All @@ -70,21 +70,21 @@ for threshold signer mode, --cosigner flags and --threshold flag are required.
}
debugAddr, _ := cmdFlags.GetString(flagDebugAddr)
grpcAddr, _ := cmdFlags.GetString(flagGRPCAddress)
if signMode == string(signer.SignModeThreshold) {
if signMode == string(cconfig.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 := cconfig.CosignersFromFlag(cosignersFlag)
if err != nil {
return err
}

cfg = signer.Config{
SignMode: signer.SignModeThreshold,
cfg = cconfig.Config{
SignMode: cconfig.SignModeThreshold,
PrivValKeyDir: keyDir,
ThresholdModeConfig: &signer.ThresholdModeConfig{
ThresholdModeConfig: &cconfig.ThresholdModeConfig{
Threshold: threshold,
Cosigners: cosigners,
GRPCTimeout: grpcTimeout,
Expand All @@ -102,8 +102,8 @@ for threshold signer mode, --cosigner flags and --threshold flag are required.
}
} else {
// Single Signer Config
cfg = signer.Config{
SignMode: signer.SignModeSingle,
cfg = cconfig.Config{
SignMode: cconfig.SignModeSingle,
PrivValKeyDir: keyDir,
ChainNodes: cn,
DebugAddr: debugAddr,
Expand Down Expand Up @@ -134,10 +134,10 @@ 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(cconfig.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"+
f.StringSliceP(flagNode, "n", []string{}, "chain cosigner in format tcp://{node-addr}:{privval-port} \n"+
"(e.g. --node tcp://sentry-1:1234 --node tcp://sentry-2:1234 --node tcp://sentry-3:1234 )")

f.StringSliceP(flagCosigner, "c", []string{},
Expand Down
17 changes: 10 additions & 7 deletions cmd/horcrux/cmd/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (
"fmt"
"time"

"github.com/strangelove-ventures/horcrux/src/cosigner/nodesecurity"

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/proto/strangelove/proto"
"github.com/strangelove-ventures/horcrux/src/multiresolver"

// "github.com/strangelove-ventures/horcrux/src/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand Down Expand Up @@ -69,7 +72,7 @@ horcrux elect 2 # elect specific leader`,
ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second)
defer cancelFunc()

grpcClient := proto.NewCosignerClient(conn)
grpcClient := proto.NewNodeServiceClient(conn)
_, err = grpcClient.TransferLeadership(
ctx,
&proto.TransferLeadershipRequest{LeaderID: leaderID},
Expand Down Expand Up @@ -116,14 +119,14 @@ func getLeaderCmd() *cobra.Command {
return fmt.Errorf("cosigner encryption keys not found (%s) - (%s): %w", keyFileECIES, keyFileRSA, err)
}

key, err := signer.LoadCosignerRSAKey(keyFileRSA)
key, err := nodesecurity.LoadCosignerRSAKey(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 := nodesecurity.LoadCosignerECIESKey(keyFileECIES)
if err != nil {
return fmt.Errorf("error reading cosigner key (%s): %w", keyFileECIES, err)
}
Expand Down Expand Up @@ -166,7 +169,7 @@ func getLeaderCmd() *cobra.Command {
ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second)
defer cancelFunc()

grpcClient := proto.NewCosignerClient(conn)
grpcClient := proto.NewNodeServiceClient(conn)

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

cconfig "github.com/strangelove-ventures/horcrux/src/config"
"github.com/strangelove-ventures/horcrux/src/cosigner/nodesecurity"
"github.com/strangelove-ventures/horcrux/src/tss"

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 @@ -42,7 +45,7 @@ type (
ChainID string `json:"chain-id" yaml:"chain-id"`
PrivValKeyFile *string `json:"key-file,omitempty" yaml:"key-file,omitempty"`
Cosigner *v2CosignerConfig `json:"cosigner" yaml:"cosigner"`
ChainNodes []v2ChainNodeConfig `json:"chain-nodes,omitempty" yaml:"chain-nodes,omitempty"`
ChainNodes []v2ChainNodeConfig `json:"chain-cosigner,omitempty" yaml:"chain-cosigner,omitempty"`
DebugAddr string `json:"debug-addr,omitempty" yaml:"debug-addr,omitempty"`
}

Expand Down Expand Up @@ -103,7 +106,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(Ed25519Key.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 +221,7 @@ func migrateCmd() *cobra.Command {
return err
}

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

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

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

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

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

signMode := signer.SignModeSingle
signMode := cconfig.SignModeSingle

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

var migratedCosigners signer.CosignersConfig
var migratedCosigners cconfig.CosignersConfig

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

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

config.Config.ThresholdModeConfig = &signer.ThresholdModeConfig{
config.Config.ThresholdModeConfig = &cconfig.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 @@ -8,11 +8,11 @@ import (
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/strangelove-ventures/horcrux/signer"
cconfig "github.com/strangelove-ventures/horcrux/src/config"
"gopkg.in/yaml.v2"
)

var config signer.RuntimeConfig
var config cconfig.RuntimeConfig

func rootCmd() *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -74,7 +74,7 @@ func initConfig() {
} else {
home = config.HomeDir
}
config = signer.RuntimeConfig{
config = cconfig.RuntimeConfig{
HomeDir: home,
ConfigFile: filepath.Join(home, "config.yaml"),
StateDir: filepath.Join(home, "state"),
Expand Down
6 changes: 4 additions & 2 deletions signer/services.go → cmd/horcrux/cmd/services.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package signer
package cmd

import (
"errors"
Expand All @@ -13,6 +13,7 @@ import (
cometservice "github.com/cometbft/cometbft/libs/service"
)

// TODO: Move RequireNotRunning outside of this package.
func RequireNotRunning(log cometlog.Logger, pidFilePath string) error {
if _, err := os.Stat(pidFilePath); err != nil {
if os.IsNotExist(err) {
Expand Down Expand Up @@ -61,7 +62,8 @@ func RequireNotRunning(log cometlog.Logger, pidFilePath string) error {
return nil
}

errno, ok := err.(syscall.Errno)
var errno syscall.Errno
ok := errors.As(err, &errno)
if !ok {
return fmt.Errorf("unexpected error type from signaling horcrux PID: %d", pid)
}
Expand Down
Loading
Loading