Skip to content

Commit

Permalink
Merge pull request #165 from NodeFactoryIo/mmuftic/fix-manual-payout
Browse files Browse the repository at this point in the history
Fix manual payout
  • Loading branch information
mpetrunic authored Jan 4, 2021
2 parents ebaf094 + 1d05c33 commit ad3b508
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.4.0
version=0.4.1
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Changelog

## [unreleased]((https://github.com/NodeFactoryIo/vedran/tree/HEAD))
[Full Changelog](https://github.com/NodeFactoryIo/vedran/compare/v0.4.0...HEAD)
## [v0.4.1]((https://github.com/NodeFactoryIo/vedran/tree/v0.4.1))
[Full Changelog](https://github.com/NodeFactoryIo/vedran/compare/v0.4.0...v0.4.1)

### Added

### Fix
- Fix manual payout #165 [#\165](https://github.com/NodeFactoryIo/vedran/pull/165) ([MakMuftic](https://github.com/MakMuftic))

### Changed

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
vedran:
command: start --auth-secret=test-secret --log-level debug --public-ip vedran --server-port 4000 --private-key ${VEDRAN_LB_PK:-0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a} --payout-interval 1 --payout-reward ${VEDRAN_LB_REWARD_POOL:-10}
image: nodefactory/vedran:v0.4.0
image: nodefactory/vedran:v0.4.1
ports:
- "4000:4000"
container_name: "vedran"
Expand Down
65 changes: 61 additions & 4 deletions infra/grafana/provisioning/dashboards/vedran-dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
},
"gridPos": {
"h": 7,
"w": 12,
"w": 6,
"x": 12,
"y": 1
},
Expand All @@ -157,7 +157,64 @@
"calcs": [
"mean"
],
"fields": "",
"fields": "/^\\{code=\"200\", handler=\"/\", instance=\"vedran:4000\", job=\"prometheus\", method=\"POST\"\\}$/",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "7.3.6",
"targets": [
{
"expr": "rate(http_request_duration_seconds_count[5m])",
"interval": "",
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Requests Per Second (HTTP)",
"type": "stat"
},
{
"datasource": null,
"fieldConfig": {
"defaults": {
"custom": {},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 7,
"w": 6,
"x": 18,
"y": 1
},
"id": 43,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "/^\\{code=\"200\", handler=\"/ws\", instance=\"vedran:4000\", job=\"prometheus\", method=\"GET\"\\}$/",
"values": false
},
"textMode": "auto"
Expand All @@ -173,7 +230,7 @@
],
"timeFrom": null,
"timeShift": null,
"title": "Requests Per Second",
"title": "Requests Per Second (WS)",
"type": "stat"
},
{
Expand Down Expand Up @@ -1497,5 +1554,5 @@
"timezone": "",
"title": "Vedran Dashboard",
"uid": "7tNmHxAGz",
"version": 4
"version": 1
}
2 changes: 1 addition & 1 deletion internal/repositories/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (f *feeRepo) RecordNewFee(nodeID string, newFee int64) error {
err := f.db.One("NodeId", nodeID, feeInDb)
if err != nil {
if err.Error() == "not found" {
err = f.db.Save(models.Fee{
err = f.db.Save(&models.Fee{
NodeId: nodeID,
TotalFee: newFee,
})
Expand Down
12 changes: 9 additions & 3 deletions internal/script/payout.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package script

import (
"bytes"
"encoding/json"
"fmt"
"github.com/NodeFactoryIo/vedran/internal/api"
Expand Down Expand Up @@ -51,7 +52,9 @@ func ExecutePayout(

log.Infof("Total reward: %s", strconv.FormatFloat(totalReward, 'f', 0, 64))

response, err := fetchStatsFromEndpoint(statsEndpoint(loadbalancerUrl), privateKey)
response, err := fetchStatsFromEndpoint(
statsEndpoint(loadbalancerUrl), privateKey, fmt.Sprintf("%f", totalReward),
)
if err != nil {
return nil, fmt.Errorf("unable to fetch stats from loadbalancer, %v", err)
}
Expand All @@ -73,13 +76,16 @@ func ExecutePayout(
)
}

func fetchStatsFromEndpoint(endpoint *url.URL, secret string) (*controllers.LoadbalancerStatsResponse, error) {
func fetchStatsFromEndpoint(endpoint *url.URL, secret string, totalReward string) (*controllers.LoadbalancerStatsResponse, error) {
sig, err := signature.Sign([]byte(constants.StatsSignedData), secret)
if err != nil {
return nil, err
}

request, _ := http.NewRequest("POST", endpoint.String(), nil)
payloadBuf := new(bytes.Buffer)
_ = json.NewEncoder(payloadBuf).Encode(controllers.LoadbalancerStatsRequest{TotalReward: totalReward})

request, _ := http.NewRequest("POST", endpoint.String(), payloadBuf)
request.Header.Set("X-Signature", hexutil.Encode(sig))

c := &http.Client{}
Expand Down

0 comments on commit ad3b508

Please sign in to comment.