fixed fee bug
This commit is contained in:
parent
42d566906d
commit
f7cf3c26e6
|
@ -22,9 +22,6 @@ const (
|
|||
StatusSkipped = "skipped"
|
||||
StatusValid = "valid"
|
||||
|
||||
StateCurrent = "current"
|
||||
StateDelinquent = "delinquent"
|
||||
|
||||
TransactionTypeVote = "vote"
|
||||
TransactionTypeNonVote = "non_vote"
|
||||
)
|
||||
|
|
|
@ -381,8 +381,9 @@ func (c *SlotWatcher) fetchAndEmitSingleBlockInfo(
|
|||
return err
|
||||
}
|
||||
|
||||
foundFeeReward := false
|
||||
for _, reward := range block.Rewards {
|
||||
if reward.RewardType == "fee" {
|
||||
if strings.ToLower(reward.RewardType) == "fee" {
|
||||
// make sure we haven't made a logic issue or something:
|
||||
assertf(
|
||||
reward.Pubkey == nodekey,
|
||||
|
@ -390,11 +391,16 @@ func (c *SlotWatcher) fetchAndEmitSingleBlockInfo(
|
|||
nodekey,
|
||||
reward.Pubkey,
|
||||
)
|
||||
amount := float64(reward.Lamports) / float64(rpc.LamportsInSol)
|
||||
amount := float64(reward.Lamports) / rpc.LamportsInSol
|
||||
c.FeeRewardsMetric.WithLabelValues(nodekey, toString(epoch)).Add(amount)
|
||||
foundFeeReward = true
|
||||
}
|
||||
}
|
||||
|
||||
if !foundFeeReward {
|
||||
c.logger.Errorf("No fee reward for slot %d", slot)
|
||||
}
|
||||
|
||||
// track block size:
|
||||
if c.config.MonitorBlockSizes {
|
||||
// now count and emit votes:
|
||||
|
@ -424,7 +430,7 @@ func (c *SlotWatcher) fetchAndEmitInflationRewards(ctx context.Context, epoch in
|
|||
|
||||
for i, rewardInfo := range rewardInfos {
|
||||
address := c.config.VoteKeys[i]
|
||||
reward := float64(rewardInfo.Amount) / float64(rpc.LamportsInSol)
|
||||
reward := float64(rewardInfo.Amount) / rpc.LamportsInSol
|
||||
c.InflationRewardsMetric.WithLabelValues(address, toString(epoch)).Add(reward)
|
||||
}
|
||||
c.logger.Infof("Fetched inflation reward for epoch %v.", epoch)
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -10,6 +10,7 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -19,6 +20,10 @@ type (
|
|||
RpcUrl string
|
||||
HttpTimeout time.Duration
|
||||
logger *zap.SugaredLogger
|
||||
|
||||
// for grindiness tracking
|
||||
usage int64
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
Request struct {
|
||||
|
@ -31,10 +36,6 @@ type (
|
|||
Commitment string
|
||||
)
|
||||
|
||||
func (c Commitment) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(map[string]string{"commitment": string(c)})
|
||||
}
|
||||
|
||||
const (
|
||||
// LamportsInSol is the number of lamports in 1 SOL (a billion)
|
||||
LamportsInSol = 1_000_000_000
|
||||
|
@ -53,6 +54,18 @@ func NewRPCClient(rpcAddr string, httpTimeout time.Duration) *Client {
|
|||
return &Client{HttpClient: http.Client{}, RpcUrl: rpcAddr, HttpTimeout: httpTimeout, logger: slog.Get()}
|
||||
}
|
||||
|
||||
func (c *Client) addUsage(usage int64) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.usage += usage
|
||||
}
|
||||
|
||||
func (c *Client) GetUsage() int64 {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
return c.usage
|
||||
}
|
||||
|
||||
func getResponse[T any](
|
||||
ctx context.Context, client *Client, method string, params []any, rpcResponse *Response[T],
|
||||
) error {
|
||||
|
@ -85,7 +98,8 @@ func getResponse[T any](
|
|||
if err != nil {
|
||||
return fmt.Errorf("error processing %s rpc call: %w", method, err)
|
||||
}
|
||||
// log response:
|
||||
// add usage + debug log response:
|
||||
client.addUsage(int64(len(body)))
|
||||
logger.Debugf("%s response: %v", method, string(body))
|
||||
|
||||
// unmarshal the response into the predicted format
|
||||
|
@ -105,7 +119,8 @@ func getResponse[T any](
|
|||
// See API docs: https://solana.com/docs/rpc/http/getepochinfo
|
||||
func (c *Client) GetEpochInfo(ctx context.Context, commitment Commitment) (*EpochInfo, error) {
|
||||
var resp Response[EpochInfo]
|
||||
if err := getResponse(ctx, c, "getEpochInfo", []any{commitment}, &resp); err != nil {
|
||||
config := map[string]string{"commitment": string(commitment)}
|
||||
if err := getResponse(ctx, c, "getEpochInfo", []any{config}, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp.Result, nil
|
||||
|
|
Loading…
Reference in New Issue