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

Commit 01edf63

Browse files
author
Gregory Hill
committed
separate host/port, silent restore fail option, fix state restore message
Signed-off-by: Gregory Hill <[email protected]>
1 parent 7c49ae9 commit 01edf63

File tree

18 files changed

+136
-76
lines changed

18 files changed

+136
-76
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ NOTES.md: project/history.go project/cmd/notes/main.go
237237
docs: CHANGELOG.md NOTES.md
238238

239239
# Tag the current HEAD commit with the current release defined in
240-
# ./release/release.go
240+
# ./project/history.go
241241
.PHONY: tag_release
242242
tag_release: test check CHANGELOG.md NOTES.md build
243243
@scripts/tag_release.sh

bcm/blockchain.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type PersistedState struct {
6969
GenesisDoc genesis.GenesisDoc
7070
}
7171

72+
// LoadOrNewBlockchain returns true if state already exists
7273
func LoadOrNewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc, logger *logging.Logger) (bool, *Blockchain, error) {
7374
logger = logger.WithScope("LoadOrNewBlockchain")
7475
logger.InfoMsg("Trying to load blockchain state from database",
@@ -92,7 +93,7 @@ func LoadOrNewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc, logger *logg
9293
return false, NewBlockchain(db, genesisDoc), nil
9394
}
9495

95-
// Pointer to blockchain state initialised from genesis
96+
// NewBlockchain returns a pointer to blockchain state initialised from genesis
9697
func NewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc) *Blockchain {
9798
bc := &Blockchain{
9899
db: db,

cmd/burrow/commands/configure.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/hyperledger/burrow/logging"
1919
"github.com/hyperledger/burrow/logging/logconfig"
2020
"github.com/hyperledger/burrow/logging/logconfig/presets"
21+
"github.com/hyperledger/burrow/rpc"
2122
cli "github.com/jawher/mow.cli"
2223
amino "github.com/tendermint/go-amino"
2324
tmEd25519 "github.com/tendermint/tendermint/crypto/ed25519"
@@ -331,10 +332,19 @@ func Configure(output Output) func(cmd *cli.Cmd) {
331332
conf.ValidatorAddress = &v.Address
332333
conf.BurrowDir = fmt.Sprintf("burrow%03d", i)
333334
conf.Tendermint.PersistentPeers = seeds
334-
conf.Tendermint.ListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", 26656+i)
335-
conf.RPC.Info.ListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", 26758+i)
336-
conf.RPC.GRPC.ListenAddress = fmt.Sprintf("127.0.0.1:%d", 10997+i)
337-
conf.RPC.Metrics.ListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", 9102+i)
335+
336+
conf.Tendermint.ListenHost = rpc.LocalHost
337+
conf.Tendermint.ListenPort = string(26656 + i)
338+
339+
conf.RPC.Info.ListenHost = rpc.LocalHost
340+
conf.RPC.Info.ListenPort = string(26758 + i)
341+
342+
conf.RPC.GRPC.ListenHost = rpc.LocalHost
343+
conf.RPC.GRPC.ListenPort = string(10997 + i)
344+
345+
conf.RPC.Metrics.ListenHost = rpc.LocalHost
346+
conf.RPC.Metrics.ListenPort = string(9102 + i)
347+
338348
conf.Logging.RootSink.Output.OutputType = "file"
339349
conf.Logging.RootSink.Output.FileConfig = &logconfig.FileConfig{Path: fmt.Sprintf("burrow%03d.log", i)}
340350

cmd/burrow/commands/deploy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const defaultChainTimeout = 15 * time.Second
1919

2020
func Deploy(output Output) func(cmd *cli.Cmd) {
2121
return func(cmd *cli.Cmd) {
22-
chainOpt := cmd.StringOpt("u chain", "127.0.0.1:10997", "chain to be used in IP:PORT format")
22+
chainOpt := cmd.StringOpt("c chain", "127.0.0.1:10997", "chain to be used in IP:PORT format")
2323

2424
signerOpt := cmd.StringOpt("s keys", "",
2525
"IP:PORT of Burrow GRPC service which jobs should or otherwise transaction submitted unsigned for mempool signing in Burrow")
@@ -49,7 +49,7 @@ func Deploy(output Output) func(cmd *cli.Cmd) {
4949
"default number of concurrent playbooks to run if multiple are specified")
5050

5151
addressOpt := cmd.StringOpt("a address", "",
52-
"default address to use; operates the same way as the [account] job, only before the deploy file is ran")
52+
"default address (or account name) to use; operates the same way as the [account] job, only before the deploy file is ran")
5353

5454
defaultFeeOpt := cmd.StringOpt("n fee", "9999", "default fee to use")
5555

cmd/burrow/commands/dump.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var cdc = amino.NewCodec()
2121

2222
func Dump(output Output) func(cmd *cli.Cmd) {
2323
return func(cmd *cli.Cmd) {
24-
chainURLOpt := cmd.StringOpt("u chain-url", "127.0.0.1:10997", "chain-url to be used in IP:PORT format")
24+
chainURLOpt := cmd.StringOpt("c chain", "127.0.0.1:10997", "chain to be used in IP:PORT format")
2525
heightOpt := cmd.IntOpt("h height", 0, "Block height to dump to, defaults to latest block height")
2626
filename := cmd.StringArg("FILE", "", "Save dump here")
2727
useJSON := cmd.BoolOpt("j json", false, "Output in json")

cmd/burrow/commands/restore.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ func Restore(output Output) func(cmd *cli.Cmd) {
1212

1313
configOpt := cmd.StringOpt("c config", "", "Use the specified burrow config file")
1414

15+
silentOpt := cmd.BoolOpt("s silent", false, "If state already exists don't throw error")
16+
1517
filename := cmd.StringArg("FILE", "", "Restore from this dump")
1618

1719
cmd.Spec = "[--config=<config file>] [--genesis=<genesis json file>] [FILE]"
@@ -44,7 +46,7 @@ func Restore(output Output) func(cmd *cli.Cmd) {
4446
output.Fatalf("could not create Burrow kernel: %v", err)
4547
}
4648

47-
if err = kern.LoadDump(conf.GenesisDoc, *filename); err != nil {
49+
if err = kern.LoadDump(conf.GenesisDoc, *filename, *silentOpt); err != nil {
4850
output.Fatalf("could not create Burrow kernel: %v", err)
4951
}
5052

consensus/tendermint/config.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tendermint
22

33
import (
4+
"fmt"
45
"math"
56
"net/url"
67
"strings"
@@ -21,7 +22,8 @@ type BurrowTendermintConfig struct {
2122
SeedMode bool
2223
// Peers to which we automatically connect
2324
PersistentPeers string
24-
ListenAddress string
25+
ListenHost string
26+
ListenPort string
2527
// Optional external that nodes may provide with their NodeInfo
2628
ExternalAddress string
2729
// Set true for strict address routability rules
@@ -37,9 +39,14 @@ type BurrowTendermintConfig struct {
3739

3840
func DefaultBurrowTendermintConfig() *BurrowTendermintConfig {
3941
tmDefaultConfig := tmConfig.DefaultConfig()
42+
url, err := url.ParseRequestURI(tmDefaultConfig.P2P.ListenAddress)
43+
if err != nil {
44+
return nil
45+
}
4046
return &BurrowTendermintConfig{
4147
Enabled: true,
42-
ListenAddress: tmDefaultConfig.P2P.ListenAddress,
48+
ListenHost: url.Hostname(),
49+
ListenPort: url.Port(),
4350
ExternalAddress: tmDefaultConfig.P2P.ExternalAddress,
4451
CreateEmptyBlocks: tmDefaultConfig.Consensus.CreateEmptyBlocks,
4552
CreateEmptyBlocksInterval: tmDefaultConfig.Consensus.CreateEmptyBlocksInterval,
@@ -72,7 +79,7 @@ func (btc *BurrowTendermintConfig) Config(rootDir string, timeoutFactor float64)
7279
conf.P2P.Seeds = btc.Seeds
7380
conf.P2P.SeedMode = btc.SeedMode
7481
conf.P2P.PersistentPeers = btc.PersistentPeers
75-
conf.P2P.ListenAddress = btc.ListenAddress
82+
conf.P2P.ListenAddress = fmt.Sprintf("%s:%s", btc.ListenHost, btc.ListenPort)
7683
conf.P2P.ExternalAddress = btc.ExternalAddress
7784
conf.P2P.AddrBookStrict = btc.AddrBookStrict
7885
// We use this in tests and I am not aware of a strong reason to reject nodes on the same IP with different ports

core/kernel.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,20 @@ func (kern *Kernel) LoadState(genesisDoc *genesis.GenesisDoc) (err error) {
151151
}
152152

153153
// LoadDump restores chain state from the given dump file
154-
func (kern *Kernel) LoadDump(genesisDoc *genesis.GenesisDoc, restoreFile string) (err error) {
155-
if _, kern.Blockchain, err = bcm.LoadOrNewBlockchain(kern.database, genesisDoc, kern.Logger); err != nil {
154+
func (kern *Kernel) LoadDump(genesisDoc *genesis.GenesisDoc, restoreFile string, silent bool) (err error) {
155+
var exists bool
156+
if exists, kern.Blockchain, err = bcm.LoadOrNewBlockchain(kern.database, genesisDoc, kern.Logger); err != nil {
156157
return fmt.Errorf("error creating or loading blockchain state: %v", err)
157158
}
159+
160+
if exists {
161+
if silent {
162+
kern.Logger.InfoMsg("State already exists, skipping...")
163+
return nil
164+
}
165+
return fmt.Errorf("existing state found, please remove before restoring")
166+
}
167+
158168
kern.Blockchain.SetBlockStore(bcm.NewBlockStore(blockchain.NewBlockStore(kern.database)))
159169

160170
if kern.State, err = state.MakeGenesisState(kern.database, genesisDoc); err != nil {
@@ -187,7 +197,8 @@ func (kern *Kernel) LoadDump(genesisDoc *genesis.GenesisDoc, restoreFile string)
187197
return fmt.Errorf("Unable to commit %v", err)
188198
}
189199

190-
kern.Logger.InfoMsg("State restore successful: %d", kern.Blockchain.LastBlockHeight())
200+
kern.Logger.InfoMsg("State restore successful -> height 0",
201+
"state_hash", kern.State.Hash())
191202
return nil
192203
}
193204

core/processes.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func ProfileLauncher(kern *Kernel, conf *rpc.ServerConfig) process.Launcher {
5959
Enabled: conf.Enabled,
6060
Launch: func() (process.Process, error) {
6161
debugServer := &http.Server{
62-
Addr: conf.ListenAddress,
62+
Addr: fmt.Sprintf("%s:%s", conf.ListenHost, conf.ListenPort),
6363
}
6464
go func() {
6565
err := debugServer.ListenAndServe()
@@ -202,7 +202,7 @@ func InfoLauncher(kern *Kernel, conf *rpc.ServerConfig) process.Launcher {
202202
Name: InfoProcessName,
203203
Enabled: conf.Enabled,
204204
Launch: func() (process.Process, error) {
205-
listener, err := process.ListenerFromAddress(conf.ListenAddress)
205+
listener, err := process.ListenerFromAddress(fmt.Sprintf("%s:%s", conf.ListenHost, conf.ListenPort))
206206
if err != nil {
207207
return nil, err
208208
}
@@ -224,7 +224,7 @@ func MetricsLauncher(kern *Kernel, conf *rpc.MetricsConfig) process.Launcher {
224224
Name: MetricsProcessName,
225225
Enabled: conf.Enabled,
226226
Launch: func() (process.Process, error) {
227-
listener, err := process.ListenerFromAddress(conf.ListenAddress)
227+
listener, err := process.ListenerFromAddress(fmt.Sprintf("%s:%s", conf.ListenHost, conf.ListenPort))
228228
if err != nil {
229229
return nil, err
230230
}
@@ -252,7 +252,7 @@ func GRPCLauncher(kern *Kernel, conf *rpc.ServerConfig, keyConfig *keys.KeysConf
252252
return nil, err
253253
}
254254

255-
listener, err := process.ListenerFromAddress(conf.ListenAddress)
255+
listener, err := process.ListenerFromAddress(fmt.Sprintf("%s:%s", conf.ListenHost, conf.ListenPort))
256256
if err != nil {
257257
return nil, err
258258
}

deploy/keys/keys.go

-7
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,8 @@ type LocalKeyClient struct {
1313
keys.KeyClient
1414
}
1515

16-
const DefaultKeysHost = "localhost"
17-
const DefaultKeysPort = "10997"
18-
1916
var keysTimeout = 5 * time.Second
2017

21-
func DefaultKeysURL() string {
22-
return fmt.Sprintf("%s:%s", DefaultKeysHost, DefaultKeysPort)
23-
}
24-
2518
// Returns an initialized key client to a docker container
2619
// running the keys server
2720
// Adding the Ip address is optional and should only be used

docs/quickstart/add-validators.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Let's generate the config and keys for a new validator account. As this node wil
2222
```bash
2323
burrow spec -v1 | burrow configure -s- --json > burrow-new.json
2424
NEW_VALIDATOR=$(jq -r '.GenesisDoc.Accounts[0].PublicKey.PublicKey' burrow-new.json)
25-
jq 'del(.GenesisDoc)' burrow-new.json | jq ".Tendermint.PersistentPeers=\"$PERSISTENT_PEER\"" | jq '.RPC.Info.Enabled=false' | jq '.RPC.GRPC.Enabled=false' | jq '.Tendermint.ListenAddress="tcp://0.0.0.0:25565"' > burrow003.json
25+
jq 'del(.GenesisDoc)' burrow-new.json | jq ".Tendermint.PersistentPeers=\"$PERSISTENT_PEER\"" | jq '.RPC.Info.Enabled=false' | jq '.RPC.GRPC.Enabled=false' | jq '.Tendermint.ListenPort="25565"' > burrow003.json
2626
```
2727

2828
Copy the following script into `deploy.yaml`:

docs/quickstart/seed-nodes.md

+30-15
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
4949

5050
#### Seed node `.burrow_seed.toml` modified line from `.burrow_init.toml`
5151
```toml
52+
BurrowDir = ".burrow_seed_0"
53+
5254
[Tendermint]
5355
SeedMode = true
54-
ListenAddress = "tcp://0.0.0.0:10000"
56+
ListenHost = "0.0.0.0"
57+
ListenPort = "10000"
5558
Moniker = "seed_node_0"
56-
TendermintRoot = ".burrow_seed_0"
5759

5860
[Execution]
5961

@@ -66,7 +68,8 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
6668
[RPC]
6769
[RPC.Info]
6870
Enabled = true
69-
ListenAddress = "tcp://127.0.0.1:10001"
71+
ListenHost = "127.0.0.1"
72+
ListenPort = "10001"
7073
[RPC.Profiler]
7174
Enabled = false
7275
[RPC.GRPC]
@@ -78,13 +81,15 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
7881
#### Validator 1 node `.burrow_val0.toml` modified line from `.burrow_init.toml`
7982

8083
```toml
84+
BurrowDir = ".burrow_node0"
85+
8186
[Tendermint]
8287
Seeds = "PUT_HERE_SEED_NODE_ID@LISTEN_EXTERNAL_ADDRESS"
8388
SeedMode = false
8489
PersistentPeers = ""
85-
ListenAddress = "tcp://0.0.0.0:20000"
90+
ListenHost = "0.0.0.0"
91+
ListenPort = "20000"
8692
Moniker = "val_node_0"
87-
TendermintRoot = ".burrow_node0"
8893

8994
[Execution]
9095

@@ -97,26 +102,30 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
97102
[RPC]
98103
[RPC.Info]
99104
Enabled = true
100-
ListenAddress = "tcp://127.0.0.1:20001"
105+
ListenHost = "127.0.0.1"
106+
ListenPort = "20001"
101107
[RPC.Profiler]
102108
Enabled = false
103109
[RPC.GRPC]
104110
Enabled = true
105-
ListenAddress = "127.0.0.1:20002"
111+
ListenHost = "127.0.0.1"
112+
ListenPort = "20002"
106113
[RPC.Metrics]
107114
Enabled = false
108115
```
109116

110117
#### Validator 2 node `.burrow_val1.toml` modified line from `.burrow_init.toml`
111118

112119
```toml
120+
BurrowDir = ".burrow_node1"
121+
113122
[Tendermint]
114123
Seeds = "PUT_HERE_SEED_NODE_ID@LISTEN_EXTERNAL_ADDRESS"
115124
SeedMode = false
116125
PersistentPeers = ""
117-
ListenAddress = "tcp://0.0.0.0:30000"
126+
ListenHost = "0.0.0.0"
127+
ListenPort = "30000"
118128
Moniker = "val_node_1"
119-
TendermintRoot = ".burrow_node1"
120129

121130
[Execution]
122131

@@ -129,12 +138,14 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
129138
[RPC]
130139
[RPC.Info]
131140
Enabled = true
132-
ListenAddress = "tcp://127.0.0.1:30001"
141+
ListenHost = "127.0.0.1"
142+
ListenPort = "30001"
133143
[RPC.Profiler]
134144
Enabled = false
135145
[RPC.GRPC]
136146
Enabled = true
137-
ListenAddress = "127.0.0.1:30002"
147+
ListenHost = "127.0.0.1"
148+
ListenPort = "30002"
138149
[RPC.Metrics]
139150
Enabled = false
140151
```
@@ -143,13 +154,15 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
143154
#### Validator 3 node `.burrow_val2.toml` modified line from `.burrow_init.toml`
144155

145156
```toml
157+
BurrowDir = ".burrow_node2"
158+
146159
[Tendermint]
147160
Seeds = "PUT_HERE_SEED_NODE_ID@LISTEN_EXTERNAL_ADDRESS"
148161
SeedMode = false
149162
PersistentPeers = ""
150-
ListenAddress = "tcp://0.0.0.0:40000"
163+
ListenHost = "0.0.0.0"
164+
ListenPort = "40000"
151165
Moniker = "val_node_2"
152-
TendermintRoot = ".burrow_node2"
153166

154167
[Execution]
155168

@@ -162,12 +175,14 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
162175
[RPC]
163176
[RPC.Info]
164177
Enabled = true
165-
ListenAddress = "tcp://127.0.0.1:40001"
178+
ListenHost = "127.0.0.1"
179+
ListenPort = "40001"
166180
[RPC.Profiler]
167181
Enabled = false
168182
[RPC.GRPC]
169183
Enabled = true
170-
ListenAddress = "127.0.0.1:40002"
184+
ListenHost = "127.0.0.1"
185+
ListenPort = "40002"
171186
[RPC.Metrics]
172187
Enabled = false
173188
```

integration/governance/governance_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ func TestGovernance(t *testing.T) {
5555
// the listener and start the node
5656
l, err := net.Listen("tcp", "localhost:0")
5757
require.NoError(t, err)
58-
testConfig.Tendermint.ListenAddress = fmt.Sprintf("tcp://%v", l.Addr().String())
58+
host, port, err := net.SplitHostPort(l.Addr().String())
59+
require.NoError(t, err)
60+
61+
testConfig.Tendermint.ListenHost = host
62+
testConfig.Tendermint.ListenPort = port
5963

6064
kernels[i], err = integration.TestKernel(acc, privateAccounts, testConfig, logconf)
6165
require.NoError(t, err)

0 commit comments

Comments
 (0)