Skip to content

Commit

Permalink
implemented jeffs nits
Browse files Browse the repository at this point in the history
  • Loading branch information
johnstonematt committed Oct 6, 2024
1 parent db8373b commit bf217cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/solana_exporter/slots.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (c *SlotWatcher) fetchAndEmitBlockProduction(ctx context.Context, endSlot i

// make sure the bounds are contained within the epoch we are currently watching:
if err := c.checkValidSlotRange(startSlot, endSlot); err != nil {
panic(err)
klog.Fatalf("invalid slot range: %v", err)
}

// fetch block production:
Expand Down
18 changes: 2 additions & 16 deletions cmd/solana_exporter/utils.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
package main

import (
"encoding/json"
"fmt"
"k8s.io/klog/v2"
)

func assertf(condition bool, format string, args ...any) {
if !condition {
panic(fmt.Errorf(format, args...))
klog.Fatalf(format, args...)
}
}

// prettyPrint is just a useful debugging function
func prettyPrint(obj any) {
// For pretty-printed JSON, use json.MarshalIndent
prettyJSON, err := json.MarshalIndent(obj, "", " ")
if err != nil {
fmt.Println("Error marshalling to pretty JSON:", err, ". obj: ", obj)
return
}

// Print the pretty JSON string
fmt.Println(string(prettyJSON))
}
9 changes: 5 additions & 4 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ func (c *Client) getResponse(ctx context.Context, method string, params []any, r
request := &rpcRequest{Version: "2.0", ID: 1, Method: method, Params: params}
buffer, err := json.Marshal(request)
if err != nil {
panic(err)
klog.Fatalf("failed to marshal request: %v", err)
}
klog.V(2).Infof("jsonrpc request: %s", string(buffer))

// make request:
req, err := http.NewRequestWithContext(ctx, "POST", c.rpcAddr, bytes.NewBuffer(buffer))
if err != nil {
panic(err)
klog.Fatalf("failed to create request: %v", err)
}
req.Header.Set("content-type", "application/json")

Expand Down Expand Up @@ -177,7 +177,7 @@ func (c *Client) GetBlockProduction(
) (*BlockProduction, error) {
// can't provide a last slot without a first:
if firstSlot == nil && lastSlot != nil {
panic("can't provide a last slot without a first!")
klog.Fatalf("can't provide a last slot without a first!")
}

// format params:
Expand All @@ -190,7 +190,8 @@ func (c *Client) GetBlockProduction(
if lastSlot != nil {
// make sure first and last slot are in order:
if *firstSlot > *lastSlot {
panic(fmt.Errorf("last slot %v is greater than first slot %v", *lastSlot, *firstSlot))
err := fmt.Errorf("last slot %v is greater than first slot %v", *lastSlot, *firstSlot)
klog.Fatalf("%v", err)
}
blockRange["lastSlot"] = *lastSlot
}
Expand Down

0 comments on commit bf217cf

Please sign in to comment.