-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Can not get Validator's Conspubkey #8045
Comments
Hmm, good point, you need to unpack the Any first: err = app.InterfaceRegistry().UnpackAny(valsResp.Validators[0].ConsensusPubkey, new(crypto.PubKey)) Also, please note that after #7419 (e.g. on master), you should: - err = app.InterfaceRegistry().UnpackAny(valsResp.Validators[0].ConsensusPubkey, new(crypto.PubKey))
+ err = app.InterfaceRegistry().UnpackAny(valsResp.Validators[0].ConsensusPubkey, new(cryptotypes.PubKey)) Let's keep this open, this DX is not ideal. Related to #7985. |
Hello @amaurymartiny , There are several modules with Any.GetCachedValue() method returns nil. So I will summary and share I have tested soon. Thanks! |
I thought this thread is more suitable for dealing/sharing with kinds of GetCachedValue returning nil. Another one is gov.Proposals. I think that is not ideal but I've coded the following one when GetCachedValue() method returns nil. My approach for concrete type of proposal content is (stargate-5) queryClient := c.GetGovQueryClient()
resp, err := queryClient.Proposals(context.Background(), &govtypes.QueryProposalsRequest{})
if err != nil {
return
}
if len(resp.Proposals) <= 0 {
return
}
for _, proposal := range resp.Proposals {
log.Println("proposal.GetContent() : ", proposal.GetContent())
log.Println("proposal.Content(any) :", proposal.Content)
var contentI govtypes.Content
err = codec.AppCodec.UnpackAny(proposal.Content, &contentI)
if err != nil {
log.Println(err)
}
log.Println("UnpackAny :", contentI)
switch i := contentI.(type) {
case *govtypes.TextProposal:
log.Printf("concrete type : %T\n", i)
log.Println(i.Title)
log.Println(i.Description)
case *distributiontypes.CommunityPoolSpendProposal:
log.Printf("concrete type : %T\n", i)
log.Println(i.Title)
log.Println(i.Description)
case *ibccoretypes.ClientUpdateProposal:
log.Printf("concrete type : %T\n", i)
log.Println(i.Title)
log.Println(i.Description)
case *paramstypesproposal.ParameterChangeProposal:
log.Printf("concrete type : %T\n", i)
log.Println(i.Title)
log.Println(i.Description)
case *upgradetypes.SoftwareUpgradeProposal:
log.Printf("concrete type : %T\n", i)
log.Println(i.Title)
log.Println(i.Description)
case *upgradetypes.CancelSoftwareUpgradeProposal:
log.Printf("concrete type : %T\n", i)
log.Println(i.Title)
log.Println(i.Description)
default:
log.Printf("type : %T\n", i)
log.Println("default")
}
...
} it returns
|
@carameleon could you confirm if this is still an issue? |
Hello, @robert-zaremba I gonna test and feedback ASAP. |
@robert-zaremba |
OK, so it's in |
@amaurymartiny
to get pubkey and related values queryClient := stakingtypes.NewQueryClient(cli.GRPC)
request := stakingtypes.QueryValidatorsRequest{Status: bonded}
resp, err := queryClient.Validators(context.Background(), &request)
require.NoError(t, err)
t.Log("the number of bonded validators :", len(resp.Validators))
consAddr, err := resp.Validators[0].GetConsAddr() //expecting cryptotypes.PubKey, got <nil>: invalid type
t.Log("consaddr :", consAddr) // ""
consPubkey, err := resp.Validators[0].ConsPubKey() //nil
t.Log("consPubkey:", consPubkey) // <nil>
tmConsPublickey, err := resp.Validators[0].TmConsPublicKey() // nil because validator.ConsPubkey is nil
t.Log("tmConsPublickey:", tmConsPublickey) // {<nil>}
var pubkey cryptotypes.PubKey
err = custom.AppCodec.UnpackAny(resp.Validators[0].ConsensusPubkey, &pubkey)
require.NoError(t, err)
valconspub_correct, err := sdktypes.Bech32ifyPubKey(sdktypes.Bech32PubKeyTypeConsPub, pubkey)
require.NoError(t, err)
t.Log("valconpub", valconspub_correct) //cosmosvalconspub1zcjduepqhv5hmywmedf2j8jpdm2xl9ssyyq0nqf7ak24nex9law4dqtx8drq0xn67q
ed25519pub, ok := pubkey.(*ed25519.PubKey)
require.Equal(t, true, ok)
pb, err := custom.AppCodec.MarshalBinaryBare(ed25519pub)
require.NoError(t, err)
valconspub_incorrect1, err := bech32.ConvertAndEncode(sdktypes.Bech32PrefixConsPub, pb)
require.NoError(t, err)
t.Log("valconpub1", valconspub_incorrect1) //cosmosvalconspub1pgstk2taj8duk54freqka4r0jcgzzq8esylwm92eunzl7h2ks9nrk3srm3pxx
valconspub_incorrect2, err := bech32.ConvertAndEncode(sdktypes.Bech32PrefixConsPub, pubkey.Bytes())
t.Log("valconpub2", valconspub_incorrect2) //cosmosvalconspub1hv5hmywmedf2j8jpdm2xl9ssyyq0nqf7ak24nex9law4dqtx8drqq729uc the list that have nil values resp.Validators[0].GetConsAddr() //expecting cryptotypes.PubKey, got <nil>: invalid type
resp.Validators[0].ConsPubKey() //nil
resp.Validators[0].TmConsPublicKey() // nil because validator.ConsPubkey is nil and different returns valconspub_correct, err := sdktypes.Bech32ifyPubKey(sdktypes.Bech32PubKeyTypeConsPub, pubkey)
//cosmosvalconspub1zcjduepqhv5hmywmedf2j8jpdm2xl9ssyyq0nqf7ak24nex9law4dqtx8drq0xn67q
ed25519pub, ok := pubkey.(*ed25519.PubKey)
pb, err := custom.AppCodec.MarshalBinaryBare(ed25519pub)
valconspub_incorrect1, err := bech32.ConvertAndEncode(sdktypes.Bech32PrefixConsPub, pb)
//cosmosvalconspub1pgstk2taj8duk54freqka4r0jcgzzq8esylwm92eunzl7h2ks9nrk3srm3pxx
valconspub_incorrect, err := bech32.ConvertAndEncode(sdktypes.Bech32PrefixConsPub, pubkey.Bytes())
//cosmosvalconspub1hv5hmywmedf2j8jpdm2xl9ssyyq0nqf7ak24nex9law4dqtx8drqq729uc So, The only way I can get the consensus_addr(cosmosvalconpub), is call the |
I think I have a clearer understanding of this issue. The gRPC client connection in the code snippets above is most likely a simple A more self-contained example was given by freak12techo on Discord: https://gist.github.com/Freak12Techno/d84492b90a05e50853cab52cb4ff8853. Could you try to do this: // Replace the following line with your own app's MakeEncodingConfig() function
// If your app exposes already `app.InterfaceRegistry`, you can use that directly instead
encCfg := simapp.MakeTestEncodingConfig()
interfaceRegistry := encCfg.InterfaceRegistry
// Use gRPC to query validator, as usual
err := validator.Validator.UnpackInterfaces(interfaceRegistry) // Unpack interfaces, to populate the Anys' cached values
fmt.Println(validator.Validator.GetConsAddr()) // Should not be nil |
I propose the following strategy for this issue:
|
Summary of Bug
QueryValidatorsResponse.validators have their conspubkey, however I can not get this with method( TmConsPubKey() )
Version
testnet : stargate-5
gaia : cosmoshub-test-stargate
sdk : github.com/cosmos/cosmos-sdk v0.40.0-rc3
tm : github.com/tendermint/tendermint v0.34.0-rc6
Steps to Reproduce
I've test on stargate-5 testnet
it returns
For Admin Use
The text was updated successfully, but these errors were encountered: