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
2 changes: 1 addition & 1 deletion internal/pkg/chain_watcher/height_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewStreamingHeightWatcher(ctx context.Context, cosmosClient *cosmos.Client,

// subscribe call hangs if the node is not running, this at least prevents
// the watcher from hanging at the start
if _, err := cosmosClient.GetCometbftClient().Status(ctx); err != nil {
if _, err := cosmosClient.GetStatus(ctx); err != nil {
return nil, errors.Wrapf(err, "failed to get cometbft status")
}

Expand Down
49 changes: 43 additions & 6 deletions internal/pkg/cosmos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package cosmos

import (
"context"
"encoding/json"
"fmt"
"math"
"net"
"net/http"
"strconv"
"strings"
"time"
Expand All @@ -14,7 +16,6 @@ import (
cstypes "github.com/cometbft/cometbft/consensus/types"
cmtjson "github.com/cometbft/cometbft/libs/json"
cometbft "github.com/cometbft/cometbft/rpc/client/http"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -99,7 +100,15 @@ func (cc *Client) GetLatestBlockHeight(ctx context.Context) (int64, error) {

res, err := cc.tmClient.GetLatestBlock(ctx, &tmservice.GetLatestBlockRequest{}, cc.callOptions...)
if err != nil {
return 0, errors.Wrapf(err, "failed to get latest block")
status, err2 := cc.GetStatus(ctx)
if err2 != nil {
return 0, errors.Wrapf(err, "failed to get latest block & status")
}
height, err := strconv.ParseInt(status.Result.SyncInfo.LatestBlockHeight, 10, 64)
if err != nil {
return 0, errors.Wrapf(err, "failed to parse height from status")
}
return height, nil
}

if res.SdkBlock != nil {
Expand Down Expand Up @@ -160,12 +169,40 @@ func (cc *Client) GetProposalsV1beta1(ctx context.Context) (v1beta1.Proposals, e
return proposals, nil
}

func (cc *Client) GetStatus(ctx context.Context) (*ctypes.ResultStatus, error) {
response, err := cc.cometbftClient.Status(ctx)
type StatusResponse struct {
Result struct {
ValidatorInfo struct {
Address string `json:"address"`
VotingPower string `json:"voting_power"`
} `json:"validator_info"`
NodeInfo struct {
Network string `json:"network"`
} `json:"node_info"`
SyncInfo struct {
LatestBlockTime string `json:"latest_block_time"`
LatestBlockHeight string `json:"latest_block_height"`
} `json:"sync_info"`
} `json:"result"`
}

func (cc *Client) GetStatus(ctx context.Context) (*StatusResponse, error) {
statusURL := strings.Replace(fmt.Sprintf("%s/status", cc.cometbftClient.Remote()), "tcp://", "http://", 1)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, statusURL, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to get status")
return nil, fmt.Errorf("failed to create request: %w", err)
}
return response, nil
c := http.Client{}
resp, err := c.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to perform HTTP request: %w", err)
}
defer resp.Body.Close()

var statusResp StatusResponse
if err := json.NewDecoder(resp.Body).Decode(&statusResp); err != nil {
return nil, fmt.Errorf("failed to decode JSON: %w", err)
}
return &statusResp, nil
}

func (cc *Client) NodeInfo(ctx context.Context) (*tmservice.GetNodeInfoResponse, error) {
Expand Down
6 changes: 5 additions & 1 deletion internal/pkg/daemon/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ func (d *Daemon) preUpgradeChecks(

// notify once about the upcoming upgrade
if currStep == urproto.UpgradeStep_MONITORING {
chainName := "unsupported-name"
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the purpose of that one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't access nodeInfo if there's no gRPC, this dependency is not necessary, as we already ask for a unique network identifier in the config (UpgradeRegistry.Network)

if d.nodeInfo != nil {
chainName = d.nodeInfo.DefaultNodeInfo.Network
}
logger.Infof(
"Detected upcoming upgrade (type: %s, tag: %s, chain: %s) Current height: %d, upgrade height: %d",
upgrade.Type, upgrade.Tag, d.nodeInfo.DefaultNodeInfo.Network, currHeight, upgrade.Height,
upgrade.Type, upgrade.Tag, chainName, currHeight, upgrade.Height,
).Notify(ctx)

if len(cfg.Enabled) == 0 {
Expand Down
40 changes: 23 additions & 17 deletions internal/pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"encoding/hex"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -135,19 +136,22 @@
return errors.Wrapf(err, "failed to get status response")
}

d.chainID = status.NodeInfo.Network
d.validatorAddress = status.ValidatorInfo.Address.String()
d.chainID = status.Result.NodeInfo.Network
d.validatorAddress = status.Result.ValidatorInfo.Address

// display information about the node
d.nodeInfo, err = d.cosmosClient.NodeInfo(ctx)
if err != nil {
return errors.Wrapf(err, "failed to get node info")
}
logger.Infof("Connected to the %s node ID: %s", d.nodeInfo.ApplicationVersion.Name, d.nodeInfo.DefaultNodeInfo.DefaultNodeID)

// if the env prefix is not set, we set it to <APP_NAME>_ (e.g "GAIAD_")
if cfg.Compose.EnvPrefix == "" {
cfg.Compose.EnvPrefix = strings.ToUpper(d.nodeInfo.ApplicationVersion.AppName) + "_"
// FIXME: this will break checks that look at nodeInfo
d.nodeInfo, err = d.cosmosClient.NodeInfo(ctx)
if err != nil {
return errors.Wrapf(err, "failed to get node info")
}
logger.Infof("Connected to the %s node ID: %s", d.nodeInfo.ApplicationVersion.Name, d.nodeInfo.DefaultNodeInfo.DefaultNodeID)

// if the env prefix is not set, we set it to <APP_NAME>_ (e.g "GAIAD_")
if cfg.Compose.EnvPrefix == "" {
cfg.Compose.EnvPrefix = strings.ToUpper(d.nodeInfo.ApplicationVersion.AppName) + "_"
}
}
logger.Infof("Using env prefix: %s", cfg.Compose.EnvPrefix)

Expand All @@ -156,13 +160,15 @@
return errors.Wrapf(err, "failed to validate docker compose settings")
}

logger.Infof("Observed latest block height: %d", status.SyncInfo.LatestBlockHeight)
d.currHeight = status.SyncInfo.LatestBlockHeight
d.currHeightTime = status.SyncInfo.LatestBlockTime
d.currHeight, err = strconv.ParseInt(status.Result.SyncInfo.LatestBlockHeight, 10, 64)

Check failure on line 163 in internal/pkg/daemon/daemon.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
logger.Infof("Observed latest block height: %d", d.currHeight)
d.currHeightTime, err = time.Parse(time.RFC3339Nano, status.Result.SyncInfo.LatestBlockTime)

Check failure on line 165 in internal/pkg/daemon/daemon.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
d.startupHeight = d.currHeight

logger.Infof("Observed node address: %s", status.ValidatorInfo.Address.String())
d.nodeAddress = status.ValidatorInfo.Address
logger.Infof("Observed node address: %s", status.Result.ValidatorInfo.Address)
d.nodeAddress, err = hex.DecodeString(status.Result.ValidatorInfo.Address)

Check failure on line 169 in internal/pkg/daemon/daemon.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)

valVP, err := strconv.ParseInt(status.Result.ValidatorInfo.VotingPower, 10, 64)

// test consensus state endpoint
logger.Info("Attempting to get consensus state")
Expand All @@ -171,8 +177,8 @@
return errors.Wrapf(err, "failed to get consensus state")
}
logger.Infof(
"Total VP: %d, Node VP: %d, Node share: %.2f", pvp.TotalVP, status.ValidatorInfo.VotingPower,
(float64(status.ValidatorInfo.VotingPower)/float64(pvp.TotalVP))*100,
"Total VP: %d, Node VP: %d, Node share: %.2f", pvp.TotalVP, valVP,
(float64(valVP)/float64(pvp.TotalVP))*100,
)

// fetch future upgrades
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/provider/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chain

import (
"context"
"fmt"
"sort"

"blazar/internal/pkg/errors"
Expand Down Expand Up @@ -32,6 +33,11 @@ func NewProvider(cosmosClient CosmosProposalsProvider, chain string, priority in
}

func (p *Provider) GetUpgrades(ctx context.Context) ([]*urproto.Upgrade, error) {
fmt.Println(p.chain)
if p.chain == "berachain_testnet_2" {
fmt.Println("HACK, delete this")
return []*urproto.Upgrade{}, nil
}
upgrades, err := p.fetchAllUpgrades(ctx)
if err != nil {
return []*urproto.Upgrade{}, err
Expand Down