Skip to content

Commit 23ec008

Browse files
authored
fix: add custom latest block structure (#24)
This PR fixes a small issue with the REST nodes where unmarshaling was failing due to the exposed models on tendermint/cometbft having proto `uint64` fields as strings. With this fix we are only unmarshaling the fields that are required by the probes.
1 parent af93876 commit 23ec008

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
golang.org/x/crypto v0.32.0
1111
golang.org/x/net v0.34.0
1212
golang.org/x/sync v0.10.0
13+
google.golang.org/grpc v1.70.0
1314
)
1415

1516
require (
@@ -142,7 +143,6 @@ require (
142143
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
143144
google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a // indirect
144145
google.golang.org/genproto/googleapis/rpc v0.0.0-20250122153221-138b5a5a4fd4 // indirect
145-
google.golang.org/grpc v1.70.0 // indirect
146146
google.golang.org/protobuf v1.36.4 // indirect
147147
gopkg.in/ini.v1 v1.67.0 // indirect
148148
gopkg.in/yaml.v3 v3.0.1 // indirect

internal/seed/probes.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import (
55
"crypto/tls"
66
"encoding/json"
77
"fmt"
8+
"io"
9+
"net/http"
10+
"strconv"
11+
"time"
12+
813
"github.com/akash-network/rpc-proxy/internal/block"
914
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
1015
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
1116
"google.golang.org/grpc"
1217
"google.golang.org/grpc/credentials"
13-
"io"
14-
"net/http"
15-
"time"
1618
)
1719

1820
// Probe is the interface that wraps the Probe method.
@@ -91,17 +93,24 @@ func GRPCProbe(ctx context.Context, node Node) (Status, error) {
9193
Reachable: true,
9294
IsLatestBlock: errLowBlock == nil,
9395
}, nil
96+
}
9497

98+
type syncInfoResponse struct {
99+
CatchingUp bool `json:"catching_up"`
100+
}
101+
102+
type latestBlockResponse struct {
103+
Block struct {
104+
Header struct {
105+
Height string `json:"height"`
106+
} `json:"header"`
107+
} `json:"block"`
95108
}
96109

97110
// RESTProbe probes a REST Node.
98111
// It checks if the node is catching up querying the REST endpoint, queries the Node latest block and tries to set the
99112
// height globally.
100113
func RESTProbe(ctx context.Context, node Node) (Status, error) {
101-
type SyncInfo struct {
102-
CatchingUp bool `json:"catching_up"`
103-
}
104-
105114
client := &http.Client{}
106115

107116
req, err := http.NewRequest("GET", fmt.Sprintf("%s/syncing", node.Address), nil)
@@ -124,7 +133,7 @@ func RESTProbe(ctx context.Context, node Node) (Status, error) {
124133
return Status{}, fmt.Errorf("reading body from REST client response: %w", err)
125134
}
126135

127-
var syncing SyncInfo
136+
var syncing syncInfoResponse
128137
if err := json.Unmarshal(body, &syncing); err != nil {
129138
return Status{}, fmt.Errorf("unmarshaling body from REST client response: %w", err)
130139
}
@@ -149,12 +158,17 @@ func RESTProbe(ctx context.Context, node Node) (Status, error) {
149158
return Status{}, fmt.Errorf("reading body from REST client response: %w", err)
150159
}
151160

152-
var latestBlock cmtservice.GetLatestBlockResponse
161+
var latestBlock latestBlockResponse
153162
if err := json.Unmarshal(latestBlockBody, &latestBlock); err != nil {
154163
return Status{}, fmt.Errorf("unmarshaling body from REST client response: %w", err)
155164
}
156165

157-
errLowBlock := block.GetInstance().SetLatestBlock(latestBlock.Block.Header.Height)
166+
height, err := strconv.ParseInt(latestBlock.Block.Header.Height, 10, 64)
167+
if err != nil {
168+
return Status{}, fmt.Errorf("parsing block height: %w", err)
169+
}
170+
171+
errLowBlock := block.GetInstance().SetLatestBlock(height)
158172

159173
return Status{
160174
CatchingUp: syncing.CatchingUp,

0 commit comments

Comments
 (0)