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

Commit

Permalink
separate host/port, silent restore fail option, fix state restore mes…
Browse files Browse the repository at this point in the history
…sage

Signed-off-by: Gregory Hill <[email protected]>
  • Loading branch information
Gregory Hill committed Apr 12, 2019
1 parent 7c49ae9 commit 01edf63
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ NOTES.md: project/history.go project/cmd/notes/main.go
docs: CHANGELOG.md NOTES.md

# Tag the current HEAD commit with the current release defined in
# ./release/release.go
# ./project/history.go
.PHONY: tag_release
tag_release: test check CHANGELOG.md NOTES.md build
@scripts/tag_release.sh
Expand Down
3 changes: 2 additions & 1 deletion bcm/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type PersistedState struct {
GenesisDoc genesis.GenesisDoc
}

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

// Pointer to blockchain state initialised from genesis
// NewBlockchain returns a pointer to blockchain state initialised from genesis
func NewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc) *Blockchain {
bc := &Blockchain{
db: db,
Expand Down
18 changes: 14 additions & 4 deletions cmd/burrow/commands/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/hyperledger/burrow/logging"
"github.com/hyperledger/burrow/logging/logconfig"
"github.com/hyperledger/burrow/logging/logconfig/presets"
"github.com/hyperledger/burrow/rpc"
cli "github.com/jawher/mow.cli"
amino "github.com/tendermint/go-amino"
tmEd25519 "github.com/tendermint/tendermint/crypto/ed25519"
Expand Down Expand Up @@ -331,10 +332,19 @@ func Configure(output Output) func(cmd *cli.Cmd) {
conf.ValidatorAddress = &v.Address
conf.BurrowDir = fmt.Sprintf("burrow%03d", i)
conf.Tendermint.PersistentPeers = seeds
conf.Tendermint.ListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", 26656+i)
conf.RPC.Info.ListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", 26758+i)
conf.RPC.GRPC.ListenAddress = fmt.Sprintf("127.0.0.1:%d", 10997+i)
conf.RPC.Metrics.ListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", 9102+i)

conf.Tendermint.ListenHost = rpc.LocalHost
conf.Tendermint.ListenPort = string(26656 + i)

conf.RPC.Info.ListenHost = rpc.LocalHost
conf.RPC.Info.ListenPort = string(26758 + i)

conf.RPC.GRPC.ListenHost = rpc.LocalHost
conf.RPC.GRPC.ListenPort = string(10997 + i)

conf.RPC.Metrics.ListenHost = rpc.LocalHost
conf.RPC.Metrics.ListenPort = string(9102 + i)

conf.Logging.RootSink.Output.OutputType = "file"
conf.Logging.RootSink.Output.FileConfig = &logconfig.FileConfig{Path: fmt.Sprintf("burrow%03d.log", i)}

Expand Down
4 changes: 2 additions & 2 deletions cmd/burrow/commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const defaultChainTimeout = 15 * time.Second

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion cmd/burrow/commands/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var cdc = amino.NewCodec()

func Dump(output Output) func(cmd *cli.Cmd) {
return func(cmd *cli.Cmd) {
chainURLOpt := cmd.StringOpt("u chain-url", "127.0.0.1:10997", "chain-url to be used in IP:PORT format")
chainURLOpt := cmd.StringOpt("c chain", "127.0.0.1:10997", "chain to be used in IP:PORT format")
heightOpt := cmd.IntOpt("h height", 0, "Block height to dump to, defaults to latest block height")
filename := cmd.StringArg("FILE", "", "Save dump here")
useJSON := cmd.BoolOpt("j json", false, "Output in json")
Expand Down
4 changes: 3 additions & 1 deletion cmd/burrow/commands/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ func Restore(output Output) func(cmd *cli.Cmd) {

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

silentOpt := cmd.BoolOpt("s silent", false, "If state already exists don't throw error")

filename := cmd.StringArg("FILE", "", "Restore from this dump")

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

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

Expand Down
13 changes: 10 additions & 3 deletions consensus/tendermint/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tendermint

import (
"fmt"
"math"
"net/url"
"strings"
Expand All @@ -21,7 +22,8 @@ type BurrowTendermintConfig struct {
SeedMode bool
// Peers to which we automatically connect
PersistentPeers string
ListenAddress string
ListenHost string
ListenPort string
// Optional external that nodes may provide with their NodeInfo
ExternalAddress string
// Set true for strict address routability rules
Expand All @@ -37,9 +39,14 @@ type BurrowTendermintConfig struct {

func DefaultBurrowTendermintConfig() *BurrowTendermintConfig {
tmDefaultConfig := tmConfig.DefaultConfig()
url, err := url.ParseRequestURI(tmDefaultConfig.P2P.ListenAddress)
if err != nil {
return nil
}
return &BurrowTendermintConfig{
Enabled: true,
ListenAddress: tmDefaultConfig.P2P.ListenAddress,
ListenHost: url.Hostname(),
ListenPort: url.Port(),
ExternalAddress: tmDefaultConfig.P2P.ExternalAddress,
CreateEmptyBlocks: tmDefaultConfig.Consensus.CreateEmptyBlocks,
CreateEmptyBlocksInterval: tmDefaultConfig.Consensus.CreateEmptyBlocksInterval,
Expand Down Expand Up @@ -72,7 +79,7 @@ func (btc *BurrowTendermintConfig) Config(rootDir string, timeoutFactor float64)
conf.P2P.Seeds = btc.Seeds
conf.P2P.SeedMode = btc.SeedMode
conf.P2P.PersistentPeers = btc.PersistentPeers
conf.P2P.ListenAddress = btc.ListenAddress
conf.P2P.ListenAddress = fmt.Sprintf("%s:%s", btc.ListenHost, btc.ListenPort)
conf.P2P.ExternalAddress = btc.ExternalAddress
conf.P2P.AddrBookStrict = btc.AddrBookStrict
// We use this in tests and I am not aware of a strong reason to reject nodes on the same IP with different ports
Expand Down
17 changes: 14 additions & 3 deletions core/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,20 @@ func (kern *Kernel) LoadState(genesisDoc *genesis.GenesisDoc) (err error) {
}

// LoadDump restores chain state from the given dump file
func (kern *Kernel) LoadDump(genesisDoc *genesis.GenesisDoc, restoreFile string) (err error) {
if _, kern.Blockchain, err = bcm.LoadOrNewBlockchain(kern.database, genesisDoc, kern.Logger); err != nil {
func (kern *Kernel) LoadDump(genesisDoc *genesis.GenesisDoc, restoreFile string, silent bool) (err error) {
var exists bool
if exists, kern.Blockchain, err = bcm.LoadOrNewBlockchain(kern.database, genesisDoc, kern.Logger); err != nil {
return fmt.Errorf("error creating or loading blockchain state: %v", err)
}

if exists {
if silent {
kern.Logger.InfoMsg("State already exists, skipping...")
return nil
}
return fmt.Errorf("existing state found, please remove before restoring")
}

kern.Blockchain.SetBlockStore(bcm.NewBlockStore(blockchain.NewBlockStore(kern.database)))

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

kern.Logger.InfoMsg("State restore successful: %d", kern.Blockchain.LastBlockHeight())
kern.Logger.InfoMsg("State restore successful -> height 0",
"state_hash", kern.State.Hash())
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions core/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ProfileLauncher(kern *Kernel, conf *rpc.ServerConfig) process.Launcher {
Enabled: conf.Enabled,
Launch: func() (process.Process, error) {
debugServer := &http.Server{
Addr: conf.ListenAddress,
Addr: fmt.Sprintf("%s:%s", conf.ListenHost, conf.ListenPort),
}
go func() {
err := debugServer.ListenAndServe()
Expand Down Expand Up @@ -202,7 +202,7 @@ func InfoLauncher(kern *Kernel, conf *rpc.ServerConfig) process.Launcher {
Name: InfoProcessName,
Enabled: conf.Enabled,
Launch: func() (process.Process, error) {
listener, err := process.ListenerFromAddress(conf.ListenAddress)
listener, err := process.ListenerFromAddress(fmt.Sprintf("%s:%s", conf.ListenHost, conf.ListenPort))
if err != nil {
return nil, err
}
Expand All @@ -224,7 +224,7 @@ func MetricsLauncher(kern *Kernel, conf *rpc.MetricsConfig) process.Launcher {
Name: MetricsProcessName,
Enabled: conf.Enabled,
Launch: func() (process.Process, error) {
listener, err := process.ListenerFromAddress(conf.ListenAddress)
listener, err := process.ListenerFromAddress(fmt.Sprintf("%s:%s", conf.ListenHost, conf.ListenPort))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -252,7 +252,7 @@ func GRPCLauncher(kern *Kernel, conf *rpc.ServerConfig, keyConfig *keys.KeysConf
return nil, err
}

listener, err := process.ListenerFromAddress(conf.ListenAddress)
listener, err := process.ListenerFromAddress(fmt.Sprintf("%s:%s", conf.ListenHost, conf.ListenPort))
if err != nil {
return nil, err
}
Expand Down
7 changes: 0 additions & 7 deletions deploy/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ type LocalKeyClient struct {
keys.KeyClient
}

const DefaultKeysHost = "localhost"
const DefaultKeysPort = "10997"

var keysTimeout = 5 * time.Second

func DefaultKeysURL() string {
return fmt.Sprintf("%s:%s", DefaultKeysHost, DefaultKeysPort)
}

// Returns an initialized key client to a docker container
// running the keys server
// Adding the Ip address is optional and should only be used
Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart/add-validators.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Let's generate the config and keys for a new validator account. As this node wil
```bash
burrow spec -v1 | burrow configure -s- --json > burrow-new.json
NEW_VALIDATOR=$(jq -r '.GenesisDoc.Accounts[0].PublicKey.PublicKey' burrow-new.json)
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
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
```

Copy the following script into `deploy.yaml`:
Expand Down
45 changes: 30 additions & 15 deletions docs/quickstart/seed-nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ From the generated `.burrow_init.toml `file, create new files for each node, and

#### Seed node `.burrow_seed.toml` modified line from `.burrow_init.toml`
```toml
BurrowDir = ".burrow_seed_0"

[Tendermint]
SeedMode = true
ListenAddress = "tcp://0.0.0.0:10000"
ListenHost = "0.0.0.0"
ListenPort = "10000"
Moniker = "seed_node_0"
TendermintRoot = ".burrow_seed_0"

[Execution]

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

```toml
BurrowDir = ".burrow_node0"

[Tendermint]
Seeds = "PUT_HERE_SEED_NODE_ID@LISTEN_EXTERNAL_ADDRESS"
SeedMode = false
PersistentPeers = ""
ListenAddress = "tcp://0.0.0.0:20000"
ListenHost = "0.0.0.0"
ListenPort = "20000"
Moniker = "val_node_0"
TendermintRoot = ".burrow_node0"

[Execution]

Expand All @@ -97,26 +102,30 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
[RPC]
[RPC.Info]
Enabled = true
ListenAddress = "tcp://127.0.0.1:20001"
ListenHost = "127.0.0.1"
ListenPort = "20001"
[RPC.Profiler]
Enabled = false
[RPC.GRPC]
Enabled = true
ListenAddress = "127.0.0.1:20002"
ListenHost = "127.0.0.1"
ListenPort = "20002"
[RPC.Metrics]
Enabled = false
```

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

```toml
BurrowDir = ".burrow_node1"

[Tendermint]
Seeds = "PUT_HERE_SEED_NODE_ID@LISTEN_EXTERNAL_ADDRESS"
SeedMode = false
PersistentPeers = ""
ListenAddress = "tcp://0.0.0.0:30000"
ListenHost = "0.0.0.0"
ListenPort = "30000"
Moniker = "val_node_1"
TendermintRoot = ".burrow_node1"

[Execution]

Expand All @@ -129,12 +138,14 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
[RPC]
[RPC.Info]
Enabled = true
ListenAddress = "tcp://127.0.0.1:30001"
ListenHost = "127.0.0.1"
ListenPort = "30001"
[RPC.Profiler]
Enabled = false
[RPC.GRPC]
Enabled = true
ListenAddress = "127.0.0.1:30002"
ListenHost = "127.0.0.1"
ListenPort = "30002"
[RPC.Metrics]
Enabled = false
```
Expand All @@ -143,13 +154,15 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
#### Validator 3 node `.burrow_val2.toml` modified line from `.burrow_init.toml`

```toml
BurrowDir = ".burrow_node2"

[Tendermint]
Seeds = "PUT_HERE_SEED_NODE_ID@LISTEN_EXTERNAL_ADDRESS"
SeedMode = false
PersistentPeers = ""
ListenAddress = "tcp://0.0.0.0:40000"
ListenHost = "0.0.0.0"
ListenPort = "40000"
Moniker = "val_node_2"
TendermintRoot = ".burrow_node2"

[Execution]

Expand All @@ -162,12 +175,14 @@ From the generated `.burrow_init.toml `file, create new files for each node, and
[RPC]
[RPC.Info]
Enabled = true
ListenAddress = "tcp://127.0.0.1:40001"
ListenHost = "127.0.0.1"
ListenPort = "40001"
[RPC.Profiler]
Enabled = false
[RPC.GRPC]
Enabled = true
ListenAddress = "127.0.0.1:40002"
ListenHost = "127.0.0.1"
ListenPort = "40002"
[RPC.Metrics]
Enabled = false
```
Expand Down
6 changes: 5 additions & 1 deletion integration/governance/governance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func TestGovernance(t *testing.T) {
// the listener and start the node
l, err := net.Listen("tcp", "localhost:0")
require.NoError(t, err)
testConfig.Tendermint.ListenAddress = fmt.Sprintf("tcp://%v", l.Addr().String())
host, port, err := net.SplitHostPort(l.Addr().String())
require.NoError(t, err)

testConfig.Tendermint.ListenHost = host
testConfig.Tendermint.ListenPort = port

kernels[i], err = integration.TestKernel(acc, privateAccounts, testConfig, logconf)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 01edf63

Please sign in to comment.