Skip to content

Commit

Permalink
should pass now.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitronit committed Aug 22, 2023
1 parent 43c286f commit 9e25881
Show file tree
Hide file tree
Showing 25 changed files with 143 additions and 118 deletions.
13 changes: 7 additions & 6 deletions cmd/horcrux/cmd/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
pcosigner2 "github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"strings"

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

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

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

key, err := pcosigner2.LoadCosignerEd25519Key(keyFile)
key, err := pcosigner.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 pcosigner2.SignModeSingle:
case pcosigner.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 := pcosigner2.PubKey("", pubKey)
pubKeyJSON, err := pcosigner.PubKey("", pubKey)
if err != nil {
return err
}
Expand All @@ -85,7 +86,7 @@ func addressCmd() *cobra.Command {
return err
}
output.ValConsAddress = bech32ValConsAddress
pubKeyBech32, err := pcosigner2.PubKey(args[1], pubKey)
pubKeyBech32, err := pcosigner.PubKey(args[1], pubKey)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/horcrux/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cmd

import (
"fmt"
"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"os"

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

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -132,7 +133,7 @@ for threshold pkg mode, --cosigner flags and --threshold flag are required.

f := cmd.Flags()
f.StringP(flagSignMode, "m", string(pcosigner.SignModeThreshold),
`sign mode, "threshold" (recommended) or "single" (unsupported). threshold mode requires --cosigner (multiple) and --threshold`, // nolint
`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"+
"(e.g. --node tcp://sentry-1:1234 --node tcp://sentry-2:1234 --node tcp://sentry-3:1234 )")
Expand Down
23 changes: 12 additions & 11 deletions cmd/horcrux/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
pcosigner2 "github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"os"
"path/filepath"

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

cometcrypto "github.com/cometbft/cometbft/crypto"
cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519"
cometcryptoencoding "github.com/cometbft/cometbft/crypto/encoding"
Expand Down Expand Up @@ -218,7 +219,7 @@ func migrateCmd() *cobra.Command {
return err
}

newEd25519Key := pcosigner2.CosignerEd25519Key{
newEd25519Key := pcosigner.CosignerEd25519Key{
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 := pcosigner2.CosignerRSAKey{
newRSAKey := pcosigner.CosignerRSAKey{
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 pcosigner2.ChainNodes
var migratedNodes pcosigner.ChainNodes

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

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

signMode := pcosigner2.SignModeSingle
signMode := pcosigner.SignModeSingle

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

var migratedCosigners pcosigner2.CosignersConfig
var migratedCosigners pcosigner.CosignersConfig

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

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

config.Config.ThresholdModeConfig = &pcosigner2.ThresholdModeConfig{
config.Config.ThresholdModeConfig = &pcosigner.ThresholdModeConfig{
Threshold: legacyCfg.Cosigner.Threshold,
Cosigners: migratedCosigners,
GRPCTimeout: legacyCfg.Cosigner.Timeout,
Expand Down
3 changes: 2 additions & 1 deletion cmd/horcrux/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cmd

import (
"fmt"
"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"os"
"path/filepath"

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

homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down
3 changes: 2 additions & 1 deletion cmd/horcrux/cmd/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ package cmd

import (
"fmt"
"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"os"
"path/filepath"

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

"github.com/spf13/cobra"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/horcrux/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cmd

import (
"fmt"
"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"os"

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

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

cometlog "github.com/cometbft/cometbft/libs/log"
Expand Down
3 changes: 2 additions & 1 deletion cmd/horcrux/cmd/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bufio"
"encoding/base64"
"fmt"
"github.com/strangelove-ventures/horcrux/pkg/types"
"io"
"os"
"strconv"
"strings"
"time"

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

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

cometjson "github.com/cometbft/cometbft/libs/json"
Expand Down
3 changes: 2 additions & 1 deletion cmd/horcrux/cmd/state_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package cmd

import (
"github.com/strangelove-ventures/horcrux/pkg/types"
"io"
"path/filepath"
"strconv"
"testing"
"time"

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

"github.com/stretchr/testify/require"
)

Expand Down
11 changes: 6 additions & 5 deletions cmd/horcrux/cmd/threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"fmt"
pcosigner2 "github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"os"
"path/filepath"
"time"

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

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

cometlog "github.com/cometbft/cometbft/libs/log"
Expand All @@ -24,11 +25,11 @@ func NewThresholdValidator(

thresholdCfg := config.Config.ThresholdModeConfig

remoteCosigners := make([]pcosigner2.ICosigner, 0, len(thresholdCfg.Cosigners)-1)
remoteCosigners := make([]pcosigner.ICosigner, 0, len(thresholdCfg.Cosigners)-1)

var p2pListen string

var security pcosigner2.ICosignerSecurity
var security pcosigner.ICosignerSecurity
var eciesErr error
security, eciesErr = config.CosignerSecurityECIES()
if eciesErr != nil {
Expand All @@ -43,7 +44,7 @@ func NewThresholdValidator(
if c.ShardID != security.GetID() {
remoteCosigners = append(
remoteCosigners,
pcosigner2.NewRemoteCosigner(c.ShardID, c.P2PAddr),
pcosigner.NewRemoteCosigner(c.ShardID, c.P2PAddr),
)
} else {
p2pListen = c.P2PAddr
Expand All @@ -54,7 +55,7 @@ func NewThresholdValidator(
return nil, nil, fmt.Errorf("cosigner config does not exist for our shard ID %d", security.GetID())
}

localCosigner := pcosigner2.NewLocalCosigner(
localCosigner := pcosigner.NewLocalCosigner(
logger,
&config,
security,
Expand Down
3 changes: 2 additions & 1 deletion pkg/cond/cond_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cond_test

import (
"github.com/strangelove-ventures/horcrux/pkg/cond"
"runtime"
"sync"
"testing"

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

"github.com/stretchr/testify/require"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/node/leader_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package node
// MockLeader is a "helper" mathod for use with testing.
import (
"errors"
"github.com/strangelove-ventures/horcrux/pkg/types"
"sync"
"time"

"github.com/strangelove-ventures/horcrux/pkg/types"
)

var _ ILeader = (*MockLeader)(nil)
Expand Down
3 changes: 2 additions & 1 deletion pkg/node/raft_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func (s *RaftStore) init() error {
}
// Create a new gRPC server which is used by both the Raft, the threshold validator and the cosigner
grpcServer := grpc.NewServer()
proto.RegisterICosignerGRPCServerServer(grpcServer, NewGRPCServer(s.thresholdValidator.myCosigner, s.thresholdValidator, s))
proto.RegisterICosignerGRPCServerServer(grpcServer,
NewGRPCServer(s.thresholdValidator.myCosigner, s.thresholdValidator, s))
transportManager.Register(grpcServer)
leaderhealth.Setup(s.raft, grpcServer, []string{"Leader"})
raftadmin.Register(grpcServer, s.raft)
Expand Down
13 changes: 7 additions & 6 deletions pkg/node/raft_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package node

import (
"crypto/rand"
pcosigner2 "github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"os"
"testing"
"time"

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

cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519"
"github.com/cometbft/cometbft/libs/log"
"github.com/ethereum/go-ethereum/crypto/ecies"
Expand All @@ -25,17 +26,17 @@ func Test_StoreInMemOpenSingleNode(t *testing.T) {
eciesKey, err := ecies.GenerateKey(rand.Reader, secp256k1.S256(), nil)
require.NoError(t, err)

key := pcosigner2.CosignerEd25519Key{
key := pcosigner.CosignerEd25519Key{
PubKey: dummyPub,
PrivateShard: []byte{},
ID: 1,
}

cosigner := pcosigner2.NewLocalCosigner(
cosigner := pcosigner.NewLocalCosigner(
log.NewNopLogger(),
&pcosigner2.RuntimeConfig{},
pcosigner2.NewCosignerSecurityECIES(
pcosigner2.CosignerECIESKey{
&pcosigner.RuntimeConfig{},
pcosigner.NewCosignerSecurityECIES(
pcosigner.CosignerECIESKey{
ID: key.ID,
ECIESKey: eciesKey,
ECIESPubs: []*ecies.PublicKey{&eciesKey.PublicKey},
Expand Down
3 changes: 2 additions & 1 deletion pkg/node/single_signer_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package node

import (
"fmt"
"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"os"
"sync"

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

cometcrypto "github.com/cometbft/cometbft/crypto"
cometprivval "github.com/cometbft/cometbft/privval"
cometproto "github.com/cometbft/cometbft/proto/tendermint/types"
Expand Down
3 changes: 2 additions & 1 deletion pkg/node/single_signer_validator_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package node

import (
"github.com/strangelove-ventures/horcrux/pkg/pcosigner"
"path/filepath"
"time"

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

"os"
"testing"

Expand Down
3 changes: 2 additions & 1 deletion pkg/node/threshold_remote_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package node
import (
"context"
"fmt"
"github.com/strangelove-ventures/horcrux/pkg/types"
"net"
"time"

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

cometcrypto "github.com/cometbft/cometbft/crypto"
cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519"
cometcryptoencoding "github.com/cometbft/cometbft/crypto/encoding"
Expand Down
Loading

0 comments on commit 9e25881

Please sign in to comment.