Skip to content
This repository was archived by the owner on Jul 13, 2022. It is now read-only.

Commit 41b6945

Browse files
authored
Update utils and block timeout for health server (#548)
- Bump to chainbridge-utils v1.0.6 - Adds env var for the block timeout for the health server - Introduces a new page in the docs for CLI options
1 parent e8dc101 commit 41b6945

File tree

7 files changed

+71
-6
lines changed

7 files changed

+71
-6
lines changed

cmd/chainbridge/main.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ func run(ctx *cli.Context) error {
163163
c := core.NewCore(sysErr)
164164

165165
for _, chain := range cfg.Chains {
166-
chainId, err := strconv.Atoi(chain.Id)
167-
if err != nil {
168-
return err
166+
chainId, errr := strconv.Atoi(chain.Id)
167+
if errr != nil {
168+
return errr
169169
}
170170
chainConfig := &core.ChainConfig{
171171
Name: chain.Name,
@@ -206,7 +206,15 @@ func run(ctx *cli.Context) error {
206206
// Start prometheus and health server
207207
if ctx.Bool(config.MetricsFlag.Name) {
208208
port := ctx.Int(config.MetricsPort.Name)
209-
h := health.NewHealthServer(port, c.Registry)
209+
blockTimeoutStr := os.Getenv(config.HealthBlockTimeout)
210+
blockTimeout := config.DefaultBlockTimeout
211+
if blockTimeoutStr != "" {
212+
blockTimeout, err = strconv.ParseInt(blockTimeoutStr, 10, 0)
213+
if err != nil {
214+
return err
215+
}
216+
}
217+
h := health.NewHealthServer(port, c.Registry, int(blockTimeout))
210218

211219
go func() {
212220
http.Handle("/metrics", promhttp.Handler())

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
const DefaultConfigPath = "./config.json"
1717
const DefaultKeystorePath = "./keys"
18+
const DefaultBlockTimeout = int64(180) // 3 minutes
1819

1920
type Config struct {
2021
Chains []RawChainConfig `json:"chains"`

config/flags.go

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import (
88
"github.com/urfave/cli/v2"
99
)
1010

11+
// Env vars
12+
var (
13+
HealthBlockTimeout = "BLOCK_TIMEOUT"
14+
)
15+
1116
var (
1217
ConfigFileFlag = &cli.StringFlag{
1318
Name: "config",

docs/cli-options.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# CLI Options
2+
3+
## Flags
4+
5+
### Global
6+
7+
```
8+
--config value JSON configuration file
9+
--verbosity value Supports levels crit (silent) to trce (trace) (default: "info")
10+
--keystore value Path to keystore directory (default: "./keys")
11+
--blockstore value Specify path for blockstore
12+
--fresh Disables loading from blockstore at start. Opts will still be used if specified. (default: false)
13+
--latest Overrides blockstore and start block, starts from latest block (default: false)
14+
--metrics Enables metric server (default: false)
15+
--metricsPort value Port to serve metrics on (default: 8001)
16+
--testkey value Applies a predetermined test keystore to the chains.
17+
--help, -h show help (default: false)
18+
--version, -v print the version (default: false)
19+
```
20+
21+
### Account Management
22+
23+
The commands can be used to manage keys in the local keystore. You can view available keys with `chainbridge accounts list`.
24+
25+
#### `chainbridge accounts generate`
26+
```
27+
--password value Password used to encrypt the keystore. Used with --generate, --import, or --unlock
28+
--sr25519 Specify account/key type as sr25519. (default: false)
29+
--secp256k1 Specify account/key type as secp256k1. (default: false)
30+
--network value Specify the network to use for the address encoding (substrate/polkadot/centrifuge) (default: substrate)
31+
```
32+
33+
#### `chainbridge accounts import`
34+
```
35+
--ethereum Import an existing ethereum keystore, such as from geth. (default: false)
36+
--privateKey value Import a hex representation of a private key into a keystore.
37+
--sr25519 Specify account/key type as sr25519. (default: false)
38+
--secp256k1 Specify account/key type as secp256k1. (default: false)
39+
--password value Password used to encrypt the keystore. Used with --generate, --import, or --unlock
40+
--network value Specify the network to use for the address encoding (substrate/polkadot/centrifuge) (default: substrate)
41+
```
42+
43+
44+
## Environment Variables
45+
46+
- `KEYSTORE_PASSWORD`: The password to use when loading the keystore.
47+
- `BLOCK_TIMEOUT`: The duration (seconds) until a chain is considered "unhealthy"

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.13
44

55
require (
66
github.com/ChainSafe/chainbridge-substrate-events v0.0.0-20200715141113-87198532025e
7-
github.com/ChainSafe/chainbridge-utils v1.0.5
7+
github.com/ChainSafe/chainbridge-utils v1.0.6
88
github.com/ChainSafe/log15 v1.0.0
99
github.com/aristanetworks/goarista v0.0.0-20200609010056-95bcf8053598 // indirect
1010
github.com/centrifuge/go-substrate-rpc-client v2.0.0+incompatible

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/ChainSafe/chainbridge-substrate-events v0.0.0-20200715141113-87198532
1717
github.com/ChainSafe/chainbridge-substrate-events v0.0.0-20200715141113-87198532025e/go.mod h1:H5fNH57wn/j1oLifOnWEqYbfJZcOWzr7jZjKKrUckSQ=
1818
github.com/ChainSafe/chainbridge-utils v1.0.5 h1:PiJyz8+Ed6/Jlq1nsQ1shY5btT1ERdaiPU8+Fg+BvZE=
1919
github.com/ChainSafe/chainbridge-utils v1.0.5/go.mod h1:T5cOZhxdY4x0DrE0EqOnMwAPE8d4bNGqiPfN16o1rzc=
20+
github.com/ChainSafe/chainbridge-utils v1.0.6 h1:DV9dNnrsU7fRG49biyRlHsPLd9Augv9lepxnP581ixM=
21+
github.com/ChainSafe/chainbridge-utils v1.0.6/go.mod h1:T5cOZhxdY4x0DrE0EqOnMwAPE8d4bNGqiPfN16o1rzc=
2022
github.com/ChainSafe/log15 v1.0.0 h1:vRDVtWtVwIH5uSCBvgTTZh6FA58UBJ6+QiiypaZfBf8=
2123
github.com/ChainSafe/log15 v1.0.0/go.mod h1:5v1+ALHtdW0NfAeeoYyKmzCAMcAeqkdhIg4uxXWIgOg=
2224
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=

mkdocs.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ theme:
2323
nav:
2424
- Overview: index.md
2525
- Installation: installation.md
26-
- Configuration: configuration.md
26+
- Configuration:
27+
- Overview: configuration.md
28+
- CLI Options: cli-options.md
2729
- Specification:
2830
- ChainBridge: spec.md
2931
- Ethereum: chains/ethereum.md

0 commit comments

Comments
 (0)