Skip to content

Commit

Permalink
refactor: api method name update
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Oct 21, 2024
1 parent 256cd70 commit c81aad0
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions disperser/apiserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (s *DispersalServer) disperseBlob(ctx context.Context, blob *core.Blob, aut
}, nil
}

func (s *DispersalServer) PaidDisperseBlob(ctx context.Context, req *pb.DispersePaidBlobRequest) (*pb.DisperseBlobReply, error) {
func (s *DispersalServer) DispersePaidBlob(ctx context.Context, req *pb.DispersePaidBlobRequest) (*pb.DisperseBlobReply, error) {
blob, err := s.validatePaidRequestAndGetBlob(ctx, req)
quorumNumbers := req.CustomQuorumNumbers
binIndex := req.BinIndex
Expand All @@ -313,27 +313,26 @@ func (s *DispersalServer) PaidDisperseBlob(ctx context.Context, req *pb.Disperse

if err != nil {
for _, quorumID := range req.CustomQuorumNumbers {
s.metrics.HandleFailedRequest(codes.InvalidArgument.String(), fmt.Sprint(quorumID), len(req.GetData()), "PaidDisperseBlob")
s.metrics.HandleFailedRequest(codes.InvalidArgument.String(), fmt.Sprint(quorumID), len(req.GetData()), "DispersePaidBlob")
}
s.metrics.HandleInvalidArgRpcRequest("PaidDisperseBlob")
s.metrics.HandleInvalidArgRpcRequest("DispersePaidBlob")
return nil, api.NewInvalidArgError(err.Error())
}

reply, err := s.paidDisperseBlob(ctx, blob, quorumNumbers, binIndex, big.NewInt(int64(cumulativePayment)), signature, "", "PaidDisperseBlob")
reply, err := s.dispersePaidBlob(ctx, blob, quorumNumbers, binIndex, big.NewInt(int64(cumulativePayment)), signature, "", "DispersePaidBlob")
if err != nil {
// Note the PaidDisperseBlob already updated metrics for this error.
// Note the DispersePaidBlob already updated metrics for this error.
s.logger.Info("failed to disperse blob", "err", err)
} else {
s.metrics.HandleSuccessfulRpcRequest("PaidDisperseBlob")
s.metrics.HandleSuccessfulRpcRequest("DispersePaidBlob")
}
return reply, err
}

// Note: disperseBlob will internally update metrics upon an error; the caller doesn't need
// to track the error again.
func (s *DispersalServer) paidDisperseBlob(ctx context.Context, blob *core.Blob, quorumNumbers []uint32, binIndex uint32, cumulativePayment *big.Int, signature []byte, authenticatedAddress string, apiMethodName string) (*pb.DisperseBlobReply, error) {
// dispersePaidBlob checks for payment metering, otherwise does the same thing as disperseBlob
func (s *DispersalServer) dispersePaidBlob(ctx context.Context, blob *core.Blob, quorumNumbers []uint32, binIndex uint32, cumulativePayment *big.Int, signature []byte, authenticatedAddress string, apiMethodName string) (*pb.DisperseBlobReply, error) {
timer := prometheus.NewTimer(prometheus.ObserverFunc(func(f float64) {
s.metrics.ObserveLatency("PaidDisperseBlob", f*1000) // make milliseconds
s.metrics.ObserveLatency("DispersePaidBlob", f*1000) // make milliseconds
}))
defer timer.ObserveDuration()

Expand Down

0 comments on commit c81aad0

Please sign in to comment.