Skip to content
This repository was archived by the owner on Jul 13, 2022. It is now read-only.
Merged
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 chains/substrate/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ As the writer receives messages from the router, it constructs proposals. If a p
package substrate

import (
"math/big"

"github.com/ChainSafe/ChainBridge/blockstore"
"github.com/ChainSafe/ChainBridge/core"
"github.com/ChainSafe/ChainBridge/crypto/sr25519"
"github.com/ChainSafe/ChainBridge/keystore"
msg "github.com/ChainSafe/ChainBridge/message"
"github.com/ChainSafe/ChainBridge/router"
"github.com/ChainSafe/log15"
"math/big"
)

var _ core.Chain = &Chain{}
Expand Down
6 changes: 3 additions & 3 deletions cmd/chainbridge/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func importPrivKey(ctx *cli.Context, keytype, datadir, key string, password []by
return "", fmt.Errorf("invalid filepath: %s", err)
}

file, err := os.OpenFile(fp, os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0600)
file, err := os.OpenFile(filepath.Clean(fp), os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return "", fmt.Errorf("Unable to Open File: %s", err)
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func importEthKey(filename, datadir string, password, newPassword []byte) (strin
return "", fmt.Errorf("invalid filepath: %s", err)
}

file, err := os.OpenFile(fp, os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0600)
file, err := os.OpenFile(filepath.Clean(fp), os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -374,7 +374,7 @@ func generateKeypair(keytype, datadir string, password []byte, subNetwork string
return "", fmt.Errorf("invalid filepath: %s", err)
}

file, err := os.OpenFile(fp, os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0600)
file, err := os.OpenFile(filepath.Clean(fp), os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return "", err
}
Expand Down
36 changes: 27 additions & 9 deletions monitor/health/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type httpMetricOptions struct {
core *core.Core
}

type chain struct {
id int
}
//type chain struct {
// id int
//}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented the struct out because it wasn't being used


func newHTTPMetricServer(opts httpMetricOptions) *HttpMetricServer {
return &HttpMetricServer{
Expand All @@ -52,7 +52,13 @@ func (s HttpMetricServer) Start() {

// Start http server
// TODO Push strconv to cli parser
http.ListenAndServe(":"+strconv.Itoa(s.port), nil)
err := http.ListenAndServe(":"+strconv.Itoa(s.port), nil)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle a graceful shutdown?


if err == http.ErrServerClosed {
log.Info("Server is shutting down", err)
} else {
log.Error("Shutting down, server error: ", err)
}
}

// healthStatus is a catch-all update that grabs the latest updates on the running chains
Expand All @@ -73,7 +79,10 @@ func (s HttpMetricServer) healthStatus(w http.ResponseWriter, r *http.Request) {
// TODO better error messaging
errorMsg := fmt.Sprintf("%s%d%s%s", "Failed to receive latest head for: ", chain.Id(), "Error:", err)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(errorMsg))
_, err = w.Write([]byte(errorMsg))
if err != nil {
log.Error("Failed to write, failed to get latest height and writing error", err)
}
}

// Get old blockheight
Expand All @@ -89,14 +98,20 @@ func (s HttpMetricServer) healthStatus(w http.ResponseWriter, r *http.Request) {
} else {
if timeDiff.Seconds() > 120 {
// Error if we exceeded the time limit
errorMsg := fmt.Sprintf("%s%s%s%s%s", "Chain height hasn't changed in: ", timeDiff, "Current height", latestHeight)
errorMsg := fmt.Sprintf("%s%s%s%s", "Chain height hasn't changed in: ", timeDiff, "Current height", latestHeight)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(errorMsg))
_, err = w.Write([]byte(errorMsg))
if err != nil {
log.Error("Failed to write, chain height hasn't changed in: %d seconds, Current height: %d", timeDiff.Seconds(), latestHeight, err)
}
} else {
// Error for having a smaller blockheight than previous
errorMsg := fmt.Sprintf("%s%s%s%s%s", "latestHeight is <= previousHeight", "previousHeight", prevHeight.height, "latestHeight", latestHeight)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(errorMsg))
_, err := w.Write([]byte(errorMsg))
if err != nil {
log.Error("Failed to write, latest height less than previous height, latest height: %d, previous height: %d", latestHeight, prevHeight.height, err)
}
}
}
} else {
Expand All @@ -109,5 +124,8 @@ func (s HttpMetricServer) healthStatus(w http.ResponseWriter, r *http.Request) {
}
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("200 - Operational"))
_, err := w.Write([]byte("200 - Operational"))
if err != nil {
log.Error("Failed to write, 200 - Operational")
}
}