diff --git a/cmd/eris-db.go b/cmd/eris-db.go index 818ab4c15c8fea753eeaf2dd960a23f296f2fd48..f67501ecc8acb7b116bcdb60e24e0190b0f3df84 100644 --- a/cmd/eris-db.go +++ b/cmd/eris-db.go @@ -17,25 +17,25 @@ package commands import ( - "os" - "strconv" - "strings" + "os" + "strconv" + "strings" - cobra "github.com/spf13/cobra" + cobra "github.com/spf13/cobra" - log "github.com/eris-ltd/eris-logger" + log "github.com/eris-ltd/eris-logger" - definitions "github.com/eris-ltd/eris-db/definitions" - version "github.com/eris-ltd/eris-db/version" + definitions "github.com/eris-ltd/eris-db/definitions" + version "github.com/eris-ltd/eris-db/version" ) // Global Do struct var do *definitions.Do -var ErisDbCmd = &cobra.Command { - Use: "eris-db", - Short: "Eris-DB is the heart of the eris chain.", - Long: `Eris-DB is the heart of the eris chain. Eris-DB combines +var ErisDbCmd = &cobra.Command{ + Use: "eris-db", + Short: "Eris-DB is the heart of the eris chain.", + Long: `Eris-DB is the heart of the eris chain. Eris-DB combines a modular consensus engine and application manager to run a chain to suit your needs. @@ -43,27 +43,27 @@ Made with <3 by Eris Industries. Complete documentation is available at https://docs.erisindustries.com ` + "\nVERSION:\n " + version.VERSION, - PersistentPreRun: func(cmd *cobra.Command, args []string) { - - log.SetLevel(log.WarnLevel) - if do.Verbose { - log.SetLevel(log.InfoLevel) - } else if do.Debug { - log.SetLevel(log.DebugLevel) - } - }, - Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, + PersistentPreRun: func(cmd *cobra.Command, args []string) { + + log.SetLevel(log.WarnLevel) + if do.Verbose { + log.SetLevel(log.InfoLevel) + } else if do.Debug { + log.SetLevel(log.DebugLevel) + } + }, + Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, } func Execute() { - InitErisDb() - AddGlobalFlags() - AddCommands() - ErisDbCmd.Execute() + InitErisDb() + AddGlobalFlags() + AddCommands() + ErisDbCmd.Execute() } func InitErisDb() { - // initialise an empty do struct for command execution + // initialise an empty do struct for command execution do = definitions.NowDo() } @@ -73,8 +73,8 @@ func AddGlobalFlags() { } func AddCommands() { - buildServeCommand() - ErisDbCmd.AddCommand(ServeCmd) + buildServeCommand() + ErisDbCmd.AddCommand(ServeCmd) } //------------------------------------------------------------------------------ @@ -83,13 +83,13 @@ func AddCommands() { // defaultVerbose is set to false unless the ERIS_DB_VERBOSE environment // variable is set to a parsable boolean. func defaultVerbose() bool { - return setDefaultBool("ERIS_DB_VERBOSE", false) + return setDefaultBool("ERIS_DB_VERBOSE", false) } // defaultDebug is set to false unless the ERIS_DB_DEBUG environment // variable is set to a parsable boolean. func defaultDebug() bool { - return setDefaultBool("ERIS_DB_DEBUG", false) + return setDefaultBool("ERIS_DB_DEBUG", false) } // setDefaultBool returns the provided default value if the environment variab;e @@ -98,8 +98,8 @@ func setDefaultBool(environmentVariable string, defaultValue bool) bool { value := os.Getenv(environmentVariable) if value != "" { if parsedValue, err := strconv.ParseBool(value); err == nil { - return parsedValue - } + return parsedValue + } } return defaultValue } diff --git a/cmd/eris-db/main.go b/cmd/eris-db/main.go index 4d37dac57b6b08a376af11b3f38663d3f6118abd..47870377f4123834fe8b1c99474c08819da54c12 100644 --- a/cmd/eris-db/main.go +++ b/cmd/eris-db/main.go @@ -21,5 +21,5 @@ import ( ) func main() { - commands.Execute() -} \ No newline at end of file + commands.Execute() +} diff --git a/cmd/serve.go b/cmd/serve.go index 7341d340952ab56b5680f7bedba5c9bcc89753ec..57e3e9ca4a891bc4f33bc01ead8cb110a153f9bf 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -17,55 +17,55 @@ package commands import ( - "os" - "path" + "os" + "path" - cobra "github.com/spf13/cobra" + cobra "github.com/spf13/cobra" - log "github.com/eris-ltd/eris-logger" + log "github.com/eris-ltd/eris-logger" - core "github.com/eris-ltd/eris-db/core" - util "github.com/eris-ltd/eris-db/util" + core "github.com/eris-ltd/eris-db/core" + util "github.com/eris-ltd/eris-db/util" ) -var ServeCmd = &cobra.Command { - Use: "serve", - Short: "Eris-DB serve starts an eris-db node with client API enabled by default.", - Long: `Eris-DB serve starts an eris-db node with client API enabled by default. +var ServeCmd = &cobra.Command{ + Use: "serve", + Short: "Eris-DB serve starts an eris-db node with client API enabled by default.", + Long: `Eris-DB serve starts an eris-db node with client API enabled by default. The Eris-DB node is modularly configured for the consensus engine and application manager. The client API can be disabled.`, - Example: `$ eris-db serve -- will start the Eris-DB node based on the configuration file "server_config.toml" in the current working directory + Example: `$ eris-db serve -- will start the Eris-DB node based on the configuration file "server_config.toml" in the current working directory $ eris-db serve --work-dir <path-to-working-directory> -- will start the Eris-DB node based on the configuration file "server_config.toml" in the provided working directory`, - PreRun: func(cmd *cobra.Command, args []string) { - // if WorkDir was not set by a flag or by $ERIS_DB_WORKDIR - // NOTE [ben]: we can consider an `Explicit` flag that eliminates - // the use of any assumptions while starting Eris-DB - if do.WorkDir == "" { - if currentDirectory, err := os.Getwd(); err != nil { - log.Fatalf("No directory provided and failed to get current working directory: %v", err) - os.Exit(1) - } else { - - do.WorkDir = currentDirectory - } - } - if !util.IsDir(do.WorkDir) { - log.Fatalf("Provided working directory %s is not a directory", do.WorkDir) - } - }, - Run: Serve, + PreRun: func(cmd *cobra.Command, args []string) { + // if WorkDir was not set by a flag or by $ERIS_DB_WORKDIR + // NOTE [ben]: we can consider an `Explicit` flag that eliminates + // the use of any assumptions while starting Eris-DB + if do.WorkDir == "" { + if currentDirectory, err := os.Getwd(); err != nil { + log.Fatalf("No directory provided and failed to get current working directory: %v", err) + os.Exit(1) + } else { + + do.WorkDir = currentDirectory + } + } + if !util.IsDir(do.WorkDir) { + log.Fatalf("Provided working directory %s is not a directory", do.WorkDir) + } + }, + Run: Serve, } // build the serve subcommand func buildServeCommand() { - addServeFlags() + addServeFlags() } func addServeFlags() { - ServeCmd.PersistentFlags().StringVarP(&do.WorkDir, "work-dir", "w", - defaultWorkDir(), "specify the working directory for the chain to run. If omitted, and no path set in $ERIS_DB_WORKDIR, the current working directory is taken.") - ServeCmd.PersistentFlags().StringVarP(&do.DataDir, "data-dir", "a", - defaultDataDir(), "specify the data directory. If omitted and not set in $ERIS_DB_DATADIR, <working_directory>/data is taken.") + ServeCmd.PersistentFlags().StringVarP(&do.WorkDir, "work-dir", "w", + defaultWorkDir(), "specify the working directory for the chain to run. If omitted, and no path set in $ERIS_DB_WORKDIR, the current working directory is taken.") + ServeCmd.PersistentFlags().StringVarP(&do.DataDir, "data-dir", "a", + defaultDataDir(), "specify the data directory. If omitted and not set in $ERIS_DB_DATADIR, <working_directory>/data is taken.") } //------------------------------------------------------------------------------ @@ -75,93 +75,92 @@ func addServeFlags() { // After the setup succeeds, serve() starts the core and halts for core to // terminate. func Serve(cmd *cobra.Command, args []string) { - // load configuration from a single location to avoid a wrong configuration - // file is loaded. - if err := do.ReadConfig(do.WorkDir, "server_config", "toml"); err != nil { - log.WithFields(log.Fields{ - "directory": do.WorkDir, - "file": "server_config.toml", - }).Fatalf("Fatal error reading configuration") - os.Exit(1) - } - // load chain_id for assertion - if do.ChainId = do.Config.GetString("chain.assert_chain_id"); - do.ChainId == "" { - log.Fatalf("Failed to read non-empty string for ChainId from config.") - os.Exit(1) - } - // load the genesis file path - do.GenesisFile = path.Join(do.WorkDir, - do.Config.GetString("chain.genesis_file")) - if do.Config.GetString("chain.genesis_file") == "" { - log.Fatalf("Failed to read non-empty string for genesis file from config.") - os.Exit(1) - } - // Ensure data directory is set and accessible - if err := do.InitialiseDataDirectory(); err != nil { - log.Fatalf("Failed to initialise data directory (%s): %v", do.DataDir, err) - os.Exit(1) - } - log.WithFields(log.Fields{ - "chainId": do.ChainId, - "workingDirectory": do.WorkDir, - "dataDirectory": do.DataDir, - "genesisFile": do.GenesisFile, - }).Info("Eris-DB serve configuring") - - consensusConfig, err := core.LoadConsensusModuleConfig(do) - if err != nil { - log.Fatalf("Failed to load consensus module configuration: %s.", err) - os.Exit(1) - } - - managerConfig, err := core.LoadApplicationManagerModuleConfig(do) - if err != nil { - log.Fatalf("Failed to load application manager module configuration: %s.", err) - os.Exit(1) - } - log.WithFields(log.Fields{ - "consensusModule": consensusConfig.Version, - "applicationManager": managerConfig.Version, - }).Debug("Modules configured") - - newCore, err := core.NewCore(do.ChainId, consensusConfig, managerConfig) - if err != nil { - log.Fatalf("Failed to load core: %s", err) - } - - serverConfig, err := core.LoadServerConfig(do) - if err != nil { - log.Fatalf("Failed to load server configuration: %s.", err) - os.Exit(1) - } - serverProcess, err := newCore.NewGatewayV0(serverConfig) - if err != nil { - log.Fatalf("Failed to load servers: %s.", err) - os.Exit(1) - } - err = serverProcess.Start() - if err != nil { - log.Fatalf("Failed to start servers: %s.", err) - os.Exit(1) - } + // load configuration from a single location to avoid a wrong configuration + // file is loaded. + if err := do.ReadConfig(do.WorkDir, "server_config", "toml"); err != nil { + log.WithFields(log.Fields{ + "directory": do.WorkDir, + "file": "server_config.toml", + }).Fatalf("Fatal error reading configuration") + os.Exit(1) + } + // load chain_id for assertion + if do.ChainId = do.Config.GetString("chain.assert_chain_id"); do.ChainId == "" { + log.Fatalf("Failed to read non-empty string for ChainId from config.") + os.Exit(1) + } + // load the genesis file path + do.GenesisFile = path.Join(do.WorkDir, + do.Config.GetString("chain.genesis_file")) + if do.Config.GetString("chain.genesis_file") == "" { + log.Fatalf("Failed to read non-empty string for genesis file from config.") + os.Exit(1) + } + // Ensure data directory is set and accessible + if err := do.InitialiseDataDirectory(); err != nil { + log.Fatalf("Failed to initialise data directory (%s): %v", do.DataDir, err) + os.Exit(1) + } + log.WithFields(log.Fields{ + "chainId": do.ChainId, + "workingDirectory": do.WorkDir, + "dataDirectory": do.DataDir, + "genesisFile": do.GenesisFile, + }).Info("Eris-DB serve configuring") + + consensusConfig, err := core.LoadConsensusModuleConfig(do) + if err != nil { + log.Fatalf("Failed to load consensus module configuration: %s.", err) + os.Exit(1) + } + + managerConfig, err := core.LoadApplicationManagerModuleConfig(do) + if err != nil { + log.Fatalf("Failed to load application manager module configuration: %s.", err) + os.Exit(1) + } + log.WithFields(log.Fields{ + "consensusModule": consensusConfig.Version, + "applicationManager": managerConfig.Version, + }).Debug("Modules configured") + + newCore, err := core.NewCore(do.ChainId, consensusConfig, managerConfig) + if err != nil { + log.Fatalf("Failed to load core: %s", err) + } + + serverConfig, err := core.LoadServerConfig(do) + if err != nil { + log.Fatalf("Failed to load server configuration: %s.", err) + os.Exit(1) + } + serverProcess, err := newCore.NewGatewayV0(serverConfig) + if err != nil { + log.Fatalf("Failed to load servers: %s.", err) + os.Exit(1) + } + err = serverProcess.Start() + if err != nil { + log.Fatalf("Failed to start servers: %s.", err) + os.Exit(1) + } _, err = newCore.NewGatewayTendermint(serverConfig) if err != nil { log.Fatalf("Failed to start Tendermint gateway") } - <- serverProcess.StopEventChannel() + <-serverProcess.StopEventChannel() } //------------------------------------------------------------------------------ // Defaults func defaultWorkDir() string { - // if ERIS_DB_WORKDIR environment variable is not set, keep do.WorkDir empty - return setDefaultString("ERIS_DB_WORKDIR", "") + // if ERIS_DB_WORKDIR environment variable is not set, keep do.WorkDir empty + return setDefaultString("ERIS_DB_WORKDIR", "") } func defaultDataDir() string { - // As the default data directory depends on the default working directory, - // wait setting a default value, and initialise the data directory from serve() - return setDefaultString("ERIS_DB_DATADIR", "") + // As the default data directory depends on the default working directory, + // wait setting a default value, and initialise the data directory from serve() + return setDefaultString("ERIS_DB_DATADIR", "") } diff --git a/config/module.go b/config/module.go index 5fd4be77c982cffdfc7b456ce16fb85467349239..39c131d269ae7861b69fdc80b039065a6c909b7e 100644 --- a/config/module.go +++ b/config/module.go @@ -18,17 +18,17 @@ package config import ( - viper "github.com/spf13/viper" + viper "github.com/spf13/viper" ) type ModuleConfig struct { - Module string - Name string - Version string - WorkDir string - DataDir string - RootDir string - ChainId string - GenesisFile string - Config *viper.Viper + Module string + Name string + Version string + WorkDir string + DataDir string + RootDir string + ChainId string + GenesisFile string + Config *viper.Viper } diff --git a/consensus/config.go b/consensus/config.go index 06b5a6afd45316df0dd9bce7802aa84a2abf6748..d676d8c214f8c794aaea43a845260f9407d2d311 100644 --- a/consensus/config.go +++ b/consensus/config.go @@ -20,27 +20,27 @@ package consensus import ( - // noops "github.com/eris-ltd/eris-db/consensus/noops" - tendermint "github.com/eris-ltd/eris-db/consensus/tendermint" - tmsp "github.com/eris-ltd/eris-db/consensus/tmsp" + // noops "github.com/eris-ltd/eris-db/consensus/noops" + tendermint "github.com/eris-ltd/eris-db/consensus/tendermint" + tmsp "github.com/eris-ltd/eris-db/consensus/tmsp" ) //------------------------------------------------------------------------------ // Helper functions func AssertValidConsensusModule(name, minorVersionString string) bool { - switch name { - case "noops" : - // noops should not have any external interfaces that can change - // over iterations - return true - case "tmsp" : - return minorVersionString == tmsp.GetTmspVersion().GetMinorVersionString() - case "tendermint" : - return minorVersionString == tendermint.GetTendermintVersion().GetMinorVersionString() - case "bigchaindb" : - // TODO: [ben] implement BigchainDB as consensus engine - return false - } - return false + switch name { + case "noops": + // noops should not have any external interfaces that can change + // over iterations + return true + case "tmsp": + return minorVersionString == tmsp.GetTmspVersion().GetMinorVersionString() + case "tendermint": + return minorVersionString == tendermint.GetTendermintVersion().GetMinorVersionString() + case "bigchaindb": + // TODO: [ben] implement BigchainDB as consensus engine + return false + } + return false } diff --git a/consensus/consensus.go b/consensus/consensus.go index 2bc719b3e05fb8975f8dc5fd5c1c096e50033bc6..369210beeb285994dd42fffdd32305e055316713 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -17,25 +17,25 @@ package consensus import ( - "fmt" + "fmt" - config "github.com/eris-ltd/eris-db/config" - definitions "github.com/eris-ltd/eris-db/definitions" - tendermint "github.com/eris-ltd/eris-db/consensus/tendermint" + config "github.com/eris-ltd/eris-db/config" + tendermint "github.com/eris-ltd/eris-db/consensus/tendermint" + definitions "github.com/eris-ltd/eris-db/definitions" ) func LoadConsensusEngineInPipe(moduleConfig *config.ModuleConfig, - pipe definitions.Pipe) error { - switch moduleConfig.Name { - case "tendermint" : - tendermintNode, err := tendermint.NewTendermintNode(moduleConfig, - pipe.GetApplication()) - if err != nil { - return fmt.Errorf("Failed to load Tendermint node: %v", err) - } - if err := pipe.SetConsensusEngine(tendermintNode); err != nil { - return fmt.Errorf("Failed to hand Tendermint node to pipe: %v", err) - } - } - return nil + pipe definitions.Pipe) error { + switch moduleConfig.Name { + case "tendermint": + tendermintNode, err := tendermint.NewTendermintNode(moduleConfig, + pipe.GetApplication()) + if err != nil { + return fmt.Errorf("Failed to load Tendermint node: %v", err) + } + if err := pipe.SetConsensusEngine(tendermintNode); err != nil { + return fmt.Errorf("Failed to hand Tendermint node to pipe: %v", err) + } + } + return nil } diff --git a/consensus/tendermint/config.go b/consensus/tendermint/config.go index aa1429d2a717da159b1b0bbdb82ad14e51750b45..20fad4cdabd521d4aadf70471966fbff9217d902 100644 --- a/consensus/tendermint/config.go +++ b/consensus/tendermint/config.go @@ -20,13 +20,13 @@ package tendermint import ( - "path" - "time" + "path" + "time" - tendermintConfig "github.com/tendermint/go-config" - viper "github.com/spf13/viper" + viper "github.com/spf13/viper" + tendermintConfig "github.com/tendermint/go-config" - config "github.com/eris-ltd/eris-db/config" + config "github.com/eris-ltd/eris-db/config" ) // NOTE [ben] Compiler check to ensure TendermintConfig successfully implements @@ -40,33 +40,33 @@ var _ tendermintConfig.Config = (*TendermintConfig)(nil) // the tendermint configuration and set the defaults. Hence we re-implement // go-config.Config on a viper subtree of the loaded Eris-DB configuration file. type TendermintConfig struct { - subTree *viper.Viper + subTree *viper.Viper } func GetTendermintConfig(loadedConfig *viper.Viper) *TendermintConfig { - // ensure we make an explicit copy - subTree := new(viper.Viper) - *subTree = *loadedConfig + // ensure we make an explicit copy + subTree := new(viper.Viper) + *subTree = *loadedConfig - return &TendermintConfig { - subTree : subTree, - } + return &TendermintConfig{ + subTree: subTree, + } } //------------------------------------------------------------------------------ // Tendermint defaults func (tmintConfig *TendermintConfig) AssertTendermintDefaults(chainId, workDir, - dataDir, rootDir string) { + dataDir, rootDir string) { - tmintConfig.Set("chain_id", chainId) - tmintConfig.SetDefault("genesis_file", path.Join(rootDir, "genesis.json")) - tmintConfig.SetDefault("proxy_app", "tcp://127.0.0.1:46658") + tmintConfig.Set("chain_id", chainId) + tmintConfig.SetDefault("genesis_file", path.Join(rootDir, "genesis.json")) + tmintConfig.SetDefault("proxy_app", "tcp://127.0.0.1:46658") tmintConfig.SetDefault("moniker", "anonymous_marmot") tmintConfig.SetDefault("node_laddr", "0.0.0.0:46656") tmintConfig.SetDefault("seeds", "") - tmintConfig.SetDefault("fast_sync", true) + tmintConfig.SetDefault("fast_sync", true) tmintConfig.SetDefault("skip_upnp", false) tmintConfig.SetDefault("addrbook_file", path.Join(rootDir, "addrbook.json")) tmintConfig.SetDefault("priv_validator_file", path.Join(rootDir, "priv_validator.json")) @@ -75,7 +75,7 @@ func (tmintConfig *TendermintConfig) AssertTendermintDefaults(chainId, workDir, tmintConfig.SetDefault("log_level", "info") tmintConfig.SetDefault("rpc_laddr", "0.0.0.0:46657") tmintConfig.SetDefault("prof_laddr", "") - tmintConfig.SetDefault("revision_file", path.Join(workDir,"revision")) + tmintConfig.SetDefault("revision_file", path.Join(workDir, "revision")) tmintConfig.SetDefault("cswal", path.Join(dataDir, "cswal")) tmintConfig.SetDefault("cswal_light", false) @@ -96,73 +96,74 @@ func (tmintConfig *TendermintConfig) AssertTendermintDefaults(chainId, workDir, //------------------------------------------------------------------------------ // Tendermint consistency checks -func(tmintConfig *TendermintConfig) AssertTendermintConsistency( - consensusConfig *config.ModuleConfig, privateValidatorFilePath string) { +func (tmintConfig *TendermintConfig) AssertTendermintConsistency( + consensusConfig *config.ModuleConfig, privateValidatorFilePath string) { - tmintConfig.Set("chain_id", consensusConfig.ChainId) - tmintConfig.Set("genesis_file", consensusConfig.GenesisFile) - // private validator file - tmintConfig.Set("priv_validator_file", privateValidatorFilePath) + tmintConfig.Set("chain_id", consensusConfig.ChainId) + tmintConfig.Set("genesis_file", consensusConfig.GenesisFile) + // private validator file + tmintConfig.Set("priv_validator_file", privateValidatorFilePath) } // implement interface github.com/tendermint/go-config/config.Config // so that `TMROOT` and config can be circumvented func (tmintConfig *TendermintConfig) Get(key string) interface{} { - return tmintConfig.subTree.Get(key) + return tmintConfig.subTree.Get(key) } func (tmintConfig *TendermintConfig) GetBool(key string) bool { - return tmintConfig.subTree.GetBool(key) + return tmintConfig.subTree.GetBool(key) } func (tmintConfig *TendermintConfig) GetFloat64(key string) float64 { - return tmintConfig.subTree.GetFloat64(key) + return tmintConfig.subTree.GetFloat64(key) } func (tmintConfig *TendermintConfig) GetInt(key string) int { - return tmintConfig.subTree.GetInt(key) + return tmintConfig.subTree.GetInt(key) } func (tmintConfig *TendermintConfig) GetString(key string) string { - return tmintConfig.subTree.GetString(key) + return tmintConfig.subTree.GetString(key) } func (tmintConfig *TendermintConfig) GetStringSlice(key string) []string { - return tmintConfig.subTree.GetStringSlice(key) + return tmintConfig.subTree.GetStringSlice(key) } func (tmintConfig *TendermintConfig) GetTime(key string) time.Time { - return tmintConfig.subTree.GetTime(key) + return tmintConfig.subTree.GetTime(key) } func (tmintConfig *TendermintConfig) GetMap(key string) map[string]interface{} { - return tmintConfig.subTree.GetStringMap(key) + return tmintConfig.subTree.GetStringMap(key) } func (tmintConfig *TendermintConfig) GetMapString(key string) map[string]string { - return tmintConfig.subTree.GetStringMapString(key) + return tmintConfig.subTree.GetStringMapString(key) } func (tmintConfig *TendermintConfig) GetConfig(key string) tendermintConfig.Config { // TODO: [ben] log out a warning as this indicates a potentially breaking code // change from Tendermints side if !tmintConfig.subTree.IsSet(key) { - return &TendermintConfig { + return &TendermintConfig{ subTree: viper.New(), - }} - return &TendermintConfig { - subTree: tmintConfig.subTree.Sub(key), - } + } + } + return &TendermintConfig{ + subTree: tmintConfig.subTree.Sub(key), + } } func (tmintConfig *TendermintConfig) IsSet(key string) bool { - return tmintConfig.IsSet(key) + return tmintConfig.IsSet(key) } func (tmintConfig *TendermintConfig) Set(key string, value interface{}) { - tmintConfig.subTree.Set(key, value) + tmintConfig.subTree.Set(key, value) } func (tmintConfig *TendermintConfig) SetDefault(key string, value interface{}) { - tmintConfig.subTree.SetDefault(key, value) + tmintConfig.subTree.SetDefault(key, value) } diff --git a/consensus/tendermint/tendermint.go b/consensus/tendermint/tendermint.go index c87719e5cd25ffa0c344cc5f32149af7fd27c751..8b25ca85ca5d180c456abde1ad61a2ce3f6329b9 100644 --- a/consensus/tendermint/tendermint.go +++ b/consensus/tendermint/tendermint.go @@ -25,18 +25,18 @@ import ( "strings" "sync" - crypto "github.com/tendermint/go-crypto" - p2p "github.com/tendermint/go-p2p" - node "github.com/tendermint/tendermint/node" - proxy "github.com/tendermint/tendermint/proxy" + crypto "github.com/tendermint/go-crypto" + p2p "github.com/tendermint/go-p2p" + node "github.com/tendermint/tendermint/node" + proxy "github.com/tendermint/tendermint/proxy" tendermint_types "github.com/tendermint/tendermint/types" - tmsp_types "github.com/tendermint/tmsp/types" + tmsp_types "github.com/tendermint/tmsp/types" log "github.com/eris-ltd/eris-logger" - config "github.com/eris-ltd/eris-db/config" - definitions "github.com/eris-ltd/eris-db/definitions" - manager_types "github.com/eris-ltd/eris-db/manager/types" + config "github.com/eris-ltd/eris-db/config" + definitions "github.com/eris-ltd/eris-db/definitions" + manager_types "github.com/eris-ltd/eris-db/manager/types" rpc_tendermint_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" // files "github.com/eris-ltd/eris-db/files" ) @@ -166,7 +166,7 @@ func (this *TendermintNode) Listeners() []p2p.Listener { func (this *TendermintNode) Peers() []rpc_tendermint_types.Peer { peers := []rpc_tendermint_types.Peer{} for _, peer := range this.tmintNode.Switch().Peers().List() { - peers = append(peers, rpc_tendermint_types.Peer { + peers = append(peers, rpc_tendermint_types.Peer{ NodeInfo: *peer.NodeInfo, IsOutbound: peer.IsOutbound(), }) @@ -187,11 +187,11 @@ func (this *TendermintNode) PublicValidatorKey() crypto.PubKey { // crypto.PubKey is an interface so copy underlying struct publicKey := this.tmintNode.PrivValidator().PubKey switch publicKey.(type) { - case crypto.PubKeyEd25519 : + case crypto.PubKeyEd25519: // type crypto.PubKeyEd25519 is [32]byte copyKeyBytes := publicKey.(crypto.PubKeyEd25519) copyPublicValidatorKey = crypto.PubKey(copyKeyBytes) - default : + default: // TODO: [ben] add error return to all these calls copyPublicValidatorKey = nil } diff --git a/consensus/tendermint/version.go b/consensus/tendermint/version.go index bba12637b7b7fa55d4462944970e279723547ac1..04dfcef7aebaf5d92543bd4bc6d0ba669ddd615e 100644 --- a/consensus/tendermint/version.go +++ b/consensus/tendermint/version.go @@ -17,21 +17,21 @@ package tendermint import ( - version "github.com/eris-ltd/eris-db/version" + version "github.com/eris-ltd/eris-db/version" ) const ( - // Client identifier to advertise over the network - tendermintClientIdentifier = "tendermint" - // Major version component of the current release - tendermintVersionMajor = 0 - // Minor version component of the current release - tendermintVersionMinor = 6 - // Patch version component of the current release - tendermintVersionPatch = 0 + // Client identifier to advertise over the network + tendermintClientIdentifier = "tendermint" + // Major version component of the current release + tendermintVersionMajor = 0 + // Minor version component of the current release + tendermintVersionMinor = 6 + // Patch version component of the current release + tendermintVersionPatch = 0 ) func GetTendermintVersion() *version.VersionIdentifier { - return version.New(tendermintClientIdentifier, tendermintVersionMajor, - tendermintVersionMinor, tendermintVersionPatch) + return version.New(tendermintClientIdentifier, tendermintVersionMajor, + tendermintVersionMinor, tendermintVersionPatch) } diff --git a/consensus/tmsp/version.go b/consensus/tmsp/version.go index 7394941818056bb93914d20e167d4bf03ffd67a6..266b37d792c4b606cdd547469f05d050edcc0b3b 100644 --- a/consensus/tmsp/version.go +++ b/consensus/tmsp/version.go @@ -17,21 +17,21 @@ package tmsp import ( - version "github.com/eris-ltd/eris-db/version" + version "github.com/eris-ltd/eris-db/version" ) const ( - // Client identifier to advertise over the network - tmspClientIdentifier = "tmsp" - // Major version component of the current release - tmspVersionMajor = 0 - // Minor version component of the current release - tmspVersionMinor = 6 - // Patch version component of the current release - tmspVersionPatch = 0 + // Client identifier to advertise over the network + tmspClientIdentifier = "tmsp" + // Major version component of the current release + tmspVersionMajor = 0 + // Minor version component of the current release + tmspVersionMinor = 6 + // Patch version component of the current release + tmspVersionPatch = 0 ) func GetTmspVersion() *version.VersionIdentifier { - return version.New(tmspClientIdentifier, tmspVersionMajor, tmspVersionMinor, - tmspVersionPatch) + return version.New(tmspClientIdentifier, tmspVersionMajor, tmspVersionMinor, + tmspVersionPatch) } diff --git a/core/config.go b/core/config.go index 941b5b54d636d373092073e549385b8c30a49b99..a2a82dbd1e07e649962f8ee37e2f61b48ceb25aa 100644 --- a/core/config.go +++ b/core/config.go @@ -117,7 +117,6 @@ func LoadServerConfig(do *definitions.Do) (*server.ServerConfig, error) { return serverConfig, err } - //------------------------------------------------------------------------------ // Helper functions diff --git a/core/core.go b/core/core.go index ae02d5b730f3e34edb9a17684e19b9d0c12fb2f7..03f56b56a47927b09d8b2bdc9e5a2302da1fcd84 100644 --- a/core/core.go +++ b/core/core.go @@ -38,7 +38,7 @@ import ( // Core is the high-level structure type Core struct { - chainId string + chainId string evsw *events.EventSwitch pipe definitions.Pipe tendermintPipe definitions.TendermintPipe @@ -65,14 +65,14 @@ func NewCore(chainId string, consensusConfig *config.ModuleConfig, if err != nil { log.Warn(fmt.Sprintf("Tendermint gateway not supported by %s", managerConfig.Version)) - return &Core { + return &Core{ chainId: chainId, evsw: evsw, pipe: pipe, tendermintPipe: nil, }, nil } - return &Core { + return &Core{ chainId: chainId, evsw: evsw, pipe: pipe, diff --git a/core/types/types.go b/core/types/types.go index 9c463920ac0d3d439e383db4f364e3f728106dab..b84b844ac3d7dbe373927bd33e6d00cd25f0dba3 100644 --- a/core/types/types.go +++ b/core/types/types.go @@ -24,7 +24,7 @@ import ( csus "github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/types" - account "github.com/eris-ltd/eris-db/account" + account "github.com/eris-ltd/eris-db/account" transaction "github.com/eris-ltd/eris-db/txs" ) @@ -192,6 +192,6 @@ func FromRoundState(rs *csus.RoundState) *ConsensusState { // copied in from NameReg type ResultListNames struct { - BlockHeight int `json:"block_height"` + BlockHeight int `json:"block_height"` Names []*transaction.NameRegEntry `json:"names"` } diff --git a/definitions/consensus.go b/definitions/consensus.go index 98e7ed86da4074356c28ed045198e035526ba487..42d1f4a2418ced8226e7f938ee3d35c9c8a9bcb6 100644 --- a/definitions/consensus.go +++ b/definitions/consensus.go @@ -17,10 +17,10 @@ package definitions import ( - crypto "github.com/tendermint/go-crypto" - p2p "github.com/tendermint/go-p2p" + crypto "github.com/tendermint/go-crypto" + p2p "github.com/tendermint/go-p2p" tendermint_types "github.com/tendermint/tendermint/types" - tmsp_types "github.com/tendermint/tmsp/types" + tmsp_types "github.com/tendermint/tmsp/types" rpc_tendermint_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" ) @@ -46,7 +46,6 @@ type ConsensusEngine interface { // Memory pool BroadcastTransaction(transaction []byte, callback func(*tmsp_types.Response)) error - } // type Communicator interface { diff --git a/definitions/pipe.go b/definitions/pipe.go index f3c6978df937e19eb49b5a703f76048247ba08de..83953e1467422c5aaba98a75bbb60247984f3f57 100644 --- a/definitions/pipe.go +++ b/definitions/pipe.go @@ -25,82 +25,82 @@ package definitions // these interfaces into an Engine, Communicator, NameReg, Permissions (suggestion) import ( - tendermint_types "github.com/tendermint/tendermint/types" + tendermint_types "github.com/tendermint/tendermint/types" - account "github.com/eris-ltd/eris-db/account" - event "github.com/eris-ltd/eris-db/event" - manager_types "github.com/eris-ltd/eris-db/manager/types" - transaction "github.com/eris-ltd/eris-db/txs" - types "github.com/eris-ltd/eris-db/core/types" + account "github.com/eris-ltd/eris-db/account" + types "github.com/eris-ltd/eris-db/core/types" + event "github.com/eris-ltd/eris-db/event" + manager_types "github.com/eris-ltd/eris-db/manager/types" + transaction "github.com/eris-ltd/eris-db/txs" ) type Pipe interface { - Accounts() Accounts - Blockchain() Blockchain - Consensus() Consensus - Events() event.EventEmitter - NameReg() NameReg - Net() Net - Transactor() Transactor - // NOTE: [ben] added to Pipe interface on 0.12 refactor - GetApplication() manager_types.Application - SetConsensusEngine(consensus ConsensusEngine) error + Accounts() Accounts + Blockchain() Blockchain + Consensus() Consensus + Events() event.EventEmitter + NameReg() NameReg + Net() Net + Transactor() Transactor + // NOTE: [ben] added to Pipe interface on 0.12 refactor + GetApplication() manager_types.Application + SetConsensusEngine(consensus ConsensusEngine) error // Support for Tendermint RPC GetTendermintPipe() (TendermintPipe, error) } type Accounts interface { - GenPrivAccount() (*account.PrivAccount, error) - GenPrivAccountFromKey(privKey []byte) (*account.PrivAccount, error) - Accounts([]*event.FilterData) (*types.AccountList, error) - Account(address []byte) (*account.Account, error) - Storage(address []byte) (*types.Storage, error) - StorageAt(address, key []byte) (*types.StorageItem, error) + GenPrivAccount() (*account.PrivAccount, error) + GenPrivAccountFromKey(privKey []byte) (*account.PrivAccount, error) + Accounts([]*event.FilterData) (*types.AccountList, error) + Account(address []byte) (*account.Account, error) + Storage(address []byte) (*types.Storage, error) + StorageAt(address, key []byte) (*types.StorageItem, error) } type Blockchain interface { - Info() (*types.BlockchainInfo, error) - GenesisHash() ([]byte, error) - ChainId() (string, error) - LatestBlockHeight() (int, error) - LatestBlock() (*tendermint_types.Block, error) - Blocks([]*event.FilterData) (*types.Blocks, error) - Block(height int) (*tendermint_types.Block, error) + Info() (*types.BlockchainInfo, error) + GenesisHash() ([]byte, error) + ChainId() (string, error) + LatestBlockHeight() (int, error) + LatestBlock() (*tendermint_types.Block, error) + Blocks([]*event.FilterData) (*types.Blocks, error) + Block(height int) (*tendermint_types.Block, error) } type Consensus interface { - State() (*types.ConsensusState, error) - Validators() (*types.ValidatorList, error) + State() (*types.ConsensusState, error) + Validators() (*types.ValidatorList, error) } type NameReg interface { - Entry(key string) (*transaction.NameRegEntry, error) - Entries([]*event.FilterData) (*types.ResultListNames, error) + Entry(key string) (*transaction.NameRegEntry, error) + Entries([]*event.FilterData) (*types.ResultListNames, error) } type Net interface { - Info() (*types.NetworkInfo, error) - ClientVersion() (string, error) - Moniker() (string, error) - Listening() (bool, error) - Listeners() ([]string, error) - Peers() ([]*types.Peer, error) - Peer(string) (*types.Peer, error) + Info() (*types.NetworkInfo, error) + ClientVersion() (string, error) + Moniker() (string, error) + Listening() (bool, error) + Listeners() ([]string, error) + Peers() ([]*types.Peer, error) + Peer(string) (*types.Peer, error) } type Transactor interface { - Call(fromAddress, toAddress, data []byte) (*types.Call, error) - CallCode(fromAddress, code, data []byte) (*types.Call, error) - // Send(privKey, toAddress []byte, amount int64) (*types.Receipt, error) - // SendAndHold(privKey, toAddress []byte, amount int64) (*types.Receipt, error) - BroadcastTx(tx transaction.Tx) (*types.Receipt, error) - Transact(privKey, address, data []byte, gasLimit, - fee int64) (*types.Receipt, error) - TransactAndHold(privKey, address, data []byte, gasLimit, - fee int64) (*transaction.EventDataCall, error) - TransactNameReg(privKey []byte, name, data string, amount, - fee int64) (*types.Receipt, error) - UnconfirmedTxs() (*types.UnconfirmedTxs, error) - SignTx(tx transaction.Tx, - privAccounts []*account.PrivAccount) (transaction.Tx, error) + Call(fromAddress, toAddress, data []byte) (*types.Call, error) + CallCode(fromAddress, code, data []byte) (*types.Call, error) + // Send(privKey, toAddress []byte, amount int64) (*types.Receipt, error) + // SendAndHold(privKey, toAddress []byte, amount int64) (*types.Receipt, error) + BroadcastTx(tx transaction.Tx) (*types.Receipt, error) + Transact(privKey, address, data []byte, gasLimit, + fee int64) (*types.Receipt, error) + TransactAndHold(privKey, address, data []byte, gasLimit, + fee int64) (*transaction.EventDataCall, error) + TransactNameReg(privKey []byte, name, data string, amount, + fee int64) (*types.Receipt, error) + UnconfirmedTxs() (*types.UnconfirmedTxs, error) + SignTx(tx transaction.Tx, + privAccounts []*account.PrivAccount) (transaction.Tx, error) } diff --git a/definitions/tendermint_pipe.go b/definitions/tendermint_pipe.go index 600fd306fdb80b7133b3aaa4ce94322d7be8ae63..9627901f95f8432c51e2e5fc8cb59a965f7b72b7 100644 --- a/definitions/tendermint_pipe.go +++ b/definitions/tendermint_pipe.go @@ -17,9 +17,9 @@ package definitions import ( - account "github.com/eris-ltd/eris-db/account" + account "github.com/eris-ltd/eris-db/account" rpc_tendermint_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" - transaction "github.com/eris-ltd/eris-db/txs" + transaction "github.com/eris-ltd/eris-db/txs" ) // NOTE: [ben] TendermintPipe is the additional pipe to carry over diff --git a/event/events.go b/event/events.go index 9df7739d88101be843ebc5a6aa99a13819d5982b..8861056cb40f4bb501c6325870a33c344d6e6494 100644 --- a/event/events.go +++ b/event/events.go @@ -30,8 +30,8 @@ import ( // that there is no need anymore for this poor wrapper. type EventEmitter interface { - Subscribe(subId, event string, callback func(evts.EventData)) (bool, error) - Unsubscribe(subId string) (bool, error) + Subscribe(subId, event string, callback func(evts.EventData)) (bool, error) + Unsubscribe(subId string) (bool, error) } // The events struct has methods for working with events. diff --git a/event_new/event.go b/event_new/event.go index 2c9e3d3e85206588fc897ab51ad862015b2fe16b..9553b3921991404a0298819c7b930e829fa67087 100644 --- a/event_new/event.go +++ b/event_new/event.go @@ -14,7 +14,6 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - // Copyright 2015, 2016 Eris Industries (UK) Ltd. // This file is part of Eris-RT diff --git a/event_new/event_test.go b/event_new/event_test.go index 178eb4c8494e8f2e4a293aee2bf524562d2493f5..fcdb0b1cdda1ed5baf49c55280beed73c92b34f7 100644 --- a/event_new/event_test.go +++ b/event_new/event_test.go @@ -14,7 +14,6 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - // Copyright 2015, 2016 Eris Industries (UK) Ltd. // This file is part of Eris-RT diff --git a/event_new/example_test.go b/event_new/example_test.go index c390e4a6123611d22bff4ce6a674baa65328f1b7..439589021747fcbd53b6fb2663b9b6d6547c2f65 100644 --- a/event_new/example_test.go +++ b/event_new/example_test.go @@ -14,7 +14,6 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - // Copyright 2015, 2016 Eris Industries (UK) Ltd. // This file is part of Eris-RT diff --git a/event_new/filter/filter.go b/event_new/filter/filter.go index 64b159e65147a846a3d7ad9cca08c0f5fc28503c..9742057dd9a16ee100c95bc86b16a715d654b219 100644 --- a/event_new/filter/filter.go +++ b/event_new/filter/filter.go @@ -14,7 +14,6 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - // Copyright 2015, 2016 Eris Industries (UK) Ltd. // This file is part of Eris-RT diff --git a/event_new/filter/filter_test.go b/event_new/filter/filter_test.go index cb1f5d2ca9d84ffa71d92764115365a77460e752..c70d1ecce6e8b9c0fb120c8eb2d6f83d049cf48e 100644 --- a/event_new/filter/filter_test.go +++ b/event_new/filter/filter_test.go @@ -14,7 +14,6 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - // Copyright 2015, 2016 Eris Industries (UK) Ltd. // This file is part of Eris-RT diff --git a/event_new/filter/generic_filter.go b/event_new/filter/generic_filter.go index 8e421ac33398c734b514399fb178dffb085cf584..6b475b97214502d5646c2ab7ccb586f33b3b8484 100644 --- a/event_new/filter/generic_filter.go +++ b/event_new/filter/generic_filter.go @@ -14,7 +14,6 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - // Copyright 2015, 2016 Eris Industries (UK) Ltd. // This file is part of Eris-RT diff --git a/manager/config.go b/manager/config.go index 9c1632815a42744972ade390d4e85922bb215027..28c84e21dac88ac0b6763eddbca1c7236e701519 100644 --- a/manager/config.go +++ b/manager/config.go @@ -20,19 +20,19 @@ package manager import ( - erismint "github.com/eris-ltd/eris-db/manager/eris-mint" + erismint "github.com/eris-ltd/eris-db/manager/eris-mint" ) //------------------------------------------------------------------------------ // Helper functions func AssertValidApplicationManagerModule(name, minorVersionString string) bool { - switch name { - case "erismint" : - return minorVersionString == erismint.GetErisMintVersion().GetMinorVersionString() - case "geth" : - // TODO: [ben] implement Geth 1.4 as an application manager - return false - } - return false + switch name { + case "erismint": + return minorVersionString == erismint.GetErisMintVersion().GetMinorVersionString() + case "geth": + // TODO: [ben] implement Geth 1.4 as an application manager + return false + } + return false } diff --git a/manager/eris-mint/accounts.go b/manager/eris-mint/accounts.go index af9fe1f931a7971f2ff27518317be713ab558ca8..67edea27409280a7263cf7db9b48e2e7c1614c9a 100644 --- a/manager/eris-mint/accounts.go +++ b/manager/eris-mint/accounts.go @@ -19,17 +19,17 @@ package erismint import ( - "bytes" - "encoding/hex" - "fmt" - "sync" + "bytes" + "encoding/hex" + "fmt" + "sync" - tendermint_common "github.com/tendermint/go-common" + tendermint_common "github.com/tendermint/go-common" - account "github.com/eris-ltd/eris-db/account" - core_types "github.com/eris-ltd/eris-db/core/types" + account "github.com/eris-ltd/eris-db/account" + core_types "github.com/eris-ltd/eris-db/core/types" definitions "github.com/eris-ltd/eris-db/definitions" - event "github.com/eris-ltd/eris-db/event" + event "github.com/eris-ltd/eris-db/event" ) // NOTE [ben] Compiler check to ensure Accounts successfully implements @@ -38,193 +38,193 @@ var _ definitions.Accounts = (*accounts)(nil) // The accounts struct has methods for working with accounts. type accounts struct { - erisMint *ErisMint - filterFactory *event.FilterFactory + erisMint *ErisMint + filterFactory *event.FilterFactory } func newAccounts(erisMint *ErisMint) *accounts { - ff := event.NewFilterFactory() + ff := event.NewFilterFactory() - ff.RegisterFilterPool("code", &sync.Pool{ - New: func() interface{} { - return &AccountCodeFilter{} - }, - }) + ff.RegisterFilterPool("code", &sync.Pool{ + New: func() interface{} { + return &AccountCodeFilter{} + }, + }) - ff.RegisterFilterPool("balance", &sync.Pool{ - New: func() interface{} { - return &AccountBalanceFilter{} - }, - }) + ff.RegisterFilterPool("balance", &sync.Pool{ + New: func() interface{} { + return &AccountBalanceFilter{} + }, + }) - return &accounts{erisMint, ff} + return &accounts{erisMint, ff} } // Generate a new Private Key Account. func (this *accounts) GenPrivAccount() (*account.PrivAccount, error) { - pa := account.GenPrivAccount() - return pa, nil + pa := account.GenPrivAccount() + return pa, nil } // Generate a new Private Key Account. func (this *accounts) GenPrivAccountFromKey(privKey []byte) ( - *account.PrivAccount, error) { - if len(privKey) != 64 { - return nil, fmt.Errorf("Private key is not 64 bytes long.") - } - fmt.Printf("PK BYTES FROM ACCOUNTS: %x\n", privKey) - pa := account.GenPrivAccountFromPrivKeyBytes(privKey) - return pa, nil + *account.PrivAccount, error) { + if len(privKey) != 64 { + return nil, fmt.Errorf("Private key is not 64 bytes long.") + } + fmt.Printf("PK BYTES FROM ACCOUNTS: %x\n", privKey) + pa := account.GenPrivAccountFromPrivKeyBytes(privKey) + return pa, nil } // Get all accounts. func (this *accounts) Accounts(fda []*event.FilterData) ( - *core_types.AccountList, error) { - accounts := make([]*account.Account, 0) - state := this.erisMint.GetState() - filter, err := this.filterFactory.NewFilter(fda) - if err != nil { - return nil, fmt.Errorf("Error in query: " + err.Error()) - } - state.GetAccounts().Iterate(func(key, value []byte) bool { - acc := account.DecodeAccount(value) - if filter.Match(acc) { - accounts = append(accounts, acc) - } - return false - }) - return &core_types.AccountList{accounts}, nil + *core_types.AccountList, error) { + accounts := make([]*account.Account, 0) + state := this.erisMint.GetState() + filter, err := this.filterFactory.NewFilter(fda) + if err != nil { + return nil, fmt.Errorf("Error in query: " + err.Error()) + } + state.GetAccounts().Iterate(func(key, value []byte) bool { + acc := account.DecodeAccount(value) + if filter.Match(acc) { + accounts = append(accounts, acc) + } + return false + }) + return &core_types.AccountList{accounts}, nil } // Get an account. func (this *accounts) Account(address []byte) (*account.Account, error) { - cache := this.erisMint.GetState() // NOTE: we want to read from mempool! - acc := cache.GetAccount(address) - if acc == nil { - acc = this.newAcc(address) - } - return acc, nil + cache := this.erisMint.GetState() // NOTE: we want to read from mempool! + acc := cache.GetAccount(address) + if acc == nil { + acc = this.newAcc(address) + } + return acc, nil } // Get the value stored at 'key' in the account with address 'address' // Both the key and value is returned. func (this *accounts) StorageAt(address, key []byte) (*core_types.StorageItem, - error) { - state := this.erisMint.GetState() - account := state.GetAccount(address) - if account == nil { - return &core_types.StorageItem{key, []byte{}}, nil - } - storageRoot := account.StorageRoot - storageTree := state.LoadStorage(storageRoot) - - _, value, _ := storageTree.Get(tendermint_common.LeftPadWord256(key).Bytes()) - if value == nil { - return &core_types.StorageItem{key, []byte{}}, nil - } - return &core_types.StorageItem{key, value}, nil + error) { + state := this.erisMint.GetState() + account := state.GetAccount(address) + if account == nil { + return &core_types.StorageItem{key, []byte{}}, nil + } + storageRoot := account.StorageRoot + storageTree := state.LoadStorage(storageRoot) + + _, value, _ := storageTree.Get(tendermint_common.LeftPadWord256(key).Bytes()) + if value == nil { + return &core_types.StorageItem{key, []byte{}}, nil + } + return &core_types.StorageItem{key, value}, nil } // Get the storage of the account with address 'address'. func (this *accounts) Storage(address []byte) (*core_types.Storage, error) { - state := this.erisMint.GetState() - account := state.GetAccount(address) - storageItems := make([]core_types.StorageItem, 0) - if account == nil { - return &core_types.Storage{nil, storageItems}, nil - } - storageRoot := account.StorageRoot - storageTree := state.LoadStorage(storageRoot) - - storageTree.Iterate(func(key, value []byte) bool { - storageItems = append(storageItems, core_types.StorageItem{ - key, value}) - return false - }) - return &core_types.Storage{storageRoot, storageItems}, nil + state := this.erisMint.GetState() + account := state.GetAccount(address) + storageItems := make([]core_types.StorageItem, 0) + if account == nil { + return &core_types.Storage{nil, storageItems}, nil + } + storageRoot := account.StorageRoot + storageTree := state.LoadStorage(storageRoot) + + storageTree.Iterate(func(key, value []byte) bool { + storageItems = append(storageItems, core_types.StorageItem{ + key, value}) + return false + }) + return &core_types.Storage{storageRoot, storageItems}, nil } // Create a new account. func (this *accounts) newAcc(address []byte) *account.Account { - return &account.Account{ - Address: address, - PubKey: nil, - Sequence: 0, - Balance: 0, - Code: nil, - StorageRoot: nil, - } + return &account.Account{ + Address: address, + PubKey: nil, + Sequence: 0, + Balance: 0, + Code: nil, + StorageRoot: nil, + } } // Filter for account code. // Ops: == or != // Could be used to match against nil, to see if an account is a contract account. type AccountCodeFilter struct { - op string - value []byte - match func([]byte, []byte) bool + op string + value []byte + match func([]byte, []byte) bool } func (this *AccountCodeFilter) Configure(fd *event.FilterData) error { - op := fd.Op - val, err := hex.DecodeString(fd.Value) - - if err != nil { - return fmt.Errorf("Wrong value type.") - } - if op == "==" { - this.match = func(a, b []byte) bool { - return bytes.Equal(a, b) - } - } else if op == "!=" { - this.match = func(a, b []byte) bool { - return !bytes.Equal(a, b) - } - } else { - return fmt.Errorf("Op: " + this.op + " is not supported for 'code' filtering") - } - this.op = op - this.value = val - return nil + op := fd.Op + val, err := hex.DecodeString(fd.Value) + + if err != nil { + return fmt.Errorf("Wrong value type.") + } + if op == "==" { + this.match = func(a, b []byte) bool { + return bytes.Equal(a, b) + } + } else if op == "!=" { + this.match = func(a, b []byte) bool { + return !bytes.Equal(a, b) + } + } else { + return fmt.Errorf("Op: " + this.op + " is not supported for 'code' filtering") + } + this.op = op + this.value = val + return nil } func (this *AccountCodeFilter) Match(v interface{}) bool { - acc, ok := v.(*account.Account) - if !ok { - return false - } - return this.match(acc.Code, this.value) + acc, ok := v.(*account.Account) + if !ok { + return false + } + return this.match(acc.Code, this.value) } // Filter for account balance. // Ops: All type AccountBalanceFilter struct { - op string - value int64 - match func(int64, int64) bool + op string + value int64 + match func(int64, int64) bool } func (this *AccountBalanceFilter) Configure(fd *event.FilterData) error { - val, err := event.ParseNumberValue(fd.Value) - if err != nil { - return err - } - match, err2 := event.GetRangeFilter(fd.Op, "balance") - if err2 != nil { - return err2 - } - this.match = match - this.op = fd.Op - this.value = val - return nil + val, err := event.ParseNumberValue(fd.Value) + if err != nil { + return err + } + match, err2 := event.GetRangeFilter(fd.Op, "balance") + if err2 != nil { + return err2 + } + this.match = match + this.op = fd.Op + this.value = val + return nil } func (this *AccountBalanceFilter) Match(v interface{}) bool { - acc, ok := v.(*account.Account) - if !ok { - return false - } - return this.match(int64(acc.Balance), this.value) + acc, ok := v.(*account.Account) + if !ok { + return false + } + return this.match(int64(acc.Balance), this.value) } diff --git a/manager/eris-mint/blockchain.go b/manager/eris-mint/blockchain.go index 398f24269234d4fbb10c8102550283e7b09cff72..d4a7475a9fc8ec65d9add666bdc3d9e486ca50d1 100644 --- a/manager/eris-mint/blockchain.go +++ b/manager/eris-mint/blockchain.go @@ -27,13 +27,13 @@ import ( "strings" "sync" - dbm "github.com/tendermint/go-db" - "github.com/tendermint/tendermint/types" + dbm "github.com/tendermint/go-db" + "github.com/tendermint/tendermint/types" - core_types "github.com/eris-ltd/eris-db/core/types" + core_types "github.com/eris-ltd/eris-db/core/types" definitions "github.com/eris-ltd/eris-db/definitions" - event "github.com/eris-ltd/eris-db/event" - state "github.com/eris-ltd/eris-db/manager/eris-mint/state" + event "github.com/eris-ltd/eris-db/event" + state "github.com/eris-ltd/eris-db/manager/eris-mint/state" ) const BLOCK_MAX = 50 diff --git a/manager/eris-mint/consensus.go b/manager/eris-mint/consensus.go index 8dccb91fba5691808a30e583bc6d6aeffd110014..386adcc1316548ec7433893bf8b507f98ecd07d9 100644 --- a/manager/eris-mint/consensus.go +++ b/manager/eris-mint/consensus.go @@ -18,10 +18,11 @@ // for the pipe to call into the ErisMint application package erismint + import ( "github.com/tendermint/tendermint/types" - core_types "github.com/eris-ltd/eris-db/core/types" + core_types "github.com/eris-ltd/eris-db/core/types" definitions "github.com/eris-ltd/eris-db/definitions" ) @@ -66,5 +67,5 @@ func (this *consensus) Validators() (*core_types.ValidatorList, error) { })*/ return &core_types.ValidatorList{blockHeight, bondedValidators, - unbondingValidators}, nil + unbondingValidators}, nil } diff --git a/manager/eris-mint/eris-mint_test.go b/manager/eris-mint/eris-mint_test.go index cc3a7a8815b1259525c5239fe9b91bc1fcc352d7..98a03d2ff4b5abf6df26a2550dbd57e28192ad50 100644 --- a/manager/eris-mint/eris-mint_test.go +++ b/manager/eris-mint/eris-mint_test.go @@ -17,16 +17,16 @@ package erismint import ( - "testing" + "testing" - assert "github.com/stretchr/testify/assert" + assert "github.com/stretchr/testify/assert" ) func TestCompatibleConsensus(t *testing.T) { - // TODO: [ben] expand by constructing and elemetary testing for each listed - // compatible consensus engine + // TODO: [ben] expand by constructing and elemetary testing for each listed + // compatible consensus engine - for _, listedConsensus := range compatibleConsensus { - assert.Nil(t, AssertCompatibleConsensus(listedConsensus)) - } + for _, listedConsensus := range compatibleConsensus { + assert.Nil(t, AssertCompatibleConsensus(listedConsensus)) + } } diff --git a/manager/eris-mint/evm/sha3/keccakf.go b/manager/eris-mint/evm/sha3/keccakf.go index 3baf13ba3d89ff1b0274711182f008dc971cb937..107156cc9d325766aaa3dccf737fb7201334641d 100644 --- a/manager/eris-mint/evm/sha3/keccakf.go +++ b/manager/eris-mint/evm/sha3/keccakf.go @@ -11,161 +11,161 @@ package sha3 // rc stores the round constants for use in the ι step. var rc = [...]uint64{ - 0x0000000000000001, - 0x0000000000008082, - 0x800000000000808A, - 0x8000000080008000, - 0x000000000000808B, - 0x0000000080000001, - 0x8000000080008081, - 0x8000000000008009, - 0x000000000000008A, - 0x0000000000000088, - 0x0000000080008009, - 0x000000008000000A, - 0x000000008000808B, - 0x800000000000008B, - 0x8000000000008089, - 0x8000000000008003, - 0x8000000000008002, - 0x8000000000000080, - 0x000000000000800A, - 0x800000008000000A, - 0x8000000080008081, - 0x8000000000008080, - 0x0000000080000001, - 0x8000000080008008, + 0x0000000000000001, + 0x0000000000008082, + 0x800000000000808A, + 0x8000000080008000, + 0x000000000000808B, + 0x0000000080000001, + 0x8000000080008081, + 0x8000000000008009, + 0x000000000000008A, + 0x0000000000000088, + 0x0000000080008009, + 0x000000008000000A, + 0x000000008000808B, + 0x800000000000008B, + 0x8000000000008089, + 0x8000000000008003, + 0x8000000000008002, + 0x8000000000000080, + 0x000000000000800A, + 0x800000008000000A, + 0x8000000080008081, + 0x8000000000008080, + 0x0000000080000001, + 0x8000000080008008, } // ro_xx represent the rotation offsets for use in the χ step. // Defining them as const instead of in an array allows the compiler to insert constant shifts. const ( - ro_00 = 0 - ro_01 = 36 - ro_02 = 3 - ro_03 = 41 - ro_04 = 18 - ro_05 = 1 - ro_06 = 44 - ro_07 = 10 - ro_08 = 45 - ro_09 = 2 - ro_10 = 62 - ro_11 = 6 - ro_12 = 43 - ro_13 = 15 - ro_14 = 61 - ro_15 = 28 - ro_16 = 55 - ro_17 = 25 - ro_18 = 21 - ro_19 = 56 - ro_20 = 27 - ro_21 = 20 - ro_22 = 39 - ro_23 = 8 - ro_24 = 14 + ro_00 = 0 + ro_01 = 36 + ro_02 = 3 + ro_03 = 41 + ro_04 = 18 + ro_05 = 1 + ro_06 = 44 + ro_07 = 10 + ro_08 = 45 + ro_09 = 2 + ro_10 = 62 + ro_11 = 6 + ro_12 = 43 + ro_13 = 15 + ro_14 = 61 + ro_15 = 28 + ro_16 = 55 + ro_17 = 25 + ro_18 = 21 + ro_19 = 56 + ro_20 = 27 + ro_21 = 20 + ro_22 = 39 + ro_23 = 8 + ro_24 = 14 ) // keccakF computes the complete Keccak-f function consisting of 24 rounds with a different // constant (rc) in each round. This implementation fully unrolls the round function to avoid // inner loops, as well as pre-calculating shift offsets. func (d *digest) keccakF() { - for _, roundConstant := range rc { - // θ step - d.c[0] = d.a[0] ^ d.a[5] ^ d.a[10] ^ d.a[15] ^ d.a[20] - d.c[1] = d.a[1] ^ d.a[6] ^ d.a[11] ^ d.a[16] ^ d.a[21] - d.c[2] = d.a[2] ^ d.a[7] ^ d.a[12] ^ d.a[17] ^ d.a[22] - d.c[3] = d.a[3] ^ d.a[8] ^ d.a[13] ^ d.a[18] ^ d.a[23] - d.c[4] = d.a[4] ^ d.a[9] ^ d.a[14] ^ d.a[19] ^ d.a[24] + for _, roundConstant := range rc { + // θ step + d.c[0] = d.a[0] ^ d.a[5] ^ d.a[10] ^ d.a[15] ^ d.a[20] + d.c[1] = d.a[1] ^ d.a[6] ^ d.a[11] ^ d.a[16] ^ d.a[21] + d.c[2] = d.a[2] ^ d.a[7] ^ d.a[12] ^ d.a[17] ^ d.a[22] + d.c[3] = d.a[3] ^ d.a[8] ^ d.a[13] ^ d.a[18] ^ d.a[23] + d.c[4] = d.a[4] ^ d.a[9] ^ d.a[14] ^ d.a[19] ^ d.a[24] - d.d[0] = d.c[4] ^ (d.c[1]<<1 ^ d.c[1]>>63) - d.d[1] = d.c[0] ^ (d.c[2]<<1 ^ d.c[2]>>63) - d.d[2] = d.c[1] ^ (d.c[3]<<1 ^ d.c[3]>>63) - d.d[3] = d.c[2] ^ (d.c[4]<<1 ^ d.c[4]>>63) - d.d[4] = d.c[3] ^ (d.c[0]<<1 ^ d.c[0]>>63) + d.d[0] = d.c[4] ^ (d.c[1]<<1 ^ d.c[1]>>63) + d.d[1] = d.c[0] ^ (d.c[2]<<1 ^ d.c[2]>>63) + d.d[2] = d.c[1] ^ (d.c[3]<<1 ^ d.c[3]>>63) + d.d[3] = d.c[2] ^ (d.c[4]<<1 ^ d.c[4]>>63) + d.d[4] = d.c[3] ^ (d.c[0]<<1 ^ d.c[0]>>63) - d.a[0] ^= d.d[0] - d.a[1] ^= d.d[1] - d.a[2] ^= d.d[2] - d.a[3] ^= d.d[3] - d.a[4] ^= d.d[4] - d.a[5] ^= d.d[0] - d.a[6] ^= d.d[1] - d.a[7] ^= d.d[2] - d.a[8] ^= d.d[3] - d.a[9] ^= d.d[4] - d.a[10] ^= d.d[0] - d.a[11] ^= d.d[1] - d.a[12] ^= d.d[2] - d.a[13] ^= d.d[3] - d.a[14] ^= d.d[4] - d.a[15] ^= d.d[0] - d.a[16] ^= d.d[1] - d.a[17] ^= d.d[2] - d.a[18] ^= d.d[3] - d.a[19] ^= d.d[4] - d.a[20] ^= d.d[0] - d.a[21] ^= d.d[1] - d.a[22] ^= d.d[2] - d.a[23] ^= d.d[3] - d.a[24] ^= d.d[4] + d.a[0] ^= d.d[0] + d.a[1] ^= d.d[1] + d.a[2] ^= d.d[2] + d.a[3] ^= d.d[3] + d.a[4] ^= d.d[4] + d.a[5] ^= d.d[0] + d.a[6] ^= d.d[1] + d.a[7] ^= d.d[2] + d.a[8] ^= d.d[3] + d.a[9] ^= d.d[4] + d.a[10] ^= d.d[0] + d.a[11] ^= d.d[1] + d.a[12] ^= d.d[2] + d.a[13] ^= d.d[3] + d.a[14] ^= d.d[4] + d.a[15] ^= d.d[0] + d.a[16] ^= d.d[1] + d.a[17] ^= d.d[2] + d.a[18] ^= d.d[3] + d.a[19] ^= d.d[4] + d.a[20] ^= d.d[0] + d.a[21] ^= d.d[1] + d.a[22] ^= d.d[2] + d.a[23] ^= d.d[3] + d.a[24] ^= d.d[4] - // Ï and Ï€ steps - d.b[0] = d.a[0] - d.b[1] = d.a[6]<<ro_06 ^ d.a[6]>>(64-ro_06) - d.b[2] = d.a[12]<<ro_12 ^ d.a[12]>>(64-ro_12) - d.b[3] = d.a[18]<<ro_18 ^ d.a[18]>>(64-ro_18) - d.b[4] = d.a[24]<<ro_24 ^ d.a[24]>>(64-ro_24) - d.b[5] = d.a[3]<<ro_15 ^ d.a[3]>>(64-ro_15) - d.b[6] = d.a[9]<<ro_21 ^ d.a[9]>>(64-ro_21) - d.b[7] = d.a[10]<<ro_02 ^ d.a[10]>>(64-ro_02) - d.b[8] = d.a[16]<<ro_08 ^ d.a[16]>>(64-ro_08) - d.b[9] = d.a[22]<<ro_14 ^ d.a[22]>>(64-ro_14) - d.b[10] = d.a[1]<<ro_05 ^ d.a[1]>>(64-ro_05) - d.b[11] = d.a[7]<<ro_11 ^ d.a[7]>>(64-ro_11) - d.b[12] = d.a[13]<<ro_17 ^ d.a[13]>>(64-ro_17) - d.b[13] = d.a[19]<<ro_23 ^ d.a[19]>>(64-ro_23) - d.b[14] = d.a[20]<<ro_04 ^ d.a[20]>>(64-ro_04) - d.b[15] = d.a[4]<<ro_20 ^ d.a[4]>>(64-ro_20) - d.b[16] = d.a[5]<<ro_01 ^ d.a[5]>>(64-ro_01) - d.b[17] = d.a[11]<<ro_07 ^ d.a[11]>>(64-ro_07) - d.b[18] = d.a[17]<<ro_13 ^ d.a[17]>>(64-ro_13) - d.b[19] = d.a[23]<<ro_19 ^ d.a[23]>>(64-ro_19) - d.b[20] = d.a[2]<<ro_10 ^ d.a[2]>>(64-ro_10) - d.b[21] = d.a[8]<<ro_16 ^ d.a[8]>>(64-ro_16) - d.b[22] = d.a[14]<<ro_22 ^ d.a[14]>>(64-ro_22) - d.b[23] = d.a[15]<<ro_03 ^ d.a[15]>>(64-ro_03) - d.b[24] = d.a[21]<<ro_09 ^ d.a[21]>>(64-ro_09) + // Ï and Ï€ steps + d.b[0] = d.a[0] + d.b[1] = d.a[6]<<ro_06 ^ d.a[6]>>(64-ro_06) + d.b[2] = d.a[12]<<ro_12 ^ d.a[12]>>(64-ro_12) + d.b[3] = d.a[18]<<ro_18 ^ d.a[18]>>(64-ro_18) + d.b[4] = d.a[24]<<ro_24 ^ d.a[24]>>(64-ro_24) + d.b[5] = d.a[3]<<ro_15 ^ d.a[3]>>(64-ro_15) + d.b[6] = d.a[9]<<ro_21 ^ d.a[9]>>(64-ro_21) + d.b[7] = d.a[10]<<ro_02 ^ d.a[10]>>(64-ro_02) + d.b[8] = d.a[16]<<ro_08 ^ d.a[16]>>(64-ro_08) + d.b[9] = d.a[22]<<ro_14 ^ d.a[22]>>(64-ro_14) + d.b[10] = d.a[1]<<ro_05 ^ d.a[1]>>(64-ro_05) + d.b[11] = d.a[7]<<ro_11 ^ d.a[7]>>(64-ro_11) + d.b[12] = d.a[13]<<ro_17 ^ d.a[13]>>(64-ro_17) + d.b[13] = d.a[19]<<ro_23 ^ d.a[19]>>(64-ro_23) + d.b[14] = d.a[20]<<ro_04 ^ d.a[20]>>(64-ro_04) + d.b[15] = d.a[4]<<ro_20 ^ d.a[4]>>(64-ro_20) + d.b[16] = d.a[5]<<ro_01 ^ d.a[5]>>(64-ro_01) + d.b[17] = d.a[11]<<ro_07 ^ d.a[11]>>(64-ro_07) + d.b[18] = d.a[17]<<ro_13 ^ d.a[17]>>(64-ro_13) + d.b[19] = d.a[23]<<ro_19 ^ d.a[23]>>(64-ro_19) + d.b[20] = d.a[2]<<ro_10 ^ d.a[2]>>(64-ro_10) + d.b[21] = d.a[8]<<ro_16 ^ d.a[8]>>(64-ro_16) + d.b[22] = d.a[14]<<ro_22 ^ d.a[14]>>(64-ro_22) + d.b[23] = d.a[15]<<ro_03 ^ d.a[15]>>(64-ro_03) + d.b[24] = d.a[21]<<ro_09 ^ d.a[21]>>(64-ro_09) - // χ step - d.a[0] = d.b[0] ^ (^d.b[1] & d.b[2]) - d.a[1] = d.b[1] ^ (^d.b[2] & d.b[3]) - d.a[2] = d.b[2] ^ (^d.b[3] & d.b[4]) - d.a[3] = d.b[3] ^ (^d.b[4] & d.b[0]) - d.a[4] = d.b[4] ^ (^d.b[0] & d.b[1]) - d.a[5] = d.b[5] ^ (^d.b[6] & d.b[7]) - d.a[6] = d.b[6] ^ (^d.b[7] & d.b[8]) - d.a[7] = d.b[7] ^ (^d.b[8] & d.b[9]) - d.a[8] = d.b[8] ^ (^d.b[9] & d.b[5]) - d.a[9] = d.b[9] ^ (^d.b[5] & d.b[6]) - d.a[10] = d.b[10] ^ (^d.b[11] & d.b[12]) - d.a[11] = d.b[11] ^ (^d.b[12] & d.b[13]) - d.a[12] = d.b[12] ^ (^d.b[13] & d.b[14]) - d.a[13] = d.b[13] ^ (^d.b[14] & d.b[10]) - d.a[14] = d.b[14] ^ (^d.b[10] & d.b[11]) - d.a[15] = d.b[15] ^ (^d.b[16] & d.b[17]) - d.a[16] = d.b[16] ^ (^d.b[17] & d.b[18]) - d.a[17] = d.b[17] ^ (^d.b[18] & d.b[19]) - d.a[18] = d.b[18] ^ (^d.b[19] & d.b[15]) - d.a[19] = d.b[19] ^ (^d.b[15] & d.b[16]) - d.a[20] = d.b[20] ^ (^d.b[21] & d.b[22]) - d.a[21] = d.b[21] ^ (^d.b[22] & d.b[23]) - d.a[22] = d.b[22] ^ (^d.b[23] & d.b[24]) - d.a[23] = d.b[23] ^ (^d.b[24] & d.b[20]) - d.a[24] = d.b[24] ^ (^d.b[20] & d.b[21]) + // χ step + d.a[0] = d.b[0] ^ (^d.b[1] & d.b[2]) + d.a[1] = d.b[1] ^ (^d.b[2] & d.b[3]) + d.a[2] = d.b[2] ^ (^d.b[3] & d.b[4]) + d.a[3] = d.b[3] ^ (^d.b[4] & d.b[0]) + d.a[4] = d.b[4] ^ (^d.b[0] & d.b[1]) + d.a[5] = d.b[5] ^ (^d.b[6] & d.b[7]) + d.a[6] = d.b[6] ^ (^d.b[7] & d.b[8]) + d.a[7] = d.b[7] ^ (^d.b[8] & d.b[9]) + d.a[8] = d.b[8] ^ (^d.b[9] & d.b[5]) + d.a[9] = d.b[9] ^ (^d.b[5] & d.b[6]) + d.a[10] = d.b[10] ^ (^d.b[11] & d.b[12]) + d.a[11] = d.b[11] ^ (^d.b[12] & d.b[13]) + d.a[12] = d.b[12] ^ (^d.b[13] & d.b[14]) + d.a[13] = d.b[13] ^ (^d.b[14] & d.b[10]) + d.a[14] = d.b[14] ^ (^d.b[10] & d.b[11]) + d.a[15] = d.b[15] ^ (^d.b[16] & d.b[17]) + d.a[16] = d.b[16] ^ (^d.b[17] & d.b[18]) + d.a[17] = d.b[17] ^ (^d.b[18] & d.b[19]) + d.a[18] = d.b[18] ^ (^d.b[19] & d.b[15]) + d.a[19] = d.b[19] ^ (^d.b[15] & d.b[16]) + d.a[20] = d.b[20] ^ (^d.b[21] & d.b[22]) + d.a[21] = d.b[21] ^ (^d.b[22] & d.b[23]) + d.a[22] = d.b[22] ^ (^d.b[23] & d.b[24]) + d.a[23] = d.b[23] ^ (^d.b[24] & d.b[20]) + d.a[24] = d.b[24] ^ (^d.b[20] & d.b[21]) - // ι step - d.a[0] ^= roundConstant - } + // ι step + d.a[0] ^= roundConstant + } } diff --git a/manager/eris-mint/evm/snative.go b/manager/eris-mint/evm/snative.go index 60c98b38fcb359dad9ab9deb7f5acbbedaabc126..b0a7385e3f96b005f6cf008dd36b22cb5f836449 100644 --- a/manager/eris-mint/evm/snative.go +++ b/manager/eris-mint/evm/snative.go @@ -4,8 +4,8 @@ import ( "encoding/hex" "fmt" - . "github.com/tendermint/go-common" ptypes "github.com/eris-ltd/eris-db/permission/types" + . "github.com/tendermint/go-common" ) //------------------------------------------------------------------------------------------------ diff --git a/manager/eris-mint/evm/test/fake_app_state.go b/manager/eris-mint/evm/test/fake_app_state.go index c910a1c3cbad0afc4ef7445d8622e74b20dac9f5..c27e54256fe7ea102ffea6bd3d12431382f1ec52 100644 --- a/manager/eris-mint/evm/test/fake_app_state.go +++ b/manager/eris-mint/evm/test/fake_app_state.go @@ -1,9 +1,9 @@ package vm import ( - . "github.com/tendermint/go-common" . "github.com/eris-ltd/eris-db/manager/eris-mint/evm" "github.com/eris-ltd/eris-db/manager/eris-mint/evm/sha3" + . "github.com/tendermint/go-common" ) type FakeAppState struct { diff --git a/manager/eris-mint/evm/types.go b/manager/eris-mint/evm/types.go index 5588d996161f338f6d6b3b8e928b74d28734d0dd..a886546e31f8148f7c2c20511e80cfec69b76714 100644 --- a/manager/eris-mint/evm/types.go +++ b/manager/eris-mint/evm/types.go @@ -1,8 +1,8 @@ package vm import ( - . "github.com/tendermint/go-common" ptypes "github.com/eris-ltd/eris-db/permission/types" + . "github.com/tendermint/go-common" ) const ( diff --git a/manager/eris-mint/namereg.go b/manager/eris-mint/namereg.go index cc161feb19dc2bd00dd5940e48b6483bb0de327b..0fd28700be2a171ff80a15bb238a9326fb704253 100644 --- a/manager/eris-mint/namereg.go +++ b/manager/eris-mint/namereg.go @@ -27,8 +27,8 @@ import ( sm "github.com/eris-ltd/eris-db/manager/eris-mint/state" "github.com/eris-ltd/eris-db/txs" - core_types "github.com/eris-ltd/eris-db/core/types" - event "github.com/eris-ltd/eris-db/event" + core_types "github.com/eris-ltd/eris-db/core/types" + event "github.com/eris-ltd/eris-db/event" ) // The net struct. diff --git a/manager/eris-mint/net.go b/manager/eris-mint/net.go index 7b63a924e6f4de107bc93762c2a79590d6510dee..66bd60c3f7a0f35fb2ad40c8056658986801f377 100644 --- a/manager/eris-mint/net.go +++ b/manager/eris-mint/net.go @@ -19,7 +19,7 @@ package erismint import ( - core_types "github.com/eris-ltd/eris-db/core/types" + core_types "github.com/eris-ltd/eris-db/core/types" ) // TODO-RPC! @@ -35,8 +35,6 @@ func newNetwork() *network { //------------------------------------------------------------------------------ // Tendermint Pipe implementation - - //----------------------------------------------------------------------------- // Eris-DB v0 Pipe implementation diff --git a/manager/eris-mint/pipe.go b/manager/eris-mint/pipe.go index a5350898d6dcfda001a6bcb0a94555697cbcca92..07734946316ab0e3336d40026cc76a4f4e061a0b 100644 --- a/manager/eris-mint/pipe.go +++ b/manager/eris-mint/pipe.go @@ -17,48 +17,48 @@ package erismint import ( - "bytes" - "fmt" + "bytes" + "fmt" - crypto "github.com/tendermint/go-crypto" - db "github.com/tendermint/go-db" tendermint_common "github.com/tendermint/go-common" + crypto "github.com/tendermint/go-crypto" + db "github.com/tendermint/go-db" tendermint_events "github.com/tendermint/go-events" - tendermint_types "github.com/tendermint/tendermint/types" - tmsp_types "github.com/tendermint/tmsp/types" - wire "github.com/tendermint/go-wire" - - log "github.com/eris-ltd/eris-logger" - - account "github.com/eris-ltd/eris-db/account" - config "github.com/eris-ltd/eris-db/config" - definitions "github.com/eris-ltd/eris-db/definitions" - event "github.com/eris-ltd/eris-db/event" - manager_types "github.com/eris-ltd/eris-db/manager/types" + wire "github.com/tendermint/go-wire" + tendermint_types "github.com/tendermint/tendermint/types" + tmsp_types "github.com/tendermint/tmsp/types" + + log "github.com/eris-ltd/eris-logger" + + account "github.com/eris-ltd/eris-db/account" + config "github.com/eris-ltd/eris-db/config" + definitions "github.com/eris-ltd/eris-db/definitions" + event "github.com/eris-ltd/eris-db/event" + vm "github.com/eris-ltd/eris-db/manager/eris-mint/evm" + state "github.com/eris-ltd/eris-db/manager/eris-mint/state" + state_types "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" + manager_types "github.com/eris-ltd/eris-db/manager/types" rpc_tendermint_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" - state "github.com/eris-ltd/eris-db/manager/eris-mint/state" - state_types "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" - transaction "github.com/eris-ltd/eris-db/txs" - vm "github.com/eris-ltd/eris-db/manager/eris-mint/evm" + transaction "github.com/eris-ltd/eris-db/txs" ) type ErisMintPipe struct { - erisMintState *state.State - eventSwitch *tendermint_events.EventSwitch - erisMint *ErisMint - // Pipe implementations - accounts *accounts - blockchain *blockchain - consensus *consensus - events event.EventEmitter - namereg *namereg - network *network - transactor *transactor - // Consensus interface - consensusEngine definitions.ConsensusEngine + erisMintState *state.State + eventSwitch *tendermint_events.EventSwitch + erisMint *ErisMint + // Pipe implementations + accounts *accounts + blockchain *blockchain + consensus *consensus + events event.EventEmitter + namereg *namereg + network *network + transactor *transactor + // Consensus interface + consensusEngine definitions.ConsensusEngine // Genesis cache - genesisDoc *state_types.GenesisDoc - genesisState *state.State + genesisDoc *state_types.GenesisDoc + genesisState *state.State } // NOTE [ben] Compiler check to ensure ErisMintPipe successfully implements @@ -70,54 +70,54 @@ var _ definitions.Pipe = (*ErisMintPipe)(nil) var _ definitions.TendermintPipe = (*ErisMintPipe)(nil) func NewErisMintPipe(moduleConfig *config.ModuleConfig, - eventSwitch *tendermint_events.EventSwitch) (*ErisMintPipe, error) { - - startedState, genesisDoc, err := startState(moduleConfig.DataDir, - moduleConfig.Config.GetString("db_backend"), moduleConfig.GenesisFile, - moduleConfig.ChainId) - if err != nil { - return nil, fmt.Errorf("Failed to start state: %v", err) - } - // assert ChainId matches genesis ChainId - log.WithFields(log.Fields{ - "chainId": startedState.ChainID, - "lastBlockHeight": startedState.LastBlockHeight, - "lastBlockHash": startedState.LastBlockHash, - }).Debug("Loaded state") - // start the application - erisMint := NewErisMint(startedState, eventSwitch) - - // NOTE: [ben] Set Host opens an RPC pipe to Tendermint; this is a remnant - // of the old Eris-DB / Tendermint and should be considered as an in-process - // call when possible - tendermintHost := moduleConfig.Config.GetString("tendermint_host") - erisMint.SetHostAddress(tendermintHost) - - // initialise the components of the pipe - events := newEvents(eventSwitch) - accounts := newAccounts(erisMint) - namereg := newNameReg(erisMint) - transactor := newTransactor(moduleConfig.ChainId, eventSwitch, erisMint, - events) - // TODO: make interface to tendermint core's rpc for these - // blockchain := newBlockchain(chainID, genDocFile, blockStore) - // consensus := newConsensus(erisdbApp) - // net := newNetwork(erisdbApp) - - return &ErisMintPipe { - erisMintState: startedState, - eventSwitch: eventSwitch, - erisMint: erisMint, - accounts: accounts, - events: events, - namereg: namereg, - transactor: transactor, + eventSwitch *tendermint_events.EventSwitch) (*ErisMintPipe, error) { + + startedState, genesisDoc, err := startState(moduleConfig.DataDir, + moduleConfig.Config.GetString("db_backend"), moduleConfig.GenesisFile, + moduleConfig.ChainId) + if err != nil { + return nil, fmt.Errorf("Failed to start state: %v", err) + } + // assert ChainId matches genesis ChainId + log.WithFields(log.Fields{ + "chainId": startedState.ChainID, + "lastBlockHeight": startedState.LastBlockHeight, + "lastBlockHash": startedState.LastBlockHash, + }).Debug("Loaded state") + // start the application + erisMint := NewErisMint(startedState, eventSwitch) + + // NOTE: [ben] Set Host opens an RPC pipe to Tendermint; this is a remnant + // of the old Eris-DB / Tendermint and should be considered as an in-process + // call when possible + tendermintHost := moduleConfig.Config.GetString("tendermint_host") + erisMint.SetHostAddress(tendermintHost) + + // initialise the components of the pipe + events := newEvents(eventSwitch) + accounts := newAccounts(erisMint) + namereg := newNameReg(erisMint) + transactor := newTransactor(moduleConfig.ChainId, eventSwitch, erisMint, + events) + // TODO: make interface to tendermint core's rpc for these + // blockchain := newBlockchain(chainID, genDocFile, blockStore) + // consensus := newConsensus(erisdbApp) + // net := newNetwork(erisdbApp) + + return &ErisMintPipe{ + erisMintState: startedState, + eventSwitch: eventSwitch, + erisMint: erisMint, + accounts: accounts, + events: events, + namereg: namereg, + transactor: transactor, network: newNetwork(), - consensus: nil, + consensus: nil, // genesis cache - genesisDoc: genesisDoc, - genesisState: nil, - }, nil + genesisDoc: genesisDoc, + genesisState: nil, + }, nil } //------------------------------------------------------------------------------ @@ -129,18 +129,18 @@ func NewErisMintPipe(moduleConfig *config.ModuleConfig, // If no state can be loaded, the JSON genesis file will be loaded into the // state database as the zero state. func startState(dataDir, backend, genesisFile, chainId string) (*state.State, - *state_types.GenesisDoc, error) { - // avoid Tendermints PanicSanity and return a clean error - if backend != db.DBBackendMemDB && - backend != db.DBBackendLevelDB { - return nil, nil, fmt.Errorf("Database backend %s is not supported by %s", - backend, GetErisMintVersion) - } - - stateDB := db.NewDB("erismint", backend, dataDir) - newState := state.LoadState(stateDB) - var genesisDoc *state_types.GenesisDoc - if newState == nil { + *state_types.GenesisDoc, error) { + // avoid Tendermints PanicSanity and return a clean error + if backend != db.DBBackendMemDB && + backend != db.DBBackendLevelDB { + return nil, nil, fmt.Errorf("Database backend %s is not supported by %s", + backend, GetErisMintVersion) + } + + stateDB := db.NewDB("erismint", backend, dataDir) + newState := state.LoadState(stateDB) + var genesisDoc *state_types.GenesisDoc + if newState == nil { genesisDoc, newState = state.MakeGenesisStateFromFile(stateDB, genesisFile) newState.Save() buf, n, err := new(bytes.Buffer), new(int), new(error) @@ -156,59 +156,59 @@ func startState(dataDir, backend, genesisFile, chainId string) (*state.State, if *err != nil { return nil, nil, fmt.Errorf("Unable to read genesisDoc from db on startState: %v", err) } - // assert loaded genesis doc has the same chainId as the provided chainId - if genesisDoc.ChainID != chainId { - return nil, nil, fmt.Errorf("ChainId (%s) loaded from genesis document in existing database does not match configuration chainId (%s).", - genesisDoc.ChainID, chainId) - } + // assert loaded genesis doc has the same chainId as the provided chainId + if genesisDoc.ChainID != chainId { + return nil, nil, fmt.Errorf("ChainId (%s) loaded from genesis document in existing database does not match configuration chainId (%s).", + genesisDoc.ChainID, chainId) + } } - return newState, genesisDoc, nil + return newState, genesisDoc, nil } //------------------------------------------------------------------------------ // Implement definitions.Pipe for ErisMintPipe func (pipe *ErisMintPipe) Accounts() definitions.Accounts { - return pipe.accounts + return pipe.accounts } func (pipe *ErisMintPipe) Blockchain() definitions.Blockchain { - return pipe.blockchain + return pipe.blockchain } func (pipe *ErisMintPipe) Consensus() definitions.Consensus { - return pipe.consensus + return pipe.consensus } func (pipe *ErisMintPipe) Events() event.EventEmitter { - return pipe.events + return pipe.events } func (pipe *ErisMintPipe) NameReg() definitions.NameReg { - return pipe.namereg + return pipe.namereg } func (pipe *ErisMintPipe) Net() definitions.Net { - return pipe.network + return pipe.network } func (pipe *ErisMintPipe) Transactor() definitions.Transactor { - return pipe.transactor + return pipe.transactor } func (pipe *ErisMintPipe) GetApplication() manager_types.Application { - return pipe.erisMint + return pipe.erisMint } func (pipe *ErisMintPipe) SetConsensusEngine( - consensus definitions.ConsensusEngine) error { - if pipe.consensusEngine == nil { - pipe.consensusEngine = consensus - } else { - return fmt.Errorf("Failed to set consensus engine for pipe; already set") - } - return nil + consensus definitions.ConsensusEngine) error { + if pipe.consensusEngine == nil { + pipe.consensusEngine = consensus + } else { + return fmt.Errorf("Failed to set consensus engine for pipe; already set") + } + return nil } func (pipe *ErisMintPipe) GetTendermintPipe() (definitions.TendermintPipe, @@ -254,7 +254,7 @@ func (pipe *ErisMintPipe) NetInfo() (*rpc_tendermint_types.ResultNetInfo, error) for _, listener := range pipe.consensusEngine.Listeners() { listeners = append(listeners, listener.String()) } - peers := pipe.consensusEngine.Peers() + peers := pipe.consensusEngine.Peers() return &rpc_tendermint_types.ResultNetInfo{ Listening: listening, Listeners: listeners, @@ -263,7 +263,7 @@ func (pipe *ErisMintPipe) NetInfo() (*rpc_tendermint_types.ResultNetInfo, error) } func (pipe *ErisMintPipe) Genesis() (*rpc_tendermint_types.ResultGenesis, error) { - return &rpc_tendermint_types.ResultGenesis { + return &rpc_tendermint_types.ResultGenesis{ // TODO: [ben] sharing pointer to unmutated GenesisDoc, but is not immutable Genesis: pipe.genesisDoc, }, nil @@ -461,7 +461,7 @@ func (pipe *ErisMintPipe) BroadcastTxSync(tx transaction.Tx) (*rpc_tendermint_ty error) { responseChannel := make(chan *tmsp_types.Response, 1) err := pipe.consensusEngine.BroadcastTransaction(transaction.EncodeTx(tx), - func(res *tmsp_types.Response) { responseChannel <- res }) + func(res *tmsp_types.Response) { responseChannel <- res }) if err != nil { return nil, fmt.Errorf("Error broadcasting transaction: %v", err) } @@ -475,7 +475,7 @@ func (pipe *ErisMintPipe) BroadcastTxSync(tx transaction.Tx) (*rpc_tendermint_ty if responseCheckTx == nil { return nil, fmt.Errorf("Error, application did not return CheckTx response.") } - resultBroadCastTx := &rpc_tendermint_types.ResultBroadcastTx { + resultBroadCastTx := &rpc_tendermint_types.ResultBroadcastTx{ Code: responseCheckTx.Code, Data: responseCheckTx.Data, Log: responseCheckTx.Log, @@ -489,7 +489,7 @@ func (pipe *ErisMintPipe) BroadcastTxSync(tx transaction.Tx) (*rpc_tendermint_ty return resultBroadCastTx, fmt.Errorf(resultBroadCastTx.Log) default: log.WithFields(log.Fields{ - "application": GetErisMintVersion().GetVersionString(), + "application": GetErisMintVersion().GetVersionString(), "TMSP_code_type": responseCheckTx.Code, }).Warn("Unknown error returned from Tendermint CheckTx on BroadcastTxSync") return resultBroadCastTx, fmt.Errorf("Unknown error returned: " + responseCheckTx.Log) diff --git a/manager/eris-mint/state/common.go b/manager/eris-mint/state/common.go index 0ea74ab8a17911f2a925566bb0529c6911f7b237..78315627205b958179113970622090efb85b3c26 100644 --- a/manager/eris-mint/state/common.go +++ b/manager/eris-mint/state/common.go @@ -1,9 +1,9 @@ package state import ( - . "github.com/tendermint/go-common" acm "github.com/eris-ltd/eris-db/account" "github.com/eris-ltd/eris-db/manager/eris-mint/evm" + . "github.com/tendermint/go-common" ) type AccountGetter interface { diff --git a/manager/eris-mint/state/genesis_test.go b/manager/eris-mint/state/genesis_test.go index ac50ef21e90e9f29f7bc2f66a2d7950fc4540a1b..73e7f92f4d4ad04f135f1270f6173dc5cae61832 100644 --- a/manager/eris-mint/state/genesis_test.go +++ b/manager/eris-mint/state/genesis_test.go @@ -9,8 +9,8 @@ import ( "time" acm "github.com/eris-ltd/eris-db/account" - ptypes "github.com/eris-ltd/eris-db/permission/types" . "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" + ptypes "github.com/eris-ltd/eris-db/permission/types" . "github.com/tendermint/go-common" tdb "github.com/tendermint/go-db" diff --git a/manager/eris-mint/state/permissions_test.go b/manager/eris-mint/state/permissions_test.go index b89ad5c7f553aacc20c71a33031077009ce55317..5c311405a0dec3288770b8cbd2e2b347b89ec6a3 100644 --- a/manager/eris-mint/state/permissions_test.go +++ b/manager/eris-mint/state/permissions_test.go @@ -10,8 +10,8 @@ import ( acm "github.com/eris-ltd/eris-db/account" "github.com/eris-ltd/eris-db/manager/eris-mint/evm" - ptypes "github.com/eris-ltd/eris-db/permission/types" . "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" + ptypes "github.com/eris-ltd/eris-db/permission/types" "github.com/eris-ltd/eris-db/txs" . "github.com/tendermint/go-common" diff --git a/manager/eris-mint/state/state.go b/manager/eris-mint/state/state.go index 9c7b49287bd67b813a34849273bd0263b7696718..582c573af9cee3dadcf42b7eaed86a6b1fddd96f 100644 --- a/manager/eris-mint/state/state.go +++ b/manager/eris-mint/state/state.go @@ -8,8 +8,8 @@ import ( "time" acm "github.com/eris-ltd/eris-db/account" - ptypes "github.com/eris-ltd/eris-db/permission/types" . "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" + ptypes "github.com/eris-ltd/eris-db/permission/types" txs "github.com/eris-ltd/eris-db/txs" . "github.com/tendermint/go-common" @@ -398,7 +398,7 @@ func (s *State) SetFireable(evc events.Fireable) { // Genesis func MakeGenesisStateFromFile(db dbm.DB, genDocFile string) (*GenesisDoc, *State) { - jsonBlob, err := ioutil.ReadFile(genDocFile) + jsonBlob, err := ioutil.ReadFile(genDocFile) if err != nil { Exit(Fmt("Couldn't read GenesisDoc file: %v", err)) } diff --git a/manager/eris-mint/transactor.go b/manager/eris-mint/transactor.go index 0f5f21b4e7809f508eae4c797471c3a6ea10f1a7..a3f515329a8ff9a40e26ce1264c7c6ab8ea126dd 100644 --- a/manager/eris-mint/transactor.go +++ b/manager/eris-mint/transactor.go @@ -29,12 +29,12 @@ import ( "github.com/tendermint/go-crypto" tEvents "github.com/tendermint/go-events" - "github.com/eris-ltd/eris-db/account" - core_types "github.com/eris-ltd/eris-db/core/types" - event "github.com/eris-ltd/eris-db/event" - "github.com/eris-ltd/eris-db/manager/eris-mint/evm" - "github.com/eris-ltd/eris-db/manager/eris-mint/state" - "github.com/eris-ltd/eris-db/txs" + "github.com/eris-ltd/eris-db/account" + core_types "github.com/eris-ltd/eris-db/core/types" + event "github.com/eris-ltd/eris-db/event" + "github.com/eris-ltd/eris-db/manager/eris-mint/evm" + "github.com/eris-ltd/eris-db/manager/eris-mint/state" + "github.com/eris-ltd/eris-db/txs" ) type transactor struct { @@ -60,7 +60,7 @@ func newTransactor(chainID string, eventSwitch tEvents.Fireable, // Run a contract's code on an isolated and unpersisted state // Cannot be used to create new contracts func (this *transactor) Call(fromAddress, toAddress, data []byte) ( - *core_types.Call, error) { + *core_types.Call, error) { cache := this.erisMint.GetCheckCache() // XXX: DON'T MUTATE THIS CACHE (used internally for CheckTx) outAcc := cache.GetAccount(toAddress) @@ -94,7 +94,7 @@ func (this *transactor) Call(fromAddress, toAddress, data []byte) ( // Run the given code on an isolated and unpersisted state // Cannot be used to create new contracts. func (this *transactor) CallCode(fromAddress, code, data []byte) ( - *core_types.Call, error) { + *core_types.Call, error) { if fromAddress == nil { fromAddress = []byte{} } @@ -148,7 +148,7 @@ func (this *transactor) UnconfirmedTxs() (*core_types.UnconfirmedTxs, error) { // Orders calls to BroadcastTx using lock (waits for response from core before releasing) func (this *transactor) Transact(privKey, address, data []byte, gasLimit, - fee int64) (*core_types.Receipt, error) { + fee int64) (*core_types.Receipt, error) { var addr []byte if len(address) == 0 { addr = nil @@ -236,7 +236,7 @@ func (this *transactor) TransactAndHold(privKey, address, data []byte, gasLimit, } func (this *transactor) TransactNameReg(privKey []byte, name, data string, - amount, fee int64) (*core_types.Receipt, error) { + amount, fee int64) (*core_types.Receipt, error) { if len(privKey) != 64 { return nil, fmt.Errorf("Private key is not of the right length: %d\n", len(privKey)) diff --git a/manager/eris-mint/version.go b/manager/eris-mint/version.go index 60b36e692df30cfabcaf98fc936a799e5cb22e2f..34cdb4b5324a9b8a52eeaa36334ffda0b01057b1 100644 --- a/manager/eris-mint/version.go +++ b/manager/eris-mint/version.go @@ -17,40 +17,40 @@ package erismint import ( - "fmt" + "fmt" - version "github.com/eris-ltd/eris-db/version" + version "github.com/eris-ltd/eris-db/version" ) const ( - // Client identifier to advertise over the network - erisMintClientIdentifier = "erismint" - // Major version component of the current release - erisMintVersionMajor = 0 - // Minor version component of the current release - erisMintVersionMinor = 12 - // Patch version component of the current release - erisMintVersionPatch = 0 + // Client identifier to advertise over the network + erisMintClientIdentifier = "erismint" + // Major version component of the current release + erisMintVersionMajor = 0 + // Minor version component of the current release + erisMintVersionMinor = 12 + // Patch version component of the current release + erisMintVersionPatch = 0 ) // Define the compatible consensus engines this application manager // is compatible and has been tested with. -var compatibleConsensus = [...]string { - "tendermint-0.6", - // "tmsp-0.6", +var compatibleConsensus = [...]string{ + "tendermint-0.6", + // "tmsp-0.6", } func GetErisMintVersion() *version.VersionIdentifier { - return version.New(erisMintClientIdentifier, erisMintVersionMajor, - erisMintVersionMinor, erisMintVersionPatch) + return version.New(erisMintClientIdentifier, erisMintVersionMajor, + erisMintVersionMinor, erisMintVersionPatch) } func AssertCompatibleConsensus(consensusMinorVersion string) error { - for _, supported := range compatibleConsensus { - if consensusMinorVersion == supported { - return nil - } - } - return fmt.Errorf("ErisMint (%s) is not compatible with consensus engine %s", - GetErisMintVersion(), consensusMinorVersion) + for _, supported := range compatibleConsensus { + if consensusMinorVersion == supported { + return nil + } + } + return fmt.Errorf("ErisMint (%s) is not compatible with consensus engine %s", + GetErisMintVersion(), consensusMinorVersion) } diff --git a/manager/manager.go b/manager/manager.go index 44a3b5dfb6627d3ae693a3a38f58c2f885de0e40..406648cd3ef36bc56857a55689c3b233870e633a 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -17,16 +17,16 @@ package manager import ( - "fmt" + "fmt" - events "github.com/tendermint/go-events" + events "github.com/tendermint/go-events" - log "github.com/eris-ltd/eris-logger" + log "github.com/eris-ltd/eris-logger" - config "github.com/eris-ltd/eris-db/config" - definitions "github.com/eris-ltd/eris-db/definitions" - erismint "github.com/eris-ltd/eris-db/manager/eris-mint" - // types "github.com/eris-ltd/eris-db/manager/types" + config "github.com/eris-ltd/eris-db/config" + definitions "github.com/eris-ltd/eris-db/definitions" + erismint "github.com/eris-ltd/eris-db/manager/eris-mint" + // types "github.com/eris-ltd/eris-db/manager/types" ) // NewApplicationPipe returns an initialised Pipe interface @@ -35,19 +35,18 @@ import ( // of an application. It is feasible this will be insufficient to support // different types of applications later down the line. func NewApplicationPipe(moduleConfig *config.ModuleConfig, - evsw *events.EventSwitch, consensusMinorVersion string) (definitions.Pipe, - error) { - switch moduleConfig.Name { - case "erismint" : - if err := erismint.AssertCompatibleConsensus(consensusMinorVersion); - err != nil { - return nil, err - } - log.WithFields(log.Fields{ - "compatibleConsensus": consensusMinorVersion, - "erisMintVersion": erismint.GetErisMintVersion().GetVersionString(), - }).Debug("Loading ErisMint") - return erismint.NewErisMintPipe(moduleConfig, evsw) - } - return nil, fmt.Errorf("Failed to return Pipe for %s", moduleConfig.Name) + evsw *events.EventSwitch, consensusMinorVersion string) (definitions.Pipe, + error) { + switch moduleConfig.Name { + case "erismint": + if err := erismint.AssertCompatibleConsensus(consensusMinorVersion); err != nil { + return nil, err + } + log.WithFields(log.Fields{ + "compatibleConsensus": consensusMinorVersion, + "erisMintVersion": erismint.GetErisMintVersion().GetVersionString(), + }).Debug("Loading ErisMint") + return erismint.NewErisMintPipe(moduleConfig, evsw) + } + return nil, fmt.Errorf("Failed to return Pipe for %s", moduleConfig.Name) } diff --git a/manager/types/application.go b/manager/types/application.go index d66a46afeba234971fb63c955eed5734322bd66d..cfcf2b82cc35cfc01c6b9da487f6908143183534 100644 --- a/manager/types/application.go +++ b/manager/types/application.go @@ -17,10 +17,10 @@ package types import ( - // TODO: [ben] this is currently only used for tmsp result type; but should - // be removed as tmsp dependencies shouldn't feature in the application - // manager - tmsp_types "github.com/tendermint/tmsp/types" + // TODO: [ben] this is currently only used for tmsp result type; but should + // be removed as tmsp dependencies shouldn't feature in the application + // manager + tmsp_types "github.com/tendermint/tmsp/types" ) // NOTE: [ben] this interface is likely to be changed. Currently it is taken @@ -30,70 +30,70 @@ import ( // Application interface applies transactions to the state. type Application interface { - // Info returns application information as a string - // NOTE: [ben] likely to move - Info() (info string) - - // Set application option (e.g. mode=mempool, mode=consensus) - // NOTE: [ben] taken from tendermint, but it is unclear what the use is, - // specifically, when will tendermint call this over tmsp ? - SetOption(key string, value string) (log string) - - // Append transaction applies a transaction to the state regardless of - // whether the transaction is valid or not. - // Currently AppendTx is taken from tmsp, and returns a result. - // This will be altered, as AppendTransaction needs to more strongly reflect - // the theoretical logic: - // Append(StateN, Transaction) = StateN+1 - // here invalid transactions are allowed, but should act as the identity on - // the state: - // Append(StateN, InvalidTransaction) = StateN - // TODO: implementation notes: - // 1. at this point the transaction should already be strongly typed - // 2. - AppendTx(tx []byte) tmsp_types.Result - - // Check Transaction validates a transaction before being allowed into the - // consensus' engine memory pool. This is the original defintion and - // intention as taken from tmsp, but should be remapped to the more - // general concept of basic, cheap verification; - // Check Transaction does not alter the state, but does require an immutable - // copy of the state. In particular there is no consensus on ordering yet. - // TODO: implementation notes: - // 1. at this point the transaction should already be strongly typed - // 2. - CheckTx(tx []byte) tmsp_types.Result - - // Commit returns the root hash of the current application state - // NOTE: [ben] Because the concept of the block has been erased here - // the commit root hash is a fully implict stateful function; - // the opposit the principle of explicit stateless functions. - // This will be amended when we introduce the concept of (streaming) - // blocks in the pipe. - Commit() tmsp_types.Result - - // Query for state. This query request is not passed over the p2p network - // and is called from Tendermint rpc directly up to the application. - // NOTE: [ben] Eris-DB will give preference to queries from the local client - // directly over the Eris-DB rpc. - // We will support this for Tendermint compatibility. - Query(query []byte) tmsp_types.Result + // Info returns application information as a string + // NOTE: [ben] likely to move + Info() (info string) + + // Set application option (e.g. mode=mempool, mode=consensus) + // NOTE: [ben] taken from tendermint, but it is unclear what the use is, + // specifically, when will tendermint call this over tmsp ? + SetOption(key string, value string) (log string) + + // Append transaction applies a transaction to the state regardless of + // whether the transaction is valid or not. + // Currently AppendTx is taken from tmsp, and returns a result. + // This will be altered, as AppendTransaction needs to more strongly reflect + // the theoretical logic: + // Append(StateN, Transaction) = StateN+1 + // here invalid transactions are allowed, but should act as the identity on + // the state: + // Append(StateN, InvalidTransaction) = StateN + // TODO: implementation notes: + // 1. at this point the transaction should already be strongly typed + // 2. + AppendTx(tx []byte) tmsp_types.Result + + // Check Transaction validates a transaction before being allowed into the + // consensus' engine memory pool. This is the original defintion and + // intention as taken from tmsp, but should be remapped to the more + // general concept of basic, cheap verification; + // Check Transaction does not alter the state, but does require an immutable + // copy of the state. In particular there is no consensus on ordering yet. + // TODO: implementation notes: + // 1. at this point the transaction should already be strongly typed + // 2. + CheckTx(tx []byte) tmsp_types.Result + + // Commit returns the root hash of the current application state + // NOTE: [ben] Because the concept of the block has been erased here + // the commit root hash is a fully implict stateful function; + // the opposit the principle of explicit stateless functions. + // This will be amended when we introduce the concept of (streaming) + // blocks in the pipe. + Commit() tmsp_types.Result + + // Query for state. This query request is not passed over the p2p network + // and is called from Tendermint rpc directly up to the application. + // NOTE: [ben] Eris-DB will give preference to queries from the local client + // directly over the Eris-DB rpc. + // We will support this for Tendermint compatibility. + Query(query []byte) tmsp_types.Result } // Tendermint has a separate interface for reintroduction of blocks type BlockchainAware interface { - // Initialise the blockchain - // validators: genesis validators from tendermint core - InitChain(validators []*tmsp_types.Validator) + // Initialise the blockchain + // validators: genesis validators from tendermint core + InitChain(validators []*tmsp_types.Validator) - // Signals the beginning of a block; - // NOTE: [ben] currently not supported by tendermint - BeginBlock(height uint64) + // Signals the beginning of a block; + // NOTE: [ben] currently not supported by tendermint + BeginBlock(height uint64) - // Signals the end of a blockchain - // validators: changed validators from app to Tendermint - // NOTE: [ben] currently not supported by tendermint - // not yet well defined what the change set contains. - EndBlock(height uint64) (validators []*tmsp_types.Validator) + // Signals the end of a blockchain + // validators: changed validators from app to Tendermint + // NOTE: [ben] currently not supported by tendermint + // not yet well defined what the change set contains. + EndBlock(height uint64) (validators []*tmsp_types.Validator) } diff --git a/rpc/tendermint/core/routes.go b/rpc/tendermint/core/routes.go index c403a6cfd6c4602ba0684331a56bc85437c41c02..19752f367ad1291223d6e7e42c753934e79883e2 100644 --- a/rpc/tendermint/core/routes.go +++ b/rpc/tendermint/core/routes.go @@ -4,8 +4,8 @@ import ( "fmt" acm "github.com/eris-ltd/eris-db/account" - ctypes "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" definitions "github.com/eris-ltd/eris-db/definitions" + ctypes "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" "github.com/eris-ltd/eris-db/txs" rpc "github.com/tendermint/go-rpc/server" ) diff --git a/rpc/tendermint/core/websocket.go b/rpc/tendermint/core/websocket.go index 4d83eb6f7b329b49b4c43e0f739f137644d5f963..c15ee966829e55216e659dbcebda092852884d0f 100644 --- a/rpc/tendermint/core/websocket.go +++ b/rpc/tendermint/core/websocket.go @@ -22,12 +22,11 @@ import ( "net/http" "strings" + events "github.com/tendermint/go-events" rpcserver "github.com/tendermint/go-rpc/server" - events "github.com/tendermint/go-events" definitions "github.com/eris-ltd/eris-db/definitions" - server "github.com/eris-ltd/eris-db/server" - + server "github.com/eris-ltd/eris-db/server" ) type TendermintWebsocketServer struct { @@ -42,7 +41,7 @@ func NewTendermintWebsocketServer(config *server.ServerConfig, if tendermintPipe == nil { return nil, fmt.Errorf("No Tendermint pipe provided.") } - tendermintRoutes := TendermintRoutes { + tendermintRoutes := TendermintRoutes{ tendermintPipe: tendermintPipe, } routes := tendermintRoutes.GetRoutes() @@ -63,7 +62,7 @@ func NewTendermintWebsocketServer(config *server.ServerConfig, } listeners[i] = listener } - return &TendermintWebsocketServer { + return &TendermintWebsocketServer{ routes: tendermintRoutes, listeners: listeners, }, nil diff --git a/rpc/tendermint/test/common.go b/rpc/tendermint/test/common.go new file mode 100644 index 0000000000000000000000000000000000000000..6d3dd4f4555b1a535ae680d17a4597921f6776a1 --- /dev/null +++ b/rpc/tendermint/test/common.go @@ -0,0 +1,46 @@ +package rpctest + +import ( + "fmt" + "github.com/eris-ltd/eris-db/test/fixtures" + "testing" +) + +// Needs to be in a _test.go file to be picked up +func TestWrapper(runner func() int) int { + ffs := fixtures.NewFileFixtures("Eris-DB") + defer ffs.RemoveAll() + + err := initGlobalVariables(ffs) + + if err != nil { + panic(err) + } + + saveNewPriv() + + // start a node + + fmt.Println() + ready := make(chan error) + go newNode(ready) + err = <-ready + + if err != nil { + panic(err) + } + + return runner() +} + +func DebugMain() { + t := &testing.T{} + TestWrapper(func() int { + testBroadcastTx(t, "HTTP") + return 0 + }) +} + +func Successor(x int) int { + return x + 1 +} diff --git a/rpc/tendermint/test/common_test.go b/rpc/tendermint/test/common_test.go index b2b0a48917df778a2f42178d9b85a8a08ebff4ae..03d4e0271f678ad4f952fab6a6c64e9c3b94883b 100644 --- a/rpc/tendermint/test/common_test.go +++ b/rpc/tendermint/test/common_test.go @@ -1,8 +1,8 @@ package rpctest import ( - "testing" "os" + "testing" ) // Needs to be in a _test.go file to be picked up @@ -13,4 +13,3 @@ func TestMain(m *testing.M) { defer os.Exit(returnValue) } - diff --git a/rpc/tendermint/test/config.go b/rpc/tendermint/test/config.go index 8bbf6f9b89101b519ceaef8c21fc8b2ef665723e..8d6ec5c0d45cc4b048f70f1e66edf221cf7db9fd 100644 --- a/rpc/tendermint/test/config.go +++ b/rpc/tendermint/test/config.go @@ -220,4 +220,3 @@ db_backend = "leveldb" # tendermint host address needs to correspond to tendermints configuration # of the rpc local address tendermint_host = "0.0.0.0:36657"` - diff --git a/rpc/tendermint/test/runner/main.go b/rpc/tendermint/test/runner/main.go index ca775c1a0cbd31169c087d0307d3240e9567c7ae..b610d564c64c77164cd51211a93cbd5be036091a 100644 --- a/rpc/tendermint/test/runner/main.go +++ b/rpc/tendermint/test/runner/main.go @@ -3,11 +3,11 @@ package main import ( "fmt" - "github.com/eris-ltd/eris-db/util" "github.com/eris-ltd/eris-db/rpc/tendermint/test" + "github.com/eris-ltd/eris-db/util" ) func main() { fmt.Printf("%s", util.IsAddress("hello"), rpctest.Successor(2)) //defer os.Exit(0) -} \ No newline at end of file +} diff --git a/rpc/tendermint/test/shared.go b/rpc/tendermint/test/shared.go index 22603b6511ad6c93a7e071e7a97345139fe5d64c..374d6aa5871f3841a9f8c2308ee5f2da13cfad3b 100644 --- a/rpc/tendermint/test/shared.go +++ b/rpc/tendermint/test/shared.go @@ -25,15 +25,15 @@ import ( // global variables for use across all tests var ( - config = server.DefaultServerConfig() - rootWorkDir string + config = server.DefaultServerConfig() + rootWorkDir string node *nm.Node - mempoolCount = 0 - chainID string - websocketAddr string + mempoolCount = 0 + chainID string + websocketAddr string websocketEndpoint string - user = makeUsers(5) // make keys + user = makeUsers(5) // make keys clients map[string]rpcclient.Client testCore *core.Core @@ -129,7 +129,7 @@ func saveNewPriv() { func makeDefaultSendTx(t *testing.T, typ string, addr []byte, amt int64) *txs.SendTx { nonce := getNonce(t, typ, user[0].Address) tx := txs.NewSendTx() - tx.AddInputWithNonce(user[0].PubKey, amt, nonce + 1) + tx.AddInputWithNonce(user[0].PubKey, amt, nonce+1) tx.AddOutput(addr, amt) return tx } @@ -142,14 +142,14 @@ func makeDefaultSendTxSigned(t *testing.T, typ string, addr []byte, amt int64) * func makeDefaultCallTx(t *testing.T, typ string, addr, code []byte, amt, gasLim, fee int64) *txs.CallTx { nonce := getNonce(t, typ, user[0].Address) - tx := txs.NewCallTxWithNonce(user[0].PubKey, addr, code, amt, gasLim, fee, nonce + 1) + tx := txs.NewCallTxWithNonce(user[0].PubKey, addr, code, amt, gasLim, fee, nonce+1) tx.Sign(chainID, user[0]) return tx } func makeDefaultNameTx(t *testing.T, typ string, name, value string, amt, fee int64) *txs.NameTx { nonce := getNonce(t, typ, user[0].Address) - tx := txs.NewNameTxWithNonce(user[0].PubKey, name, value, amt, fee, nonce + 1) + tx := txs.NewNameTxWithNonce(user[0].PubKey, name, value, amt, fee, nonce+1) tx.Sign(chainID, user[0]) return tx } diff --git a/rpc/v0/json_service.go b/rpc/v0/json_service.go index d880790ac2e3cca83831f3565c25d9f4e8248849..e7226487d58613cd50961b827d257e57078aeab9 100644 --- a/rpc/v0/json_service.go +++ b/rpc/v0/json_service.go @@ -6,13 +6,13 @@ import ( "github.com/gin-gonic/gin" - log "github.com/eris-ltd/eris-logger" + log "github.com/eris-ltd/eris-logger" - definitions "github.com/eris-ltd/eris-db/definitions" - event "github.com/eris-ltd/eris-db/event" - rpc "github.com/eris-ltd/eris-db/rpc" - rpc_tendermint "github.com/eris-ltd/eris-db/rpc/tendermint" - server "github.com/eris-ltd/eris-db/server" + definitions "github.com/eris-ltd/eris-db/definitions" + event "github.com/eris-ltd/eris-db/event" + rpc "github.com/eris-ltd/eris-db/rpc" + rpc_tendermint "github.com/eris-ltd/eris-db/rpc/tendermint" + server "github.com/eris-ltd/eris-db/server" ) // Server used to handle JSON-RPC 2.0 requests. Implements server.Server @@ -61,7 +61,7 @@ type ErisDbJsonService struct { // Create a new JSON-RPC 2.0 service for erisdb (tendermint). func NewErisDbJsonService(codec rpc.Codec, pipe definitions.Pipe, - eventSubs *event.EventSubscriptions) server.HttpService { + eventSubs *event.EventSubscriptions) server.HttpService { tmhttps := &ErisDbJsonService{codec: codec, pipe: pipe, eventSubs: eventSubs} mtds := &ErisDbMethods{codec, pipe} diff --git a/rpc/v0/methods.go b/rpc/v0/methods.go index 1c4feeec6c6b3b5f946f567526e4c74dab8ce1b5..be89ebbe103e6e1a2652b185c7436633c7de703d 100644 --- a/rpc/v0/methods.go +++ b/rpc/v0/methods.go @@ -1,9 +1,9 @@ package rpc_v0 import ( - core_types "github.com/eris-ltd/eris-db/core/types" - definitions "github.com/eris-ltd/eris-db/definitions" - rpc "github.com/eris-ltd/eris-db/rpc" + core_types "github.com/eris-ltd/eris-db/core/types" + definitions "github.com/eris-ltd/eris-db/definitions" + rpc "github.com/eris-ltd/eris-db/rpc" rpc_tendermint "github.com/eris-ltd/eris-db/rpc/tendermint" "github.com/eris-ltd/eris-db/txs" ) diff --git a/rpc/v0/restServer.go b/rpc/v0/restServer.go index 41655fd4d865f2a1652ba21daf2a2cc27dd61155..a1e1e01f5a780a09ed61d66fd56e92654b10f798 100644 --- a/rpc/v0/restServer.go +++ b/rpc/v0/restServer.go @@ -8,11 +8,11 @@ import ( "github.com/gin-gonic/gin" - core_types "github.com/eris-ltd/eris-db/core/types" + core_types "github.com/eris-ltd/eris-db/core/types" definitions "github.com/eris-ltd/eris-db/definitions" - event "github.com/eris-ltd/eris-db/event" - rpc "github.com/eris-ltd/eris-db/rpc" - server "github.com/eris-ltd/eris-db/server" + event "github.com/eris-ltd/eris-db/event" + rpc "github.com/eris-ltd/eris-db/rpc" + server "github.com/eris-ltd/eris-db/server" "github.com/eris-ltd/eris-db/txs" "github.com/eris-ltd/eris-db/util" ) diff --git a/rpc/v0/wsService.go b/rpc/v0/wsService.go index 98438280f605efe03099c4990a9bd52e13931ca2..73f396e856bed1d7a32b57634c10b8d79648418f 100644 --- a/rpc/v0/wsService.go +++ b/rpc/v0/wsService.go @@ -4,15 +4,15 @@ import ( "encoding/json" "fmt" - "github.com/tendermint/go-events" + "github.com/tendermint/go-events" - log "github.com/eris-ltd/eris-logger" + log "github.com/eris-ltd/eris-logger" - definitions "github.com/eris-ltd/eris-db/definitions" - event "github.com/eris-ltd/eris-db/event" - rpc "github.com/eris-ltd/eris-db/rpc" + definitions "github.com/eris-ltd/eris-db/definitions" + event "github.com/eris-ltd/eris-db/event" + rpc "github.com/eris-ltd/eris-db/rpc" rpc_tendermint "github.com/eris-ltd/eris-db/rpc/tendermint" - server "github.com/eris-ltd/eris-db/server" + server "github.com/eris-ltd/eris-db/server" ) // Used for ErisDb. Implements WebSocketService. @@ -24,7 +24,7 @@ type ErisDbWsService struct { // Create a new websocket service. func NewErisDbWsService(codec rpc.Codec, - pipe definitions.Pipe) server.WebSocketService { + pipe definitions.Pipe) server.WebSocketService { tmwss := &ErisDbWsService{codec: codec, pipe: pipe} mtds := &ErisDbMethods{codec, pipe} diff --git a/server/config.go b/server/config.go index 8c5195b17aba9e42e25c9c7bada11eb97044c1e1..13078f985532f58ffa073c3fd9829f93a057ef9c 100644 --- a/server/config.go +++ b/server/config.go @@ -17,157 +17,157 @@ package server import ( - "fmt" - "math" + "fmt" + "math" - viper "github.com/spf13/viper" + viper "github.com/spf13/viper" ) type ( - ServerConfig struct { + ServerConfig struct { ChainId string - Bind Bind `toml:"bind"` - TLS TLS `toml:"TLS"` - CORS CORS `toml:"CORS"` - HTTP HTTP `toml:"HTTP"` - WebSocket WebSocket `toml:"web_socket"` + Bind Bind `toml:"bind"` + TLS TLS `toml:"TLS"` + CORS CORS `toml:"CORS"` + HTTP HTTP `toml:"HTTP"` + WebSocket WebSocket `toml:"web_socket"` Tendermint Tendermint - Logging Logging `toml:"logging"` - } - - Bind struct { - Address string `toml:"address"` - Port uint16 `toml:"port"` - } - - TLS struct { - TLS bool `toml:"tls"` - CertPath string `toml:"cert_path"` - KeyPath string `toml:"key_path"` - } - - // Options stores configurations - CORS struct { - Enable bool `toml:"enable"` - AllowOrigins []string `toml:"allow_origins"` - AllowCredentials bool `toml:"allow_credentials"` - AllowMethods []string `toml:"allow_methods"` - AllowHeaders []string `toml:"allow_headers"` - ExposeHeaders []string `toml:"expose_headers"` - MaxAge uint64 `toml:"max_age"` - } - - HTTP struct { - JsonRpcEndpoint string `toml:"json_rpc_endpoint"` - } - - WebSocket struct { - WebSocketEndpoint string `toml:"websocket_endpoint"` - MaxWebSocketSessions uint16 `toml:"max_websocket_sessions"` - ReadBufferSize uint64 `toml:"read_buffer_size"` - WriteBufferSize uint64 `toml:"write_buffer_size"` - } + Logging Logging `toml:"logging"` + } + + Bind struct { + Address string `toml:"address"` + Port uint16 `toml:"port"` + } + + TLS struct { + TLS bool `toml:"tls"` + CertPath string `toml:"cert_path"` + KeyPath string `toml:"key_path"` + } + + // Options stores configurations + CORS struct { + Enable bool `toml:"enable"` + AllowOrigins []string `toml:"allow_origins"` + AllowCredentials bool `toml:"allow_credentials"` + AllowMethods []string `toml:"allow_methods"` + AllowHeaders []string `toml:"allow_headers"` + ExposeHeaders []string `toml:"expose_headers"` + MaxAge uint64 `toml:"max_age"` + } + + HTTP struct { + JsonRpcEndpoint string `toml:"json_rpc_endpoint"` + } + + WebSocket struct { + WebSocketEndpoint string `toml:"websocket_endpoint"` + MaxWebSocketSessions uint16 `toml:"max_websocket_sessions"` + ReadBufferSize uint64 `toml:"read_buffer_size"` + WriteBufferSize uint64 `toml:"write_buffer_size"` + } Tendermint struct { RpcLocalAddress string Endpoint string } - Logging struct { - ConsoleLogLevel string `toml:"console_log_level"` - FileLogLevel string `toml:"file_log_level"` - LogFile string `toml:"log_file"` - } + Logging struct { + ConsoleLogLevel string `toml:"console_log_level"` + FileLogLevel string `toml:"file_log_level"` + LogFile string `toml:"log_file"` + } ) func ReadServerConfig(viper *viper.Viper) (*ServerConfig, error) { - // TODO: [ben] replace with a more elegant way of asserting - // the possible conversion to the type domain - - // check domain range for bind.port - bindPortInt := viper.GetInt("bind.port") - var bindPortUint16 uint16 = 0 - if bindPortInt >= 0 && bindPortInt <= math.MaxUint16 { - bindPortUint16 = uint16(bindPortInt) - } else { - return nil, fmt.Errorf("Failed to read binding port from configuration: %v", - bindPortInt) - } - // check domain range for cors.max_age - maxAge := viper.GetInt("cors.max_age") - var maxAgeUint64 uint64 = 0 - if maxAge >= 0 { - maxAgeUint64 = uint64(maxAge) - } else { - return nil, fmt.Errorf("Failed to read maximum age for CORS: %v", maxAge) - } - // check domain range for websocket.max_sessions - maxWebsocketSessions := viper.GetInt("websocket.max_sessions") - var maxWebsocketSessionsUint16 uint16 = 0 - if maxWebsocketSessions >= 0 && maxWebsocketSessions <= math.MaxUint16 { - maxWebsocketSessionsUint16 = uint16(maxWebsocketSessions) - } else { - return nil, fmt.Errorf("Failed to read maximum websocket sessions: %v", - maxWebsocketSessions) - } - // check domain range for websocket.read_buffer_size - readBufferSize := viper.GetInt("websocket.read_buffer_size") - var readBufferSizeUint64 uint64 = 0 - if readBufferSize >= 0 { - readBufferSizeUint64 = uint64(readBufferSize) - } else { - return nil, fmt.Errorf("Failed to read websocket read buffer size: %v", - readBufferSize) - } - - // check domain range for websocket.write_buffer_size - writeBufferSize := viper.GetInt("websocket.read_buffer_size") - var writeBufferSizeUint64 uint64 = 0 - if writeBufferSize >= 0 { - writeBufferSizeUint64 = uint64(writeBufferSize) - } else { - return nil, fmt.Errorf("Failed to read websocket write buffer size: %v", - writeBufferSize) - } - - return &ServerConfig { - Bind: Bind { - Address: viper.GetString("bind.address"), - Port: bindPortUint16, - }, - TLS: TLS { - TLS: viper.GetBool("tls.tls"), - CertPath: viper.GetString("tls.cert_path"), - KeyPath: viper.GetString("tls.key_path"), - }, - CORS: CORS { - Enable: viper.GetBool("cors.enable"), - AllowOrigins: viper.GetStringSlice("cors.allow_origins"), - AllowCredentials: viper.GetBool("cors.allow_credentials"), - AllowMethods: viper.GetStringSlice("cors.allow_methods"), - AllowHeaders: viper.GetStringSlice("cors.allow_headers"), - ExposeHeaders: viper.GetStringSlice("cors.expose_headers"), - MaxAge: maxAgeUint64, - }, - HTTP: HTTP { - JsonRpcEndpoint: viper.GetString("http.json_rpc_endpoint"), - }, - WebSocket: WebSocket { - WebSocketEndpoint: viper.GetString("websocket.endpoint"), - MaxWebSocketSessions: maxWebsocketSessionsUint16, - ReadBufferSize: readBufferSizeUint64, - WriteBufferSize: writeBufferSizeUint64, - }, - Tendermint: Tendermint { + // TODO: [ben] replace with a more elegant way of asserting + // the possible conversion to the type domain + + // check domain range for bind.port + bindPortInt := viper.GetInt("bind.port") + var bindPortUint16 uint16 = 0 + if bindPortInt >= 0 && bindPortInt <= math.MaxUint16 { + bindPortUint16 = uint16(bindPortInt) + } else { + return nil, fmt.Errorf("Failed to read binding port from configuration: %v", + bindPortInt) + } + // check domain range for cors.max_age + maxAge := viper.GetInt("cors.max_age") + var maxAgeUint64 uint64 = 0 + if maxAge >= 0 { + maxAgeUint64 = uint64(maxAge) + } else { + return nil, fmt.Errorf("Failed to read maximum age for CORS: %v", maxAge) + } + // check domain range for websocket.max_sessions + maxWebsocketSessions := viper.GetInt("websocket.max_sessions") + var maxWebsocketSessionsUint16 uint16 = 0 + if maxWebsocketSessions >= 0 && maxWebsocketSessions <= math.MaxUint16 { + maxWebsocketSessionsUint16 = uint16(maxWebsocketSessions) + } else { + return nil, fmt.Errorf("Failed to read maximum websocket sessions: %v", + maxWebsocketSessions) + } + // check domain range for websocket.read_buffer_size + readBufferSize := viper.GetInt("websocket.read_buffer_size") + var readBufferSizeUint64 uint64 = 0 + if readBufferSize >= 0 { + readBufferSizeUint64 = uint64(readBufferSize) + } else { + return nil, fmt.Errorf("Failed to read websocket read buffer size: %v", + readBufferSize) + } + + // check domain range for websocket.write_buffer_size + writeBufferSize := viper.GetInt("websocket.read_buffer_size") + var writeBufferSizeUint64 uint64 = 0 + if writeBufferSize >= 0 { + writeBufferSizeUint64 = uint64(writeBufferSize) + } else { + return nil, fmt.Errorf("Failed to read websocket write buffer size: %v", + writeBufferSize) + } + + return &ServerConfig{ + Bind: Bind{ + Address: viper.GetString("bind.address"), + Port: bindPortUint16, + }, + TLS: TLS{ + TLS: viper.GetBool("tls.tls"), + CertPath: viper.GetString("tls.cert_path"), + KeyPath: viper.GetString("tls.key_path"), + }, + CORS: CORS{ + Enable: viper.GetBool("cors.enable"), + AllowOrigins: viper.GetStringSlice("cors.allow_origins"), + AllowCredentials: viper.GetBool("cors.allow_credentials"), + AllowMethods: viper.GetStringSlice("cors.allow_methods"), + AllowHeaders: viper.GetStringSlice("cors.allow_headers"), + ExposeHeaders: viper.GetStringSlice("cors.expose_headers"), + MaxAge: maxAgeUint64, + }, + HTTP: HTTP{ + JsonRpcEndpoint: viper.GetString("http.json_rpc_endpoint"), + }, + WebSocket: WebSocket{ + WebSocketEndpoint: viper.GetString("websocket.endpoint"), + MaxWebSocketSessions: maxWebsocketSessionsUint16, + ReadBufferSize: readBufferSizeUint64, + WriteBufferSize: writeBufferSizeUint64, + }, + Tendermint: Tendermint{ RpcLocalAddress: viper.GetString("tendermint.rpc_local_address"), Endpoint: viper.GetString("tendermint.endpoint"), }, - Logging: Logging{ - ConsoleLogLevel: viper.GetString("logging.console_log_level"), - FileLogLevel: viper.GetString("logging.file_log_level"), - LogFile: viper.GetString("logging.log_file"), - }, - }, nil + Logging: Logging{ + ConsoleLogLevel: viper.GetString("logging.console_log_level"), + FileLogLevel: viper.GetString("logging.file_log_level"), + LogFile: viper.GetString("logging.log_file"), + }, + }, nil } // NOTE: [ben] only preserved for /test/server tests; but should not be used and @@ -192,7 +192,7 @@ func DefaultServerConfig() *ServerConfig { ReadBufferSize: 4096, WriteBufferSize: 4096, }, - Tendermint: Tendermint { + Tendermint: Tendermint{ RpcLocalAddress: "0.0.0.0:46657", Endpoint: "/websocket", }, diff --git a/server/server.go b/server/server.go index d95d1d4c5dc2984b1d0eade614866c9d9755ac72..f1d38c3dea5fdd2c1c9fb4ed949c52df44f78998 100644 --- a/server/server.go +++ b/server/server.go @@ -185,7 +185,7 @@ func (this *ServeProcess) StopEventChannel() <-chan struct{} { // Creates a new serve process. func NewServeProcess(config *ServerConfig, servers ...Server) (*ServeProcess, - error) { + error) { var scfg ServerConfig if config == nil { return nil, fmt.Errorf("Nil passed as server configuration") diff --git a/test/fixtures/file_fixtures.go b/test/fixtures/file_fixtures.go index 5c1da7bebe6c7ddf6ef405905010a552f508b6dd..5935e54c20d7b9c4203f4a22680ff23ce6ee3a62 100644 --- a/test/fixtures/file_fixtures.go +++ b/test/fixtures/file_fixtures.go @@ -2,15 +2,15 @@ package fixtures import ( "github.com/docker/docker/pkg/ioutils" - "path" "os" + "path" ) // FileFixtures writes files to a temporary location for use in testing. type FileFixtures struct { tempDir string // If an error has occurred setting up fixtures - Error error + Error error } // Set up a new FileFixtures object by passing an interlaced list of file names @@ -21,7 +21,7 @@ func NewFileFixtures(identifyingPrefix string) *FileFixtures { dir, err := ioutils.TempDir("", identifyingPrefix) return &FileFixtures{ tempDir: dir, - Error: err, + Error: err, } } @@ -33,7 +33,7 @@ func (ffs *FileFixtures) AddFile(name, content string) string { } filePath := path.Join(ffs.tempDir, name) ffs.AddDir(path.Dir(name)) - if (ffs.Error == nil) { + if ffs.Error == nil { ffs.Error = createWriteClose(filePath, content) } return filePath @@ -50,7 +50,6 @@ func (ffs *FileFixtures) AddDir(name string) string { return filePath } - // Cleans up the the temporary files (with fire) func (ffs *FileFixtures) RemoveAll() { if err := os.RemoveAll(ffs.tempDir); err != nil { @@ -72,4 +71,3 @@ func createWriteClose(filename, content string) error { defer f.Close() return nil } - diff --git a/test/mock/mock_web_api_test.g_ b/test/mock/mock_web_api_test.g_ index 378097c82bf287465529995e2f98f1af2dfaeb39..0579640bbf5dde56ec90c22afb7da5f307e245f3 100644 --- a/test/mock/mock_web_api_test.g_ +++ b/test/mock/mock_web_api_test.g_ @@ -9,13 +9,13 @@ import ( "runtime" "testing" - account "github.com/eris-ltd/eris-db/account" + account "github.com/eris-ltd/eris-db/account" core_types "github.com/eris-ltd/eris-db/core/types" - event "github.com/eris-ltd/eris-db/event" - rpc "github.com/eris-ltd/eris-db/rpc" - rpc_v0 "github.com/eris-ltd/eris-db/rpc/v0" - server "github.com/eris-ltd/eris-db/server" - td "github.com/eris-ltd/eris-db/test/testdata/testdata" + event "github.com/eris-ltd/eris-db/event" + rpc "github.com/eris-ltd/eris-db/rpc" + rpc_v0 "github.com/eris-ltd/eris-db/rpc/v0" + server "github.com/eris-ltd/eris-db/server" + td "github.com/eris-ltd/eris-db/test/testdata/testdata" "github.com/eris-ltd/eris-db/txs" "github.com/gin-gonic/gin" diff --git a/test/mock/pipe.g_ b/test/mock/pipe.g_ index e1e416127ddb73ff9b55f1311265aa07a4f97d62..61fc0398cfe6c358553d2b129f15e90c878cca2b 100644 --- a/test/mock/pipe.g_ +++ b/test/mock/pipe.g_ @@ -7,12 +7,13 @@ import ( core_types "github.com/eris-ltd/eris-db/core/types" definitions "github.com/eris-ltd/eris-db/definitions" event "github.com/eris-ltd/eris-db/event" + manager_types "github.com/eris-ltd/eris-db/manager/types" - td "github.com/eris-ltd/eris-db/test/testdata/testdata" - types "github.com/eris-ltd/eris-db/txs" + td "github.com/eris-ltd/eris-db/test/testdata/testdata" + types "github.com/eris-ltd/eris-db/txs" + evts "github.com/tendermint/go-events" mintTypes "github.com/tendermint/tendermint/types" - evts "github.com/tendermint/go-events" ) // Base struct. diff --git a/test/server/ws_burst_test.go b/test/server/ws_burst_test.go index 4316af17980813a26409f2c9b2099936accf3b18..aef23a19a0a5e521212e8dc9aab01dc5afa16ddb 100644 --- a/test/server/ws_burst_test.go +++ b/test/server/ws_burst_test.go @@ -1,9 +1,9 @@ package server import ( - "github.com/stretchr/testify/assert" "github.com/eris-ltd/eris-db/client" "github.com/eris-ltd/eris-db/server" + "github.com/stretchr/testify/assert" "testing" "time" ) diff --git a/util/fs.go b/util/fs.go index 11322e68ac9a139fd970e0e6f5fd016d10ec5e05..7d41c1ddd51d28de1859daf291062d2afd5d4290 100644 --- a/util/fs.go +++ b/util/fs.go @@ -17,32 +17,32 @@ package util import ( - "fmt" - "io" - "os" + "fmt" + "io" + "os" ) // Ensure the directory exists or create it if needed. func EnsureDir(dir string, mode os.FileMode) error { - if fileOptions, err := os.Stat(dir); os.IsNotExist(err) { - if errMake := os.MkdirAll(dir, mode); errMake != nil { - return fmt.Errorf("Could not create directory %s. %v", dir, err) - } - } else if err != nil { - return fmt.Errorf("Error asserting directory %s: %v", dir, err) - } else if !fileOptions.IsDir() { - return fmt.Errorf("Path already exists as a file: %s", dir) - } - return nil + if fileOptions, err := os.Stat(dir); os.IsNotExist(err) { + if errMake := os.MkdirAll(dir, mode); errMake != nil { + return fmt.Errorf("Could not create directory %s. %v", dir, err) + } + } else if err != nil { + return fmt.Errorf("Error asserting directory %s: %v", dir, err) + } else if !fileOptions.IsDir() { + return fmt.Errorf("Path already exists as a file: %s", dir) + } + return nil } // Check whether the provided directory exists func IsDir(directory string) bool { - fileInfo, err := os.Stat(directory) - if err != nil { - return false - } - return fileInfo.IsDir() + fileInfo, err := os.Stat(directory) + if err != nil { + return false + } + return fileInfo.IsDir() } // copied from http://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang @@ -50,34 +50,34 @@ func IsDir(directory string) bool { // the same, then return success. Otherise, attempt to create a hard link // between the two files. If that fail, copy the file contents from src to dst. func CopyFile(src, dst string) (err error) { - sfi, err := os.Stat(src) - if err != nil { - return - } - if !sfi.Mode().IsRegular() { - // cannot copy non-regular files (e.g., directories, - // symlinks, devices, etc.) - return fmt.Errorf("CopyFile: non-regular source file %s (%q)", sfi.Name(), sfi.Mode().String()) - } - dfi, err := os.Stat(dst) - if err != nil { - if !os.IsNotExist(err) { - return - } - } else { - if !(dfi.Mode().IsRegular()) { - return fmt.Errorf("CopyFile: non-regular destination file %s (%q)", dfi.Name(), dfi.Mode().String()) - } - if os.SameFile(sfi, dfi) { - return - } - } - // NOTE: [ben] we do not want to create a hard link currently - // if err = os.Link(src, dst); err == nil { - // return - // } - err = copyFileContents(src, dst) - return + sfi, err := os.Stat(src) + if err != nil { + return + } + if !sfi.Mode().IsRegular() { + // cannot copy non-regular files (e.g., directories, + // symlinks, devices, etc.) + return fmt.Errorf("CopyFile: non-regular source file %s (%q)", sfi.Name(), sfi.Mode().String()) + } + dfi, err := os.Stat(dst) + if err != nil { + if !os.IsNotExist(err) { + return + } + } else { + if !(dfi.Mode().IsRegular()) { + return fmt.Errorf("CopyFile: non-regular destination file %s (%q)", dfi.Name(), dfi.Mode().String()) + } + if os.SameFile(sfi, dfi) { + return + } + } + // NOTE: [ben] we do not want to create a hard link currently + // if err = os.Link(src, dst); err == nil { + // return + // } + err = copyFileContents(src, dst) + return } // copyFileContents copies the contents of the file named src to the file named @@ -85,25 +85,25 @@ func CopyFile(src, dst string) (err error) { // destination file exists, all its contents will be replaced by the contents // of the source file. func copyFileContents(src, dst string) (err error) { - in, err := os.Open(src) - if err != nil { - return - } - defer in.Close() - out, err := os.Create(dst) - if err != nil { - return - } - defer func() { - cerr := out.Close() - if err == nil { - err = cerr - } - }() - if _, err = io.Copy(out, in); err != nil { - return - } - // TODO: [ben] this blocks, so copy should be put in go-routine - err = out.Sync() - return + in, err := os.Open(src) + if err != nil { + return + } + defer in.Close() + out, err := os.Create(dst) + if err != nil { + return + } + defer func() { + cerr := out.Close() + if err == nil { + err = cerr + } + }() + if _, err = io.Copy(out, in); err != nil { + return + } + // TODO: [ben] this blocks, so copy should be put in go-routine + err = out.Sync() + return } diff --git a/version/version.go b/version/version.go index 63efe9030180e48ac6c7c2c620c7c625349fa228..d6e52b9dc9acd7e0477ef2187f632be03b82472c 100644 --- a/version/version.go +++ b/version/version.go @@ -20,47 +20,47 @@ package version import ( - "fmt" + "fmt" ) // IMPORTANT: this version number needs to be manually kept // in sync at the bottom of this file for the deployment scripts to parse // the version number. const ( - // Client identifier to advertise over the network - erisClientIdentifier = "eris-db" - // Major version component of the current release - erisVersionMajor = 0 - // Minor version component of the current release - erisVersionMinor = 12 - // Patch version component of the current release - erisVersionPatch = 0 + // Client identifier to advertise over the network + erisClientIdentifier = "eris-db" + // Major version component of the current release + erisVersionMajor = 0 + // Minor version component of the current release + erisVersionMinor = 12 + // Patch version component of the current release + erisVersionPatch = 0 ) var erisVersion *VersionIdentifier func init() { - erisVersion = New(erisClientIdentifier, erisVersionMajor, - erisVersionMinor, erisVersionPatch) + erisVersion = New(erisClientIdentifier, erisVersionMajor, + erisVersionMinor, erisVersionPatch) } //------------------------------------------------------------------------------ // versioning globally for Eris-DB and scoped for modules type VersionIdentifier struct { - clientIdentifier string - versionMajor uint8 - versionMinor uint8 - versionPatch uint8 + clientIdentifier string + versionMajor uint8 + versionMinor uint8 + versionPatch uint8 } func New(client string, major, minor, patch uint8) *VersionIdentifier { - v := new(VersionIdentifier) - v.clientIdentifier = client - v.versionMajor = major - v.versionMinor = minor - v.versionPatch = patch - return v + v := new(VersionIdentifier) + v.clientIdentifier = client + v.versionMajor = major + v.versionMinor = minor + v.versionPatch = patch + return v } // GetVersionString returns `client-major.minor.patch` for Eris-DB @@ -68,16 +68,17 @@ func New(client string, major, minor, patch uint8) *VersionIdentifier { // MakeVersionString builds the same version string with provided parameters. func GetVersionString() string { return erisVersion.GetVersionString() } func (v *VersionIdentifier) GetVersionString() string { - return fmt.Sprintf("%s-%d.%d.%d", v.clientIdentifier, v.versionMajor, - v.versionMinor, v.versionPatch) + return fmt.Sprintf("%s-%d.%d.%d", v.clientIdentifier, v.versionMajor, + v.versionMinor, v.versionPatch) } + // note: the arguments are passed in as int (rather than uint8) // because on asserting the version constructed from the configuration file // the casting of an int to uint8 is uglier than expanding the type range here. // Should the configuration file have an invalid integer (that could not convert) // then this will equally be reflected in a failed assertion of the version string. func MakeVersionString(client string, major, minor, patch int) string { - return fmt.Sprintf("%s-%d.%d.%d", client, major, minor, patch) + return fmt.Sprintf("%s-%d.%d.%d", client, major, minor, patch) } // GetMinorVersionString returns `client-major.minor` for Eris-DB @@ -86,23 +87,25 @@ func MakeVersionString(client string, major, minor, patch int) string { // provided parameters. func GetMinorVersionString() string { return erisVersion.GetVersionString() } func (v *VersionIdentifier) GetMinorVersionString() string { - return fmt.Sprintf("%s-%d.%d", v.clientIdentifier, v.versionMajor, - v.versionMinor) + return fmt.Sprintf("%s-%d.%d", v.clientIdentifier, v.versionMajor, + v.versionMinor) } + // note: similar remark applies here on the use of `int` over `uint8` // for the arguments as above for MakeVersionString() func MakeMinorVersionString(client string, major, minor, patch int) string { - return fmt.Sprintf("%s-%d.%d", client, major, minor) + return fmt.Sprintf("%s-%d.%d", client, major, minor) } // GetVersion returns a tuple of client, major, minor, and patch as types, // either for Eris-DB without a receiver or the called version structure. func GetVersion() (client string, major, minor, patch uint8) { - return erisVersion.GetVersion() } -func (version *VersionIdentifier) GetVersion() ( - client string, major, minor, patch uint8) { - return version.clientIdentifier, version.versionMajor, version.versionMinor, - version.versionPatch + return erisVersion.GetVersion() +} +func (version *VersionIdentifier) GetVersion() ( + client string, major, minor, patch uint8) { + return version.clientIdentifier, version.versionMajor, version.versionMinor, + version.versionPatch } //------------------------------------------------------------------------------ @@ -111,13 +114,14 @@ func (version *VersionIdentifier) GetVersion() ( // MatchesMinorVersion matches the client identifier, major and minor version // number of the reference version identifier to be equal with the receivers. func MatchesMinorVersion(referenceVersion *VersionIdentifier) bool { - return erisVersion.MatchesMinorVersion(referenceVersion) } + return erisVersion.MatchesMinorVersion(referenceVersion) +} func (version *VersionIdentifier) MatchesMinorVersion( - referenceVersion *VersionIdentifier) bool { - referenceClient, referenceMajor, referenceMinor, _ := referenceVersion.GetVersion() - return version.clientIdentifier == referenceClient && - version.versionMajor == referenceMajor && - version.versionMinor == referenceMinor + referenceVersion *VersionIdentifier) bool { + referenceClient, referenceMajor, referenceMinor, _ := referenceVersion.GetVersion() + return version.clientIdentifier == referenceClient && + version.versionMajor == referenceMajor && + version.versionMinor == referenceMinor } //------------------------------------------------------------------------------ @@ -125,6 +129,7 @@ func (version *VersionIdentifier) MatchesMinorVersion( // NOTE [ben]: deprecate public const version string const TENDERMINT_VERSION = "0.5.0" + // IMPORTANT: Eris-DB version must be on the last line of this file for // the deployment script DOCKER/build.sh to pick up the right label. const VERSION = "0.12.0-rc2"