Skip to content

Commit b935c57

Browse files
committed
Implement suggested fixes.
1 parent b2ffbb5 commit b935c57

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

app/grpc_server/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func run(logger *log.Logger) error {
3232
HttpHost string `conf:"default:0.0.0.0:8000"`
3333
GrpcHost string `conf:"default:0.0.0.0:8001"`
3434
MaxTickFetchUrl string `conf:"default:http://127.0.0.1:8080/max-tick"`
35-
ReadRetryCount int `conf:"default:5"`
35+
ReadMaxRetries int `conf:"default:5"`
3636
}
3737
Pool struct {
3838
NodeFetcherUrl string `conf:"default:http://127.0.0.1:8080/status"`
@@ -84,7 +84,7 @@ func run(logger *log.Logger) error {
8484
return errors.Wrap(err, "creating qubic pool")
8585
}
8686

87-
rpcServer := rpc.NewServer(cfg.Server.GrpcHost, cfg.Server.HttpHost, logger, pool, cfg.Server.MaxTickFetchUrl, cfg.Server.ReadRetryCount)
87+
rpcServer := rpc.NewServer(cfg.Server.GrpcHost, cfg.Server.HttpHost, logger, pool, cfg.Server.MaxTickFetchUrl, cfg.Server.ReadMaxRetries)
8888
err = rpcServer.Start()
8989
if err != nil {
9090
return errors.Wrap(err, "starting rpc server")

foundation/rpc_server/rpc_server.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ type Server struct {
3434
listenAddrHTTP string
3535
qPool *qubic.Pool
3636
maxTickFetchUrl string
37-
readRetryCount int
37+
ReadMaxRetries int
3838
}
3939

40-
func NewServer(listenAddrGRPC, listenAddrHTTP string, logger *log.Logger, qPool *qubic.Pool, maxTickFetchUrl string, readRetryCount int) *Server {
40+
func NewServer(listenAddrGRPC, listenAddrHTTP string, logger *log.Logger, qPool *qubic.Pool, maxTickFetchUrl string, readMaxRetries int) *Server {
4141
return &Server{
4242
listenAddrGRPC: listenAddrGRPC,
4343
listenAddrHTTP: listenAddrHTTP,
4444
logger: logger,
4545
qPool: qPool,
4646
maxTickFetchUrl: maxTickFetchUrl,
47-
readRetryCount: readRetryCount,
47+
ReadMaxRetries: readMaxRetries,
4848
}
4949
}
5050

5151
func (s *Server) GetBalance(ctx context.Context, req *protobuff.GetBalanceRequest) (*protobuff.GetBalanceResponse, error) {
5252

5353
var identityInfo types.AddressInfo
54-
err := WithRetry(ctx, s.qPool, s.readRetryCount, func(ctx context.Context, client *qubic.Client) error {
54+
err := WithRetry(ctx, s.qPool, s.ReadMaxRetries, func(ctx context.Context, client *qubic.Client) error {
5555
res, err := client.GetIdentity(ctx, req.Id)
5656
if err != nil {
5757
return errors.Wrap(err, "getting identity info from node")
@@ -81,7 +81,7 @@ func (s *Server) GetBalance(ctx context.Context, req *protobuff.GetBalanceReques
8181
func (s *Server) GetTickInfo(ctx context.Context, _ *emptypb.Empty) (*protobuff.GetTickInfoResponse, error) {
8282

8383
var tickInfo types.TickInfo
84-
err := WithRetry(ctx, s.qPool, s.readRetryCount, func(ctx context.Context, client *qubic.Client) error {
84+
err := WithRetry(ctx, s.qPool, s.ReadMaxRetries, func(ctx context.Context, client *qubic.Client) error {
8585
res, err := client.GetTickInfo(ctx)
8686
if err != nil {
8787
return errors.Wrap(err, "getting tick info from node")
@@ -105,7 +105,7 @@ func (s *Server) GetTickInfo(ctx context.Context, _ *emptypb.Empty) (*protobuff.
105105
func (s *Server) GetBlockHeight(ctx context.Context, _ *emptypb.Empty) (*protobuff.GetBlockHeightResponse, error) {
106106

107107
var tickInfo types.TickInfo
108-
err := WithRetry(ctx, s.qPool, s.readRetryCount, func(ctx context.Context, client *qubic.Client) error {
108+
err := WithRetry(ctx, s.qPool, s.ReadMaxRetries, func(ctx context.Context, client *qubic.Client) error {
109109
res, err := client.GetTickInfo(ctx)
110110
if err != nil {
111111
return errors.Wrap(err, "getting tick info from node")
@@ -134,7 +134,7 @@ func (s *Server) QuerySmartContract(ctx context.Context, req *protobuff.QuerySma
134134

135135
var scData types.SmartContractData
136136

137-
err = WithRetry(ctx, s.qPool, s.readRetryCount, func(ctx context.Context, client *qubic.Client) error {
137+
err = WithRetry(ctx, s.qPool, s.ReadMaxRetries, func(ctx context.Context, client *qubic.Client) error {
138138
res, err := client.QuerySmartContract(ctx, qubic.RequestContractFunction{
139139
ContractIndex: req.ContractIndex,
140140
InputType: uint16(req.InputType),
@@ -157,7 +157,7 @@ func (s *Server) QuerySmartContract(ctx context.Context, req *protobuff.QuerySma
157157
func (s *Server) GetIssuedAssets(ctx context.Context, req *protobuff.IssuedAssetsRequest) (*protobuff.IssuedAssetsResponse, error) {
158158

159159
var assets types.IssuedAssets
160-
err := WithRetry(ctx, s.qPool, s.readRetryCount, func(ctx context.Context, client *qubic.Client) error {
160+
err := WithRetry(ctx, s.qPool, s.ReadMaxRetries, func(ctx context.Context, client *qubic.Client) error {
161161
res, err := client.GetIssuedAssets(ctx, req.Identity)
162162
if err != nil {
163163
return errors.Wrap(err, "getting issued assets from node")
@@ -208,7 +208,7 @@ func (s *Server) GetIssuedAssets(ctx context.Context, req *protobuff.IssuedAsset
208208
func (s *Server) GetOwnedAssets(ctx context.Context, req *protobuff.OwnedAssetsRequest) (*protobuff.OwnedAssetsResponse, error) {
209209

210210
var assets types.OwnedAssets
211-
err := WithRetry(ctx, s.qPool, s.readRetryCount, func(ctx context.Context, client *qubic.Client) error {
211+
err := WithRetry(ctx, s.qPool, s.ReadMaxRetries, func(ctx context.Context, client *qubic.Client) error {
212212
res, err := client.GetOwnedAssets(ctx, req.Identity)
213213
if err != nil {
214214
return errors.Wrap(err, "getting owned assets from node")
@@ -277,7 +277,7 @@ func (s *Server) GetOwnedAssets(ctx context.Context, req *protobuff.OwnedAssetsR
277277
func (s *Server) GetPossessedAssets(ctx context.Context, req *protobuff.PossessedAssetsRequest) (*protobuff.PossessedAssetsResponse, error) {
278278

279279
var assets types.PossessedAssets
280-
err := WithRetry(ctx, s.qPool, s.readRetryCount, func(ctx context.Context, client *qubic.Client) error {
280+
err := WithRetry(ctx, s.qPool, s.ReadMaxRetries, func(ctx context.Context, client *qubic.Client) error {
281281
res, err := client.GetPossessedAssets(ctx, req.Identity)
282282
if err != nil {
283283
return errors.Wrap(err, "getting possessed assets from node")
@@ -428,7 +428,7 @@ type RetryableCall func(ctx context.Context, client *qubic.Client) error
428428
func WithRetry(ctx context.Context, pool *qubic.Pool, maxRetries int, call RetryableCall) error {
429429
var lastErr error
430430

431-
for attempt := 0; attempt <= maxRetries; attempt++ {
431+
for attempt := 0; attempt < maxRetries; attempt++ {
432432
client, err := pool.Get()
433433
if err != nil {
434434
lastErr = status.Errorf(codes.Internal, "failed to get client from pool: %v", err)

0 commit comments

Comments
 (0)