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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 14 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 10 additions & 3 deletions
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

Lines changed: 14 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 0 additions & 7 deletions
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

0 commit comments

Comments
 (0)