Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

RC 0.2.0 #30

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion cmd/gateway_server/internal/models/qos_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package models
import "time"

type PublicQosNode struct {
NodePublicKey string `json:"node_public_key"`
ServiceUrl string `json:"service_url"`
Chain string `json:"chain"`
SessionHeight uint `json:"session_height"`
AppPublicKey string `json:"app_public_key"`
TimeoutUntil time.Time `json:"timeout_until"`
TimeoutReason string `json:"timeout_reason"`
LastKnownErr string `json:"last_known_err"`
IsHeathy bool `json:"is_heathy"`
IsHealthy bool `json:"is_healthy"`
IsSynced bool `json:"is_synced"`
LastKnownHeight uint64 `json:"last_known_height"`
P90Latency float64 `json:"p90_latency"`
Expand Down
3 changes: 2 additions & 1 deletion cmd/gateway_server/internal/transform/qos_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ func ToPublicQosNode(node *internal_model.QosNode) *models.PublicQosNode {
latency = 0.0
}
return &models.PublicQosNode{
NodePublicKey: node.MorseNode.PublicKey,
ServiceUrl: node.MorseNode.ServiceUrl,
Chain: node.GetChain(),
SessionHeight: node.MorseSession.SessionHeader.SessionHeight,
AppPublicKey: node.MorseSigner.PublicKey,
TimeoutReason: string(node.GetTimeoutReason()),
LastKnownErr: node.GetLastKnownErrorStr(),
IsHeathy: node.IsHealthy(),
IsHealthy: node.IsHealthy(),
IsSynced: node.IsSynced(),
LastKnownHeight: node.GetLastKnownHeight(),
TimeoutUntil: node.GetTimeoutUntil(),
Expand Down
2 changes: 1 addition & 1 deletion internal/node_selector_service/checks/error_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const kickOutSessionPenalty = time.Hour * 24

var (
errsKickSession = []string{"failed to find correct servicer PK", "the max number of relays serviced for this node is exceeded", "the evidence is sealed, either max relays reached or claim already submitted"}
errsTimeout = []string{"connection refused", "the request block height is out of sync with the current block height", "no route to host", "unexpected EOF", "i/o timeout", "tls: failed to verify certificate", "no such host", "the block height passed is invalid", "request timeout"}
errsTimeout = []string{"connection refused", "the request block height is out of sync with the current block height", "no route to host", "unexpected EOF", "i/o timeout", "tls: failed to verify certificate", "no such host", "the block height passed is invalid", "request timeout", "error executing the http request"}
)

func doesErrorContains(errsSubString []string, err error) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (c *EvmDataIntegrityCheck) Perform() {

majorityBlockHash := findMajorityBlockHash(nodeResponseCounts)

// Blcok hash must not be empty
if majorityBlockHash == "" {
return
}

// Penalize other node operators with a timeout if they don't attest with same block hash.
for _, nodeResp := range nodeResponsePairs {
if nodeResp.result.Result.Hash != majorityBlockHash {
Expand Down
22 changes: 14 additions & 8 deletions internal/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

var (
counterRelayRequest *prometheus.CounterVec
histogramRelayRequestLatency prometheus.Histogram
histogramRelayRequestLatency *prometheus.HistogramVec
)

const (
Expand All @@ -40,13 +40,14 @@ func init() {
Name: "relay_counter",
Help: "Request to send an actual relay and if it succeeded",
},
[]string{"success", "altruist", "reason"},
[]string{"success", "altruist", "reason", "chain_id"},
)
histogramRelayRequestLatency = prometheus.NewHistogram(
histogramRelayRequestLatency = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "relay_latency",
Help: "percentile on the request to send a relay",
},
[]string{"success", "altruist", "chain_id"},
)
prometheus.MustRegister(counterRelayRequest, histogramRelayRequestLatency)
}
Expand Down Expand Up @@ -77,21 +78,26 @@ func NewRelayer(pocketService pokt_v0.PocketService, sessionRegistry session_reg

func (r *Relayer) SendRelay(req *models.SendRelayRequest) (*models.SendRelayResponse, error) {

success := false
altruist := false

startTime := time.Now()
// Measure end to end latency for send relay
defer func() {
histogramRelayRequestLatency.Observe(float64(time.Since(startTime)))
histogramRelayRequestLatency.WithLabelValues(strconv.FormatBool(success), strconv.FormatBool(altruist), req.Chain).Observe(float64(time.Since(startTime)))
}()

rsp, err := r.sendNodeSelectorRelay(req)

// Node selector relay was successful
if err == nil {
success = true
counterRelayRequest.WithLabelValues("true", "false", "").Inc()
return rsp, nil
}

counterRelayRequest.WithLabelValues("false", "true", reasonRelayFailedPocketErr).Inc()
altruist = true
counterRelayRequest.WithLabelValues("false", "true", reasonRelayFailedPocketErr, req.Chain).Inc()

r.logger.Sugar().Errorw("failed to send to pokt", "poktErr", err)
altruistRsp, altruistErr := r.altruistRelay(req)
Expand Down Expand Up @@ -145,7 +151,7 @@ func (r *Relayer) sendRandomNodeRelay(req *models.SendRelayRequest) (*models.Sen
})

if err != nil {
counterRelayRequest.WithLabelValues("false", "true", reasonRelayFailedSessionErr).Inc()
counterRelayRequest.WithLabelValues("false", "true", reasonRelayFailedSessionErr, req.Chain).Inc()
return nil, err
}

Expand All @@ -163,7 +169,7 @@ func (r *Relayer) sendRandomNodeRelay(req *models.SendRelayRequest) (*models.Sen
rsp, err := r.pocketClient.SendRelay(req)

// record if relay was successful
counterRelayRequest.WithLabelValues(strconv.FormatBool(err == nil), "false", "").Inc()
counterRelayRequest.WithLabelValues(strconv.FormatBool(err == nil), "false", "", req.Chain).Inc()

return rsp, err
}
Expand Down Expand Up @@ -195,7 +201,7 @@ func (r *Relayer) altruistRelay(req *models.SendRelayRequest) (*models.SendRelay
err := r.httpRequester.DoTimeout(request, response, requestTimeout)

success := err == nil
counterRelayRequest.WithLabelValues(strconv.FormatBool(success), "true", "").Inc()
counterRelayRequest.WithLabelValues(strconv.FormatBool(success), "true", "", req.Chain).Inc()

if !success {
return nil, err
Expand Down
Loading