Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute payout transactions #127

Merged
merged 30 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3f1a4f3
Add tx functions
Nov 11, 2020
ffc3be9
Merge branch 'dev' of github.com:NodeFactoryIo/vedran into mmuftic/ex…
Nov 13, 2020
5e38049
Improve transaction function
Nov 13, 2020
11244b5
Refactor displaying transaction status
Nov 13, 2020
74f4de4
Fix typo
Nov 13, 2020
ad11c23
Update CHANGELOG file
Nov 13, 2020
ef01416
Replace go-substrate-rpc-client with our fork
Nov 17, 2020
13d95dc
Use rpc lib fork
Nov 19, 2020
46b655a
Add scheduled payout
Nov 19, 2020
59b79cc
Tidy go.mod
Nov 19, 2020
771c2f5
Expand README file with payouts
Nov 19, 2020
df99d1f
Refactor start flags
Nov 24, 2020
8240c41
Merge changes from dev
Dec 1, 2020
0eba2c0
Update README file with required flag
Dec 1, 2020
96e88f8
WIP refactoring transaction execution
Dec 1, 2020
ac9b64f
Restructure transaction code
Dec 2, 2020
8974169
WIP fix invalid transaction error
Dec 2, 2020
52033a8
Merge branch 'dev' of github.com:NodeFactoryIo/vedran into mmuftic/ex…
Dec 2, 2020
4f5daed
Fix naming conflict in payout script
Dec 2, 2020
3479999
Refactor transaction flow to support new mapping on payout address
Dec 2, 2020
c6c5da6
Fix invalid address generation
Dec 3, 2020
9be0e6b
Fix wallet-secret flag set to required
Dec 3, 2020
c48069c
Fix typo
Dec 3, 2020
d795eb3
Rename wallet-secret flag to private-key
Dec 3, 2020
c833971
Fix typo
Dec 4, 2020
d80f469
Improve logging on payout
Dec 4, 2020
0b3c8ad
Merge branch 'mmuftic/execute-transactions' of github.com:NodeFactory…
Dec 4, 2020
68e1d5e
Update flags naming
Dec 4, 2020
de0be53
Fix typo
Dec 4, 2020
a97bd24
Remove private key from configuration
Dec 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Calculating reward distribution [\#124](https://github.com/NodeFactoryIo/vedran/pull/124) ([MakMuftic](https://github.com/MakMuftic))
- Add payout CLI command [\#126](https://github.com/NodeFactoryIo/vedran/pull/126) ([MakMuftic](https://github.com/MakMuftic))
- Support WS connections [#\132](https://github.com/NodeFactoryIo/vedran/pull/132) ([MakMuftic](https://github.com/MakMuftic))
- Execute payout transactions [\#127](https://github.com/NodeFactoryIo/vedran/pull/127) ([MakMuftic](https://github.com/MakMuftic))

### Fix

Expand Down
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Start command will start application on 2 ports that need to be exposed to publi

`--auth-secret` authentication secret used for generating tokens

`--wallet-secret` - loadbalancers wallet secret

### Most important flags

`--server-port` - port on which RPC API is exposed - **DEFAULT** [80]
Expand All @@ -84,9 +86,9 @@ Start command will start application on 2 ports that need to be exposed to publi

`--capacity` - maximum number of nodes allowed to connect - **DEFAULT** [-1] unlimited capacity

`--whitelist` - Comma separated list of node id-s, if provided only these nodes will be allowed to connect. This flag can't be used together with --whitelist-file flag, only one option for setting whitelisted nodes can be used - **DEFAULT** no nodes whitelisted
`--whitelist` - comma separated list of node id-s, if provided only these nodes will be allowed to connect. This flag can't be used together with --whitelist-file flag, only one option for setting whitelisted nodes can be used - **DEFAULT** no nodes whitelisted

`--whitelist-file` - Path to file with node id-s in each line that should be whitelisted. This flag can't be used together with --whitelist flag, only one option for setting whitelisted nodes can be used - **DEFAULT** no file used
`--whitelist-file` - path to file with node id-s in each line that should be whitelisted. This flag can't be used together with --whitelist flag, only one option for setting whitelisted nodes can be used - **DEFAULT** no file used

`--fee` - value between 0-1 representing fee percentage that loadbalancer will take - **DEFAULT** [0.1]

Expand All @@ -96,6 +98,33 @@ Start command will start application on 2 ports that need to be exposed to publi

`--log-file` - path to file in which logs will be saved - **DEFAULT** [stdout]

## Payouts

### Automatic payout

When starting _vedran loadbalancer_ it is possible to configure automatic payout by providing these flags:

`--wallet-secret` - loadbalancers wallet secret

`--payout-interval` - automatic payout interval specified as number of days

`--payout-reward` - defined reward amount that will be distributed on the payout (amount in Planck)

If all flags have been provided than each {_payout-interval_} days automatic payout will be started.

### Manual payout

It is possible to run payout script at any time by invoking `vedran payout` command trough console.
This command has two required flags:

`--secret` - loadbalancer wallet secret

`--reward` - defined reward amount that will be distributed on the payout (amount in Planck)

Additionally, it is possible to change url on which payout script will connect with loadbalancer when executing transactions by setting flag (default value will be _http://localhost:80_)

`--load-balancer-url` - loadbalancer url

## Vedran loadbalancer API

`POST api/v1/nodes`
Expand Down
12 changes: 9 additions & 3 deletions cmd/payout.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/NodeFactoryIo/vedran/internal/script"
"github.com/NodeFactoryIo/vedran/internal/ui"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"net/url"
Expand Down Expand Up @@ -49,7 +50,7 @@ func init() {
_ = payoutCmd.MarkFlagRequired("secret")
payoutCmd.Flags().StringVar(
&totalReward,
"total-reward",
"reward",
"",
"[REQUIRED] total reward pool in Planck",
)
Expand All @@ -65,10 +66,15 @@ func init() {
func payoutCommand(_ *cobra.Command, _ []string) {
DisplayBanner()
fmt.Println("Payout script running...")
err := script.ExecutePayout(secret, totalRewardAsFloat64, loadbalancerURL)
transactions, err := script.ExecutePayout(secret, totalRewardAsFloat64, loadbalancerURL)
if transactions != nil {
// display even if only part of transactions executed
ui.DisplayTransactionsStatus(transactions)
}
if err != nil {
log.Errorf("Unable to execute payout, because of: %v", err)
return
} else {
log.Info("Payout execution finished")
}
log.Info("Payout execution finished")
}
51 changes: 51 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"errors"
"fmt"
schedulepayout "github.com/NodeFactoryIo/vedran/internal/schedule/payout"
"net/url"
"strconv"
"strings"

Expand Down Expand Up @@ -33,6 +35,12 @@ var (
selection string
serverPort int32
publicIP string
walletSecret string
// payout related flags
payoutNumberOfDays int32
payoutTotalReward string
payoutTotalRewardAsFloat64 float64
autoPayoutDisabled bool
// logging related flags
logLevel string
logFile string
Expand Down Expand Up @@ -101,6 +109,23 @@ var startCmd = &cobra.Command{
if whitelistArray != nil && whitelistFile != "" {
return errors.New("only one flag for setting whitelisted nodes should be set")
}

if walletSecret == "" {
return errors.New("payout secret needs to be set")
}

autoPayoutDisabled = payoutNumberOfDays == 0 && payoutTotalReward == ""
if !autoPayoutDisabled {
if payoutNumberOfDays <= 0 {
return errors.New("invalid payout interval")
}
rewardAsFloat64, err := strconv.ParseFloat(payoutTotalReward, 64)
if err != nil {
return errors.New("invalid total reward value")
}
payoutTotalRewardAsFloat64 = rewardAsFloat64
}

return nil
},
}
Expand Down Expand Up @@ -198,6 +223,26 @@ func init() {
"20000:30000",
"[OPTIONAL] Range of ports which is used to open tunnels")

startCmd.Flags().StringVar(
&walletSecret,
"wallet-secret",
"",
"[REQUIRED] Loadbalancer wallet secret",
)

startCmd.Flags().Int32Var(
&payoutNumberOfDays,
"payout-interval",
0,
"[OPTIONAL] Payout interval in days, meaning each X days automatic payout will be executed")

startCmd.Flags().StringVar(
&payoutTotalReward,
"payout-reward",
"",
"[REQUIRED] Total reward pool in Planck",
)

RootCmd.AddCommand(startCmd)
}

Expand Down Expand Up @@ -231,6 +276,11 @@ func startCommand(_ *cobra.Command, _ []string) {
}
log.Debugf("Whitelisting set to: %t", whitelistEnabled)

if !autoPayoutDisabled {
lbUrl, _ := url.Parse("http://" + publicIP + ":" + string(serverPort))
schedulepayout.StartScheduledPayout(payoutNumberOfDays, walletSecret, payoutTotalRewardAsFloat64, lbUrl)
}

tunnel.StartHttpTunnelServer(tunnelServerPort, pPool)
loadbalancer.StartLoadBalancerServer(configuration.Configuration{
AuthSecret: authSecret,
Expand All @@ -244,5 +294,6 @@ func startCommand(_ *cobra.Command, _ []string) {
TunnelServerAddress: tunnelServerAddress,
PortPool: pPool,
WhitelistEnabled: whitelistEnabled,
Secret: walletSecret,
})
}
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ module github.com/NodeFactoryIo/vedran
go 1.15

require (
github.com/NodeFactoryIo/go-substrate-rpc-client v1.1.1-0.20201117130410-fe8589d08563
github.com/asdine/storm/v3 v3.2.1
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/ethereum/go-ethereum v1.9.24 // indirect
github.com/golang/gddo v0.0.0-20200831202555-721e228c7686
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.4.0
github.com/gorilla/websocket v1.4.1
github.com/gosuri/uitable v0.0.4
github.com/inconshreveable/go-vhost v0.0.0-20160627193104-06d84117953b
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20200625001655-4c5254603344
golang.org/x/net v0.0.0-20200822124328-c89045814202
)
Loading