Skip to content

Commit cb67dad

Browse files
author
Roman Shtylman
committed
make it so
0 parents  commit cb67dad

File tree

12 files changed

+684
-0
lines changed

12 files changed

+684
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode
2+
build

.gitlab-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
image: golang:1.13
2+
3+
unit_test:
4+
stage: test
5+
script:
6+
- make test

LICENSE.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Blue Oak Model License
2+
3+
Version 1.0.0
4+
5+
## Purpose
6+
7+
This license gives everyone as much permission to work with
8+
this software as possible, while protecting contributors
9+
from liability.
10+
11+
## Acceptance
12+
13+
In order to receive this license, you must agree to its
14+
rules. The rules of this license are both obligations
15+
under that agreement and conditions to your license.
16+
You must not do anything with this software that triggers
17+
a rule that you cannot or will not follow.
18+
19+
## Copyright
20+
21+
Each contributor licenses you to do everything with this
22+
software that would otherwise infringe that contributor's
23+
copyright in it.
24+
25+
## Notices
26+
27+
You must ensure that everyone who gets a copy of
28+
any part of this software from you, with or without
29+
changes, also gets the text of this license or a link to
30+
<https://blueoakcouncil.org/license/1.0.0>.
31+
32+
## Excuse
33+
34+
If anyone notifies you in writing that you have not
35+
complied with [Notices](#notices), you can keep your
36+
license by taking all practical steps to comply within 30
37+
days after the notice. If you do not do so, your license
38+
ends immediately.
39+
40+
## Patent
41+
42+
Each contributor licenses you to do everything with this
43+
software that would otherwise infringe any patent claims
44+
they can license or become able to license.
45+
46+
## Reliability
47+
48+
No contributor can revoke this license.
49+
50+
## No Liability
51+
52+
***As far as the law allows, this software comes as is,
53+
without any warranty or condition, and no contributor
54+
will be liable to anyone for any damages related to this
55+
software or this license, under any kind of legal claim.***

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
GOLINT:=$(shell go list -f {{.Target}} golang.org/x/lint/golint)
2+
3+
all: build
4+
5+
build: build/signer
6+
7+
build/signer: cmd/signer/main.go $(wildcard internal/**/*.go)
8+
CGO_ENABLED=0 go build -o ./build/signer ${gobuild_flags} ./cmd/signer
9+
10+
lint: tools
11+
@$(GOLINT) -set_exit_status ./...
12+
13+
test:
14+
@go test -short ./...
15+
16+
race:
17+
@go test -race -short ./...
18+
19+
msan:
20+
@go test -msan -short ./...
21+
22+
tools:
23+
@go install golang.org/x/lint/golint
24+
25+
clean:
26+
rm -rf build
27+
28+
.PHONY: all lint test race msan tools clean build

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Tendermint Validator
2+
3+
A lightweight single key tendermint validator for sentry nodes.
4+
5+
## Design
6+
7+
A lightweight alternative to using a full node instance for validating blocks. The validator is able to connect to any number of sentry nodes and will sign blocks provided by the nodes. The validator maintains a watermark file to protect against double signing.
8+
9+
## Pre-requisites
10+
11+
Before starting, please make sure to fully understand node and validator requirements and operation for your particular network and chain.
12+
13+
## Setup
14+
15+
_The security of any key material is outside the scope of this guide. At a minimum we recommend performing key material steps on airgapped computers and using your audited security procedures._
16+
17+
### Setup Validator Instance
18+
19+
Configure the instance with a [toml](https://github.com/toml-lang/toml) file. Below is a sample configuration.
20+
21+
```toml
22+
# Path to priv validator key json file
23+
key_file = "/path/to/priv_validator_key.json"
24+
25+
# The state directory stores watermarks for double signing protection.
26+
# Each validator instance maintains a watermark.
27+
state_dir = "/path/to/state/dir"
28+
29+
# The network chain id for your p2p nodes
30+
chain_id = "chain-id-here"
31+
32+
# Configure any number of p2p network nodes.
33+
# We recommend at least 2 nodes for redundancy.
34+
[[node]]
35+
address = "tcp://<node-a ip>:1234"
36+
37+
[[node]]
38+
address = "tcp://<node-b ip>:1234"
39+
```
40+
41+
## Configure p2p network nodes
42+
43+
Validators are not directly connected to the p2p network nor do they store chain and application state. They rely on nodes to receive blocks from the p2p network, make signing requests, and relay the signed blocks back to the p2p network.
44+
45+
To make a node available as a relay for a validator, find the `priv_validator_laddr` (or equivalent) configuration item in your node's configuration file. Change this value, to accept connections on an IP address and port of your choosing.
46+
47+
```diff
48+
# TCP or UNIX socket address for Tendermint to listen on for
49+
# connections from an external PrivValidator process
50+
-priv_validator_laddr = ""
51+
+priv_validator_laddr = "tcp://0.0.0.0:1234"
52+
```
53+
54+
_Full configuration and operation of your tendermint node is outside the scope of this guide. You should consult your network's documentation for node configuration._
55+
56+
_We recommend hosting nodes on separate and isolated infrastructure from your validator instances._
57+
58+
## Launch validator
59+
60+
Once your validator instance and node is configured, you can launch the signer.
61+
62+
```bash
63+
signer --config /path/to/config.toml
64+
```
65+
66+
_We recommend using systemd or similar service management program as appropriate for your runtime platform._
67+
68+
## Security
69+
70+
Security and management of any key material is outside the scope of this service. Always consider your own security and risk profile when dealing with sensitive keys, services, or infrastructure.
71+
72+
## No Liability
73+
74+
As far as the law allows, this software comes as is,
75+
without any warranty or condition, and no contributor
76+
will be liable to anyone for any damages related to this
77+
software or this license, under any kind of legal claim.
78+
79+
## References
80+
81+
- https://docs.tendermint.com/master/tendermint-core/validators.html
82+
- https://hub.cosmos.network/master/validators/overview.html

cmd/signer/main.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"net"
8+
"os"
9+
"path"
10+
"sync"
11+
"time"
12+
13+
"tendermint-signer/internal/signer"
14+
15+
cmn "github.com/tendermint/tendermint/libs/common"
16+
tmlog "github.com/tendermint/tendermint/libs/log"
17+
"github.com/tendermint/tendermint/privval"
18+
)
19+
20+
func fileExists(filename string) bool {
21+
info, err := os.Stat(filename)
22+
if os.IsNotExist(err) {
23+
return false
24+
}
25+
return !info.IsDir()
26+
}
27+
28+
func main() {
29+
logger := tmlog.NewTMLogger(
30+
tmlog.NewSyncWriter(os.Stdout),
31+
).With("module", "validator")
32+
33+
var configFile = flag.String("config", "", "path to configuration file")
34+
flag.Parse()
35+
36+
if *configFile == "" {
37+
panic("--config flag is required")
38+
}
39+
40+
config, err := signer.LoadConfigFromFile(*configFile)
41+
if err != nil {
42+
log.Fatal(err)
43+
}
44+
45+
logger.Info(
46+
"Tendermint Validator",
47+
"priv-key", config.PrivValKeyFile,
48+
"priv-state-dir", config.PrivValStateDir,
49+
)
50+
51+
signer.InitSerialization()
52+
53+
// services to stop on shutdown
54+
var services []cmn.Service
55+
56+
chainID := config.ChainID
57+
if chainID == "" {
58+
log.Fatal("chain_id option is required")
59+
}
60+
61+
stateFile := path.Join(config.PrivValStateDir, fmt.Sprintf("%s_priv_validator_state.json", chainID))
62+
63+
if !fileExists(stateFile) {
64+
log.Fatalf("State file missing: %s\n", stateFile)
65+
}
66+
67+
val := privval.LoadFilePV(config.PrivValKeyFile, stateFile)
68+
pv := &signer.PvGuard{PrivValidator: val}
69+
70+
for _, node := range config.Nodes {
71+
dialer := net.Dialer{Timeout: 30 * time.Second}
72+
signer := signer.NewNodeClient(node.Address, logger, config.ChainID, pv, dialer)
73+
74+
err := signer.Start()
75+
if err != nil {
76+
panic(err)
77+
}
78+
79+
services = append(services, signer)
80+
}
81+
82+
wg := sync.WaitGroup{}
83+
wg.Add(1)
84+
cmn.TrapSignal(logger, func() {
85+
for _, service := range services {
86+
err := service.Stop()
87+
if err != nil {
88+
panic(err)
89+
}
90+
}
91+
wg.Done()
92+
})
93+
wg.Wait()
94+
}

go.mod

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module tendermint-signer
2+
3+
require (
4+
github.com/BurntSushi/toml v0.3.1
5+
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 // indirect
6+
github.com/davecgh/go-spew v1.1.1 // indirect
7+
github.com/fortytw2/leaktest v1.3.0 // indirect
8+
github.com/go-kit/kit v0.9.0 // indirect
9+
github.com/go-logfmt/logfmt v0.4.0 // indirect
10+
github.com/go-stack/stack v1.8.0 // indirect
11+
github.com/gogo/protobuf v1.2.1 // indirect
12+
github.com/golang/protobuf v1.3.2 // indirect
13+
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
14+
github.com/magiconair/properties v1.8.0 // indirect
15+
github.com/pkg/errors v0.8.1 // indirect
16+
github.com/stretchr/testify v1.3.0 // indirect
17+
github.com/tendermint/go-amino v0.14.1
18+
github.com/tendermint/tendermint v0.31.5
19+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
20+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
21+
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 // indirect
22+
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 // indirect
23+
google.golang.org/genproto v0.0.0-20190219182410-082222b4a5c5 // indirect
24+
google.golang.org/grpc v1.19.0 // indirect
25+
)
26+
27+
go 1.13

0 commit comments

Comments
 (0)