@@ -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.
100113func 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