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

CERT 7649 Allow dynamic price feed providers #20

Merged
merged 12 commits into from
Dec 1, 2024

Conversation

nivcertora
Copy link
Collaborator

@nivcertora nivcertora commented Nov 28, 2024

https://certora.atlassian.net/browse/CERT-7649

PR Summary: Refactoring and Enhancements to Git Management and Price Feed Integration

This pull request introduces significant refactoring and enhancements to the Quorum project, focusing on improving the modularity, scalability, and maintainability of Git repository management and price feed integrations. Below are the key changes included in this PR:


1. Refactored GitManager

  • Enhanced Initialization:
    • Modified the GitManager class to accept a ground_truth configuration (gt_config) directly during initialization.
    • Benefit: Promotes decoupling by allowing GitManager to utilize pre-loaded configuration data, enhancing flexibility and testability.

2. Implemented Price Feed Providers

  • Introduced price_feed_utils.py:

    • Defined PriceFeedProvider enum, PriceFeedData Pydantic model, and PriceFeedProviderBase abstract base class.
    • Purpose: Establishes a clear interface and standardized data models for all price feed providers.
  • Updated Price Feed APIs:

    • ChainLinkAPI & ChronicleAPI:
      • Now inherit from PriceFeedProviderBase.
      • Transitioned to a decorator-based Singleton pattern using the @singleton decorator, replacing metaclass-based Singleton implementations.
      • Implemented the _get_price_feeds_info method to adhere to the abstract base class requirements.
      • Benefit: Ensures consistency across different price feed providers and simplifies Singleton implementation.

3. Introduced PriceFeedCheck

  • New PriceFeedCheck Class:
    • Replaces the deprecated FeedPriceCheck class.
    • Functionality:
      • Verifies price feed addresses in source code against data from multiple providers (e.g., Chainlink, Chronicle).
      • Utilizes the Strategy pattern by accepting a list of PriceFeedProviderBase instances, allowing dynamic integration of various providers.
    • Benefit: Enhances scalability by supporting multiple price feed providers and improving verification mechanisms.

4. Configuration Enhancements

  • Renamed Configuration File:

    • Changed repos.json to ground_truth.json to better reflect its purpose.
    • Updated all references in the codebase, documentation, and setup scripts accordingly.
  • Added config_loader.py:

    • Centralizes the loading and validation of customer configurations from ground_truth.json.
    • Features:
      • Validates supported price feed providers.
      • Maps provider names to their respective API instances (ChainLinkAPI, ChronicleAPI).
    • Benefit: Streamlines configuration management and ensures consistent handling of customer-specific settings.

5. .gitignore Update

  • Ignored Cache Directories:
    • Added **cache** to .gitignore to exclude all cache directories from version control.
    • Benefit: Prevents accidental inclusion of cache data, maintaining a clean repository.

6. Documentation and Packaging Updates

  • Updated README.md:

    • Reflected the renaming of repos.json to ground_truth.json.
    • Provided updated examples and clarified the structure and purpose of configuration files.
  • Modified setup.py:

    • Ensured that ground_truth.json is included in the package data for proper distribution.
    • Benefit: Guarantees that necessary configuration files are available upon installation.

@nivcertora nivcertora requested a review from a team November 28, 2024 10:25
@nivcertora nivcertora self-assigned this Nov 28, 2024
@github-actions github-actions bot force-pushed the niv/CERT-7649-Support-Different-providers branch from 46925d2 to 87f3dd3 Compare November 28, 2024 16:12
@github-actions github-actions bot force-pushed the niv/CERT-7649-Support-Different-providers branch from e7bd5f0 to e54fabe Compare November 28, 2024 17:26
@github-actions github-actions bot force-pushed the niv/CERT-7649-Support-Different-providers branch from e54fabe to b4a2bbb Compare November 28, 2024 17:27
Copy link
Contributor

@liav-certora liav-certora left a comment

Choose a reason for hiding this comment

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

Left some comments but overall looks good for what this PR aims to achieve.

Comment on lines +31 to +36
# Replace the provider names with the actual API objects
for i, provider in enumerate(providers):
if provider == PriceFeedProvider.CHAINLINK:
providers[i] = ChainLinkAPI()
elif provider == PriceFeedProvider.CHRONICLE:
providers[i] = ChronicleAPI()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think saving some kind of mapping may be better but for now (small number of providers) this is also ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree

@@ -45,7 +47,7 @@ def load_config(config_path: str) -> dict[str, Any] | None:
pp.pretty_print(f"Failed to parse given config file {config_path}:\n{e}", pp.Colors.FAILURE)


def proposals_check(customer: str, chain_name: str, proposal_addresses: list[str]) -> None:
def proposals_check(customer: str, chain_name: str, proposal_addresses: list[str], providers: list[PriceFeedProviderBase]) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, for now, it doesn't seem like that big of a deal but I don't like that we need to pass providers just for a single check out of all other checks. I think letting the PriceFeedCheck itself have access to the config would have been better. I can live with this for now but as we'll implement more and more checks, extending the parameters to this function might become really ugly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree but its much better for testing to make it input instead of a dependancy

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So i go with that solution

Comment on lines +56 to +59
if cache_file.exists():
with open(cache_file, 'r') as file:
data: dict = json.load(file)
self.memory[chain] = {addr: PriceFeedData(**feed) for addr, feed in data.items()}
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be missing something here but price feed data isn't updating? I mean I see you never update the cache only create it or read from it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Create is the update, the same as it worked before

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't know why but I don't really like the name ground_truth but I also doesn't have a better name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed Configuration File:

Changed repos.json to ground_truth.json to better reflect its purpose.

@nivcertora nivcertora merged commit 5070b95 into main Dec 1, 2024
@nivcertora nivcertora deleted the niv/CERT-7649-Support-Different-providers branch December 1, 2024 12:45
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.

2 participants