Skip to content

Commit

Permalink
feat(devnet): Local Gossamer Devnet (ChainSafe#2008)
Browse files Browse the repository at this point in the history
* wip

* revise function, add test

* cleanup

* more wip

* add pubip flag to cli

* go mod tidy after upgrading to 1.17

* add config tests

* devnet cmd test

* fix bob

* fix confd command

* update dockerfiles

* use dev go.mod and go.sum

* fix logs

* update lint settings

* fix linting

* add readme

* update README

* remove symlinking step

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/alice.Dockerfile

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/alice.Dockerfile

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/alice.Dockerfile

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/alice.Dockerfile

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/alice.Dockerfile

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* cr feedback, fix metrics on bob

* fix go.mod

* go mod tidy

* Update devnet/cmd/update-dd-agent-confd/main.go

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/cmd/update-dd-agent-confd/main.go

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* cr feedback

* update readme

* Update devnet/README.md

Co-authored-by: noot <36753753+noot@users.noreply.github.com>

* cr feedback

* more cr feedback

* use embed

* add license

* trimpath

* Update devnet/bob.Dockerfile

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
Co-authored-by: noot <36753753+noot@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 6, 2021
1 parent af7725f commit 23ce39f
Show file tree
Hide file tree
Showing 22 changed files with 1,245 additions and 15 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ linters-settings:
locale: UK
ignore-words:
- gossamer
- flavor
gocritic:
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
disabled-checks:
Expand Down
5 changes: 5 additions & 0 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,11 @@ func setDotNetworkConfig(ctx *cli.Context, tomlCfg ctoml.NetworkConfig, cfg *dot
cfg.NoMDNS = true
}

// check --pubip flag and update node configuration
if pubip := ctx.GlobalString(PublicIPFlag.Name); pubip != "" {
cfg.PublicIP = pubip
}

if len(cfg.PersistentPeers) == 0 {
cfg.PersistentPeers = []string(nil)
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/gossamer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,21 @@ func TestNetworkConfigFromFlags(t *testing.T) {
MinPeers: testCfg.Network.MinPeers,
},
},
{
"Test gossamer --pubip",
[]string{"config", "pubip"},
[]interface{}{testCfgFile.Name(), "10.0.5.2"},
dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: false,
DiscoveryInterval: time.Second * 10,
MinPeers: testCfg.Network.MinPeers,
PublicIP: "10.0.5.2",
},
},
}

for _, c := range testcases {
Expand Down
6 changes: 6 additions & 0 deletions cmd/gossamer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ var (
Name: "nomdns",
Usage: "Disables network mDNS discovery",
}
// PublicIPFlag uses the supplied IP for broadcasting
PublicIPFlag = cli.StringFlag{
Name: "pubip",
Usage: "Overrides public IP address used for peer to peer networking",
}
)

// RPC service configuration flags
Expand Down Expand Up @@ -404,6 +409,7 @@ var (
RolesFlag,
NoBootstrapFlag,
NoMDNSFlag,
PublicIPFlag,

// rpc flags
RPCEnabledFlag,
Expand Down
54 changes: 54 additions & 0 deletions devnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Gossamer Devnet

Docker container and Docker Compose for a Gossamer Devnet currently with three authority nodes running the `gssmr` chain with keys `alice`, `bob` and `charlie`.

## Requirements

- [Docker Compose](https://docs.docker.com/compose/install/)

## Running the Devnet

From the Gossamer root run the following commands to run the devnet

```sh
# will rebuild the containers based on the current code
docker-compose up --abort-on-container-exit --build

# will run the devnet without rebuilding
docker-compose up --abort-on-container-exit

# destroys the devnet
docker-compose down
```

> **_NOTE:_** The devnet is not stateful, so subsequent runs will start from the genesis block.
## Prometheus Datadog Integration

All Prometheus metrics from the nodes are piped to Datadog. You can setup your own dashboard and add additional tags by modifying the Dockerfiles. Currently the metrics are prefixed with `gossamer.local.devnet` and are tagged (Prometheus label) with a `key` tag for `alice`, `bob`, and `charlie`.

For metrics to be piped to Datadog, you will require a Datadog API key. Please contact Elizabeth or myself (Tim) for access to datadog if you don't already have it.

The Datadog API key must be an environment variable on your own machine, which Docker Compose will pick up and inject when building the node images.

```
export $DD_API_KEY=YourKey
```

## Files

### Dockerfiles

There are two Docker files used in the devnet. `alice.Dockerfile` is the lead node and is intiated with the `babe-lead` flag to build the first block. `bob.Dockerfile` is used for both `bob` and `charlie`.

### cmd/update-dd-agent-confd

A command line app to create a `confd.yml` file used by the Datadog agent when piping metrics to Datadog. It's used in the both `alice.Dockerfile` and `bob.Dockerfile` to create specific `confd.yml` files.

### alice.node.key

This key is injected in `alice.Dockerfile` so it uses the same public key for the `bootnodes` param in `bob.Dockerfile`.

### docker-compose.yml

The Docker Compose file. Specifies the IP addresses of all the nodes.
29 changes: 29 additions & 0 deletions devnet/alice.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2021 ChainSafe Systems (ON)
# SPDX-License-Identifier: LGPL-3.0-only

FROM golang:1.17

ARG DD_API_KEY=somekey
RUN DD_API_KEY=${DD_API_KEY} DD_AGENT_MAJOR_VERSION=7 DD_INSTALL_ONLY=true DD_SITE="datadoghq.com" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)"

WORKDIR /gossamer

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN go install -trimpath github.com/ChainSafe/gossamer/cmd/gossamer

# use modified genesis-spec.json with only 3 authority nodes
RUN cp -f devnet/chain/gssmr/genesis-spec.json chain/gssmr/genesis-spec.json

RUN gossamer --key=alice init

# use a hardcoded key for alice, so we can determine what the peerID is for subsequent nodes
RUN cp devnet/alice.node.key ~/.gossamer/gssmr/node.key

RUN go run devnet/cmd/update-dd-agent-confd/main.go -n=gossamer.local.devnet -t=key:alice > /etc/datadog-agent/conf.d/openmetrics.d/conf.yaml

ENTRYPOINT service datadog-agent start && gossamer --key=alice --babe-lead --publish-metrics --rpc --rpc-external=true --pubip=10.5.0.2
EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp
35 changes: 35 additions & 0 deletions devnet/bob.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2021 ChainSafe Systems (ON)
# SPDX-License-Identifier: LGPL-3.0-only

FROM golang:1.17

ARG DD_API_KEY=somekey
RUN DD_API_KEY=${DD_API_KEY} DD_AGENT_MAJOR_VERSION=7 DD_INSTALL_ONLY=true DD_SITE="datadoghq.com" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)"

WORKDIR /gossamer

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN go install -trimpath github.com/ChainSafe/gossamer/cmd/gossamer

# use modified genesis-spec.json with only 3 authority nodes
RUN cp -f devnet/chain/gssmr/genesis-spec.json chain/gssmr/genesis-spec.json

ARG key
RUN test -n "$key"
ARG pubip
RUN test -n "$pubip"

ENV key=${key}
ENV pubip=${pubip}

RUN gossamer --key=${key} init

RUN go run devnet/cmd/update-dd-agent-confd/main.go -n=gossamer.local.devnet -t=key:${key} > /etc/datadog-agent/conf.d/openmetrics.d/conf.yaml

ENTRYPOINT service datadog-agent start && gossamer --key=${key} --bootnodes=/ip4/10.5.0.2/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU --publish-metrics --rpc --pubip=${pubip}

EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp
Loading

0 comments on commit 23ce39f

Please sign in to comment.