Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

feat: add moniker and valoper address to signatures query #627

Merged
merged 6 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
71 changes: 57 additions & 14 deletions cmd/blobstream/query/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strconv"
"time"

stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

common2 "github.com/ethereum/go-ethereum/common"

celestiatypes "github.com/celestiaorg/celestia-app/x/qgb/types"
Expand Down Expand Up @@ -134,10 +136,19 @@ func Signers() *cobra.Command {
}

type signature struct {
EvmAddress string `json:"evmAddress"`
Signature string `json:"signature"`
Signed bool `json:"signed"`
EvmAddress string `json:"evmAddress"`
Moniker string `json:"moniker"`
Signature string `json:"signature"`
Signed bool `json:"signed"`
ValopAddress string `json:"valopAddress"`
}

type validatorInfo struct {
EvmAddress string `json:"evmAddress"`
Moniker string `json:"moniker"`
ValopAddress string `json:"valopAddress"`
}

type queryOutput struct {
Signatures []signature `json:"signatures"`
Nonce uint64 `json:"nonce"`
Expand All @@ -162,6 +173,16 @@ func getSignaturesAndPrintThem(
return err
}

validatorSet, err := appQuerier.QueryStakingValidatorSet(ctx)
if err != nil {
return err
}

validatorsInfo, err := toValidatorsInfo(ctx, appQuerier, validatorSet)
if err != nil {
return err
}

att, err := appQuerier.QueryAttestationByNonce(ctx, nonce)
if err != nil {
return err
Expand All @@ -180,7 +201,7 @@ func getSignaturesAndPrintThem(
if err != nil {
return err
}
qOutput := toQueryOutput(toValsetConfirmsMap(confirms), nonce, *lastValset)
qOutput := toQueryOutput(toValsetConfirmsMap(confirms), validatorsInfo, nonce, *lastValset)
if outputFile == "" {
printConfirms(logger, qOutput)
} else {
Expand All @@ -203,7 +224,7 @@ func getSignaturesAndPrintThem(
if err != nil {
return err
}
qOutput := toQueryOutput(toDataCommitmentConfirmsMap(confirms), nonce, *lastValset)
qOutput := toQueryOutput(toDataCommitmentConfirmsMap(confirms), validatorsInfo, nonce, *lastValset)
if outputFile == "" {
printConfirms(logger, qOutput)
} else {
Expand All @@ -218,6 +239,24 @@ func getSignaturesAndPrintThem(
return nil
}

func toValidatorsInfo(ctx context.Context, appQuerier *rpc.AppQuerier, validatorSet []stakingtypes.Validator) (map[string]validatorInfo, error) {
validatorsInfo := make(map[string]validatorInfo)
for _, val := range validatorSet {
evmAddr, err := appQuerier.QueryEVMAddress(ctx, val.OperatorAddress)
if err != nil {
return nil, err
}
if evmAddr != "" {
validatorsInfo[evmAddr] = validatorInfo{
EvmAddress: evmAddr,
Moniker: val.GetMoniker(),
ValopAddress: val.OperatorAddress,
}
}
}
return validatorsInfo, nil
}
rach-id marked this conversation as resolved.
Show resolved Hide resolved

func parseNonce(ctx context.Context, querier *rpc.AppQuerier, nonce string) (uint64, error) {
switch nonce {
case "latest":
Expand Down Expand Up @@ -245,24 +284,28 @@ func toDataCommitmentConfirmsMap(confirms []types.DataCommitmentConfirm) map[str
return confirmsMap
}

func toQueryOutput(confirmsMap map[string]string, nonce uint64, lastValset celestiatypes.Valset) queryOutput {
func toQueryOutput(confirmsMap map[string]string, validatorsInfo map[string]validatorInfo, nonce uint64, lastValset celestiatypes.Valset) queryOutput {
currThreshold := uint64(0)
signatures := make([]signature, len(lastValset.Members))
// create the signature slice to be used for outputting the data
for key, val := range lastValset.Members {
sig, found := confirmsMap[val.EvmAddress]
if found {
signatures[key] = signature{
EvmAddress: val.EvmAddress,
Signature: sig,
Signed: true,
EvmAddress: val.EvmAddress,
Signature: sig,
Signed: true,
Moniker: validatorsInfo[val.EvmAddress].Moniker,
ValopAddress: validatorsInfo[val.EvmAddress].ValopAddress,
}
currThreshold += val.Power
} else {
signatures[key] = signature{
EvmAddress: val.EvmAddress,
Signature: "",
Signed: false,
EvmAddress: val.EvmAddress,
Signature: "",
Signed: false,
Moniker: validatorsInfo[val.EvmAddress].Moniker,
ValopAddress: validatorsInfo[val.EvmAddress].ValopAddress,
}
}
}
rach-id marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -290,13 +333,13 @@ func printConfirms(logger tmlog.Logger, qOutput queryOutput) {
logger.Info("orchestrators that signed the attestation")
for _, sig := range qOutput.Signatures {
if sig.Signed {
logger.Info(sig.EvmAddress, "signed", sig.Signed, "signature", sig.Signature)
logger.Info(sig.Moniker, "signed", sig.Signed, "evm_address", "valop_address", sig.ValopAddress, sig.EvmAddress, "signature", sig.Signature)
rach-id marked this conversation as resolved.
Show resolved Hide resolved
}
}
logger.Info("orchestrators that missed signing the attestation")
for _, sig := range qOutput.Signatures {
if !sig.Signed {
logger.Info(sig.EvmAddress, "signed", sig.Signed)
logger.Info(sig.Moniker, "signed", sig.Signed, "evm_address", sig.EvmAddress, "valop_address", sig.ValopAddress)
}
}
logger.Info("done")
Expand Down
31 changes: 31 additions & 0 deletions rpc/app_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"strconv"
"time"

"github.com/cosmos/cosmos-sdk/types/query"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
cosmosgrpc "github.com/cosmos/cosmos-sdk/types/grpc"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -319,6 +322,34 @@ func (aq *AppQuerier) QueryLastValsetBeforeNonce(ctx context.Context, nonce uint
return resp.Valset, nil
}

// QueryStakingValidatorSet returns the list of all validators in the network.
func (aq *AppQuerier) QueryStakingValidatorSet(ctx context.Context) ([]stakingtypes.Validator, error) {
queryClient := stakingtypes.NewQueryClient(aq.clientConn)
resp, err := queryClient.Validators(
ctx,
&stakingtypes.QueryValidatorsRequest{Pagination: &query.PageRequest{Limit: 10000}},
rach-id marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
return nil, err
}

return resp.Validators, nil
}

// QueryEVMAddress returns the EVM address corresponding to a validator valop address.
func (aq *AppQuerier) QueryEVMAddress(ctx context.Context, valopAddress string) (string, error) {
queryClient := celestiatypes.NewQueryClient(aq.clientConn)
resp, err := queryClient.EVMAddress(
ctx,
&celestiatypes.QueryEVMAddressRequest{ValidatorAddress: valopAddress},
)
if err != nil {
return "", err
}

return resp.EvmAddress, nil
}

// QueryHistoricalLastValsetBeforeNonce returns the last historical valset before nonce for a certain height.
func (aq *AppQuerier) QueryHistoricalLastValsetBeforeNonce(ctx context.Context, nonce uint64, height uint64) (*celestiatypes.Valset, error) {
queryClient := celestiatypes.NewQueryClient(aq.clientConn)
Expand Down
Loading