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

Support chains with no gRPC & with BLS keys #43

Merged
merged 6 commits into from
Feb 28, 2025
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
33 changes: 17 additions & 16 deletions internal/pkg/cosmos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (cc *Client) GetLatestBlockHeight(ctx context.Context) (int64, error) {
if err2 != nil {
return 0, errors.Wrapf(err, "failed to get latest block & status")
}
return status.Result.SyncInfo.LatestBlockHeight, nil
return status.SyncInfo.LatestBlockHeight, nil
}

if res.SdkBlock != nil {
Expand Down Expand Up @@ -166,19 +166,17 @@ func (cc *Client) GetProposalsV1beta1(ctx context.Context) (v1beta1.Proposals, e
}

type StatusResponse struct {
Result struct {
ValidatorInfo struct {
Address string `json:"address"`
VotingPower uint64 `json:"voting_power,string"`
} `json:"validator_info"`
NodeInfo struct {
Network string `json:"network"`
} `json:"node_info"`
SyncInfo struct {
LatestBlockTime string `json:"latest_block_time"`
LatestBlockHeight int64 `json:"latest_block_height,string"`
} `json:"sync_info"`
} `json:"result"`
ValidatorInfo struct {
Address string `json:"address"`
VotingPower uint64 `json:"voting_power,string"`
} `json:"validator_info"`
NodeInfo struct {
Network string `json:"network"`
} `json:"node_info"`
SyncInfo struct {
LatestBlockTime string `json:"latest_block_time"`
LatestBlockHeight int64 `json:"latest_block_height,string"`
} `json:"sync_info"`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0/5 i preferred the previous struct layout more because it more closely resembled to what we had in the tmrpc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the Result wrapper? i removed it because it "leaks" to the caller

i was even thinking of keeping the return value of Status() the same, and casting from this StatusResponse to tm.StatusResponse, so that when we can delete this code, no callers change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would the cast work? i think it's very strict, also when it comes to struct tags. if not you can just write a converter function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, i meant a manual "cast"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the converter function may be a little bit more sophisticated to maybe throw errors if we upgrade tendermint lib and it stops working


func (cc *Client) GetStatus(ctx context.Context) (*StatusResponse, error) {
Expand All @@ -203,11 +201,14 @@ func (cc *Client) GetStatus(ctx context.Context) (*StatusResponse, error) {
}
defer resp.Body.Close()

var statusResp StatusResponse
var statusResp struct {
Result StatusResponse `json:"result"`
}

if err := json.NewDecoder(resp.Body).Decode(&statusResp); err != nil {
return nil, errors.Wrapf(err, "failed to decode JSON")
}
return &statusResp, nil
return &statusResp.Result, nil
}

func (cc *Client) NodeInfo(ctx context.Context) (*tmservice.GetNodeInfoResponse, error) {
Expand Down
16 changes: 8 additions & 8 deletions internal/pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func (d *Daemon) Init(ctx context.Context, cfg *config.Config) error {
return errors.Wrapf(err, "failed to get status response")
}

d.chainID = status.Result.NodeInfo.Network
d.validatorAddress = status.Result.ValidatorInfo.Address
d.chainID = status.NodeInfo.Network
d.validatorAddress = status.ValidatorInfo.Address

// display information about the node
if cfg.Compose.EnvPrefix == "" {
Expand All @@ -160,21 +160,21 @@ func (d *Daemon) Init(ctx context.Context, cfg *config.Config) error {
return errors.Wrapf(err, "failed to validate docker compose settings")
}

d.currHeight = status.Result.SyncInfo.LatestBlockHeight
logger.Infof("Observed latest block height: %d", d.currHeight)
d.currHeightTime, err = time.Parse(time.RFC3339Nano, status.Result.SyncInfo.LatestBlockTime)
logger.Infof("Observed latest block height: %d", status.SyncInfo.LatestBlockHeight)
d.currHeight = status.SyncInfo.LatestBlockHeight
d.currHeightTime, err = time.Parse(time.RFC3339Nano, status.SyncInfo.LatestBlockTime)
if err != nil {
return errors.Wrapf(err, "failed to parse latest block time from status endpoint")
}
d.startupHeight = d.currHeight

logger.Infof("Observed node address: %s", status.Result.ValidatorInfo.Address)
d.nodeAddress, err = hex.DecodeString(status.Result.ValidatorInfo.Address)
logger.Infof("Observed node address: %s", status.ValidatorInfo.Address)
d.nodeAddress, err = hex.DecodeString(status.ValidatorInfo.Address)
if err != nil {
return errors.Wrapf(err, "failed to parse node address from status endpoint")
}

valVP := status.Result.ValidatorInfo.VotingPower
valVP := status.ValidatorInfo.VotingPower

// test consensus state endpoint
logger.Info("Attempting to get consensus state")
Expand Down