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

Resolve Iris, Tgrade prefix and "panic: pubkey is incorrect size" problems #37

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 td2/chain-details.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
// altValopers is used to get a bech32 prefix for chains using non-standard naming
var altValopers = &valoperOverrides{
Prefixes: map[string]string{
"ival": "ica", // Iris hub
"iva": "ica", // Iris hub
"tgrade": "tgrade", // Tgrade

// TODO: was told tgrade also has a custom prefix, but not sure what the pair is
// "tval": "tvalcons",
Expand Down
20 changes: 19 additions & 1 deletion td2/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"errors"
"fmt"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/types/bech32"
slashing "github.com/cosmos/cosmos-sdk/x/slashing/types"
staking "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand All @@ -13,6 +16,12 @@ import (
"time"
)

type CryptoKey interface {
Marshal() (dAtA []byte, err error)
Unmarshal(dAtA []byte) error
Address() crypto.Address
}

// ValInfo holds most of the stats/info used for secondary alarms. It is refreshed roughly every minute.
type ValInfo struct {
Moniker string `json:"moniker"`
Expand Down Expand Up @@ -151,7 +160,16 @@ func getVal(ctx context.Context, client *rpchttp.HTTP, valoper string) (pub []by
if err != nil {
return
}
pk := ed25519.PubKey{}
var pk CryptoKey
var keyType string = val.Validator.ConsensusPubkey.TypeUrl
switch keyType {
case "/cosmos.crypto.ed25519.PubKey":
pk = &ed25519.PubKey{}
case "/cosmos.crypto.secp256k1.PubKey":
pk = &secp256k1.PubKey{}
default:
pk = &secp256r1.PubKey{}
}
err = pk.Unmarshal(val.Validator.ConsensusPubkey.Value)
if err != nil {
return
Expand Down