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
Show all changes
26 commits
Select commit Hold shift + click to select a range
7bb24be
add metrics
GregTheGreek Aug 19, 2020
6c36d1b
Print json strings for generated configs in e2e tests (#509)
steviezhang Aug 19, 2020
564495f
add health check
GregTheGreek Aug 19, 2020
796de46
Isolate bootstrapping tests for testing purposes (#510)
steviezhang Aug 19, 2020
c0fa2e7
Update metrics/http.go
GregTheGreek Aug 19, 2020
bf89ca4
Refactor files to monitor folder (#512)
Aug 20, 2020
6cb08f7
Fixing linter issues (#513)
Aug 22, 2020
f3eaeb1
rename structs
GregTheGreek Aug 24, 2020
e658ebf
Merge branch 'greg/backport/metrics' of github.com:ChainSafe/ChainBri…
GregTheGreek Aug 24, 2020
80f095c
cleanup files
GregTheGreek Aug 24, 2020
75a0b1d
remove use of blockstore
GregTheGreek Aug 24, 2020
f411669
fix headers
GregTheGreek Aug 24, 2020
7951d43
Merge branch 'master' into greg/backport/metrics
GregTheGreek Aug 24, 2020
b16a856
Update monitor/health/health.go
GregTheGreek Aug 25, 2020
76451d0
some updates
GregTheGreek Aug 25, 2020
d69af89
t push:x
GregTheGreek Aug 25, 2020
a601200
switch registry to array
GregTheGreek Aug 25, 2020
d751a7e
pull timestamp from listener
GregTheGreek Aug 25, 2020
3861489
reset test files
GregTheGreek Aug 25, 2020
c545ba0
update code
GregTheGreek Aug 25, 2020
f211bde
Cleanup health server. Adds chain stats to response
Aug 26, 2020
e674a63
Adds cli flags
Aug 26, 2020
267f0ec
Cleanup
Aug 26, 2020
9d235c6
Merge branch 'master' of github.com:ChainSafe/ChainBridge into greg/b…
Aug 26, 2020
8a03d65
Adds missing license headers
Aug 26, 2020
cd619a0
Merge branch 'master' of github.com:ChainSafe/ChainBridge into greg/b…
Aug 26, 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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

[![Build Status](https://travis-ci.com/ChainSafe/ChainBridge.svg?branch=master)](https://travis-ci.com/ChainSafe/ChainBridge)

<h3><b>[WIP]</b></h3>

# Contents

- [Installation](#installation)
- [Configuration](#configuration)
- [Running](#running)
- [Chain Implementations](#chain-implementations)
- [Testing](#testing)
- [Simulations](#simulations)
Expand Down Expand Up @@ -97,6 +95,12 @@ To import private keys as keystores, use `chainbridge account import --privateKe

For testing purposes, chainbridge provides 5 test keys. The can be used with `--testkey <name>`, where `name` is one of `Alice`, `Bob`, `Charlie`, `Dave`, or `Eve`.

## Metrics

A basic health status check can be enabled with the `--metrics` flag (default port `8001`, use `--metricsPort` to specify).

The endpoint `/health` will return the current block height and a timestamp of when it was processed. If the timestamp is at least 120 seconds old an error will be returned.

# Chain Implementations

- Ethereum (Solidity): [chainbridge-solidity](https://github.com/ChainSafe/chainbridge-solidity)
Expand All @@ -109,7 +113,7 @@ For testing purposes, chainbridge provides 5 test keys. The can be used with `--

A substrate pallet that can be integrated into a chain, as well as an example pallet to demonstrate chain integration.

# MKdocs
# Docs

MKdocs will generate static HTML files for Chainsafe markdown files located in `Chainbridge/docs/`

Expand Down
5 changes: 5 additions & 0 deletions chains/ethereum/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/ChainSafe/ChainBridge/crypto/secp256k1"
"github.com/ChainSafe/ChainBridge/keystore"
msg "github.com/ChainSafe/ChainBridge/message"
metrics "github.com/ChainSafe/ChainBridge/metrics/types"
"github.com/ChainSafe/ChainBridge/router"
"github.com/ChainSafe/log15"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -205,6 +206,10 @@ func (c *Chain) Name() string {
return c.cfg.Name
}

func (c *Chain) LatestBlock() metrics.LatestBlock {
return c.listener.latestBlock
}

// Stop signals to any running routines to exit
func (c *Chain) Stop() {
close(c.stop)
Expand Down
17 changes: 11 additions & 6 deletions chains/ethereum/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ChainSafe/ChainBridge/blockstore"
"github.com/ChainSafe/ChainBridge/chains"
msg "github.com/ChainSafe/ChainBridge/message"
metrics "github.com/ChainSafe/ChainBridge/metrics/types"
utils "github.com/ChainSafe/ChainBridge/shared/ethereum"
"github.com/ChainSafe/log15"
eth "github.com/ethereum/go-ethereum"
Expand All @@ -41,17 +42,19 @@ type listener struct {
blockstore blockstore.Blockstorer
stop <-chan int
sysErr chan<- error // Reports fatal error to core
latestBlock metrics.LatestBlock
}

// NewListener creates and returns a listener
func NewListener(conn Connection, cfg *Config, log log15.Logger, bs blockstore.Blockstorer, stop <-chan int, sysErr chan<- error) *listener {
return &listener{
cfg: *cfg,
conn: conn,
log: log,
blockstore: bs,
stop: stop,
sysErr: sysErr,
cfg: *cfg,
conn: conn,
log: log,
blockstore: bs,
stop: stop,
sysErr: sysErr,
latestBlock: metrics.LatestBlock{LastUpdated: time.Now()},
}
}

Expand Down Expand Up @@ -132,6 +135,8 @@ func (l *listener) pollBlocks() error {

// Goto next block and reset retry counter
currentBlock.Add(currentBlock, big.NewInt(1))
l.latestBlock.Height = big.NewInt(0).Set(latestBlock)
l.latestBlock.LastUpdated = time.Now()
retry = BlockRetryLimit
}
}
Expand Down
5 changes: 5 additions & 0 deletions chains/substrate/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/ChainSafe/ChainBridge/crypto/sr25519"
"github.com/ChainSafe/ChainBridge/keystore"
msg "github.com/ChainSafe/ChainBridge/message"
metrics "github.com/ChainSafe/ChainBridge/metrics/types"
"github.com/ChainSafe/ChainBridge/router"
"github.com/ChainSafe/log15"
)
Expand Down Expand Up @@ -132,6 +133,10 @@ func (c *Chain) SetRouter(r *router.Router) {
c.listener.setRouter(r)
}

func (c *Chain) LatestBlock() metrics.LatestBlock {
return c.listener.latestBlock
Comment thread
ansermino marked this conversation as resolved.
}

func (c *Chain) Id() msg.ChainId {
return c.cfg.Id
}
Expand Down
5 changes: 5 additions & 0 deletions chains/substrate/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ChainSafe/ChainBridge/blockstore"
"github.com/ChainSafe/ChainBridge/chains"
msg "github.com/ChainSafe/ChainBridge/message"
metrics "github.com/ChainSafe/ChainBridge/metrics/types"
utils "github.com/ChainSafe/ChainBridge/shared/substrate"
"github.com/ChainSafe/log15"
"github.com/centrifuge/go-substrate-rpc-client/types"
Expand All @@ -28,6 +29,7 @@ type listener struct {
log log15.Logger
stop <-chan int
sysErr chan<- error
latestBlock metrics.LatestBlock
}

// Frequency of polling for a new block
Expand All @@ -45,6 +47,7 @@ func NewListener(conn *Connection, name string, id msg.ChainId, startBlock uint6
log: log,
stop: stop,
sysErr: sysErr,
latestBlock: metrics.LatestBlock{LastUpdated: time.Now()},
}
}

Expand Down Expand Up @@ -159,6 +162,8 @@ func (l *listener) pollBlocks() error {
}

currentBlock++
l.latestBlock.Height = big.NewInt(0).SetUint64(currentBlock)
l.latestBlock.LastUpdated = time.Now()
retry = BlockRetryLimit
}
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/chainbridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ChainSafe/ChainBridge/config"
"github.com/ChainSafe/ChainBridge/core"
msg "github.com/ChainSafe/ChainBridge/message"
"github.com/ChainSafe/ChainBridge/metrics/health"
log "github.com/ChainSafe/log15"
"github.com/urfave/cli/v2"
)
Expand All @@ -30,6 +31,8 @@ var cliFlags = []cli.Flag{
config.BlockstorePathFlag,
config.FreshStartFlag,
config.LatestBlockFlag,
config.MetricsFlag,
config.MetricsPort,
}

var generateFlags = []cli.Flag{
Expand Down Expand Up @@ -188,6 +191,12 @@ func run(ctx *cli.Context) error {
c.AddChain(newChain)
}

// Start metrics server
if ctx.Bool(config.MetricsFlag.Name) {
port := ctx.Int(config.MetricsPort.Name)
go health.Start(port, c.Registry)
}

c.Start()

return nil
Expand Down
14 changes: 14 additions & 0 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ var (
}
)

// Metrics flags
var (
MetricsFlag = &cli.BoolFlag{
Name: "metrics",
Usage: "Enables metric server",
}

MetricsPort = &cli.IntFlag{
Name: "metricsPort",
Usage: "Port to serve metrics on",
Value: 8001,
}
)

// Generate subcommand flags
var (
PasswordFlag = &cli.StringFlag{
Expand Down
2 changes: 2 additions & 0 deletions core/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package core

import (
msg "github.com/ChainSafe/ChainBridge/message"
metrics "github.com/ChainSafe/ChainBridge/metrics/types"
"github.com/ChainSafe/ChainBridge/router"
)

Expand All @@ -13,6 +14,7 @@ type Chain interface {
SetRouter(*router.Router)
Id() msg.ChainId
Name() string
LatestBlock() metrics.LatestBlock
Stop()
}

Expand Down
13 changes: 6 additions & 7 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,36 @@ import (
"os/signal"
"syscall"

msg "github.com/ChainSafe/ChainBridge/message"
"github.com/ChainSafe/ChainBridge/router"

"github.com/ChainSafe/log15"
)

type Core struct {
registry map[msg.ChainId]Chain
Registry []Chain
route *router.Router
log log15.Logger
sysErr <-chan error
}

func NewCore(sysErr <-chan error) *Core {
return &Core{
registry: make(map[msg.ChainId]Chain),
Registry: make([]Chain, 0),
route: router.NewRouter(log15.New("system", "router")),
log: log15.New("system", "core"),
sysErr: sysErr,
}
}

// AddChain registers the chain in the registry and calls Chain.SetRouter()
// AddChain registers the chain in the Registry and calls Chain.SetRouter()
func (c *Core) AddChain(chain Chain) {
c.registry[chain.Id()] = chain
c.Registry = append(c.Registry, chain)
chain.SetRouter(c.route)
}

// Start will call all registered chains' Start methods and block forever (or until signal is received)
func (c *Core) Start() {
for _, chain := range c.registry {
for _, chain := range c.Registry {
err := chain.Start()
if err != nil {
c.log.Error(
Expand All @@ -65,7 +64,7 @@ func (c *Core) Start() {
}

// Signal chains to shutdown
for _, chain := range c.registry {
for _, chain := range c.Registry {
chain.Stop()
}
}
Expand Down
Loading