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

Release v0.5.0 #180

Merged
merged 24 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.4.3
version=0.5.0
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

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


## [v0.5.0]((https://github.com/NodeFactoryIo/vedran/tree/v0.5.0))
[Full Changelog](https://github.com/NodeFactoryIo/vedran/compare/v0.4.3...v0.5.0)

### Added
- Add target block metric [\#177](https://github.com/NodeFactoryIo/vedran/pull/177) ([MakMuftic](https://github.com/MakMuftic))

### Fix
- Fix min TLS version [\#175](https://github.com/NodeFactoryIo/vedran/pull/175) ([MakMuftic](https://github.com/MakMuftic))

### Changed
- Replace go-substrate-rpc-client fork [\#176](https://github.com/NodeFactoryIo/vedran/pull/176) ([MakMuftic](https://github.com/MakMuftic))

## [v0.4.3]((https://github.com/NodeFactoryIo/vedran/tree/v0.4.3))
[Full Changelog](https://github.com/NodeFactoryIo/vedran/compare/v0.4.2...v0.4.3\)

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Start command will start application on 2 ports that need to be exposed to publi
|----|-----------|:--------:|
|`--server-port`|port on which RPC API is exposed|80|
|`--public-ip`|public IP address of loadbalancer|uses multiple services to find out public IP|
|`--cert-file`|SSL certification file|uses HTTP|
|`--key-file`|SSL price key file|uses HTTP|
|`--cert-file`|path to SSL certification file|uses HTTP|
|`--key-file`|path to SSL private key file|uses HTTP|
|`--tunnel-port`|port on which tunnel server is listening for connect requests|5223|
|`--tunnel-port-range`|range of ports that will be used for creating tunnels|20000:30000|

Expand All @@ -125,6 +125,7 @@ Start command will start application on 2 ports that need to be exposed to publi
|`--lb-payout-address`|address on which load balancer fee will be sent|-|
|`--log-level`|log level (debug, info, warn, error)|error|
|`--log-file`|path to file in which logs will be saved|`stdout`|
|`--root-dir`|root directory for all generated files (e.g. database file, log file)|uses current directory|

### Obtaining DOTs
If you want to do anything on Polkadot, Kusama, or Westend, then you'll need to get an account and some DOT, KSM, or WND tokens, respectively.
Expand Down
4 changes: 2 additions & 2 deletions 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.2
image: nodefactory/vedran:v0.5.0
environment:
- PROM_FEE_STATS_INTERVAL=10s
- PROM_PAYOUT_STATS_INTERVAL=5s
Expand All @@ -26,7 +26,7 @@ services:
container_name: "vedran"

vedran-daemon:
image: nodefactory/vedran-daemon:v0.3.0
image: nodefactory/vedran-daemon:v0.3.2
depends_on:
- vedran
- polkadot
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ 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/decred/base58 v1.0.2
github.com/centrifuge/go-substrate-rpc-client/v2 v2.1.0
github.com/decred/base58 v1.0.3
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/ethereum/go-ethereum v1.9.24
github.com/ethereum/go-ethereum v1.9.25
github.com/golang/gddo v0.0.0-20200831202555-721e228c7686
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
Expand Down
73 changes: 49 additions & 24 deletions go.sum

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions internal/active/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ func CheckIfMetricsValid(nodeID string, repos *repositories.Repos) (bool, error)
if err != nil {
return false, err
}
// check if node synced
if metrics.BestBlockHeight != metrics.TargetBlockHeight {
log.Debugf(
"Node %s not synced. Best block: %d, Target block: %d",
nodeID, metrics.BestBlockHeight, metrics.TargetBlockHeight,
)
return false, nil
}

latestBlockMetrics, err := repos.MetricsRepo.GetLatestBlockMetrics()
if err != nil {
return false, err
Expand Down
33 changes: 33 additions & 0 deletions internal/active/active_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestCheckIfNodeActive(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
nodeMetricsError: nil,
Expand All @@ -60,6 +61,32 @@ func TestCheckIfNodeActive(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
nodeMetricsError: nil,
latestMetrics: &models.LatestBlockMetrics{
BestBlockHeight: 0,
FinalizedBlockHeight: 0,
},
latestMetricsError: nil,
expectedResult: false,
expectedError: nil,
},
{
name: "not active node::node not synced",
node: models.Node{ID: "1"},
nodePing: &models.Ping{
NodeId: "1",
Timestamp: time.Now(),
},
nodePingError: nil,
nodeMetrics: &models.Metrics{
NodeId: "1",
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1300,
ReadyTransactionCount: 0,
},
nodeMetricsError: nil,
Expand All @@ -84,6 +111,7 @@ func TestCheckIfNodeActive(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
nodeMetricsError: nil,
Expand All @@ -108,6 +136,7 @@ func TestCheckIfNodeActive(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 994,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
nodeMetricsError: nil,
Expand All @@ -132,6 +161,7 @@ func TestCheckIfNodeActive(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
nodeMetricsError: nil,
Expand All @@ -155,6 +185,7 @@ func TestCheckIfNodeActive(t *testing.T) {
NodeId: "1",
PeerCount: 0,
BestBlockHeight: 1000,
TargetBlockHeight: 1000,
FinalizedBlockHeight: 995,
ReadyTransactionCount: 0,
},
Expand All @@ -180,6 +211,7 @@ func TestCheckIfNodeActive(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
nodeMetricsError: errors.New("metrics-error"),
Expand All @@ -204,6 +236,7 @@ func TestCheckIfNodeActive(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
nodeMetricsError: nil,
Expand Down
4 changes: 2 additions & 2 deletions internal/api/api.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package api

import (
gsrpc "github.com/NodeFactoryIo/go-substrate-rpc-client"
"github.com/NodeFactoryIo/go-substrate-rpc-client/types"
gsrpc "github.com/centrifuge/go-substrate-rpc-client/v2"
"github.com/centrifuge/go-substrate-rpc-client/v2/types"
)

func InitializeSubstrateAPI(substrateRPCUrl string) (*gsrpc.SubstrateAPI, error) {
Expand Down
2 changes: 2 additions & 0 deletions internal/controllers/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type MetricsRequest struct {
PeerCount int32 `json:"peer_count"`
BestBlockHeight int64 `json:"best_block_height"`
FinalizedBlockHeight int64 `json:"finalized_block_height"`
TargetBlockHeight int64 `json:"target_block_height"`
ReadyTransactionCount int32 `json:"ready_transaction_count"`
}

Expand Down Expand Up @@ -41,6 +42,7 @@ func (c ApiController) SaveMetricsHandler(w http.ResponseWriter, r *http.Request
PeerCount: metricsRequest.PeerCount,
BestBlockHeight: metricsRequest.BestBlockHeight,
FinalizedBlockHeight: metricsRequest.FinalizedBlockHeight,
TargetBlockHeight: metricsRequest.TargetBlockHeight,
ReadyTransactionCount: metricsRequest.ReadyTransactionCount,
})

Expand Down
48 changes: 48 additions & 0 deletions internal/controllers/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func TestApiController_SaveMetricsHandler(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
metricsRepoFindByIDError: nil,
Expand All @@ -92,6 +93,7 @@ func TestApiController_SaveMetricsHandler(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
nodeId: "1",
Expand Down Expand Up @@ -123,6 +125,7 @@ func TestApiController_SaveMetricsHandler(t *testing.T) {
PeerCount: 10,
BestBlockHeight: 100,
FinalizedBlockHeight: 100,
TargetBlockHeight: 100,
ReadyTransactionCount: 10,
},
nodeId: "1",
Expand Down Expand Up @@ -154,6 +157,7 @@ func TestApiController_SaveMetricsHandler(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
nodeId: "1",
Expand All @@ -173,6 +177,7 @@ func TestApiController_SaveMetricsHandler(t *testing.T) {
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1000,
ReadyTransactionCount: 0,
},
metricsRepoFindByIDError: nil,
Expand All @@ -188,6 +193,48 @@ func TestApiController_SaveMetricsHandler(t *testing.T) {
metricsRepoSaveError: nil,
metricsRepoSaveNumOfCalls: 1,
},
{
name: "Valid metrics save request and node should not be added to active nodes as node is not synced",
metricsRequest: MetricsRequest{
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1400,
ReadyTransactionCount: 0,
},
nodeId: "1",
httpStatus: http.StatusOK,
// NodeRepo.FindByID
nodeRepoIsNodeOnCooldownReturns: false,
nodeRepoIsNodeOnCooldownError: nil,
nodeRepoIsNodeOnNumOfCalls: 1,
// NodeRepo.AddNodeToActive
nodeRepoAddNodeToActiveError: nil,
nodeRepoAddNodeToActiveNumOfCalls: 0,
// NodeRepo.IsNodeActive
nodeRepoIsNodeActiveReturn: false,
// MetricsRepo.FindByID
metricsRepoFindByIDReturn: &models.Metrics{
NodeId: "1",
PeerCount: 0,
BestBlockHeight: 1000,
FinalizedBlockHeight: 995,
TargetBlockHeight: 1400,
ReadyTransactionCount: 0,
},
metricsRepoFindByIDError: nil,
metricsRepoFindByIDNumOfCalls: 1,
// MetricsRepo.GetLatestBlockMetrics
metricsRepoGetLatestBlockMetricsReturn: &models.LatestBlockMetrics{
BestBlockHeight: 1000,
FinalizedBlockHeight: 999,
},
metricsRepoGetLatestBlockMetricsError: nil,
metricsRepoGetLatestBlockMetricsNumOfCalls: 0,
// MetricsRepo.Save
metricsRepoSaveError: nil,
metricsRepoSaveNumOfCalls: 1,
},
{
name: "Invalid metrics save request",
metricsRequest: struct{ PeerCount string }{PeerCount: "10"},
Expand All @@ -200,6 +247,7 @@ func TestApiController_SaveMetricsHandler(t *testing.T) {
PeerCount: 10,
BestBlockHeight: 100,
FinalizedBlockHeight: 100,
TargetBlockHeight: 100,
ReadyTransactionCount: 10,
},
nodeId: "1",
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/NodeFactoryIo/go-substrate-rpc-client/signature"
"github.com/NodeFactoryIo/vedran/internal/configuration"
"github.com/NodeFactoryIo/vedran/internal/constants"
"github.com/NodeFactoryIo/vedran/internal/middleware"
"github.com/NodeFactoryIo/vedran/internal/models"
"github.com/NodeFactoryIo/vedran/internal/repositories"
mocks "github.com/NodeFactoryIo/vedran/mocks/repositories"
"github.com/centrifuge/go-substrate-rpc-client/v2/signature"
"github.com/ethereum/go-ethereum/common/hexutil"
muxhelpper "github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
Expand Down
14 changes: 8 additions & 6 deletions internal/loadbalancer/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loadbalancer

import (
"crypto/tls"
"fmt"
"net/http"
"path"
Expand Down Expand Up @@ -99,12 +100,13 @@ func StartLoadBalancerServer(
r := router.CreateNewApiRouter(apiController, privateKey)
prometheus.RecordMetrics(*repos)
if props.CertFile != "" {
err = http.ListenAndServeTLS(
fmt.Sprintf(":%d", props.Port),
props.CertFile,
props.KeyFile,
handlers.CORS()(r),
)
tlsConfig := &tls.Config{MinVersion: tls.VersionTLS10}
server := &http.Server{
Addr: fmt.Sprintf(":%d", props.Port),
Handler: handlers.CORS()(r),
TLSConfig: tlsConfig,
}
err = server.ListenAndServeTLS(props.CertFile, props.KeyFile)
} else {
err = http.ListenAndServe(fmt.Sprintf(":%d", props.Port), handlers.CORS()(r))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/middleware/signature.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package middleware

import (
"github.com/NodeFactoryIo/go-substrate-rpc-client/signature"
"github.com/NodeFactoryIo/vedran/internal/constants"
"github.com/centrifuge/go-substrate-rpc-client/v2/signature"
"github.com/ethereum/go-ethereum/common/hexutil"
log "github.com/sirupsen/logrus"
"net/http"
Expand Down
1 change: 1 addition & 0 deletions internal/models/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Metrics struct {
PeerCount int32
BestBlockHeight int64
FinalizedBlockHeight int64
TargetBlockHeight int64
ReadyTransactionCount int32
}

Expand Down
6 changes: 3 additions & 3 deletions internal/payout/tx.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package payout

import (
gsrpc "github.com/NodeFactoryIo/go-substrate-rpc-client"
"github.com/NodeFactoryIo/go-substrate-rpc-client/signature"
"github.com/NodeFactoryIo/go-substrate-rpc-client/types"
gsrpc "github.com/centrifuge/go-substrate-rpc-client/v2"
"github.com/centrifuge/go-substrate-rpc-client/v2/signature"
"github.com/centrifuge/go-substrate-rpc-client/v2/types"
"github.com/decred/base58"
"math/big"
"sync"
Expand Down
2 changes: 1 addition & 1 deletion internal/payout/txdetails.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package payout

import (
"github.com/NodeFactoryIo/go-substrate-rpc-client/rpc/author"
"github.com/centrifuge/go-substrate-rpc-client/v2/rpc/author"
log "github.com/sirupsen/logrus"
"math/big"
)
Expand Down
Loading