From bb662b88613a785f90e1cc0a6d40e3f481cb35b2 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 24 Sep 2015 15:48:44 -0400 Subject: [PATCH] more config options --- Makefile | 3 ++- config/tendermint/config.go | 8 +++++++- config/tendermint_test/config.go | 5 ++++- node/node.go | 12 ++++++++++++ p2p/netaddress.go | 4 ++++ vm/config.go | 13 +++++++++++++ vm/vm.go | 17 +++++++++++------ 7 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 vm/config.go diff --git a/Makefile b/Makefile index 1ca7d075..d5a8d702 100644 --- a/Makefile +++ b/Makefile @@ -50,4 +50,5 @@ gen_client: go generate rpc/core_client/*.go revision: - -echo `git rev-parse --verify HEAD` >> $(TMROOT)/revisions + -echo `git rev-parse --verify HEAD` > $(TMROOT)/revision + -echo `git rev-parse --verify HEAD` >> $(TMROOT)/revision_history diff --git a/config/tendermint/config.go b/config/tendermint/config.go index 46604cd7..18730dc2 100644 --- a/config/tendermint/config.go +++ b/config/tendermint/config.go @@ -54,6 +54,9 @@ func GetConfig(rootDir string) cfg.Config { if mapConfig.IsSet("chain_id") { Exit("Cannot set 'chain_id' via config.toml") } + if mapConfig.IsSet("revisions_file") { + Exit("Cannot set 'revisions_file' via config.toml. It must match what's in the Makefile") + } mapConfig.SetDefault("chain_id", "tendermint_testnet_10") mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json") mapConfig.SetDefault("moniker", "anonymous") @@ -65,9 +68,12 @@ func GetConfig(rootDir string) cfg.Config { mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json") mapConfig.SetDefault("db_backend", "leveldb") mapConfig.SetDefault("db_dir", rootDir+"/data") + mapConfig.SetDefault("vm_log", true) mapConfig.SetDefault("log_level", "info") mapConfig.SetDefault("rpc_laddr", "0.0.0.0:46657") - mapConfig.SetDefault("revisions_file", rootDir+"/revisions") + mapConfig.SetDefault("prof_laddr", "") + mapConfig.SetDefault("revisions_file", rootDir+"/revision") + mapConfig.SetDefault("local_routing", false) return mapConfig } diff --git a/config/tendermint_test/config.go b/config/tendermint_test/config.go index f0857a77..8ed63473 100644 --- a/config/tendermint_test/config.go +++ b/config/tendermint_test/config.go @@ -70,8 +70,11 @@ func GetConfig(rootDir string) cfg.Config { mapConfig.SetDefault("db_backend", "memdb") mapConfig.SetDefault("db_dir", rootDir+"/data") mapConfig.SetDefault("log_level", "debug") + mapConfig.SetDefault("vm_log", true) mapConfig.SetDefault("rpc_laddr", "0.0.0.0:36657") - mapConfig.SetDefault("revisions_file", rootDir+"/revisions") + mapConfig.SetDefault("prof_laddr", "") + mapConfig.SetDefault("revisions_file", rootDir+"/revision") + mapConfig.SetDefault("local_routing", false) return mapConfig } diff --git a/node/node.go b/node/node.go index 99594a33..9a78cfc4 100644 --- a/node/node.go +++ b/node/node.go @@ -24,6 +24,7 @@ import ( sm "github.com/tendermint/tendermint/state" stypes "github.com/tendermint/tendermint/state/types" "github.com/tendermint/tendermint/types" + "github.com/tendermint/tendermint/vm" "github.com/tendermint/tendermint/wire" ) @@ -127,6 +128,17 @@ func NewNode() *Node { // they should all satisfy events.Eventable SetFireable(eventSwitch, pexReactor, bcReactor, mempoolReactor, consensusReactor) + // run the profile server + profileHost := config.GetString("prof_laddr") + if profileHost != "" { + go func() { + log.Warn("Profile server", "error", http.ListenAndServe(profileHost, nil)) + }() + } + + // set vm log level + vm.SetDebug(config.GetBool("vm_log")) + return &Node{ sw: sw, evsw: eventSwitch, diff --git a/p2p/netaddress.go b/p2p/netaddress.go index 0730ab94..f6567e05 100644 --- a/p2p/netaddress.go +++ b/p2p/netaddress.go @@ -110,6 +110,10 @@ func (na *NetAddress) DialTimeout(timeout time.Duration) (net.Conn, error) { } func (na *NetAddress) Routable() bool { + if config.GetBool("local_routing") { + return na.Valid() + } + // TODO(oga) bitcoind doesn't include RFC3849 here, but should we? return na.Valid() && !(na.RFC1918() || na.RFC3927() || na.RFC4862() || na.RFC4193() || na.RFC4843() || na.Local()) diff --git a/vm/config.go b/vm/config.go new file mode 100644 index 00000000..bbc2fe40 --- /dev/null +++ b/vm/config.go @@ -0,0 +1,13 @@ +package vm + +import ( + cfg "github.com/tendermint/tendermint/config" +) + +var config cfg.Config = nil + +func init() { + cfg.OnConfig(func(newConfig cfg.Config) { + config = newConfig + }) +} diff --git a/vm/vm.go b/vm/vm.go index 7d60752e..a0d59827 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -36,14 +36,19 @@ func (err ErrPermission) Error() string { return fmt.Sprintf("Contract does not have permission to %s", err.typ) } +const ( + dataStackCapacity = 1024 + callStackCapacity = 100 // TODO ensure usage. + memoryCapacity = 1024 * 1024 // 1 MB +) + type Debug bool -const ( - dataStackCapacity = 1024 - callStackCapacity = 100 // TODO ensure usage. - memoryCapacity = 1024 * 1024 // 1 MB - dbg Debug = true -) +var dbg Debug + +func SetDebug(d bool) { + dbg = Debug(d) +} func (d Debug) Printf(s string, a ...interface{}) { if d {