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

feat: add flag to enable price-feeder on node start #157

Conversation

leonz789
Copy link
Contributor

@leonz789 leonz789 commented Aug 4, 2024

Description

add flag `--oracle` to start price-feeder on exocored node start.

----

Closes #XXX

Summary by CodeRabbit

  • New Features

    • Introduced new command-line flags for starting the Exocore node, allowing users to enable an oracle feeder and specify a mnemonic for the validator.
  • Improvements

    • Enhanced control flow to allow asynchronous operation of the price feeder during node startup.
    • Added new dependencies to support price feeding functionality and updated various dependencies to improve stability and performance.

These changes will provide users with more flexibility in managing their nodes and ensure a better overall experience.

Copy link
Contributor

coderabbitai bot commented Aug 4, 2024

Walkthrough

The recent changes enhance the Exocore node's command-line interface by introducing flags for oracle feeding and consensus key mnemonics, enabling the price feeder to operate asynchronously during startup. Additionally, the go.mod file reflects updates to various dependencies, indicating ongoing maintenance efforts aimed at improving stability and incorporating new features.

Changes

File Change Summary
cmd/exocored/root.go Added flagOracle and flagMnemonic for command options; implemented asynchronous price feeder startup.
go.mod Introduced github.com/ExocoreNetwork/price-feeder dependency; updated multiple dependencies for improved stability and performance.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExocoreNode
    participant PriceFeeder

    User->>ExocoreNode: Start with --oracle and --mnemonic flags
    ExocoreNode->>PriceFeeder: Launch price feeder in a goroutine
    PriceFeeder-->>ExocoreNode: Price feeder running
    ExocoreNode->>User: Node started successfully
Loading

In the fields where bunnies play,
New flags and features brighten the day!
With feeders running, side by side,
Our code hops forth with joyful pride! 🐰✨
Let's celebrate this leap so grand,
In the world of nodes, we take a stand!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Comment on lines +149 to +157
go func() {
defer func() {
if err := recover(); err != nil {
fmt.Println("price-feeder failed", err)
}
}()
mnemonic, _ := cmd.Flags().GetString(flagMnemonic)
pricefeeder.StartPriceFeeder(path.Join(clientCtx.HomeDir, confPath, confOracle), mnemonic, path.Join(clientCtx.HomeDir, confPath))
}()

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 84d4148 and 12be611.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (2)
  • cmd/exocored/root.go (4 hunks)
  • go.mod (11 hunks)
Additional context used
GitHub Check: CodeQL
cmd/exocored/root.go

[notice] 149-157: Spawning a Go routine
Spawning a Go routine may be a possible source of non-determinism

Additional comments not posted (20)
cmd/exocored/root.go (2)

58-63: LGTM!

The new constants are well-defined and improve code readability.


141-143: LGTM!

The new flags flagOracle and flagMnemonic enhance the functionality of startCmd.

go.mod (18)

10-10: LGTM!

The new dependency github.com/ExocoreNetwork/price-feeder is necessary for the new price feeder functionality.


21-21: LGTM!

The update to github.com/ethereum/go-ethereum from 1.13.5-0.20231027145059-2d7dba024d76 to 1.13.15 is likely to include important improvements.


33-33: LGTM!

The update to github.com/spf13/cast from 1.5.1 to 1.6.0 is likely to include important improvements.


34-34: LGTM!

The update to github.com/spf13/cobra from 1.7.0 to 1.8.0 is likely to include important improvements.


36-36: LGTM!

The update to github.com/spf13/viper from 1.16.0 to 1.18.2 is likely to include important improvements.


54-54: LGTM!

The update to github.com/davecgh/go-spew from 1.1.1 to 1.1.2-0.20180830191138-d8f796af33cc is likely to include important improvements.


71-71: LGTM!

The update to cloud.google.com/go/storage from 1.30.1 to 1.35.1 is likely to include important improvements.


124-124: LGTM!

The update to github.com/go-ole/go-ole from 1.2.6 to 1.3.0 is likely to include important improvements.


156-156: LGTM!

The update to github.com/holiman/uint256 from 1.2.3 to 1.2.4 is likely to include important improvements.


186-186: LGTM!

The update to github.com/pelletier/go-toml/v2 from 2.0.9 to 2.1.0 is likely to include important improvements.


188-188: LGTM!

The update to github.com/pmezard/go-difflib from 1.0.0 to 1.0.1-0.20181226105442-5d4384ee4fb2 is likely to include important improvements.


231-231: LGTM!

The update to golang.org/x/oauth2 from 0.13.0 to 0.15.0 is likely to include important improvements.


238-238: LGTM!

The update to google.golang.org/api from 0.149.0 to 0.153.0 is likely to include important improvements.


201-201: LGTM!

The new dependency github.com/sagikazarmark/locafero is likely for new functionality or improvements.


202-202: LGTM!

The new dependency github.com/sagikazarmark/slog-shim is likely for new functionality or improvements.


207-207: LGTM!

The new dependency github.com/sourcegraph/conc is likely for new functionality or improvements.


210-210: LGTM!

The update to github.com/subosito/gotenv from 1.4.2 to 1.6.0 is likely to include important improvements.


229-229: LGTM!

The update to go.uber.org/atomic from 1.10.0 to 1.11.0 is likely to include important improvements.

Comment on lines +144 to +160
preRunE := startCmd.PreRunE
// add preRun to run price-feeder first before starting the node
startCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if enableFeeder, _ := cmd.Flags().GetBool(flagOracle); enableFeeder {
clientCtx := cmd.Context().Value(client.ClientContextKey).(*client.Context)
go func() {
defer func() {
if err := recover(); err != nil {
fmt.Println("price-feeder failed", err)
}
}()
mnemonic, _ := cmd.Flags().GetString(flagMnemonic)
pricefeeder.StartPriceFeeder(path.Join(clientCtx.HomeDir, confPath, confOracle), mnemonic, path.Join(clientCtx.HomeDir, confPath))
}()
}
return preRunE(cmd, args)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve error handling within the goroutine.

Spawning a goroutine can introduce non-determinism. Ensure that any panic is logged appropriately to aid in debugging.

go func() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println("price-feeder failed", err)
+			// Log the error with more context
+			log.Printf("price-feeder panic: %v", err)
		}
	}()
	mnemonic, _ := cmd.Flags().GetString(flagMnemonic)
	pricefeeder.StartPriceFeeder(path.Join(clientCtx.HomeDir, confPath, confOracle), mnemonic, path.Join(clientCtx.HomeDir, confPath))
}()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
preRunE := startCmd.PreRunE
// add preRun to run price-feeder first before starting the node
startCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if enableFeeder, _ := cmd.Flags().GetBool(flagOracle); enableFeeder {
clientCtx := cmd.Context().Value(client.ClientContextKey).(*client.Context)
go func() {
defer func() {
if err := recover(); err != nil {
fmt.Println("price-feeder failed", err)
}
}()
mnemonic, _ := cmd.Flags().GetString(flagMnemonic)
pricefeeder.StartPriceFeeder(path.Join(clientCtx.HomeDir, confPath, confOracle), mnemonic, path.Join(clientCtx.HomeDir, confPath))
}()
}
return preRunE(cmd, args)
}
preRunE := startCmd.PreRunE
// add preRun to run price-feeder first before starting the node
startCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if enableFeeder, _ := cmd.Flags().GetBool(flagOracle); enableFeeder {
clientCtx := cmd.Context().Value(client.ClientContextKey).(*client.Context)
go func() {
defer func() {
if err := recover(); err != nil {
fmt.Println("price-feeder failed", err)
// Log the error with more context
log.Printf("price-feeder panic: %v", err)
}
}()
mnemonic, _ := cmd.Flags().GetString(flagMnemonic)
pricefeeder.StartPriceFeeder(path.Join(clientCtx.HomeDir, confPath, confOracle), mnemonic, path.Join(clientCtx.HomeDir, confPath))
}()
}
return preRunE(cmd, args)
}
Tools
GitHub Check: CodeQL

[notice] 149-157: Spawning a Go routine
Spawning a Go routine may be a possible source of non-determinism

@cloud8little
Copy link
Contributor

using oracle config file like:

urls:
  mainnet: !!str https://eth-mainnet.g.alchemy.com/v2/GnF5oGDBAH0p7OQhkdE7AQKQ_bfYsSyZ
  sepolia: !!str https://eth-sepolia.g.alchemy.com/v2/Ru0n0aw_MVLJ9RUhgnIl036n4IM_mHCB
  holesky: !!str https://ethereum-holesky-rpc.publicnode.com
tokens:
  ETHUSDT: 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419_mainnet
exocored start --metrics trace --log_level debug --minimum-gas-prices=0.0001aexo --json-rpc.api eth,txpool,personal,net,debug,web3 --api.enable --json-rpc.enable true --home /root/.test-pr157 --chain-id exocoretestnet_233-2 --oracle=true --mnemonic="wonder quality resource ketchup occur stadium vicious output situate plug second monkey harbor vanish then myself primary feed earth story real soccer shove like"
I[2024-08-05|04:06:09.918] flagOracle:                                  is=oracle
I[2024-08-05|04:06:09.918] flagMnemonic                                 is=mnemonic
I[2024-08-05|04:06:09.925] enable oracle                                is=true
4:06AM INF Unlocking keyring module=server
4:06AM INF starting ABCI with Tendermint module=server
I[2024-08-05|04:06:09.925] mnemonic                                     is="wonder quality resource ketchup occur stadium vicious output situate plug second monkey harbor vanish then myself primary feed earth story real soccer shove like"
I[2024-08-05|04:06:09.925] price feeder config path                     is=/root/.test-pr157/config/oracle_feeder.yaml
Using config file: /root/.test-pr157/config/oracle_feeder.yaml
price-feeder failed 1 error(s) decoding:

* 'tokens[0]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[ethusdt:0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419_mainnet]'

@cloud8little
Copy link
Contributor

Test passed, but the downside of this solution is whenever whitelist a new token/asset, it needs restart exocore node to enable new token price feeding.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 12be611 and 2187b2e.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • go.mod (10 hunks)
Additional comments not posted (13)
go.mod (13)

10-10: New dependency added: github.com/ExocoreNetwork/price-feeder v0.1.4.

This addition aligns with the PR objective of enhancing the node's capabilities with price-feeder functionality.


33-33: Dependency update: github.com/spf13/cast to v1.6.0.

Ensure compatibility with the rest of the codebase and verify any new features or bug fixes.


34-34: Dependency update: github.com/spf13/cobra to v1.8.0.

Check for any improvements or bug fixes relevant to the command-line interface.


36-36: Dependency update: github.com/spf13/viper to v1.18.2.

Ensure that configuration handling remains compatible with the updated version.


54-54: Dependency update: github.com/davecgh/go-spew to a specific commit version.

Check the impact of this specific commit on the project for any bug fixes or performance improvements.


71-71: Dependency update: cloud.google.com/go/storage to v1.35.1.

Verify compatibility with storage-related functionality and check for any new features or bug fixes.


115-115: Dependency update: github.com/fsnotify/fsnotify to v1.7.0.

Ensure that file system notifications remain compatible with the updated version.


124-124: Dependency update: github.com/go-ole/go-ole to v1.3.0.

Verify compatibility with OLE-related functionality and check for any new features or bug fixes.


156-156: Dependency update: github.com/holiman/uint256 to v1.2.4.

Ensure compatibility with uint256-related operations and verify any bug fixes or performance improvements.


186-186: Dependency update: github.com/pelletier/go-toml/v2 to v2.1.0.

Ensure compatibility with TOML parsing and serialization, and check for any new features or bug fixes.


188-188: Dependency update: github.com/pmezard/go-difflib to a specific commit version.

Check the impact of this specific commit on the project for any bug fixes or performance improvements.


231-231: Dependency update: golang.org/x/oauth2 to v0.15.0.

Ensure compatibility with OAuth2-related functionality and verify any security patches or new features.


238-238: Dependency update: google.golang.org/api to v0.153.0.

Ensure compatibility with Google API-related functionality and check for any new features or bug fixes.

@cloud8little cloud8little added this to the Testnet V5 milestone Aug 28, 2024
@bwhour
Copy link
Contributor

bwhour commented Sep 4, 2024

use the pr179 to replace this 157

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2187b2e and a916f05.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • go.mod (10 hunks)
Additional comments not posted (13)
go.mod (13)

10-10: New dependency added: github.com/ExocoreNetwork/price-feeder

The addition of github.com/ExocoreNetwork/price-feeder at version v0.1.5 aligns with the PR's objective to enhance the Exocore node's functionality by enabling the price-feeder feature. Ensure that this version is stable and has been security vetted.


124-124: ```shell
#!/bin/bash

Search for import statements of github.com/go-ole/go-ole in the codebase

rg 'import.github.com/go-ole/go-ole' --glob '.go'

Search for usages of go-ole in the codebase

rg 'ole.' --glob '*.go'


---

`115-115`: ```shell
#!/bin/bash
# Search for instances where fsnotify is used in the codebase to understand its usage.
rg 'fsnotify' -A 3

# Check for any breaking changes or deprecations in the fsnotify changelog or release notes.
# Assuming the changelog or release notes might be present in the repository.
rg 'breaking changes|deprecations' -A 5

186-186: ```shell
#!/bin/bash

Search for import statements of github.com/pelletier/go-toml/v2 to identify usage in the codebase.

ast-grep --lang go --pattern 'import "github.com/pelletier/go-toml/v2"'

Search for test cases related to TOML parsing.

rg 'TOML' --type go -A 5


---

`238-238`: ```shell
#!/bin/bash
# Search for usages of google.golang.org/api in the codebase
rg 'google\.golang\.org/api' -A 3

# Check for any breaking changes or deprecations in the v0.153.0 release notes or documentation
# Note: This assumes that release notes or changelogs are present in markdown or text files.
rg 'v0\.153\.0' -A 5 --type markdown --type text

54-54: ```shell
#!/bin/bash

Check if the specific commit exists in the upstream repository of github.com/davecgh/go-spew

git ls-remote https://github.com/davecgh/go-spew.git d8f796af33cc

If the commit exists, fetch the commit message and details

if git ls-remote https://github.com/davecgh/go-spew.git | grep -q d8f796af33cc; then
git clone https://github.com/davecgh/go-spew.git temp-go-spew-repo
cd temp-go-spew-repo
git show d8f796af33cc
cd ..
rm -rf temp-go-spew-repo
fi


---

`231-231`: ```shell
#!/bin/bash
# Search for files that might contain release notes or changelog information.
fd --type f --name '*CHANGELOG*' --name '*RELEASE*' --name '*NOTES*'

# If any files are found, search for version v0.15.0 in those files.
for file in $(fd --type f --name '*CHANGELOG*' --name '*RELEASE*' --name '*NOTES*'); do
  echo "Searching in $file"
  rg --type markdown -A 5 'v0.15.0' "$file"
done

156-156: ```shell
#!/bin/bash

Search for a changelog or release notes for github.com/holiman/uint256 to identify changes in version v1.2.4.

rg --files-with-matches "github.com/holiman/uint256" | xargs -I {} rg "v1.2.4" {}

Search the codebase for usage of github.com/holiman/uint256 to determine if any arithmetic operations are affected by the update.

ast-grep --lang go --pattern 'uint256.$($)'


---

`33-33`: **Dependency updated: `github.com/spf13/cast`**

Upgraded from `v1.5.1` to `v1.6.0`. Review the release notes of this version to ensure there are no breaking changes that could affect the existing codebase.

---

`34-34`: **Dependency updated: `github.com/spf13/cobra`**

Updated from `v1.7.0` to `v1.8.0`. This is a commonly used library for CLI applications; ensure compatibility with other CLI-related dependencies.

---

`188-188`: **Dependency updated: `github.com/pmezard/go-difflib`**

Updated to a specific commit `v1.0.1-0.20181226105442-5d4384ee4fb2`. Similar to `go-spew`, this points to a specific commit rather than a stable release. Verify the stability and necessity of this commit.

---

`71-71`: ```shell
#!/bin/bash
# Corrected command to check if CHANGELOG.md exists in the repository
fd --type f --glob 'CHANGELOG.md'

# If CHANGELOG.md exists, search for entries related to cloud.google.com/go/storage
if [ -f "CHANGELOG.md" ]; then
  rg 'cloud.google.com/go/storage' CHANGELOG.md
fi

36-36: ```shell
#!/bin/bash

Review the CHANGELOG.md file for any deprecation notices or significant changes related to viper.

rg 'viper' CHANGELOG.md -A 5

Check if the functions used in the codebase are affected by any changes in the updated version.

rg 'viper.New|viper.SetConfigFile|viper.ReadInConfig|viper.BindPFlag' CHANGELOG.md -A 5


</blockquote></details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a916f05 and 50390ad.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • go.mod (10 hunks)
Files skipped from review as they are similar to previous changes (1)
  • go.mod

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 50390ad and 35a2f68.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • go.mod (10 hunks)
Files skipped from review as they are similar to previous changes (1)
  • go.mod

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 35a2f68 and 8e1ad22.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • go.mod (10 hunks)
Files skipped from review as they are similar to previous changes (1)
  • go.mod

@leonz789 leonz789 merged commit 7f05dad into ExocoreNetwork:develop Sep 9, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants