Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion cmd/horcrux/cmd/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

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

"github.com/cometbft/cometbft/crypto"
cometprivval "github.com/cometbft/cometbft/privval"
Expand Down Expand Up @@ -46,7 +47,7 @@ func addressCmd() *cobra.Command {
return err
}

key, err := pcosigner.LoadCosignerEd25519Key(keyFile)
key, err := cipher.LoadCosignerEd25519Key(keyFile)
if err != nil {
return fmt.Errorf("error reading cosigner key: %w, check that key is present for chain ID: %s", err, chainID)
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/horcrux/cmd/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"time"

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

grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/client"
"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 @@ -70,16 +70,16 @@ horcrux elect 2 # elect specific leader`,
ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second)
defer cancelFunc()

grpcClient := proto.NewICosignerGRPCServerClient(conn)
grpcClient := proto.NewIRaftGRPCClient(conn)
_, err = grpcClient.TransferLeadership(
ctx,
&proto.CosignerGRPCTransferLeadershipRequest{LeaderID: leaderID},
&proto.RaftGRPCTransferLeadershipRequest{LeaderID: leaderID},
)
if err != nil {
return err
}

res, err := grpcClient.GetLeader(ctx, &proto.CosignerGRPCGetLeaderRequest{})
res, err := grpcClient.GetLeader(ctx, &proto.RaftGRPCGetLeaderRequest{})
if err != nil {
return err
}
Expand Down Expand Up @@ -167,9 +167,9 @@ func getLeaderCmd() *cobra.Command {
ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second)
defer cancelFunc()

grpcClient := proto.NewICosignerGRPCServerClient(conn)
grpcClient := proto.NewIRaftGRPCClient(conn)

res, err := grpcClient.GetLeader(ctx, &proto.CosignerGRPCGetLeaderRequest{})
res, err := grpcClient.GetLeader(ctx, &proto.RaftGRPCGetLeaderRequest{})
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/horcrux/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"

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

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

newEd25519Key := pcosigner.CosignerEd25519Key{
newEd25519Key := cipher.CosignerEd25519Key{
PubKey: legacyCosignerKey.PubKey,
PrivateShard: legacyCosignerKey.ShareKey,
ID: legacyCosignerKey.ID,
Expand Down
6 changes: 4 additions & 2 deletions cmd/horcrux/cmd/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"os"
"path/filepath"

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

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

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

csKeys, err := pcosigner.CreateCosignerEd25519ShardsFromFile(keyFile, threshold, shards)
csKeys, err := cipher.CreateCosignerEd25519ShardsFromFile(keyFile, threshold, shards)
if err != nil {
return err
}
Expand All @@ -134,7 +136,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 = cipher.WriteCosignerEd25519ShardFile(c, filename); err != nil {
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "Created Ed25519 Shard %s\n", filename)
Expand Down
25 changes: 13 additions & 12 deletions cmd/horcrux/cmd/threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ func NewThresholdValidator(

thresholdCfg := config.Config.ThresholdModeConfig
// NOTE: Shouldnt this be a list of concrete type instead of interface type?
remoteCosigners := make([]node.ICosigner, 0, len(thresholdCfg.Cosigners)-1)
remoteCosigners := make([]pcosigner.IRemoteCosigner, 0, len(thresholdCfg.Cosigners)-1) // list of remote cosigners
// peers := make([]pcosigner.ICosigner, 0, len(thresholdCfg.Cosigners)-1)

var p2pListen string

var cosign pcosigner.Cosigner
var security pcosigner.ICosignerSecurity
var eciesErr error
security, eciesErr = config.CosignerSecurityECIES()
Expand All @@ -42,24 +43,25 @@ func NewThresholdValidator(

for _, c := range thresholdCfg.Cosigners {
if c.ShardID != security.GetID() {
remoteCosigners = append(
remoteCosigners,
pcosigner.NewRemoteCosigner(c.ShardID, c.P2PAddr),
)
remoteCosigners = append(remoteCosigners, pcosigner.NewRemoteCosigner(security.GetID(), c.P2PAddr))
logger.Info("Added remote cosigner", "id", c.ShardID, "address", c.P2PAddr)
} else {
p2pListen = c.P2PAddr
cosign = pcosigner.NewCosign(c.ShardID, c.P2PAddr)
logger.Info("Created a new cosigner", "id", c.ShardID, "address", c.P2PAddr)

}
}

if p2pListen == "" {
if cosign.GetAddress() == "" {
return nil, nil, fmt.Errorf("cosigner config does not exist for our shard ID %d", security.GetID())
}

localCosigner := pcosigner.NewLocalCosigner(
logger,
&config,
security,
p2pListen,
cosign,
)

// Validated prior in ValidateThresholdModeConfig
Expand All @@ -74,7 +76,6 @@ func NewThresholdValidator(
// RAFT node ID is the cosigner ID
nodeID := fmt.Sprint(security.GetID())

// Start RAFT store listener
raftStore := node.NewRaftStore(nodeID,
raftDir, p2pListen, raftTimeout, logger)
if err := raftStore.Start(); err != nil {
Expand All @@ -88,9 +89,9 @@ func NewThresholdValidator(
thresholdCfg.Threshold,
grpcTimeout,
maxWaitForSameBlockAttempts,
localCosigner,
remoteCosigners,
raftStore, // raftStore implements the ILeader interface
localCosigner, // our "server"
remoteCosigners, // remote Cosigners are the peers we are requesting remotely (client to server)
raftStore, // raftStore implements the ILeader interface
)

raftStore.SetThresholdValidator(val)
Expand Down
37 changes: 0 additions & 37 deletions docs/misc.md

This file was deleted.

Loading