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

Fee Rate Improvements Part 1 #17668

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Fee Rate Improvements Part 1 #17668

wants to merge 21 commits into from

Conversation

aqk
Copy link
Contributor

@aqk aqk commented Mar 7, 2024

Purpose:

Current Behavior:

New Behavior:

Testing Notes:

@aqk aqk requested a review from a team as a code owner March 7, 2024 18:26
@aqk aqk added the Changed Required label for PR that categorizes merge commit message as "Changed" for changelog label Mar 8, 2024
@github-actions github-actions bot added the merge_conflict Branch has conflicts that prevent merge to main label Mar 15, 2024
Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@aqk aqk requested review from altendky and emlowe March 18, 2024 15:57
Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

@github-actions github-actions bot removed the merge_conflict Branch has conflicts that prevent merge to main label Mar 18, 2024
@aqk aqk marked this pull request as draft March 19, 2024 17:39
@aqk aqk marked this pull request as ready for review March 19, 2024 17:39
@aqk aqk marked this pull request as draft March 21, 2024 17:19
@aqk aqk marked this pull request as ready for review March 21, 2024 17:19
@aqk aqk marked this pull request as draft March 21, 2024 17:26
@aqk aqk marked this pull request as ready for review March 21, 2024 17:28
@aqk aqk closed this Mar 21, 2024
@aqk aqk reopened this Mar 21, 2024
Copy link
Contributor

File Coverage Missing Lines
chia/_tests/wallet/test_fee_store.py 96.7% lines 79, 84
chia/wallet/fee_record.py 96.9% lines 20
chia/wallet/wallet_fee_rate.py 0.0% lines 1, 3, 5, 7-9, 12-15, 20-21, 23-24
chia/wallet/wallet_fee_store.py 76.1% lines 45, 119-121, 125-130, 133, 135-136, 140-143
Total Missing Coverage
178 lines 34 lines 80%

Copy link

Pull Request Test Coverage Report for Build 8422161012

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 144 of 178 (80.9%) changed or added relevant lines in 4 files are covered.
  • 26 unchanged lines in 8 files lost coverage.
  • Overall coverage decreased (-0.03%) to 90.792%

Changes Missing Coverage Covered Lines Changed/Added Lines %
chia/wallet/fee_record.py 31 32 96.88%
chia/_tests/wallet/test_fee_store.py 59 61 96.72%
chia/wallet/wallet_fee_rate.py 0 14 0.0%
chia/wallet/wallet_fee_store.py 54 71 76.06%
Files with Coverage Reduction New Missed Lines %
chia/_tests/simulation/test_simulation.py 1 96.52%
chia/_tests/core/util/test_lockfile.py 1 91.09%
chia/server/node_discovery.py 1 79.96%
chia/wallet/wallet_node.py 2 88.49%
chia/full_node/weight_proof.py 2 90.73%
chia/full_node/full_node.py 4 84.63%
chia/server/server.py 4 80.0%
chia/timelord/timelord.py 11 72.49%
Totals Coverage Status
Change from base Build 8378992295: -0.03%
Covered Lines: 97545
Relevant Lines: 107410

💛 - Coveralls

@emlowe
Copy link
Contributor

emlowe commented Mar 26, 2024

@aqk There is a lot of coverage missing here - I think that needs to be fixed before this can get merged in

Copy link
Contributor

@altendky altendky left a comment

Choose a reason for hiding this comment

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

first thoughts

MEMPOOL_CONSIDERED_FULL_RATIO = 0.8


class FeeStore:
Copy link
Contributor

Choose a reason for hiding this comment

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

Make this a dataclass.

self.db_wrapper = db_wrapper

# REVIEW: Should we use two tables: one for mempool data, one for estimates?
async with self.db_wrapper.writer_maybe_transaction() as conn:
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't think we need the 'maybe' form here. I think that is mostly for performance critical cases?

Generally we call this a writer so it is clear what you are using at the call sites.

async with self.db_wrapper.writer_maybe_transaction() as writer:

clvm_cost: CLVMCost

def get_rate_as_float(self) -> float:
return float(self.mojos) / float(self.clvm_cost)
Copy link
Contributor

Choose a reason for hiding this comment

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

>>> 3 / 2
1.5

Minor, but shouldn't need to float() these.

Suggested change
return float(self.mojos) / float(self.clvm_cost)
return self.mojos / self.clvm_cost

from chia.util.streamable import Streamable, streamable


@typing_extensions.final
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 fine and we don't have a policy (I haven't even identified my own personal preference solidly yet) around when we do and don't use the extensions/backport modules, but... final is available from stdlib typing in all Python versions we support now. Leave as is or change as you prefer.


"""

MINUTES_IN_WEEK = 1440 * 7 * 60 # Approximate number of entries to keep
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 the 1440 was left over from some other calculation perhaps?

Suggested change
MINUTES_IN_WEEK = 1440 * 7 * 60 # Approximate number of entries to keep
MINUTES_IN_WEEK = 7 * 24 * 60 # Approximate number of entries to keep

Or even start with the seconds first using datetime.timedelta(weeks=1).total_seconds(). Maybe. Maybe not. I dislike the stdlib time features sufficiently that I would probably just type out the numbers.

# Approximate number of entries to keep

Is this because 18.75 seconds per block and ... do we have one transaction block for every three blocks? on average? I would personally find an actual calculation easier to follow since we (should?) have constants for the block rates. If my guessing there was even correct.

if row is not None:

return self._row_to_fee_record(row)
logging.getLogger(__name__).error(f"Dumping whole DB: {str()}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs changed multiple places. Should probably also report what error as well as actually outputting something. Or delete.

Suggested change
logging.getLogger(__name__).error(f"Dumping whole DB: {str()}")
self.log.error(f"Dumping whole DB: {str()}")

def _row_to_fee_record(cls, row: sqlite3.Row) -> FeeRecord:
return FeeRecord.from_bytes(row[0]) # cast: mypy limitation

async def get_fee_record(self, key: FeeRecordKey) -> Optional[FeeRecord]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this expected to need to check non-existence a lot? If not, perhaps just raising an exception when you request a not-present data point might be better.

logging.getLogger(__name__).error(f"Dumping whole DB: {str()}")
return None

async def get_fee_record2(self, key: FeeRecordKey) -> Optional[FeeRecord]:
Copy link
Contributor

Choose a reason for hiding this comment

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

If we need two methods, it would be good to clarify the difference better than 2. (I expect this is part of a temporary exploration or somesuch)

async def prune(self) -> None:
"""Delete records older than SECONDS_IN_WEEK"""
async with self.db_wrapper.writer_maybe_transaction() as conn:
now_secs = time.time()
Copy link
Contributor

Choose a reason for hiding this comment

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

You may want to make the clock callable be an attribute so that you can more readily test things like this.

cursor = await conn.execute("DELETE FROM fee_records WHERE block_index>?", (block_index,))
await cursor.close()

async def prune(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably ought to be able to specify the age and/or time. Maybe two separate methods? I'm not exactly sure offhand what the best interface is here.

Copy link
Contributor

This PR has been flagged as stale due to no activity for over 60 days. It will not be automatically closed, but it has been given a stale-pr label and should be manually reviewed by the relevant parties.

@github-actions github-actions bot added the stale-pr Flagged as stale and in need of manual review label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changed Required label for PR that categorizes merge commit message as "Changed" for changelog coverage-diff stale-pr Flagged as stale and in need of manual review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants