fix reward value being added to counter multiple times
continuous-integration/drone/push Build was killed
Details
continuous-integration/drone/push Build was killed
Details
An update to the heliumapi made minTime fuzzy, causing an activity to be returned even if it occured before the specified minTime.
This commit is contained in:
parent
dec12e1780
commit
9501dc9dc0
32
exporter.go
32
exporter.go
|
@ -529,8 +529,7 @@ func (e *Exporter) collectAccountTransactionsMetrics(wg *sync.WaitGroup, ch chan
|
|||
}
|
||||
}
|
||||
|
||||
// add 1 second to the last update time to avoid querying the same activity twice
|
||||
minTime := account.LastUpdate.Add(time.Second * 1)
|
||||
minTime := account.LastUpdate
|
||||
// Explicitly set max_time, to avoid issues with server-side caching
|
||||
maxTime := time.Now()
|
||||
activities, err := heliumapi.GetActivityForAccount(account.Address, activityTypes, &minTime, &maxTime)
|
||||
|
@ -541,18 +540,25 @@ func (e *Exporter) collectAccountTransactionsMetrics(wg *sync.WaitGroup, ch chan
|
|||
|
||||
// impl based on https://github.com/helium/hotspot-app/blob/918563fba84d1abf4554a43a4d42bb838d017bd3/src/features/wallet/root/useActivityItem.tsx#L336
|
||||
for _, activity := range activities.AddGatewayV1 {
|
||||
if activity.Time > lastActivityTime {
|
||||
account.Tx.WithdrawalTotal += activity.StakingFee
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.AssertLocationV1 {
|
||||
if activity.Time > lastActivityTime {
|
||||
account.Tx.WithdrawalTotal += activity.StakingFee
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.AssertLocationV2 {
|
||||
if activity.Time > lastActivityTime {
|
||||
account.Tx.WithdrawalTotal += activity.StakingFee
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.PaymentV1 {
|
||||
if activity.Time > lastActivityTime {
|
||||
if activity.Payer == account.Address {
|
||||
account.Tx.WithdrawalTotal += activity.Amount
|
||||
} else {
|
||||
|
@ -560,7 +566,9 @@ func (e *Exporter) collectAccountTransactionsMetrics(wg *sync.WaitGroup, ch chan
|
|||
}
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.PaymentV2 {
|
||||
if activity.Time > lastActivityTime {
|
||||
if activity.Payer == account.Address {
|
||||
paymentTotal := 0
|
||||
for _, payment := range activity.Payments {
|
||||
|
@ -576,29 +584,39 @@ func (e *Exporter) collectAccountTransactionsMetrics(wg *sync.WaitGroup, ch chan
|
|||
}
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.RewardsV1 {
|
||||
if activity.Time > lastActivityTime {
|
||||
for _, reward := range activity.Rewards {
|
||||
account.RewardsTotal[reward.Type] += reward.Amount
|
||||
account.Tx.DepositTotal += reward.Amount
|
||||
}
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.RewardsV2 {
|
||||
if activity.Time > lastActivityTime {
|
||||
for _, reward := range activity.Rewards {
|
||||
account.RewardsTotal[reward.Type] += reward.Amount
|
||||
account.Tx.DepositTotal += reward.Amount
|
||||
}
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.StakeValidatorV1 {
|
||||
if activity.Time > lastActivityTime {
|
||||
account.Tx.WithdrawalTotal += activity.Stake
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.TokenBurnV1 {
|
||||
if activity.Time > lastActivityTime {
|
||||
account.Tx.WithdrawalTotal += activity.Amount
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.TransferHotspotV1 {
|
||||
if activity.Time > lastActivityTime {
|
||||
if activity.Buyer == account.Address {
|
||||
account.Tx.WithdrawalTotal += activity.AmountToSeller
|
||||
} else {
|
||||
|
@ -606,10 +624,13 @@ func (e *Exporter) collectAccountTransactionsMetrics(wg *sync.WaitGroup, ch chan
|
|||
}
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.UnstakeValidatorV1 {
|
||||
if activity.Time > lastActivityTime {
|
||||
account.Tx.WithdrawalTotal += activity.StakeAmount
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
account.LastUpdate = time.Unix(lastActivityTime, 0)
|
||||
|
||||
for rType, rTotal := range account.RewardsTotal {
|
||||
|
@ -791,8 +812,7 @@ func (e *Exporter) collectHotspotRewardsMetrics(wg *sync.WaitGroup, ch chan<- pr
|
|||
}
|
||||
}
|
||||
|
||||
// add 1 second to the last update time to avoid querying the same activity twice
|
||||
minTime := hotspot.LastUpdate.Add(time.Second * 1)
|
||||
minTime := hotspot.LastUpdate
|
||||
// Explicitly set max_time, to avoid issues with server-side caching
|
||||
maxTime := time.Now()
|
||||
activities, err := heliumapi.GetHotspotActivity(hotspot.Address, activityTypes, &minTime, &maxTime)
|
||||
|
@ -802,17 +822,21 @@ func (e *Exporter) collectHotspotRewardsMetrics(wg *sync.WaitGroup, ch chan<- pr
|
|||
}
|
||||
|
||||
for _, activity := range activities.RewardsV1 {
|
||||
if activity.Time > lastActivityTime {
|
||||
for _, reward := range activity.Rewards {
|
||||
hotspot.RewardsTotal[reward.Type] += reward.Amount
|
||||
}
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
for _, activity := range activities.RewardsV2 {
|
||||
if activity.Time > lastActivityTime {
|
||||
for _, reward := range activity.Rewards {
|
||||
hotspot.RewardsTotal[reward.Type] += reward.Amount
|
||||
}
|
||||
updateLastActivityTime(activity.Time)
|
||||
}
|
||||
}
|
||||
hotspot.LastUpdate = time.Unix(lastActivityTime, 0)
|
||||
|
||||
for rType, rTotal := range hotspot.RewardsTotal {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
@ -124,7 +125,7 @@ func getHeliumApiWithCursor(path string, params *map[string]string) ([][]byte, e
|
|||
defer resp.Body.Close()
|
||||
|
||||
// read the response body and add it to the result array
|
||||
// log.Printf("querying %v", req.URL.String())
|
||||
log.Printf("querying %v", req.URL.String())
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read response body of %v: %v", req.URL.String(), err)
|
||||
|
|
Reference in New Issue