Skip to content

Commit

Permalink
Fix import paths and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
nitronit committed Feb 16, 2024
1 parent 2e39f23 commit e16edda
Show file tree
Hide file tree
Showing 45 changed files with 2,883 additions and 277 deletions.
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
8 changes: 5 additions & 3 deletions cmd/horcrux/cmd/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/client"
"github.com/strangelove-ventures/horcrux/proto/strangelove/proto"
"github.com/strangelove-ventures/horcrux/src/multiresolver"
"github.com/strangelove-ventures/horcrux/src/proto"

// "github.com/strangelove-ventures/horcrux/src/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand Down Expand Up @@ -70,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 @@ -167,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
3 changes: 2 additions & 1 deletion cmd/horcrux/cmd/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func createCosignerEd25519ShardsCmd() *cobra.Command {
}

if chainID == "" {
return fmt.Errorf("chain-id flag must not be empty")
return fmt.Errorf(
"chain-id flag must not be empty")
}

if threshold == 0 {
Expand Down
2 changes: 2 additions & 0 deletions cmd/horcrux/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func startCmd() *cobra.Command {
panic(fmt.Errorf("unexpected sign mode: %s", config.Config.SignMode))
}

// Start the service so the Sentry can connecto to our GRPC server
if config.Config.GRPCAddr != "" {
grpcServer := connector.NewSentrySignerGRPCServer(logger, val, config.Config.GRPCAddr)
services = append(services, grpcServer)
Expand All @@ -73,6 +74,7 @@ func startCmd() *cobra.Command {

go EnableDebugAndMetrics(cmd.Context(), out)

// "Entrypoint" to start remote signers
services, err = connector.StartRemoteSigners(services, logger, val, config.Config.Nodes())
if err != nil {
return fmt.Errorf("failed to start remote signer(s): %w", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/horcrux/cmd/threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewThresholdValidator(

for _, c := range thresholdCfg.Cosigners {
if c.ShardID != security.GetID() {
rc, err := cosigner.NewRemoteCosigner(c.ShardID, c.P2PAddr)
rc, err := cosigner.NewCosignerClient(c.ShardID, c.P2PAddr)
if err != nil {
return nil, nil, fmt.Errorf("failed to initialize remote cosigner: %w", err)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func NewThresholdValidator(
raftStore,
)

raftStore.SetThresholdValidator(val)
raftStore.SetThresholdValidator(val, localCosigner)

if err := val.Start(ctx); err != nil {
return nil, nil, fmt.Errorf("failed to start threshold validator: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
gitlab.com/unit410/threshold-ed25519 v0.0.0-20220812172601-56783212c4cc
golang.org/x/sync v0.5.0
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -131,7 +132,6 @@ require (
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
15 changes: 15 additions & 0 deletions proto/protoc_local_.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -eox pipefail

echo "Generating proto code"

# OUT_DIR=$(pwd)/proto
# echo $OUT_DIR
# protoc --go_out=$(pwd) strangelove/horcrux/cosigner.proto
protoc -I=. --go_out=./ --go-grpc_out=./ --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative strangelove/proto/cosigner.proto
protoc -I=. --go_out=./ --go-grpc_out=./ --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative strangelove/proto/node.proto
protoc -I=. --go_out=./ --go-grpc_out=./ --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative strangelove/proto/connector.proto

#protoc -I=. --go-grpc_out=./ --go-grpc_opt=paths=source_relative strangelove/horcrux/connector.proto
# protoc -I=. --go_out=strangelove/proto --go_opt=paths=source_relative strangelove/horcrux/node.proto
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
syntax = "proto3";
package strangelove.horcrux;

import "strangelove/horcrux/cosigner.proto";
import "strangelove/horcrux/node.proto";

option go_package = "github.com/strangelove-ventures/horcrux/signer/proto";
option go_package = "github.com/strangelove-ventures/horcrux/src/proto";

service RemoteSigner {
// Connection to the remote signer (E.g the Sentry)
service Connector {
rpc PubKey (PubKeyRequest) returns (PubKeyResponse) {}
rpc Sign(strangelove.horcrux.SignBlockRequest) returns (strangelove.horcrux.SignBlockResponse) {}
}
Expand Down
27 changes: 13 additions & 14 deletions proto/strangelove/horcrux/cosigner.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
syntax = "proto3";
package strangelove.horcrux;

option go_package = "github.com/strangelove-ventures/horcrux/signer/proto";
option go_package = "strangelove/horcrux/proto";

service Cosigner {
rpc SetNoncesAndSign (SetNoncesAndSignRequest) returns (SetNoncesAndSignResponse) {}
rpc GetNonces (GetNoncesRequest) returns (GetNoncesResponse) {}
rpc Ping(PingRequest) returns (PingResponse) {}

rpc SignBlock (SignBlockRequest) returns (SignBlockResponse) {}
rpc TransferLeadership (TransferLeadershipRequest) returns (TransferLeadershipResponse) {}
rpc GetLeader (GetLeaderRequest) returns (GetLeaderResponse) {}
}


Expand Down Expand Up @@ -56,6 +52,16 @@ message GetNoncesResponse {
repeated UUIDNonce nonces = 1;
}

message PingRequest {}
message PingResponse {}
/*
message GetLeaderRequest {}
message GetLeaderResponse {
int32 leader = 1;
}
message TransferLeadershipRequest {
string leaderID = 1;
}
Expand All @@ -65,14 +71,6 @@ message TransferLeadershipResponse {
string leaderAddress = 2;
}
message GetLeaderRequest {}

message GetLeaderResponse {
int32 leader = 1;
}

message PingRequest {}
message PingResponse {}
message Block {
int64 height = 1;
Expand All @@ -90,4 +88,5 @@ message SignBlockRequest {
message SignBlockResponse {
bytes signature = 1;
int64 timestamp = 2;
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
syntax = "proto3";
package strangelove.horcrux;

option go_package = "github.com/strangelove-ventures/horcrux/signer/proto";
option go_package = "github.com/strangelove-ventures/horcrux/src/proto";

service TresholdValidator{
rpc Validate(ValidateRequest) returns (ValidateResponse);
// TODO: ADD rpc Validate(ValidateRequest) returns (ValidateResponse);

rpc SignBlock (SignBlockRequest) returns (SignBlockResponse) {}
rpc TransferLeadership (TransferLeadershipRequest) returns (TransferLeadershipResponse) {}
rpc GetLeader (GetLeaderRequest) returns (GetLeaderResponse) {}
}

message SignBlockRequest {
string chainID = 1;
Block block = 2;
}

message SignBlockResponse {
bytes signature = 1;
int64 timestamp = 2;
}

message TransferLeadershipRequest {
string leaderID = 1;
}
Expand All @@ -26,23 +36,10 @@ message GetLeaderResponse {
int32 leader = 1;
}

message PingRequest {}
message PingResponse {}

message Block {
int64 height = 1;
int64 round = 2;
int32 step = 3;
bytes signBytes = 4;
int64 timestamp = 5;
}

message SignBlockRequest {
string chainID = 1;
Block block = 2;
}

message SignBlockResponse {
bytes signature = 1;
int64 timestamp = 2;
}
Loading

0 comments on commit e16edda

Please sign in to comment.