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: change target's type in fee estimate map #65

Conversation

vladimirfomene
Copy link
Contributor

@vladimirfomene vladimirfomene commented Dec 6, 2023

Fixes #64.

Summary by CodeRabbit

  • Refactor
    • Updated the method for fetching fee estimates to use more efficient data types.
    • Improved the fee rate conversion process for enhanced accuracy and performance.

@coveralls
Copy link

coveralls commented Dec 8, 2023

Pull Request Test Coverage Report for Build 8167049960

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.04%) to 84.795%

Totals Coverage Status
Change from base Build 8166942496: -0.04%
Covered Lines: 909
Relevant Lines: 1072

💛 - Coveralls

@vladimirfomene vladimirfomene force-pushed the fix-confirmation-target-type branch 3 times, most recently from cfecec7 to 053a88e Compare December 8, 2023 19:31
@oleonardolima
Copy link
Collaborator

@vladimirfomene I got curious, did the CI suddenly start failing?

@vladimirfomene
Copy link
Contributor Author

@oleonardolima is failing because some dependencies have been updated so we have to pin them to make sure we are able to build with our MSRV

@oleonardolima
Copy link
Collaborator

@oleonardolima is failing because some dependencies have been updated so we have to pin them to make sure we are able to build with our MSRV

Oh, thanks! I saw that the rustls dependency version got yanked, and lead to this 😅

@vladimirfomene vladimirfomene force-pushed the fix-confirmation-target-type branch 2 times, most recently from ce3f98b to 830aa9f Compare December 9, 2023 10:16
Copy link
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

utACK

@oleonardolima
Copy link
Collaborator

oleonardolima commented Dec 12, 2023

@vladimirfomene through a re-review and some manual tests here, I saw that a fn and a test still expect the old parameter signature, and would need to be updated as well:

  • convert_fee_rate fn:
    /// Get a fee value in sats/vbytes from the estimates
    /// that matches the confirmation target set as parameter.
    pub fn convert_fee_rate(target: usize, estimates: HashMap<String, f64>) -> Result<f32, Error> {
    let fee_val = {
    let mut pairs = estimates
    .into_iter()
    .filter_map(|(k, v)| Some((k.parse::<usize>().ok()?, v)))
    .collect::<Vec<_>>();
    pairs.sort_unstable_by_key(|(k, _)| std::cmp::Reverse(*k));
    pairs
    .into_iter()
    .find(|(k, _)| k <= &target)
    .map(|(_, v)| v)
    .unwrap_or(1.0)
    };
    Ok(fee_val as f32)
    }
  • feerate_parsing test:
    #[test]
    fn feerate_parsing() {
    let esplora_fees = serde_json::from_str::<HashMap<String, f64>>(
    r#"{
    "25": 1.015,
    "5": 2.3280000000000003,
    "12": 2.0109999999999997,
    "15": 1.018,
    "17": 1.018,
    "11": 2.0109999999999997,
    "3": 3.01,
    "2": 4.9830000000000005,
    "6": 2.2359999999999998,
    "21": 1.018,
    "13": 1.081,
    "7": 2.2359999999999998,
    "8": 2.2359999999999998,
    "16": 1.018,
    "20": 1.018,
    "22": 1.017,
    "23": 1.017,
    "504": 1,
    "9": 2.2359999999999998,
    "14": 1.018,
    "10": 2.0109999999999997,
    "24": 1.017,
    "1008": 1,
    "1": 4.9830000000000005,
    "4": 2.3280000000000003,
    "19": 1.018,
    "144": 1,
    "18": 1.018
    }
    "#,
    )
    .unwrap();
    assert_eq!(convert_fee_rate(6, esplora_fees.clone()).unwrap(), 2.236);
    assert_eq!(
    convert_fee_rate(26, esplora_fees).unwrap(),
    1.015,
    "should inherit from value for 25"
    );
    }

@notmandatory
Copy link
Member

Please rebase to pick up changes in #69 that fix CI.

@vladimirfomene vladimirfomene added the enhancement New feature or request label Jan 2, 2024
@vladimirfomene vladimirfomene force-pushed the fix-confirmation-target-type branch 2 times, most recently from d59775b to 3add7f9 Compare January 2, 2024 10:42
Copy link
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

ACK 3add7f9

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

utACK 3add7f9

Copy link

coderabbitai bot commented Mar 6, 2024

Walkthrough

The recent updates involve modifying the get_fee_estimates method in both the AsyncClient and BlockingClient to use u16 instead of String as the key type for confirmation targets in the returned HashMap. Additionally, the convert_fee_rate function now also expects a HashMap with u16 keys. These changes streamline the handling of fee rate estimates, aligning data types with external sources like electrs.

Changes

Files Change Summary
src/async.rs, src/blocking.rs Updated get_fee_estimates to return HashMap<u16, f64> for confirmation targets.
src/lib.rs Adjusted convert_fee_rate to accept HashMap<u16, f64> and updated processing logic.

Assessment against linked issues

Objective Addressed Explanation
Keys in feerates mapping should be u16, not String. (#64)

Poem

In the realm of code, where the bits do hop,
A rabbit worked, with no intent to stop.
🐇💻 With a leap and a bound, it refined its craft,
Changing strings to numbers, with its latest draft.
"U16!", it cheered, with a joyful tone,
For in the world of types, a seed was sown.
🌟✨ Through the digital fields, it danced with glee,
Celebrating the change, for all to see.

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c487b31 and 82e87fb.
Files selected for processing (3)
  • src/async.rs (2 hunks)
  • src/blocking.rs (1 hunks)
  • src/lib.rs (2 hunks)
Additional comments: 4
src/blocking.rs (1)
  • 284-284: The change from String to u16 for the key type in the HashMap returned by get_fee_estimates aligns with the PR objectives to match the data types used by electrs. This is a positive change for type safety and consistency.
src/async.rs (1)
  • 369-375: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [372-385]

The update in the get_fee_estimates method to use u16 as the key type for the HashMap instead of String is consistent with the changes made in the BlockingClient and aligns with the PR's goal to improve type safety and consistency with electrs. This is a commendable change.

src/lib.rs (2)
  • 91-97: The convert_fee_rate function has been updated to accept a HashMap<u16, f64> instead of HashMap<String, f64>. This change aligns with the PR's objective to use u16 as the key type for fee rate estimates, ensuring type safety and consistency with the data provided by electrs. The logic within the function correctly handles the new key type, sorting the keys in reverse order and finding the appropriate fee rate based on the confirmation target. This change improves the usability and reliability of the library when interacting with Bitcoin's Electrum server.
  • 336-336: The test feerate_parsing has been updated to use a HashMap<u16, f64> for esplora_fees, reflecting the changes made to the convert_fee_rate function. This ensures that the test remains valid and accurately tests the functionality with the new key data type. The assertions within the test check for correct fee rate conversion based on given confirmation targets, which is essential for verifying the correctness of the convert_fee_rate function after the data type change.

@notmandatory
Copy link
Member

FYI I had to rebase this since #75 was merged.

@notmandatory notmandatory merged commit 98edbc5 into bitcoindevkit:master Mar 6, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keys in feerates mapping should be u16, not String.
5 participants