Skip to content

Commit

Permalink
update doc and simplify rosetta config
Browse files Browse the repository at this point in the history
Signed-off-by: Xin Li <xin.li@hedera.com>
  • Loading branch information
xin-hedera committed Jan 5, 2022
1 parent bd35bc4 commit 3348f5c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 34 deletions.
15 changes: 8 additions & 7 deletions hedera-mirror-rosetta/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ hedera:
apiConfigEnvKey = "HEDERA_MIRROR_ROSETTA_API_CONFIG"
configName = "application"
configTypeYaml = "yml"
configPrefix = "hedera::mirror::rosetta" // use "::" since it's the delimiter set for viper
envKeyDelimiter = "_"
keyDelimiter = "::"
)

// LoadConfig loads configuration from yaml files and env variables
func LoadConfig() (*Rosetta, error) {
func LoadConfig() (*Config, error) {
// NodeMap's key has '.', set viper key delimiter to avoid parsing it as a nested key
v := viper.NewWithOptions(viper.KeyDelimiter(keyDelimiter))
v.SetConfigType(configTypeYaml)
Expand Down Expand Up @@ -97,16 +98,16 @@ func LoadConfig() (*Rosetta, error) {
v.SetEnvKeyReplacer(strings.NewReplacer(keyDelimiter, envKeyDelimiter))

var config Config
if err := v.Unmarshal(&config, viper.DecodeHook(nodeMapDecodeHookFunc)); err != nil {
if err := v.UnmarshalKey(configPrefix, &config, viper.DecodeHook(nodeMapDecodeHookFunc)); err != nil {
return nil, err
}

var password = config.Hedera.Mirror.Rosetta.Db.Password
config.Hedera.Mirror.Rosetta.Db.Password = "<omitted>"
log.Infof("Using configuration: %+v", config.Hedera.Mirror.Rosetta)
config.Hedera.Mirror.Rosetta.Db.Password = password
var password = config.Db.Password
config.Db.Password = "<omitted>"
log.Infof("Using configuration: %+v", config)
config.Db.Password = password

return &config.Hedera.Mirror.Rosetta, nil
return &config, nil
}

func mergeExternalConfigFile(v *viper.Viper) error {
Expand Down
12 changes: 10 additions & 2 deletions hedera-mirror-rosetta/app/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,16 @@ func createYamlConfigFile(content string, t *testing.T) (string, string) {
return tempDir, customConfig
}

func getDefaultConfig() *Rosetta {
config := Config{}
type FullConfig struct {
Hedera struct {
Mirror struct {
Rosetta Config
}
}
}

func getDefaultConfig() *Config {
config := FullConfig{}
yaml.Unmarshal([]byte(defaultConfig), &config)
return &config.Hedera.Mirror.Rosetta
}
12 changes: 0 additions & 12 deletions hedera-mirror-rosetta/app/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ import (
)

type Config struct {
Hedera Hedera
}

type Hedera struct {
Mirror Mirror
}

type Mirror struct {
Rosetta Rosetta
}

type Rosetta struct {
Db Db
Log Log
Network string
Expand Down
16 changes: 8 additions & 8 deletions hedera-mirror-rosetta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func configLogger(level string) {
// ref: https://www.rosetta-api.org/docs/node_deployment.html#online-mode-endpoints
func newBlockchainOnlineRouter(
asserter *rosettaAsserter.Asserter,
config config.Config,
dbClient interfaces.DbClient,
network *rTypes.NetworkIdentifier,
rosetta config.Rosetta,
version *rTypes.Version,
) (http.Handler, error) {
accountRepo := persistence.NewAccountRepository(dbClient)
Expand All @@ -99,7 +99,7 @@ func newBlockchainOnlineRouter(
constructionAPIService, err := services.NewConstructionAPIService(
baseService,
network.Network,
rosetta.Nodes,
config.Nodes,
construction.NewTransactionConstructor(tokenRepo),
)
if err != nil {
Expand All @@ -109,7 +109,7 @@ func newBlockchainOnlineRouter(

accountAPIService := services.NewAccountAPIService(baseService, accountRepo)
accountAPIController := server.NewAccountAPIController(accountAPIService, asserter)
healthController, err := middleware.NewHealthController(rosetta.Db)
healthController, err := middleware.NewHealthController(config.Db)
metricsController := middleware.NewMetricsController()
if err != nil {
return nil, err
Expand All @@ -131,23 +131,23 @@ func newBlockchainOnlineRouter(
// ref: https://www.rosetta-api.org/docs/node_deployment.html#offline-mode-endpoints
func newBlockchainOfflineRouter(
asserter *rosettaAsserter.Asserter,
config config.Config,
network *rTypes.NetworkIdentifier,
rosetta config.Rosetta,
version *rTypes.Version,
) (http.Handler, error) {
baseService := services.NewOfflineBaseService()

constructionAPIService, err := services.NewConstructionAPIService(
baseService,
network.Network,
rosetta.Nodes,
config.Nodes,
construction.NewTransactionConstructor(nil),
)
if err != nil {
return nil, err
}
constructionAPIController := server.NewConstructionAPIController(constructionAPIService, asserter)
healthController, err := middleware.NewHealthController(rosetta.Db)
healthController, err := middleware.NewHealthController(config.Db)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -202,14 +202,14 @@ func main() {
if rosettaConfig.Online {
dbClient := db.ConnectToDb(rosettaConfig.Db)

router, err = newBlockchainOnlineRouter(asserter, dbClient, network, *rosettaConfig, version)
router, err = newBlockchainOnlineRouter(asserter, *rosettaConfig, dbClient, network, version)
if err != nil {
log.Fatal(err)
}

log.Info("Serving Rosetta API in ONLINE mode")
} else {
router, err = newBlockchainOfflineRouter(asserter, network, *rosettaConfig, version)
router, err = newBlockchainOfflineRouter(asserter, *rosettaConfig, network, version)
if err != nil {
log.Fatal(err)
}
Expand Down
23 changes: 18 additions & 5 deletions hedera-mirror-rosetta/test/bdd-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ The client currently supports basic crypto create, crypto transfer, and HTS scen
## Requirements

- golang 1.17+
- a testnet account with private key
- two testnet accounts with private key
- aws / gcp credentials with requester pay enabled to access the Hedera network cloud storage

## Test Client Configuration

Configuration properties can be customized in an `application.yml` file in the test client source directory. Most
properties have default values and should work out of the box.

The only required property is an operator account and its private key, for example:
The only required property is two operator accounts and the corresponding private keys, for example:

```yaml
hedera:
Expand All @@ -31,8 +31,12 @@ hedera:
operators:
- privateKey: 90e42b7c...
id: 0.0.65342
- privateKey: 91e33b87...
id: 0.0.65345
```
Note for crypto create and crypto transfer scenarios, only one operator account is required.
Please refer to the [appendix](#test-configuration-properties) for the complete list of properties.
## Run the Test
Expand Down Expand Up @@ -72,6 +76,14 @@ Please refer to the [appendix](#test-configuration-properties) for the complete
$ go test -v
```

Note you can run tests with the `--godog.tags` flag to filter features, for example, to run `crypto` scenarions:

```shell
$ go test -v --godog.tags=crypto
```

`--godog.tags` also supports complex expressions, please refer to the [official documentation](https://github.com/cucumber/godog#tags).

## Appendix

### Test Configuration Properties
Expand All @@ -82,12 +94,13 @@ The following table lists the available properties along with their default valu
| ------------------------------------------------------- | --------------------- | -------------------------------------------------------------------------- |
| `hedera.mirror.rosetta.test.log.level` | debug | The log level |
| `hedera.mirror.rosetta.test.operators` | [] | A list of operators with the account ids and corresponding private keys |
| `hedera.mirror.rosetta.test.operators.id` | | The operator account id, in the format of shard.realm.num |
| `hedera.mirror.rosetta.test.operators.privateKey` | | The operator's private key in hex |
| `hedera.mirror.rosetta.test.operators[].id` | | The operator account id, in the format of shard.realm.num |
| `hedera.mirror.rosetta.test.operators[].privateKey` | | The operator's private key in hex |
| `hedera.mirror.rosetta.test.server.dataRetry.backOff` | 1s | The amount of time to wait between data request retries, if the request can be retried. |
| `hedera.mirror.rosetta.test.server.dataRetry.max` | 20 | The max retries of a data request |
| `hedera.mirror.rosetta.test.server.httpTimeout` | 25s | The timeout of an http request sent to the rosetta server |
| `hedera.mirror.rosetta.test.server.network` | {} | A map of main nodes with its service endpoint as the key and the node account id as its value |
| `hedera.mirror.rosetta.test.server.offlineUrl` | http://localhost:5701 | The url of the offline rosetta server |
| `hedera.mirror.rosetta.test.server.onlineUrl` | http://localhost:5700 | The url of the online rosetta server |
| `hedera.mirror.rosetta.test.server.httpTimeout` | 25s | The timeout of an http request sent to the rosetta server |
| `hedera.mirror.rosetta.test.server.submitRetry.backOff` | 200ms | The amount of time to wait between submit request retries |
| `hedera.mirror.rosetta.test.server.submitRetry.max` | 5 | The max retries of a submit request |

0 comments on commit 3348f5c

Please sign in to comment.