Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] #1990: Enable peer startup via env vars in the absence of config.json #2188

Merged
merged 1 commit into from May 11, 2022

Conversation

ilchu
Copy link
Contributor

@ilchu ilchu commented May 10, 2022

Signed-off-by: Ilia Churin ilia.ch@netogami.net

Description of the Change

In the case when the minimal cli client (iroha) was provided with no config.json either in the same directory or as an environment variable, do not stop the execution, but instead require that all the variables from the default json be provided as environment variables too, and load them onto default configuration.

Issue

Resolves #1990.

Benefits

Presumably easier and more flexible setup of peer through cli.

Possible Drawbacks

As the fix chooses to fall back on default impl for config, it has the same problems that were discussed in #2101 and #2118. The question is which variables should be allowed to be set via environment, and which subset of them should be required when using default, if we're going to stick with it at all. As of now, the default configuration is generated with Default and all the variables from the configs/peer/config.json are required to proceed if no file was found.

@github-actions github-actions bot added the iroha2-dev The re-implementation of a BFT hyperledger in RUST label May 10, 2022
@@ -143,7 +146,9 @@ where
broker: Broker,
) -> Result<Self> {
if !config.disable_panic_terminal_colors {
color_eyre::install()?;
if let Err(e) = color_eyre::install() {
iroha_logger::error!("Tried to install eyre_hook twice: {:?}", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was not able to trace the exact reason, but somehow with this workflow when no config was provided color_eyre kept crashing. AFAICT the only other spots where install() is used are kagami and logger, but they don't seem to be called at that stage. Will double check the error again, but this was a stumbling point for me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm asking because I think this also happened to sdk devs when bootstraping iroha

Copy link
Contributor Author

@ilchu ilchu May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then at least it's not only me, but something in the code. I guess then as a workaround this will suffice for now, and I'll create a separate issue for the problem later today.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kagami is a completely unrelated executable, so this is probably the only place this happens. Log and ignore for now, but we ned to figure out why this happens. IMO there's a tokio task that tries to do the same thing in a different thread and breaks the install process.

cli/src/main.rs Outdated Show resolved Hide resolved
cli/src/main.rs Outdated Show resolved Hide resolved
cli/README.md Outdated Show resolved Hide resolved
@ilchu ilchu force-pushed the cli-env-vars branch 3 times, most recently from c493f24 to 166c5bf Compare May 10, 2022 11:43
cli/src/main.rs Outdated Show resolved Hide resolved
cli/README.md Outdated Show resolved Hide resolved
@Arjentix Arjentix self-assigned this May 10, 2022
mversic
mversic previously approved these changes May 11, 2022
cli/README.md Outdated Show resolved Hide resolved
cli/src/main.rs Outdated Show resolved Hide resolved
cli/src/main.rs Outdated Show resolved Hide resolved
@ilchu ilchu force-pushed the cli-env-vars branch 2 times, most recently from 5731324 to 6b34b1c Compare May 11, 2022 11:52
@codecov
Copy link

codecov bot commented May 11, 2022

Codecov Report

Merging #2188 (e8bbee3) into iroha2-dev (89059b3) will decrease coverage by 76.65%.
The diff coverage is n/a.

❗ Current head e8bbee3 differs from pull request most recent head b3fe9f3. Consider uploading reports for the commit b3fe9f3 to get more accurate results

@@              Coverage Diff               @@
##           iroha2-dev   #2188       +/-   ##
==============================================
- Coverage       76.65%       0   -76.66%     
==============================================
  Files             185       0      -185     
  Lines           26672       0    -26672     
==============================================
- Hits            20445       0    -20445     
+ Misses           6227       0     -6227     
Impacted Files Coverage Δ
cli/src/lib.rs
cli/src/main.rs
core/src/smartcontracts/isi/query.rs
...ions_validators/src/public_blockchain/key_value.rs
telemetry/src/ws.rs
tools/kagami/src/main.rs
core/src/smartcontracts/mod.rs
client/examples/million_accounts_genesis.rs
actor/src/actor_id.rs
client/tests/integration/tx_rollback.rs
... and 175 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89059b3...b3fe9f3. Read the comment docs.

cli/src/main.rs Outdated Show resolved Hide resolved
"Additionally, in case of absence of both IROHA2_CONFIG_PATH and `config.json`
in the current directory, all the variables from `config.json` should be set via the environment
as follows:"
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain that they need to passed as a JSON string. I'd add an example of that could be run from the command line in the comments/docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a paragraph in the amended commit describing that.

@ilchu ilchu force-pushed the cli-env-vars branch 2 times, most recently from e8bbee3 to 7da5290 Compare May 11, 2022 13:18
The environment variables replacing `config.json` should be passed as JSON strings, meaning that any inner quotes should be properly escaped in the command line as shown in the rather unwieldy example below.

``` bash
IROHA_TORII="{\"P2P_ADDR\": \"127.0.0.1:1339\", \"API_URL\": \"127.0.0.1:8080\"}" IROHA_SUMERAGI="{\"TRUSTED_PEERS\": [{\"address\": \"127.0.0.1:1337\",\"public_key\": \"ed01201c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b\"},{\"address\": \"127.0.0.1:1338\",\"public_key\": \"ed0120cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1\"},{\"address\": \"127.0.0.1:1339\",\"public_key\": \"ed0120faca9e8aa83225cb4d16d67f27dd4f93fc30ffa11adc1f5c88fd5495ecc91020\"},{\"address\": \"127.0.0.1:1340\",\"public_key\": \"ed01208e351a70b6a603ed285d666b8d689b680865913ba03ce29fb7d13a166c4e7f1f\"}]}" IROHA_KURA="{\"INIT_MODE\": \"strict\",\"BLOCK_STORE_PATH\": \"./blocks\"}" IROHA_BLOCK_SYNC="{\"GOSSIP_PERIOD_MS\": 10000,\"BATCH_SIZE\": 2}" IROHA_PUBLIC_KEY="ed01201c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b" IROHA_PRIVATE_KEY="{\"digest_function\": \"ed25519\",\"payload\": \"282ed9f3cf92811c3818dbc4ae594ed59dc1a2f78e4241e31924e101d6b1fb831c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b\"}" IROHA_GENESIS="{\"ACCOUNT_PUBLIC_KEY\": \"ed01204cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf\",\"ACCOUNT_PRIVATE_KEY\": {\"digest_function\": \"ed25519\",\"payload\": \"d748e18ce60cb30dea3e73c9019b7af45a8d465e3d71bcc9a5ef99a008205e534cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf\"}}" ./iroha
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little ugly, but this is meant to be technical documentation. Add some <details> tags around it and we can merge.

Signed-off-by: Ilia Churin <ilia.ch@netogami.net>
@appetrosyan appetrosyan merged commit 6e3522c into hyperledger:iroha2-dev May 11, 2022
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <ilia.ch@netogami.net>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <ilia.ch@netogami.net>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <ilia.ch@netogami.net>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <ilia.ch@netogami.net>
ilchu added a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…ce of config.json (hyperledger#2188)

Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
ilchu added a commit to ilchu/iroha that referenced this pull request Aug 2, 2022
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
@appetrosyan appetrosyan mentioned this pull request Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iroha2-dev The re-implementation of a BFT hyperledger in RUST
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants