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

vendor necessary comet #241

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
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
57 changes: 26 additions & 31 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,52 +35,36 @@ linters-settings:
alias: cryptotypes
- pkg: github.com/cosmos/cosmos-sdk/x/slashing/types
alias: slashingtypes
- pkg: github.com/cometbft/cometbft/types
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/types
alias: comet
- pkg: github.com/cometbft/cometbft/config
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/config
alias: cometconfig
- pkg: github.com/cometbft/cometbft/crypto
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/crypto
alias: cometcrypto
- pkg: github.com/cometbft/cometbft/crypto/ed25519
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519
alias: cometcryptoed25519
- pkg: github.com/cometbft/cometbft/crypto/encoding
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/crypto/bn254
alias: cometcryptobn254
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/crypto/encoding
alias: cometcryptoencoding
- pkg: github.com/tendermint/go-amino
alias: amino
- pkg: github.com/cometbft/cometbft/libs/bytes
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/libs/bytes
alias: cometbytes
- pkg: github.com/cometbft/cometbft/libs/json
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/libs/json
alias: cometjson
- pkg: github.com/cometbft/cometbft/libs/log
alias: cometlog
- pkg: github.com/cometbft/cometbft/libs/net
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/libs/net
alias: cometnet
- pkg: github.com/cometbft/cometbft/libs/os
alias: cometos
- pkg: github.com/cometbft/cometbft/libs/rand
alias: cometrand
- pkg: github.com/cometbft/cometbft/libs/service
alias: cometservice
- pkg: github.com/cometbft/cometbft/p2p/conn
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/p2p/conn
alias: cometp2pconn
- pkg: github.com/cometbft/cometbft/privval
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/privval
alias: cometprivval
- pkg: github.com/cometbft/cometbft/proto/tendermint/types
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/proto/types
alias: cometproto
- pkg: github.com/cometbft/cometbft/proto/tendermint/crypto
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/proto/crypto
alias: cometprotocrypto
- pkg: github.com/cometbft/cometbft/proto/tendermint/privval
- pkg: github.com/strangelove-ventures/horcrux/v3/comet/proto/privval
alias: cometprotoprivval
- pkg: github.com/cometbft/cometbft/rpc/client
alias: cometrpcclient
- pkg: github.com/cometbft/cometbft/rpc/client/http
alias: cometrpchttp
- pkg: github.com/cometbft/cometbft/rpc/jsonrpc/client
alias: cometrpcjsonclient
- pkg: github.com/cometbft/cometbft/rpc/jsonrpc/types
alias: cometrpcjsontypes
- pkg: github.com/cometbft/cometbft/rpc/core/types
alias: cometrpctypes
- pkg: github.com/ecies/go/v2
alias: ecies
- pkg: github.com/grpc-ecosystem/go-grpc-middleware/retry
Expand All @@ -99,8 +83,19 @@ linters-settings:
alias: boltdb
- pkg: math/rand
alias: mrand
- pkg: github.com/consensys/gnark-crypto/ecc/bn254/ecdsa
alias: ecdsa_bn254
- pkg: github.com/strangelove-ventures/horcrux/v3/signer/bn254
alias: horcruxbn254
- pkg: github.com/strangelove-ventures/horcrux/v3/grpc/cosigner
alias: grpccosigner
- pkg: github.com/strangelove-ventures/horcrux/v3/grpc/horcrux
alias: grpchorcrux
maligned:
suggest-new: true
govet:
misspell:
locale: US
run:
skip-dirs:
- comet
21 changes: 12 additions & 9 deletions cmd/horcrux/cmd/address.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package cmd

import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"strings"

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

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

var pubKey crypto.PubKey
var pubKey []byte

chainID := args[0]

Expand All @@ -45,7 +45,7 @@ func addressCmd() *cobra.Command {
return err
}

key, err := signer.LoadCosignerEd25519Key(keyFile)
key, err := signer.LoadCosignerKey(keyFile)
if err != nil {
return fmt.Errorf("error reading cosigner key: %w, check that key is present for chain ID: %s", err, chainID)
}
Expand All @@ -61,26 +61,29 @@ func addressCmd() *cobra.Command {
return fmt.Errorf("error reading priv-validator key: %w, check that key is present for chain ID: %s", err, chainID)
}

filePV := cometprivval.LoadFilePVEmptyState(keyFile, "")
pubKey = filePV.Key.PubKey
filePV, err := cometprivval.LoadFilePV(keyFile, "", false)
if err != nil {
return err
}
pubKey = filePV.Key.PubKey.Bytes()
default:
panic(fmt.Errorf("unexpected sign mode: %s", config.Config.SignMode))
}

pubKeyAddress := pubKey.Address()
address := sha256.New().Sum(pubKey)[:20]

pubKeyJSON, err := signer.PubKey("", pubKey)
if err != nil {
return err
}

output := AddressCmdOutput{
HexAddress: strings.ToUpper(hex.EncodeToString(pubKeyAddress)),
HexAddress: strings.ToUpper(hex.EncodeToString(address)),
PubKey: pubKeyJSON,
}

if len(args) == 2 {
bech32ValConsAddress, err := bech32.ConvertAndEncode(args[1]+"valcons", pubKeyAddress)
bech32ValConsAddress, err := bech32.ConvertAndEncode(args[1]+"valcons", address)
if err != nil {
return err
}
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 @@ -8,9 +8,9 @@ import (
grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/v3/client"
grpccosigner "github.com/strangelove-ventures/horcrux/v3/grpc/cosigner"
"github.com/strangelove-ventures/horcrux/v3/signer"
"github.com/strangelove-ventures/horcrux/v3/signer/multiresolver"
"github.com/strangelove-ventures/horcrux/v3/signer/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand Down Expand Up @@ -69,16 +69,16 @@ horcrux elect 2 # elect specific leader`,
ctx, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second)
defer cancelFunc()

grpcClient := proto.NewCosignerClient(conn)
grpcClient := grpccosigner.NewCosignerClient(conn)
_, err = grpcClient.TransferLeadership(
ctx,
&proto.TransferLeadershipRequest{LeaderID: leaderID},
&grpccosigner.TransferLeadershipRequest{LeaderID: leaderID},
)
if err != nil {
return err
}

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

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

res, err := grpcClient.GetLeader(ctx, &proto.GetLeaderRequest{})
res, err := grpcClient.GetLeader(ctx, &grpccosigner.GetLeaderRequest{})
if err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/horcrux/cmd/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"net/http/pprof"
"time"

"github.com/armon/go-metrics"
gmprometheus "github.com/armon/go-metrics/prometheus"
cometlog "github.com/cometbft/cometbft/libs/log"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/strangelove-ventures/horcrux/v3/signer"
)

func AddPrometheusMetrics(mux *http.ServeMux, out io.Writer) {
logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)).With("module", "metrics")
logger := slog.New(slog.NewTextHandler(out, nil)).With("module", "metrics")

// Add metrics from raft's implementation of go-metrics
cfg := gmprometheus.DefaultPrometheusOpts
Expand All @@ -37,7 +38,7 @@ func AddPrometheusMetrics(mux *http.ServeMux, out io.Writer) {

// EnableDebugAndMetrics - Initialization errors are not fatal, only logged
func EnableDebugAndMetrics(ctx context.Context, out io.Writer) {
logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)).With("module", "debugserver")
logger := slog.New(slog.NewTextHandler(out, nil)).With("module", "debugserver")

// Configure Shared Debug HTTP Server for pprof and prometheus
if len(config.Config.DebugAddr) == 0 {
Expand All @@ -61,6 +62,8 @@ func EnableDebugAndMetrics(ctx context.Context, out io.Writer) {
// Add prometheus metrics
AddPrometheusMetrics(mux, out)

go signer.StartMetrics(ctx)

// Configure Debug Server Network Parameters
srv := &http.Server{
Handler: mux,
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 @@ -8,11 +8,11 @@ import (
"os"
"path/filepath"

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"
cometcrypto "github.com/strangelove-ventures/horcrux/v3/comet/crypto"
cometcryptoed25519 "github.com/strangelove-ventures/horcrux/v3/comet/crypto/ed25519"
"github.com/strangelove-ventures/horcrux/v3/comet/encoding"
cometprotocrypto "github.com/strangelove-ventures/horcrux/v3/comet/proto/crypto"
"github.com/strangelove-ventures/horcrux/v3/signer"
amino "github.com/tendermint/go-amino"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -103,7 +103,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(CosignerKey.PubKey)
//
// To support reading the public key bytes from these key files, we fallback to
// amino unmarshalling if the protobuf unmarshalling fails
Expand All @@ -118,7 +118,7 @@ func (key *v2CosignerKey) UnmarshalJSON(data []byte) error {
}
pubkey = pub
} else {
pubkey, err = cometcryptoencoding.PubKeyFromProto(protoPubkey)
pubkey, err = encoding.PubKeyFromProto(protoPubkey)
if err != nil {
return err
}
Expand Down Expand Up @@ -218,13 +218,14 @@ func migrateCmd() *cobra.Command {
return err
}

newEd25519Key := signer.CosignerEd25519Key{
PubKey: legacyCosignerKey.PubKey,
newEd25519Key := &signer.CosignerKey{
KeyType: signer.CosignerKeyTypeEd25519,
PubKey: legacyCosignerKey.PubKey.Bytes(),
PrivateShard: legacyCosignerKey.ShareKey,
ID: legacyCosignerKey.ID,
}

newEd25519KeyBz, err := newEd25519Key.MarshalJSON()
newEd25519KeyBz, err := json.Marshal(newEd25519Key)
if err != nil {
return fmt.Errorf("failed to marshal new Ed25519 key to json: %w", err)
}
Expand All @@ -234,13 +235,13 @@ func migrateCmd() *cobra.Command {
return fmt.Errorf("failed to write new Ed25519 key to %s: %w", newEd25519Path, err)
}

newRSAKey := signer.CosignerRSAKey{
newRSAKey := &signer.CosignerRSAKey{
RSAKey: legacyCosignerKey.RSAKey,
ID: legacyCosignerKey.ID,
RSAPubs: legacyCosignerKey.RSAPubs,
}

newRSAKeyBz, err := newRSAKey.MarshalJSON()
newRSAKeyBz, err := json.Marshal(newRSAKey)
if err != nil {
return fmt.Errorf("failed to marshal new RSA key to json: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/horcrux/cmd/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestMigrateV2toV3(t *testing.T) {
newKeyShardFileBz, err := os.ReadFile(newKeyShardFile)
require.NoError(t, err)

require.Equal(t, testdata.CosignerEd25519KeyMigrated, string(newKeyShardFileBz))
require.Equal(t, testdata.CosignerKeyMigrated, string(newKeyShardFileBz))

newRSAKeyFileBz, err := os.ReadFile(newRSAKeyFile)
require.NoError(t, err)
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestMigrateV2toV3DifferentKeyFilePath(t *testing.T) {
newKeyShardFileBz, err := os.ReadFile(newKeyShardFile)
require.NoError(t, err)

require.Equal(t, testdata.CosignerEd25519KeyMigrated, string(newKeyShardFileBz))
require.Equal(t, testdata.CosignerKeyMigrated, string(newKeyShardFileBz))

newRSAKeyFileBz, err := os.ReadFile(newRSAKeyFile)
require.NoError(t, err)
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestMigrateV2toV3KeysOnly(t *testing.T) {
newKeyShardFileBz, err := os.ReadFile(newKeyShardFile)
require.NoError(t, err)

require.Equal(t, testdata.CosignerEd25519KeyMigrated, string(newKeyShardFileBz))
require.Equal(t, testdata.CosignerKeyMigrated, string(newKeyShardFileBz))

newRSAKeyFileBz, err := os.ReadFile(newRSAKeyFile)
require.NoError(t, err)
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestMigrateV2toV3ConfigAlreadyMigrated(t *testing.T) {
newKeyShardFileBz, err := os.ReadFile(newKeyShardFile)
require.NoError(t, err)

require.Equal(t, testdata.CosignerEd25519KeyMigrated, string(newKeyShardFileBz))
require.Equal(t, testdata.CosignerKeyMigrated, string(newKeyShardFileBz))

newRSAKeyFileBz, err := os.ReadFile(newRSAKeyFile)
require.NoError(t, err)
Expand All @@ -208,7 +208,7 @@ func TestMigrateV2toV3AlreadyMigrated(t *testing.T) {

ed25519KeyShardFile := filepath.Join(tmp, "test_shard.json")

err = os.WriteFile(ed25519KeyShardFile, []byte(testdata.CosignerEd25519KeyMigrated), 0600)
err = os.WriteFile(ed25519KeyShardFile, []byte(testdata.CosignerKeyMigrated), 0600)
require.NoError(t, err)

rsaKeyShardFile := filepath.Join(tmp, "rsa_keys.json")
Expand Down
2 changes: 1 addition & 1 deletion cmd/horcrux/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func rootCmd() *cobra.Command {
cmd.AddCommand(configCmd())
cmd.AddCommand(startCmd())
cmd.AddCommand(addressCmd())
cmd.AddCommand(createCosignerEd25519ShardsCmd())
cmd.AddCommand(createCosignerShardsCmd())
cmd.AddCommand(createCosignerECIESShardsCmd())

rsaCmd := createCosignerRSAShardsCmd()
Expand Down
Loading
Loading